aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test/test_compilers.rb
blob: 7ad6f2df75eaa4a291d4779759b0a7acf6a686da (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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
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