forked from Homebrew/legacy-homebrew
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: reorganize compiler selection tests
Signed-off-by: Jack Nagel <jacknagel@gmail.com>
- Loading branch information
Showing
3 changed files
with
145 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters