brew/Library/Homebrew/test/test_compilers.rb
Jack Nagel cc08d08d74 Switch compilers when no build is specified
Given the current state of OS X compilers, the original fails_with
behavior is becoming less useful, mostly resulting in build failures
each time the compiler is updated. So make the following changes:

When a build is specified, we retain the old behavior: switch compilers
if the available compiler is <= the build, don't switch if it is > the
build.

When no build is specified, unconditionally switch compilers, and don't
output the advice message. This allows us to mark formulae as
perpetually failing, avoiding the need to update formulae each time a
new compiler build is made available.

As a bonus, this makes the logic much easier to reason about.

Closes Homebrew/homebrew#18175.
2013-03-12 13:55:15 -05:00

116 lines
2.5 KiB
Ruby

require 'testing_env'
require 'test/testball'
class CompilerTests < Test::Unit::TestCase
def setup
%w{HOMEBREW_USE_CLANG HOMEBREW_USE_LLVM HOMEBREW_USE_GCC}.each { |v| ENV.delete(v) }
end
def teardown
ENV.send MacOS.default_compiler
end
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)
cs.select_compiler
assert_equal case MacOS.clang_build_version
when 0..210 then :gcc
else :clang
end, ENV.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
cs.select_compiler
assert_equal MacOS.default_compiler, ENV.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
cs.select_compiler
assert_equal MacOS.default_compiler, ENV.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
cs.select_compiler
assert_equal :llvm, ENV.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
cs.select_compiler
assert_equal :clang, ENV.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
cs.select_compiler
assert_equal case MacOS.gcc_42_build_version
when nil then :llvm
else :gcc
end, ENV.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)
cs.select_compiler
assert_not_equal :clang, ENV.compiler
end
end