aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test
diff options
context:
space:
mode:
authorMisty De Meo2013-06-28 01:38:09 -0500
committerMisty De Meo2013-09-01 13:19:13 -0700
commitef1d9c0cd04c21b5b19cae17e83bbdc6ef28d712 (patch)
treee65e63fa2b446cc0ec80694f2572acba589b70e7 /Library/Homebrew/test
parent71268b7f16f017a94304488e3b3cbc4c1ca3bfe7 (diff)
downloadbrew-ef1d9c0cd04c21b5b19cae17e83bbdc6ef28d712.tar.bz2
Implement fails_with for non-Apple compilers
This adds support for non-Apple GCC compilers in the fails_with code. A fails_with block for a non-Apple compiler looks like: fails_with :gcc => '4.8.1' do cause 'Foo' end Non-Apple compilers don't have build numbers, so compiler failures are based on version strings instead. Internally non-Apple compilers can be distinguished because they are passed around as strings instead of symbols. In addition, this alters the priority list for compilers, with the following changes: * Apple GCC 4.2 and LLVM-GCC swap positions, with GCC now taking priority. (Maybe LLVM-GCC should just go away.) * Non-Apple GCC compilers are ranked below GCC 4.2 but above LLVM-GCC and Apple GCC 4.0.
Diffstat (limited to 'Library/Homebrew/test')
-rw-r--r--Library/Homebrew/test/test_compiler_selector.rb40
-rw-r--r--Library/Homebrew/test/test_fails_with.rb11
2 files changed, 43 insertions, 8 deletions
diff --git a/Library/Homebrew/test/test_compiler_selector.rb b/Library/Homebrew/test/test_compiler_selector.rb
index 17c3b0449..5374a5452 100644
--- a/Library/Homebrew/test/test_compiler_selector.rb
+++ b/Library/Homebrew/test/test_compiler_selector.rb
@@ -22,16 +22,29 @@ class CompilerSelectorTests < Test::Unit::TestCase
MacOS.stubs(:gcc_build_version).returns(5666)
MacOS.stubs(:llvm_build_version).returns(2336)
MacOS.stubs(:clang_build_version).returns(425)
+ # Yes, this is ugly - we only want one GCC version to be available.
+ MacOS.send(:alias_method, :old_non_apple_gcc_version, :non_apple_gcc_version)
+ MacOS.send(:define_method, :non_apple_gcc_version) do |name|
+ if name == 'gcc-4.8'
+ '4.8.1'
+ else
+ nil
+ end
+ end
@f = Double.new
@cc = :clang
end
+ def teardown
+ MacOS.send(:alias_method, :non_apple_gcc_version, :old_non_apple_gcc_version)
+ end
+
def actual_cc
CompilerSelector.new(@f).compiler
end
def test_all_compiler_failures
- @f << :clang << :llvm << :gcc
+ @f << :clang << :llvm << :gcc << 'gcc-4.8'
assert_raise(CompilerSelectionError) { actual_cc }
end
@@ -41,7 +54,7 @@ class CompilerSelectorTests < Test::Unit::TestCase
def test_fails_with_clang
@f << :clang
- assert_equal :llvm, actual_cc
+ assert_equal :gcc, actual_cc
end
def test_fails_with_llvm
@@ -54,13 +67,18 @@ class CompilerSelectorTests < Test::Unit::TestCase
assert_equal :clang, actual_cc
end
+ def test_fails_with_non_apple_gcc
+ @f << "gcc-4.8"
+ 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
+ @f << :gcc << :clang << 'gcc-4.8'
assert_equal :llvm, actual_cc
end
@@ -69,22 +87,32 @@ class CompilerSelectorTests < Test::Unit::TestCase
assert_equal :clang, actual_cc
end
+ def test_mixed_failures_4
+ @f << :clang << "gcc-4.8"
+ assert_equal :gcc, actual_cc
+ end
+
def test_older_clang_precedence
MacOS.stubs(:clang_build_version).returns(211)
- @f << :gcc
+ @f << :gcc << 'gcc-4.8'
assert_equal :llvm, actual_cc
end
+ def test_non_apple_gcc_precedence
+ @f << :clang << :gcc
+ assert_equal 'gcc-4.8', actual_cc
+ end
+
def test_missing_gcc
MacOS.stubs(:gcc_build_version).returns(nil)
- @f << :clang << :llvm
+ @f << :clang << :llvm << 'gcc-4.8'
assert_raise(CompilerSelectionError) { 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
+ @f << :clang << 'gcc-4.8'
assert_raise(CompilerSelectionError) { actual_cc }
end
end
diff --git a/Library/Homebrew/test/test_fails_with.rb b/Library/Homebrew/test/test_fails_with.rb
index 2b344cc3d..31f318a4c 100644
--- a/Library/Homebrew/test/test_fails_with.rb
+++ b/Library/Homebrew/test/test_fails_with.rb
@@ -3,7 +3,7 @@ require 'test/testball'
class FailsWithTests < Test::Unit::TestCase
class Double < Compiler
- attr_accessor :name, :build
+ attr_accessor :name, :build, :version
end
def assert_fails_with(cc)
@@ -18,10 +18,11 @@ class FailsWithTests < Test::Unit::TestCase
@f.send(:fails_with, *args, &block)
end
- def build_cc(sym, build)
+ def build_cc(sym, build, version=nil)
cc = Double.new
cc.name = sym
cc.build = build
+ cc.version = version
cc
end
@@ -47,6 +48,12 @@ class FailsWithTests < Test::Unit::TestCase
assert_fails_with cc
end
+ def test_non_apple_gcc_version
+ fails_with(:gcc => '4.8.2')
+ cc = build_cc("gcc-4.8", nil, "4.8.1")
+ assert_fails_with cc
+ end
+
def test_multiple_failures
fails_with(:llvm)
fails_with(:clang)