From 9bcd9ba9b31fea19dc56bc2f5c69cf584d3bd23c Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Wed, 11 Mar 2026 19:14:59 +0900 Subject: Suppress bundled gems warning for subfeatures found outside stdlib [Bug #21828] Co-Authored-By: Claude Opus 4.6 --- lib/bundled_gems.rb | 7 +++++++ test/test_bundled_gems.rb | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/lib/bundled_gems.rb b/lib/bundled_gems.rb index 403d80b48c..c5893a241e 100644 --- a/lib/bundled_gems.rb +++ b/lib/bundled_gems.rb @@ -133,6 +133,13 @@ module Gem::BUNDLED_GEMS # :nodoc: if subfeature prefix = feature.split("/").first + "-" return if specs.any? { |spec, _| spec.start_with?(prefix) } + + # Don't warn if the feature is found outside the standard library + # (e.g., benchmark-ips's lib dir is on $LOAD_PATH but not in specs) + resolved = $LOAD_PATH.resolve_feature_path(feature) rescue nil + if resolved + return unless resolved[1].start_with?(LIBDIR) || resolved[1].start_with?(ARCHDIR) + end end return if WARNED[name] diff --git a/test/test_bundled_gems.rb b/test/test_bundled_gems.rb index e44c8348ad..8cb4232b09 100644 --- a/test/test_bundled_gems.rb +++ b/test/test_bundled_gems.rb @@ -53,4 +53,20 @@ class TestBundlerGem < Gem::TestCase assert warning assert_match(/benchmark/, warning) end + + def test_no_warning_for_subfeature_found_outside_stdlib + # When a subfeature like "benchmark/ips" is found on $LOAD_PATH + # from a non-standard-library location (e.g., benchmark-ips gem's lib dir), + # don't warn even if the gem is not in specs (Bug #21828) + Dir.mktmpdir do |dir| + FileUtils.mkdir_p(File.join(dir, "benchmark")) + File.write(File.join(dir, "benchmark", "ips.rb"), "") + $LOAD_PATH.unshift(dir) + begin + assert_nil Gem::BUNDLED_GEMS.warning?("benchmark/ips", specs: {}) + ensure + $LOAD_PATH.shift + end + end + end end -- cgit v1.2.3