aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Reiter2017-02-21 20:10:49 +0100
committerGitHub2017-02-21 20:10:49 +0100
commit6d4aa91b3768cefc35c5adf55ced4928795a89f8 (patch)
treef05106aa6bd330fa42ee68c365d44c970eca5bfe
parenta5af18380ba4c159796b335c5ac453e3529b57a2 (diff)
parent5ec95978104eab9679340e739c3a5fd5786b4722 (diff)
downloadbrew-6d4aa91b3768cefc35c5adf55ced4928795a89f8.tar.bz2
Merge pull request #2076 from reitermarkus/spec-os_mac_keg
Convert OS::Mac::Keg test to spec.
-rw-r--r--Library/Homebrew/test/os/mac/keg_spec.rb32
-rw-r--r--Library/Homebrew/test/os/mac/keg_test.rb69
-rw-r--r--Library/Homebrew/test/spec_helper.rb2
-rw-r--r--Library/Homebrew/test/support/helper/fixtures.rb13
4 files changed, 47 insertions, 69 deletions
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 000000000..562c2ba6a
--- /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 d1103415d..000000000
--- 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 d8694eefc..b58125aec 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 000000000..716fe2008
--- /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