tests: reorganize compiler selection tests
Signed-off-by: Jack Nagel <jacknagel@gmail.com>
This commit is contained in:
parent
d4f7577185
commit
1d0be89fa5
143
Library/Homebrew/test/test_compilers.rb
Normal file
143
Library/Homebrew/test/test_compilers.rb
Normal file
@ -0,0 +1,143 @@
|
||||
require 'testing_env'
|
||||
|
||||
require 'extend/ARGV' # needs to be after test/unit to avoid conflict with OptionsParser
|
||||
ARGV.extend(HomebrewArgvExtension)
|
||||
|
||||
require 'extend/ENV'
|
||||
ENV.extend(HomebrewEnvExtension)
|
||||
|
||||
require 'test/testball'
|
||||
|
||||
module CompilerTestsEnvExtension
|
||||
def unset_use_cc
|
||||
vars = %w{HOMEBREW_USE_CLANG HOMEBREW_USE_LLVM HOMEBREW_USE_GCC}
|
||||
vars.each { |v| ENV.delete(v) }
|
||||
end
|
||||
end
|
||||
ENV.extend(CompilerTestsEnvExtension)
|
||||
|
||||
class CompilerTests < Test::Unit::TestCase
|
||||
def test_llvm_failure
|
||||
ENV.unset_use_cc
|
||||
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
|
||||
|
||||
ENV.send MacOS.default_compiler
|
||||
end
|
||||
|
||||
def test_all_compiler_failures
|
||||
ENV.unset_use_cc
|
||||
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
|
||||
|
||||
ENV.send MacOS.default_compiler
|
||||
end
|
||||
|
||||
def test_no_compiler_failures
|
||||
ENV.unset_use_cc
|
||||
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 0 then f.fails_with? :gcc
|
||||
else !(f.fails_with? :gcc)
|
||||
end
|
||||
|
||||
cs.select_compiler
|
||||
|
||||
assert_equal MacOS.default_compiler, ENV.compiler
|
||||
|
||||
ENV.send MacOS.default_compiler
|
||||
end
|
||||
|
||||
def test_mixed_compiler_failures
|
||||
ENV.unset_use_cc
|
||||
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
|
||||
|
||||
ENV.send MacOS.default_compiler
|
||||
end
|
||||
|
||||
def test_more_mixed_compiler_failures
|
||||
ENV.unset_use_cc
|
||||
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
|
||||
|
||||
ENV.send MacOS.default_compiler
|
||||
end
|
||||
|
||||
def test_even_more_mixed_compiler_failures
|
||||
ENV.unset_use_cc
|
||||
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 0 then f.fails_with? :gcc
|
||||
else !(f.fails_with? :gcc)
|
||||
end
|
||||
|
||||
cs.select_compiler
|
||||
|
||||
assert_equal case MacOS.clang_build_version
|
||||
when 0..210 then :gcc
|
||||
else :clang
|
||||
end, ENV.compiler
|
||||
|
||||
ENV.send MacOS.default_compiler
|
||||
end
|
||||
|
||||
def test_block_with_no_build_compiler_failures
|
||||
ENV.unset_use_cc
|
||||
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_equal MacOS.default_compiler, ENV.compiler
|
||||
|
||||
ENV.send MacOS.default_compiler
|
||||
end
|
||||
end
|
||||
@ -8,8 +8,6 @@ ENV.extend(HomebrewEnvExtension)
|
||||
|
||||
require 'test/testball'
|
||||
|
||||
require 'hardware'
|
||||
|
||||
class AbstractDownloadStrategy
|
||||
attr_reader :url
|
||||
end
|
||||
@ -68,74 +66,4 @@ class FormulaTests < Test::Unit::TestCase
|
||||
assert_equal downloader.url, "file:///#{TEST_FOLDER}/tarballs/testball-0.1.tbz"
|
||||
end
|
||||
end
|
||||
|
||||
def test_compiler_selection
|
||||
%W{HOMEBREW_USE_CLANG HOMEBEW_USE_LLVM HOMEBREW_USE_GCC}.each { |e| ENV.delete(e) }
|
||||
|
||||
f = TestAllCompilerFailures.new
|
||||
assert f.fails_with? :clang
|
||||
assert f.fails_with? :llvm
|
||||
assert f.fails_with? :gcc
|
||||
cs = CompilerSelector.new(f)
|
||||
cs.select_compiler
|
||||
assert_equal MacOS.default_compiler, ENV.compiler
|
||||
ENV.send MacOS.default_compiler
|
||||
|
||||
f = TestNoCompilerFailures.new
|
||||
assert !(f.fails_with? :clang)
|
||||
assert !(f.fails_with? :llvm)
|
||||
assert !(f.fails_with? :gcc)
|
||||
cs = CompilerSelector.new(f)
|
||||
cs.select_compiler
|
||||
assert_equal MacOS.default_compiler, ENV.compiler
|
||||
ENV.send MacOS.default_compiler
|
||||
|
||||
f = TestLLVMFailure.new
|
||||
assert !(f.fails_with? :clang)
|
||||
assert f.fails_with? :llvm
|
||||
assert !(f.fails_with? :gcc)
|
||||
cs = CompilerSelector.new(f)
|
||||
cs.select_compiler
|
||||
assert_equal case MacOS.clang_build_version
|
||||
when 0..210 then :gcc
|
||||
else :clang
|
||||
end, ENV.compiler
|
||||
ENV.send MacOS.default_compiler
|
||||
|
||||
f = TestMixedCompilerFailures.new
|
||||
assert f.fails_with? :clang
|
||||
assert !(f.fails_with? :llvm)
|
||||
assert f.fails_with? :gcc
|
||||
cs = CompilerSelector.new(f)
|
||||
cs.select_compiler
|
||||
assert_equal :llvm, ENV.compiler
|
||||
ENV.send MacOS.default_compiler
|
||||
|
||||
f = TestMoreMixedCompilerFailures.new
|
||||
assert !(f.fails_with? :clang)
|
||||
assert f.fails_with? :llvm
|
||||
assert f.fails_with? :gcc
|
||||
cs = CompilerSelector.new(f)
|
||||
cs.select_compiler
|
||||
assert_equal :clang, ENV.compiler
|
||||
ENV.send MacOS.default_compiler
|
||||
|
||||
f = TestEvenMoreMixedCompilerFailures.new
|
||||
assert f.fails_with? :clang
|
||||
assert f.fails_with? :llvm
|
||||
assert !(f.fails_with? :gcc)
|
||||
cs = CompilerSelector.new(f)
|
||||
cs.select_compiler
|
||||
assert_equal :clang, ENV.compiler
|
||||
ENV.send MacOS.default_compiler
|
||||
|
||||
f = TestBlockWithoutBuildCompilerFailure.new
|
||||
assert f.fails_with? :clang
|
||||
assert !(f.fails_with? :llvm)
|
||||
assert !(f.fails_with? :gcc)
|
||||
cs = CompilerSelector.new(f)
|
||||
cs.select_compiler
|
||||
assert_equal MacOS.default_compiler, ENV.compiler
|
||||
ENV.send MacOS.default_compiler
|
||||
end
|
||||
end
|
||||
|
||||
@ -8,6 +8,7 @@ EXIT=0
|
||||
/usr/bin/ruby test_formula.rb $* || EXIT=1
|
||||
/usr/bin/ruby test_versions.rb $* || EXIT=1
|
||||
/usr/bin/ruby test_checksums.rb $* || EXIT=1
|
||||
/usr/bin/ruby test_compilers.rb $* || EXIT=1
|
||||
/usr/bin/ruby test_inreplace.rb $* || EXIT=1
|
||||
/usr/bin/ruby test_hardware.rb $* || EXIT=1
|
||||
/usr/bin/ruby test_formula_install.rb $* || EXIT=1
|
||||
@ -20,4 +21,4 @@ EXIT=0
|
||||
/usr/bin/ruby test_updater.rb $* || EXIT=1
|
||||
/usr/bin/ruby test_string.rb $* || EXIT=1
|
||||
|
||||
exit $EXIT
|
||||
exit $EXIT
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user