Merge pull request #2076 from reitermarkus/spec-os_mac_keg

Convert OS::Mac::Keg test to spec.
This commit is contained in:
Markus Reiter 2017-02-21 20:10:49 +01:00 committed by GitHub
commit 6d4aa91b37
4 changed files with 47 additions and 69 deletions

View File

@ -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

View File

@ -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

View File

@ -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?

View File

@ -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