2012-05-25 23:44:11 -05:00
|
|
|
require 'testing_env'
|
|
|
|
|
|
|
|
class MachOPathnameTests < Test::Unit::TestCase
|
2014-06-10 21:20:02 -05:00
|
|
|
def dylib_path(name)
|
2014-06-10 21:49:41 -05:00
|
|
|
Pathname.new("#{TEST_DIRECTORY}/mach/#{name}.dylib")
|
2014-06-10 21:20:02 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def bundle_path(name)
|
2014-06-10 21:49:41 -05:00
|
|
|
Pathname.new("#{TEST_DIRECTORY}/mach/#{name}.bundle")
|
2014-06-10 21:20:02 -05:00
|
|
|
end
|
|
|
|
|
2012-05-25 23:44:11 -05:00
|
|
|
def test_fat_dylib
|
2014-06-10 21:20:02 -05:00
|
|
|
pn = dylib_path("fat")
|
2012-05-25 23:44:11 -05:00
|
|
|
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?
|
2014-06-04 16:31:57 -05:00
|
|
|
assert_equal :universal, pn.arch
|
2012-05-25 23:44:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_i386_dylib
|
2014-06-10 21:20:02 -05:00
|
|
|
pn = dylib_path("i386")
|
2012-05-25 23:44:11 -05:00
|
|
|
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?
|
2012-06-16 11:35:02 -05:00
|
|
|
assert !pn.mach_o_bundle?
|
2012-05-25 23:44:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_x86_64_dylib
|
2014-06-10 21:20:02 -05:00
|
|
|
pn = dylib_path("x86_64")
|
2012-05-25 23:44:11 -05:00
|
|
|
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?
|
2012-06-16 11:35:02 -05:00
|
|
|
assert !pn.mach_o_bundle?
|
2012-05-25 23:44:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_mach_o_executable
|
2014-06-10 21:49:41 -05:00
|
|
|
pn = Pathname.new("#{TEST_DIRECTORY}/mach/a.out")
|
2012-05-25 23:44:11 -05:00
|
|
|
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?
|
2012-06-16 11:35:02 -05:00
|
|
|
assert !pn.mach_o_bundle?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_fat_bundle
|
2014-06-10 21:20:02 -05:00
|
|
|
pn = bundle_path("fat")
|
2012-06-16 11:35:02 -05:00
|
|
|
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?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_i386_bundle
|
2014-06-10 21:20:02 -05:00
|
|
|
pn = bundle_path("i386")
|
2012-06-16 11:35:02 -05:00
|
|
|
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?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_x86_64_bundle
|
2014-06-10 21:20:02 -05:00
|
|
|
pn = bundle_path("x86_64")
|
2012-06-16 11:35:02 -05:00
|
|
|
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?
|
2012-05-25 23:44:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_non_mach_o
|
2014-06-10 21:49:41 -05:00
|
|
|
pn = Pathname.new("#{TEST_DIRECTORY}/tarballs/testball-0.1.tbz")
|
2012-05-25 23:44:11 -05:00
|
|
|
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?
|
2012-06-16 11:35:02 -05:00
|
|
|
assert !pn.mach_o_bundle?
|
2014-06-04 16:31:57 -05:00
|
|
|
assert_equal :dunno, pn.arch
|
2012-05-25 23:44:11 -05:00
|
|
|
end
|
2014-06-10 21:20:37 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
class ArchitectureListExtensionTests < MachOPathnameTests
|
|
|
|
def setup
|
|
|
|
@archs = [:i386, :x86_64, :ppc7400, :ppc64].extend(ArchitectureListExtension)
|
|
|
|
end
|
2012-05-28 20:39:05 -05:00
|
|
|
|
2013-08-11 20:53:16 -07:00
|
|
|
def test_architecture_list_extension_universal_checks
|
|
|
|
assert @archs.universal?
|
|
|
|
assert @archs.intel_universal?
|
|
|
|
assert @archs.ppc_universal?
|
|
|
|
assert @archs.cross_universal?
|
|
|
|
assert @archs.fat?
|
|
|
|
|
|
|
|
non_universal = [:i386].extend ArchitectureListExtension
|
|
|
|
assert !non_universal.universal?
|
|
|
|
|
|
|
|
intel_only = [:i386, :x86_64].extend ArchitectureListExtension
|
|
|
|
assert intel_only.universal?
|
|
|
|
assert !intel_only.ppc_universal?
|
|
|
|
assert !intel_only.cross_universal?
|
|
|
|
|
|
|
|
ppc_only = [:ppc970, :ppc64].extend ArchitectureListExtension
|
|
|
|
assert ppc_only.universal?
|
|
|
|
assert !ppc_only.intel_universal?
|
|
|
|
assert !ppc_only.cross_universal?
|
|
|
|
|
|
|
|
cross = [:ppc7400, :i386].extend ArchitectureListExtension
|
|
|
|
assert cross.universal?
|
|
|
|
assert !cross.intel_universal?
|
|
|
|
assert !cross.ppc_universal?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_architecture_list_extension_massaging_flags
|
|
|
|
@archs.remove_ppc!
|
|
|
|
assert_equal 2, @archs.length
|
|
|
|
assert_match(/-arch i386/, @archs.as_arch_flags)
|
|
|
|
assert_match(/-arch x86_64/, @archs.as_arch_flags)
|
|
|
|
end
|
2012-05-28 20:39:05 -05:00
|
|
|
|
2013-08-11 20:53:16 -07:00
|
|
|
def test_architecture_list_arch_flags_methods
|
2014-06-10 21:20:02 -05:00
|
|
|
pn = dylib_path("fat")
|
2013-08-11 20:53:16 -07:00
|
|
|
assert pn.archs.intel_universal?
|
|
|
|
assert_equal "-arch x86_64 -arch i386", pn.archs.as_arch_flags
|
|
|
|
assert_equal "x86_64;i386", pn.archs.as_cmake_arch_flags
|
2012-05-28 20:39:05 -05:00
|
|
|
end
|
2012-05-25 23:44:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
class TextExecutableTests < Test::Unit::TestCase
|
2014-06-10 20:40:51 -05:00
|
|
|
attr_reader :pn
|
|
|
|
|
|
|
|
def setup
|
|
|
|
@pn = HOMEBREW_PREFIX.join("an_executable")
|
|
|
|
end
|
|
|
|
|
2012-08-30 00:09:29 -05:00
|
|
|
def teardown
|
2014-06-10 20:40:51 -05:00
|
|
|
HOMEBREW_PREFIX.join("an_executable").unlink
|
2012-08-30 00:09:29 -05:00
|
|
|
end
|
|
|
|
|
2012-05-25 23:44:11 -05:00
|
|
|
def test_simple_shebang
|
|
|
|
pn.write '#!/bin/sh'
|
|
|
|
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_equal [], pn.archs
|
2014-06-04 16:31:57 -05:00
|
|
|
assert_equal :dunno, pn.arch
|
2012-05-25 23:44:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_shebang_with_options
|
|
|
|
pn.write '#! /usr/bin/perl -w'
|
|
|
|
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_equal [], pn.archs
|
2014-06-04 16:31:57 -05:00
|
|
|
assert_equal :dunno, pn.arch
|
2012-05-25 23:44:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_malformed_shebang
|
2012-06-15 20:02:49 -05:00
|
|
|
pn.write ' #!'
|
2012-05-25 23:44:11 -05:00
|
|
|
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_equal [], pn.archs
|
2014-06-04 16:31:57 -05:00
|
|
|
assert_equal :dunno, pn.arch
|
2012-05-25 23:44:11 -05:00
|
|
|
end
|
|
|
|
end
|