diff options
| author | Jack Nagel | 2013-04-01 12:56:56 -0500 |
|---|---|---|
| committer | Jack Nagel | 2013-04-02 13:19:04 -0500 |
| commit | 2f49fd07b14875e7fad02ee8b8ac93af87ff7f72 (patch) | |
| tree | 02034d92d10a7d9933c8e557a184372926a1b2f2 /Library | |
| parent | c679e557ba735b932eee7c37facf6ec147c265d0 (diff) | |
| download | brew-2f49fd07b14875e7fad02ee8b8ac93af87ff7f72.tar.bz2 | |
Isolate compiler selector tests
Diffstat (limited to 'Library')
| -rwxr-xr-x | Library/Homebrew/build.rb | 4 | ||||
| -rw-r--r-- | Library/Homebrew/compilers.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/test/test_compiler_selector.rb | 89 | ||||
| -rw-r--r-- | Library/Homebrew/test/test_compilers.rb | 86 | ||||
| -rw-r--r-- | Library/Homebrew/test/testball.rb | 47 |
5 files changed, 93 insertions, 135 deletions
diff --git a/Library/Homebrew/build.rb b/Library/Homebrew/build.rb index 88a216dc2..0f76c55d5 100755 --- a/Library/Homebrew/build.rb +++ b/Library/Homebrew/build.rb @@ -114,7 +114,9 @@ def install f end end - ENV.send(CompilerSelector.new(f).compiler) if f.fails_with? ENV.compiler + if f.fails_with? ENV.compiler + ENV.send CompilerSelector.new(f, ENV.compiler).compiler + end f.brew do if ARGV.flag? '--git' diff --git a/Library/Homebrew/compilers.rb b/Library/Homebrew/compilers.rb index f716256ef..a68d4f3d2 100644 --- a/Library/Homebrew/compilers.rb +++ b/Library/Homebrew/compilers.rb @@ -42,7 +42,7 @@ class CompilerQueue end class CompilerSelector - def initialize(f, old_compiler=ENV.compiler) + def initialize(f, old_compiler) @f = f @old_compiler = old_compiler @compilers = CompilerQueue.new diff --git a/Library/Homebrew/test/test_compiler_selector.rb b/Library/Homebrew/test/test_compiler_selector.rb new file mode 100644 index 000000000..6e3a36366 --- /dev/null +++ b/Library/Homebrew/test/test_compiler_selector.rb @@ -0,0 +1,89 @@ +require 'testing_env' +require 'compilers' + +class CompilerSelectorTests < Test::Unit::TestCase + class Double + def initialize + @failures = [] + end + + def <<(cc) + @failures << cc + end + + def fails_with?(cc) + return false if cc.nil? + @failures.include?(cc.name) + end + end + + def setup + MacOS.stubs(:gcc_build_version).returns(5666) + MacOS.stubs(:llvm_build_version).returns(2336) + MacOS.stubs(:clang_build_version).returns(425) + @f = Double.new + @cc = :clang + end + + def actual_cc + CompilerSelector.new(@f, @cc).compiler + end + + def test_all_compiler_failures + @f << :clang << :llvm << :gcc + assert_equal @cc, actual_cc + end + + def test_no_compiler_failures + assert_equal @cc, actual_cc + end + + def test_fails_with_clang + @f << :clang + assert_equal :llvm, actual_cc + end + + def test_fails_with_llvm + @f << :llvm + assert_equal :clang, actual_cc + end + + def test_fails_with_gcc + @f << :gcc + assert_equal :clang, actual_cc + end + + def test_mixed_failures_1 + @f << :clang << :llvm + assert_equal :gcc, actual_cc + end + + def test_mixed_failures_2 + @f << :gcc << :clang + assert_equal :llvm, actual_cc + end + + def test_mixed_failures_3 + @f << :llvm << :gcc + assert_equal :clang, actual_cc + end + + def test_older_clang_precedence + MacOS.stubs(:clang_build_version).returns(211) + @f << :gcc + assert_equal :llvm, actual_cc + end + + def test_missing_gcc + MacOS.stubs(:gcc_build_version).returns(nil) + @f << :clang << :llvm + assert_equal @cc, actual_cc + end + + def test_missing_llvm_and_gcc + MacOS.stubs(:gcc_build_version).returns(nil) + MacOS.stubs(:llvm_build_version).returns(nil) + @f << :clang + assert_equal @cc, actual_cc + end +end diff --git a/Library/Homebrew/test/test_compilers.rb b/Library/Homebrew/test/test_compilers.rb deleted file mode 100644 index ff94c2d9f..000000000 --- a/Library/Homebrew/test/test_compilers.rb +++ /dev/null @@ -1,86 +0,0 @@ -require 'testing_env' -require 'test/testball' - -class CompilerTests < Test::Unit::TestCase - def test_llvm_failure - f = TestLLVMFailure.new - cs = CompilerSelector.new(f) - - assert !(f.fails_with? :clang) - assert f.fails_with? :llvm - assert !(f.fails_with? :gcc) - assert_equal case MacOS.clang_build_version - when 0..318 then :gcc - else :clang - end, cs.compiler - end - - def test_all_compiler_failures - f = TestAllCompilerFailures.new - cs = CompilerSelector.new(f) - - assert f.fails_with? :clang - assert f.fails_with? :llvm - assert f.fails_with? :gcc - assert_equal MacOS.default_compiler, cs.compiler - end - - def test_no_compiler_failures - f = TestNoCompilerFailures.new - cs = CompilerSelector.new(f) - - assert !(f.fails_with? :clang) - assert !(f.fails_with? :llvm) - assert case MacOS.gcc_42_build_version - when nil then f.fails_with? :gcc - else !(f.fails_with? :gcc) - end - assert_equal MacOS.default_compiler, cs.compiler - end - - def test_mixed_compiler_failures - f = TestMixedCompilerFailures.new - cs = CompilerSelector.new(f) - - assert f.fails_with? :clang - assert !(f.fails_with? :llvm) - assert f.fails_with? :gcc - assert_equal :llvm, cs.compiler - end - - def test_more_mixed_compiler_failures - f = TestMoreMixedCompilerFailures.new - cs = CompilerSelector.new(f) - - assert !(f.fails_with? :clang) - assert f.fails_with? :llvm - assert f.fails_with? :gcc - assert_equal :clang, cs.compiler - end - - def test_even_more_mixed_compiler_failures - f = TestEvenMoreMixedCompilerFailures.new - cs = CompilerSelector.new(f) - - assert f.fails_with? :clang - assert f.fails_with? :llvm - assert case MacOS.gcc_42_build_version - when nil then f.fails_with? :gcc - else !(f.fails_with? :gcc) - end - assert_equal case MacOS.gcc_42_build_version - when nil then :llvm - else :gcc - end, cs.compiler - end - - def test_block_with_no_build_compiler_failures - f = TestBlockWithoutBuildCompilerFailure.new - cs = CompilerSelector.new(f) - - assert f.fails_with? :clang - assert !(f.fails_with? :llvm) - assert !(f.fails_with? :gcc) - assert_not_equal :clang, cs.compiler - end -end diff --git a/Library/Homebrew/test/testball.rb b/Library/Homebrew/test/testball.rb index f685f5e2c..32f307f10 100644 --- a/Library/Homebrew/test/testball.rb +++ b/Library/Homebrew/test/testball.rb @@ -45,53 +45,6 @@ class ConfigureFails < Formula end end -class TestCompilerFailures < Formula - def initialize name=nil - @stable = SoftwareSpec.new "file:///#{TEST_FOLDER}/tarballs/testball-0.1.tbz" - super "compilerfailures" - end -end - -class TestAllCompilerFailures < TestCompilerFailures - fails_with :clang - fails_with :llvm - fails_with :gcc -end - -class TestNoCompilerFailures < TestCompilerFailures - fails_with(:clang) { build 42 } - fails_with(:llvm) { build 42 } - fails_with(:gcc) { build 42 } -end - -class TestLLVMFailure < TestCompilerFailures - fails_with :llvm -end - -class TestMixedCompilerFailures < TestCompilerFailures - fails_with(:clang) { build MacOS.clang_build_version } - fails_with(:llvm) { build 42 } - fails_with(:gcc) { build 5666 } -end - -class TestMoreMixedCompilerFailures < TestCompilerFailures - fails_with(:clang) { build 42 } - fails_with(:llvm) { build 2336 } - fails_with(:gcc) { build 5666 } -end - -class TestEvenMoreMixedCompilerFailures < TestCompilerFailures - fails_with :clang - fails_with(:llvm) { build 2336 } - fails_with(:gcc) { build 5648 } -end - -class TestBlockWithoutBuildCompilerFailure < TestCompilerFailures - fails_with :clang do - cause "failure" - end -end - class SpecTestBall < Formula homepage 'http://example.com' url 'file:///foo.com/testball-0.1.tbz' |
