2015-08-03 13:09:07 +01:00
|
|
|
require "testing_env"
|
|
|
|
require "compilers"
|
|
|
|
require "software_spec"
|
2013-04-01 12:56:56 -05:00
|
|
|
|
2014-06-18 20:32:51 -05:00
|
|
|
class CompilerSelectorTests < Homebrew::TestCase
|
2014-08-30 23:38:12 -05:00
|
|
|
class Double < SoftwareSpec
|
2013-04-01 12:56:56 -05:00
|
|
|
def <<(cc)
|
2014-08-30 23:38:12 -05:00
|
|
|
fails_with(cc)
|
2014-08-30 23:11:02 -05:00
|
|
|
self
|
2013-04-01 12:56:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-06-11 21:05:31 -05:00
|
|
|
class CompilerVersions
|
|
|
|
attr_accessor :gcc_4_0_build_version, :gcc_build_version,
|
|
|
|
:llvm_build_version, :clang_build_version
|
|
|
|
|
2014-09-18 15:50:54 -05:00
|
|
|
def initialize
|
|
|
|
@gcc_4_0_build_version = nil
|
|
|
|
@gcc_build_version = 5666
|
|
|
|
@llvm_build_version = 2336
|
|
|
|
@clang_build_version = 425
|
2014-06-11 21:05:31 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def non_apple_gcc_version(name)
|
2014-09-18 15:50:54 -05:00
|
|
|
case name
|
|
|
|
when "gcc-4.8" then "4.8.1"
|
|
|
|
when "gcc-4.7" then "4.7.1"
|
|
|
|
end
|
2013-06-28 01:38:09 -05:00
|
|
|
end
|
2013-04-01 12:56:56 -05:00
|
|
|
end
|
|
|
|
|
2014-06-11 21:05:31 -05:00
|
|
|
def setup
|
|
|
|
@f = Double.new
|
|
|
|
@cc = :clang
|
|
|
|
@versions = CompilerVersions.new
|
2014-09-18 15:50:54 -05:00
|
|
|
@selector = CompilerSelector.new(
|
|
|
|
@f, @versions, [:clang, :gcc, :llvm, :gnu]
|
|
|
|
)
|
2013-06-28 01:38:09 -05:00
|
|
|
end
|
|
|
|
|
2013-04-01 12:56:56 -05:00
|
|
|
def actual_cc
|
2014-09-18 15:50:54 -05:00
|
|
|
@selector.compiler
|
2013-04-01 12:56:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_all_compiler_failures
|
2014-09-18 15:50:54 -05:00
|
|
|
@f << :clang << :llvm << :gcc << { :gcc => "4.8" } << { :gcc => "4.7" }
|
2014-06-10 22:43:47 -05:00
|
|
|
assert_raises(CompilerSelectionError) { actual_cc }
|
2013-04-01 12:56:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_no_compiler_failures
|
|
|
|
assert_equal @cc, actual_cc
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_fails_with_clang
|
|
|
|
@f << :clang
|
2013-06-28 01:38:09 -05:00
|
|
|
assert_equal :gcc, actual_cc
|
2013-04-01 12:56:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_fails_with_llvm
|
|
|
|
@f << :llvm
|
|
|
|
assert_equal :clang, actual_cc
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_fails_with_gcc
|
|
|
|
@f << :gcc
|
|
|
|
assert_equal :clang, actual_cc
|
|
|
|
end
|
|
|
|
|
2013-06-28 01:38:09 -05:00
|
|
|
def test_fails_with_non_apple_gcc
|
2014-08-30 23:11:02 -05:00
|
|
|
@f << { :gcc => "4.8" }
|
2013-06-28 01:38:09 -05:00
|
|
|
assert_equal :clang, actual_cc
|
|
|
|
end
|
|
|
|
|
2013-04-01 12:56:56 -05:00
|
|
|
def test_mixed_failures_1
|
2014-09-18 15:50:54 -05:00
|
|
|
@f << :clang << :gcc
|
|
|
|
assert_equal :llvm, actual_cc
|
2013-04-01 12:56:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_mixed_failures_2
|
2014-09-18 15:50:54 -05:00
|
|
|
@f << :clang << :llvm
|
|
|
|
assert_equal :gcc, actual_cc
|
2013-04-01 12:56:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_mixed_failures_3
|
2014-09-18 15:50:54 -05:00
|
|
|
@f << :gcc << :llvm
|
2013-04-01 12:56:56 -05:00
|
|
|
assert_equal :clang, actual_cc
|
|
|
|
end
|
|
|
|
|
2013-06-28 01:38:09 -05:00
|
|
|
def test_mixed_failures_4
|
2014-08-30 23:11:02 -05:00
|
|
|
@f << :clang << { :gcc => "4.8" }
|
2013-06-28 01:38:09 -05:00
|
|
|
assert_equal :gcc, actual_cc
|
|
|
|
end
|
|
|
|
|
2014-09-18 15:50:54 -05:00
|
|
|
def test_mixed_failures_5
|
|
|
|
@f << :clang << :gcc << :llvm << { :gcc => "4.8" }
|
|
|
|
assert_equal "gcc-4.7", actual_cc
|
2013-04-01 12:56:56 -05:00
|
|
|
end
|
|
|
|
|
2013-09-10 13:08:03 -07:00
|
|
|
def test_llvm_precedence
|
2013-06-28 01:38:09 -05:00
|
|
|
@f << :clang << :gcc
|
2013-09-10 13:08:03 -07:00
|
|
|
assert_equal :llvm, actual_cc
|
2013-06-28 01:38:09 -05:00
|
|
|
end
|
|
|
|
|
2013-04-01 12:56:56 -05:00
|
|
|
def test_missing_gcc
|
2014-08-30 23:41:12 -05:00
|
|
|
@versions.gcc_build_version = nil
|
2014-09-18 15:50:54 -05:00
|
|
|
@f << :clang << :llvm << { :gcc => "4.8" } << { :gcc => "4.7" }
|
2014-06-10 22:43:47 -05:00
|
|
|
assert_raises(CompilerSelectionError) { actual_cc }
|
2013-04-01 12:56:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_missing_llvm_and_gcc
|
2014-08-30 23:41:12 -05:00
|
|
|
@versions.gcc_build_version = @versions.llvm_build_version = nil
|
2014-09-18 15:50:54 -05:00
|
|
|
@f << :clang << { :gcc => "4.8" } << { :gcc => "4.7" }
|
2014-06-10 22:43:47 -05:00
|
|
|
assert_raises(CompilerSelectionError) { actual_cc }
|
2013-04-01 12:56:56 -05:00
|
|
|
end
|
|
|
|
end
|