Skip to content

Commit 9bcd9ba

Browse files
hsbtclaude
authored andcommitted
Suppress bundled gems warning for subfeatures found outside stdlib [Bug #21828]
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 764a245 commit 9bcd9ba

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

lib/bundled_gems.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ def self.warning?(name, specs: nil)
133133
if subfeature
134134
prefix = feature.split("/").first + "-"
135135
return if specs.any? { |spec, _| spec.start_with?(prefix) }
136+
137+
# Don't warn if the feature is found outside the standard library
138+
# (e.g., benchmark-ips's lib dir is on $LOAD_PATH but not in specs)
139+
resolved = $LOAD_PATH.resolve_feature_path(feature) rescue nil
140+
if resolved
141+
return unless resolved[1].start_with?(LIBDIR) || resolved[1].start_with?(ARCHDIR)
142+
end
136143
end
137144

138145
return if WARNED[name]

test/test_bundled_gems.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,20 @@ def test_warning_without_hyphenated_gem
5353
assert warning
5454
assert_match(/benchmark/, warning)
5555
end
56+
57+
def test_no_warning_for_subfeature_found_outside_stdlib
58+
# When a subfeature like "benchmark/ips" is found on $LOAD_PATH
59+
# from a non-standard-library location (e.g., benchmark-ips gem's lib dir),
60+
# don't warn even if the gem is not in specs (Bug #21828)
61+
Dir.mktmpdir do |dir|
62+
FileUtils.mkdir_p(File.join(dir, "benchmark"))
63+
File.write(File.join(dir, "benchmark", "ips.rb"), "")
64+
$LOAD_PATH.unshift(dir)
65+
begin
66+
assert_nil Gem::BUNDLED_GEMS.warning?("benchmark/ips", specs: {})
67+
ensure
68+
$LOAD_PATH.shift
69+
end
70+
end
71+
end
5672
end

0 commit comments

Comments
 (0)