aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test/test_compilers.rb
blob: 19eb6943496e59e77227557d65e6bbef159650a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
require 'testing_env'
require 'test/testball'

class CompilerTests < Test::Unit::TestCase
  def setup
    %w{HOMEBREW_USE_CLANG HOMEBREW_USE_LLVM HOMEBREW_USE_GCC}.each { |v| ENV.delete(v) }
  end

  def teardown
    ENV.send MacOS.default_compiler
  end

  def test_llvm_failure
    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
  end

  def test_all_compiler_failures
    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
  end

  def test_no_compiler_failures
    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 nil then f.fails_with? :gcc
      else !(f.fails_with? :gcc)
      end

    cs.select_compiler

    assert_equal MacOS.default_compiler, ENV.compiler
  end

  def test_mixed_compiler_failures
    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
  end

  def test_more_mixed_compiler_failures
    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
  end

  def test_even_more_mixed_compiler_failures
    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 nil 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
  end

  def test_block_with_no_build_compiler_failures
    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
  end
end