Isolate compiler selector tests

This commit is contained in:
Jack Nagel 2013-04-01 12:56:56 -05:00
parent c679e557ba
commit 2f49fd07b1
5 changed files with 93 additions and 135 deletions

View File

@ -114,7 +114,9 @@ def install f
end end
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 f.brew do
if ARGV.flag? '--git' if ARGV.flag? '--git'

View File

@ -42,7 +42,7 @@ class CompilerQueue
end end
class CompilerSelector class CompilerSelector
def initialize(f, old_compiler=ENV.compiler) def initialize(f, old_compiler)
@f = f @f = f
@old_compiler = old_compiler @old_compiler = old_compiler
@compilers = CompilerQueue.new @compilers = CompilerQueue.new

View File

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

View File

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

View File

@ -45,53 +45,6 @@ class ConfigureFails < Formula
end end
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 class SpecTestBall < Formula
homepage 'http://example.com' homepage 'http://example.com'
url 'file:///foo.com/testball-0.1.tbz' url 'file:///foo.com/testball-0.1.tbz'