diff options
| -rw-r--r-- | Library/Homebrew/mach.rb | 5 | ||||
| -rw-r--r-- | Library/Homebrew/test/mach/fat.bundle | bin | 0 -> 16472 bytes | |||
| -rw-r--r-- | Library/Homebrew/test/mach/i386.bundle | bin | 0 -> 4168 bytes | |||
| -rw-r--r-- | Library/Homebrew/test/mach/x86_64.bundle | bin | 0 -> 4184 bytes | |||
| -rw-r--r-- | Library/Homebrew/test/test_mach.rb | 74 |
5 files changed, 64 insertions, 15 deletions
diff --git a/Library/Homebrew/mach.rb b/Library/Homebrew/mach.rb index ebbc4b57e..7b9d4d345 100644 --- a/Library/Homebrew/mach.rb +++ b/Library/Homebrew/mach.rb @@ -52,6 +52,7 @@ module MachO type = case read(4, offset + 12).unpack("N")[0] when 0x00000002, 0x02000000 then :executable when 0x00000006, 0x06000000 then :dylib + when 0x00000008, 0x08000000 then :bundle else :dunno end @@ -105,4 +106,8 @@ module MachO def mach_o_executable? mach_data.map{ |m| m.fetch :type }.include? :executable end + + def mach_o_bundle? + mach_data.map{ |m| m.fetch :type }.include? :bundle + end end diff --git a/Library/Homebrew/test/mach/fat.bundle b/Library/Homebrew/test/mach/fat.bundle Binary files differnew file mode 100644 index 000000000..f60f1e8bb --- /dev/null +++ b/Library/Homebrew/test/mach/fat.bundle diff --git a/Library/Homebrew/test/mach/i386.bundle b/Library/Homebrew/test/mach/i386.bundle Binary files differnew file mode 100644 index 000000000..b6f94710d --- /dev/null +++ b/Library/Homebrew/test/mach/i386.bundle diff --git a/Library/Homebrew/test/mach/x86_64.bundle b/Library/Homebrew/test/mach/x86_64.bundle Binary files differnew file mode 100644 index 000000000..d1bde419f --- /dev/null +++ b/Library/Homebrew/test/mach/x86_64.bundle diff --git a/Library/Homebrew/test/test_mach.rb b/Library/Homebrew/test/test_mach.rb index a0efb6928..b9acd337f 100644 --- a/Library/Homebrew/test/test_mach.rb +++ b/Library/Homebrew/test/test_mach.rb @@ -3,6 +3,10 @@ require 'testing_env' require 'extend/ARGV' # needs to be after test/unit to avoid conflict with OptionsParser ARGV.extend(HomebrewArgvExtension) +def file pn + `/usr/bin/file -h '#{pn}'`.chomp +end + class MachOPathnameTests < Test::Unit::TestCase def test_fat_dylib pn = Pathname.new("#{TEST_FOLDER}/mach/fat.dylib") @@ -15,8 +19,7 @@ class MachOPathnameTests < Test::Unit::TestCase assert !pn.mach_o_executable? assert !pn.text_executable? assert pn.arch == :universal - assert_match /Mach-O (64-bit )?dynamically linked shared library/, - `/usr/bin/file -h '#{pn}'`.chomp + assert_match /Mach-O (64-bit )?dynamically linked shared library/, file(pn) end def test_i386_dylib @@ -29,8 +32,8 @@ class MachOPathnameTests < Test::Unit::TestCase assert pn.dylib? assert !pn.mach_o_executable? assert !pn.text_executable? - assert_match /Mach-O (64-bit )?dynamically linked shared library/, - `/usr/bin/file -h '#{pn}'`.chomp + assert !pn.mach_o_bundle? + assert_match /Mach-O dynamically linked shared library/, file(pn) end def test_x86_64_dylib @@ -43,8 +46,8 @@ class MachOPathnameTests < Test::Unit::TestCase assert pn.dylib? assert !pn.mach_o_executable? assert !pn.text_executable? - assert_match /Mach-O (64-bit )?dynamically linked shared library/, - `/usr/bin/file -h '#{pn}'`.chomp + assert !pn.mach_o_bundle? + assert_match /Mach-O 64-bit dynamically linked shared library/, file(pn) end def test_mach_o_executable @@ -57,8 +60,50 @@ class MachOPathnameTests < Test::Unit::TestCase assert !pn.dylib? assert pn.mach_o_executable? assert !pn.text_executable? - assert_match /Mach-O (64-bit )?executable/, - `/usr/bin/file -h '#{pn}'`.chomp + assert !pn.mach_o_bundle? + assert_match /Mach-O (64-bit )?executable/, file(pn) + end + + def test_fat_bundle + pn = Pathname.new("#{TEST_FOLDER}/mach/fat.bundle") + assert pn.universal? + assert !pn.i386? + assert !pn.x86_64? + assert !pn.ppc7400? + assert !pn.ppc64? + assert !pn.dylib? + assert !pn.mach_o_executable? + assert !pn.text_executable? + assert pn.mach_o_bundle? + assert_match /Mach-O (64-bit )?bundle/, file(pn) + end + + def test_i386_bundle + pn = Pathname.new("#{TEST_FOLDER}/mach/i386.bundle") + assert !pn.universal? + assert pn.i386? + assert !pn.x86_64? + assert !pn.ppc7400? + assert !pn.ppc64? + assert !pn.dylib? + assert !pn.mach_o_executable? + assert !pn.text_executable? + assert pn.mach_o_bundle? + assert_match /Mach-O bundle/, file(pn) + end + + def test_x86_64_bundle + pn = Pathname.new("#{TEST_FOLDER}/mach/x86_64.bundle") + assert !pn.universal? + assert !pn.i386? + assert pn.x86_64? + assert !pn.ppc7400? + assert !pn.ppc64? + assert !pn.dylib? + assert !pn.mach_o_executable? + assert !pn.text_executable? + assert pn.mach_o_bundle? + assert_match /Mach-O 64-bit bundle/, file(pn) end def test_non_mach_o @@ -71,11 +116,10 @@ class MachOPathnameTests < Test::Unit::TestCase assert !pn.dylib? assert !pn.mach_o_executable? assert !pn.text_executable? + assert !pn.mach_o_bundle? assert pn.arch == :dunno - assert_no_match /Mach-O (64-bit )?dynamically linked shared library/, - `/usr/bin/file -h '#{pn}'`.chomp - assert_no_match /Mach-O [^ ]* ?executable/, - `/usr/bin/file -h '#{pn}'`.chomp + assert_no_match /Mach-O (64-bit )?dynamically linked shared library/, file(pn) + assert_no_match /Mach-O [^ ]* ?executable/, file(pn) end def test_architecture_list_extension @@ -114,7 +158,7 @@ class TextExecutableTests < Test::Unit::TestCase assert pn.text_executable? assert_equal [], pn.archs assert pn.arch == :dunno - assert_match /text executable/, `/usr/bin/file -h '#{pn}'`.chomp + assert_match /text executable/, file(pn) end def test_shebang_with_options @@ -130,7 +174,7 @@ class TextExecutableTests < Test::Unit::TestCase assert pn.text_executable? assert_equal [], pn.archs assert pn.arch == :dunno - assert_match /text executable/, `/usr/bin/file -h '#{pn}'`.chomp + assert_match /text executable/, file(pn) end def test_malformed_shebang @@ -146,7 +190,7 @@ class TextExecutableTests < Test::Unit::TestCase assert !pn.text_executable? assert_equal [], pn.archs assert pn.arch == :dunno - assert_no_match /text executable/, `/usr/bin/file -h '#{pn}'`.chomp + assert_no_match /text executable/, file(pn) end def teardown |
