diff --git a/Library/Homebrew/test/os/mac/keg_spec.rb b/Library/Homebrew/test/os/mac/keg_spec.rb new file mode 100644 index 0000000000..562c2ba6a6 --- /dev/null +++ b/Library/Homebrew/test/os/mac/keg_spec.rb @@ -0,0 +1,32 @@ +require "keg" + +describe Keg do + include FileUtils + + subject { described_class.new(keg_path) } + + describe "#mach_o_files" do + let(:keg_path) { HOMEBREW_CELLAR/"a/1.0" } + + before(:each) { (keg_path/"lib").mkpath } + + after(:each) { subject.unlink } + + it "skips hardlinks" do + cp dylib_path("i386"), keg_path/"lib/i386.dylib" + ln keg_path/"lib/i386.dylib", keg_path/"lib/i386_hardlink.dylib" + + subject.link + expect(subject.mach_o_files.count).to eq(1) + end + + it "isn't confused by symlinks" do + cp dylib_path("i386"), keg_path/"lib/i386.dylib" + ln keg_path/"lib/i386.dylib", keg_path/"lib/i386_hardlink.dylib" + ln_s keg_path/"lib/i386.dylib", keg_path/"lib/i386_symlink.dylib" + + subject.link + expect(subject.mach_o_files.count).to eq(1) + end + end +end diff --git a/Library/Homebrew/test/os/mac/keg_test.rb b/Library/Homebrew/test/os/mac/keg_test.rb deleted file mode 100644 index d1103415de..0000000000 --- a/Library/Homebrew/test/os/mac/keg_test.rb +++ /dev/null @@ -1,69 +0,0 @@ -require "testing_env" -require "keg" -require "stringio" - -class OSMacLinkTests < Homebrew::TestCase - include FileUtils - - def setup - super - - keg = HOMEBREW_CELLAR.join("foo", "1.0") - keg.join("bin").mkpath - - %w[hiworld helloworld goodbye_cruel_world].each do |file| - touch keg.join("bin", file) - end - - @keg = Keg.new(keg) - @dst = HOMEBREW_PREFIX.join("bin", "helloworld") - @nonexistent = Pathname.new("/some/nonexistent/path") - - @mode = OpenStruct.new - - @old_stdout = $stdout - $stdout = StringIO.new - - mkpath HOMEBREW_PREFIX/"bin" - mkpath HOMEBREW_PREFIX/"lib" - end - - def teardown - @keg.unlink - - $stdout = @old_stdout - - rmtree HOMEBREW_PREFIX/"lib" - - super - end - - def test_mach_o_files_skips_hardlinks - a = HOMEBREW_CELLAR/"a/1.0" - (a/"lib").mkpath - FileUtils.cp dylib_path("i386"), a/"lib/i386.dylib" - FileUtils.ln a/"lib/i386.dylib", a/"lib/i386_link.dylib" - - keg = Keg.new(a) - keg.link - - assert_equal 1, keg.mach_o_files.size - ensure - keg.unlink - end - - def test_mach_o_files_isnt_confused_by_symlinks - a = HOMEBREW_CELLAR/"a/1.0" - (a/"lib").mkpath - FileUtils.cp dylib_path("i386"), a/"lib/i386.dylib" - FileUtils.ln a/"lib/i386.dylib", a/"lib/i386_link.dylib" - FileUtils.ln_s a/"lib/i386.dylib", a/"lib/1.dylib" - - keg = Keg.new(a) - keg.link - - assert_equal 1, keg.mach_o_files.size - ensure - keg.unlink - end -end diff --git a/Library/Homebrew/test/spec_helper.rb b/Library/Homebrew/test/spec_helper.rb index d8694eefc5..b58125aecc 100644 --- a/Library/Homebrew/test/spec_helper.rb +++ b/Library/Homebrew/test/spec_helper.rb @@ -15,6 +15,7 @@ require "global" require "tap" require "test/support/helper/shutup" +require "test/support/helper/fixtures" TEST_DIRECTORIES = [ CoreTap.instance.path/"Formula", @@ -29,6 +30,7 @@ TEST_DIRECTORIES = [ RSpec.configure do |config| config.order = :random config.include(Test::Helper::Shutup) + config.include(Test::Helper::Fixtures) config.before(:each) do |example| if example.metadata[:needs_macos] skip "not on macOS" unless OS.mac? diff --git a/Library/Homebrew/test/support/helper/fixtures.rb b/Library/Homebrew/test/support/helper/fixtures.rb new file mode 100644 index 0000000000..716fe20081 --- /dev/null +++ b/Library/Homebrew/test/support/helper/fixtures.rb @@ -0,0 +1,13 @@ +module Test + module Helper + module Fixtures + def dylib_path(name) + Pathname.new("#{TEST_FIXTURE_DIR}/mach/#{name}.dylib") + end + + def bundle_path(name) + Pathname.new("#{TEST_FIXTURE_DIR}/mach/#{name}.bundle") + end + end + end +end