Skip to content

Commit

Permalink
tests: reorganize compiler selection tests
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Nagel <jacknagel@gmail.com>
  • Loading branch information
jacknagel committed Apr 14, 2012
1 parent 141f21d commit 2289f98
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 73 deletions.
143 changes: 143 additions & 0 deletions Library/Homebrew/test/test_compilers.rb
@@ -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
72 changes: 0 additions & 72 deletions Library/Homebrew/test/test_formula.rb
Expand Up @@ -8,8 +8,6 @@

require 'test/testball'

require 'hardware'

class AbstractDownloadStrategy
attr_reader :url
end
Expand Down Expand Up @@ -68,74 +66,4 @@ def test_mirror_support
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
3 changes: 2 additions & 1 deletion Library/Homebrew/test/tests
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 2289f98

Please sign in to comment.