diff options
| author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2026-03-11 19:14:59 +0900 |
|---|---|---|
| committer | Takashi Kokubun <takashikkbn@gmail.com> | 2026-03-11 17:42:58 -0700 |
| commit | 9bcd9ba9b31fea19dc56bc2f5c69cf584d3bd23c (patch) | |
| tree | cabadf4ede4ef27ef649f3f487d5a4baa70625e6 | |
| parent | 764a245ef9e305a515a8be54b87c8b7b3ac45af0 (diff) | |
Suppress bundled gems warning for subfeatures found outside stdlib [Bug #21828]
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| -rw-r--r-- | lib/bundled_gems.rb | 7 | ||||
| -rw-r--r-- | test/test_bundled_gems.rb | 16 |
2 files changed, 23 insertions, 0 deletions
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 |
