Expand stub-out scope of Fiddle.dlopen

This commit is contained in:
Hiroshi SHIBATA 2025-01-23 15:19:58 +09:00
parent ec2bd6f74e
commit 470784cbd9
Notes: git 2025-02-04 22:37:22 +00:00
2 changed files with 15 additions and 7 deletions

View File

@ -2,7 +2,6 @@
require "rbconfig" require "rbconfig"
require "shellwords" require "shellwords"
require "fiddle"
module Bundler module Bundler
class CLI::Doctor class CLI::Doctor
@ -57,6 +56,14 @@ module Bundler
Dir.glob("#{spec.full_gem_path}/**/*.bundle") Dir.glob("#{spec.full_gem_path}/**/*.bundle")
end end
def lookup_with_fiddle(path)
require "fiddle"
Fiddle.dlopen(path)
false
rescue Fiddle::DLError
true
end
def check! def check!
require_relative "check" require_relative "check"
Bundler::CLI::Check.new({}).run Bundler::CLI::Check.new({}).run
@ -73,10 +80,7 @@ module Bundler
definition.specs.each do |spec| definition.specs.each do |spec|
bundles_for_gem(spec).each do |bundle| bundles_for_gem(spec).each do |bundle|
bad_paths = dylibs(bundle).select do |f| bad_paths = dylibs(bundle).select do |f|
Fiddle.dlopen(f) lookup_with_fiddle(f)
false
rescue Fiddle::DLError
true
end end
if bad_paths.any? if bad_paths.any?
broken_links[spec] ||= [] broken_links[spec] ||= []

View File

@ -54,16 +54,20 @@ RSpec.describe "bundle doctor" do
doctor = Bundler::CLI::Doctor.new({}) doctor = Bundler::CLI::Doctor.new({})
expect(doctor).to receive(:bundles_for_gem).exactly(2).times.and_return ["/path/to/myrack/myrack.bundle"] expect(doctor).to receive(:bundles_for_gem).exactly(2).times.and_return ["/path/to/myrack/myrack.bundle"]
expect(doctor).to receive(:dylibs).exactly(2).times.and_return ["/usr/lib/libSystem.dylib"] expect(doctor).to receive(:dylibs).exactly(2).times.and_return ["/usr/lib/libSystem.dylib"]
allow(Fiddle).to receive(:dlopen).with("/usr/lib/libSystem.dylib").and_return(true) allow(doctor).to receive(:lookup_with_fiddle).with("/usr/lib/libSystem.dylib").and_return(false)
expect { doctor.run }.not_to raise_error expect { doctor.run }.not_to raise_error
expect(@stdout.string).to be_empty expect(@stdout.string).to be_empty
end end
class Fiddle
class DLError < StandardError; end
end unless defined?(Fiddle)
it "exits with a message if one of the linked libraries is missing" do it "exits with a message if one of the linked libraries is missing" do
doctor = Bundler::CLI::Doctor.new({}) doctor = Bundler::CLI::Doctor.new({})
expect(doctor).to receive(:bundles_for_gem).exactly(2).times.and_return ["/path/to/myrack/myrack.bundle"] expect(doctor).to receive(:bundles_for_gem).exactly(2).times.and_return ["/path/to/myrack/myrack.bundle"]
expect(doctor).to receive(:dylibs).exactly(2).times.and_return ["/usr/local/opt/icu4c/lib/libicui18n.57.1.dylib"] expect(doctor).to receive(:dylibs).exactly(2).times.and_return ["/usr/local/opt/icu4c/lib/libicui18n.57.1.dylib"]
allow(Fiddle).to receive(:dlopen).with("/usr/local/opt/icu4c/lib/libicui18n.57.1.dylib").and_raise(Fiddle::DLError) allow(doctor).to receive(:lookup_with_fiddle).with("/usr/local/opt/icu4c/lib/libicui18n.57.1.dylib").and_return(true)
expect { doctor.run }.to raise_error(Bundler::ProductionError, <<~E.strip), @stdout.string expect { doctor.run }.to raise_error(Bundler::ProductionError, <<~E.strip), @stdout.string
The following gems are missing OS dependencies: The following gems are missing OS dependencies:
* bundler: /usr/local/opt/icu4c/lib/libicui18n.57.1.dylib * bundler: /usr/local/opt/icu4c/lib/libicui18n.57.1.dylib