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
|
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'
require 'hardware'
class AbstractDownloadStrategy
attr_reader :url
end
class MostlyAbstractFormula <Formula
@url=''
@homepage = 'http://example.com/'
end
class TestBallOverrideBrew <Formula
def initialize
super "foo"
end
def brew
end
end
class FormulaTests < Test::Unit::TestCase
def test_prefix
nostdout do
TestBall.new.brew do |f|
assert_equal File.expand_path(f.prefix), (HOMEBREW_CELLAR+f.name+'0.1').to_s
assert_kind_of Pathname, f.prefix
end
end
end
def test_class_naming
assert_equal 'ShellFm', Formula.class_s('shell.fm')
assert_equal 'Fooxx', Formula.class_s('foo++')
assert_equal 'SLang', Formula.class_s('s-lang')
assert_equal 'PkgConfig', Formula.class_s('pkg-config')
assert_equal 'FooBar', Formula.class_s('foo_bar')
end
def test_cant_override_brew
assert_raises(RuntimeError) { TestBallOverrideBrew.new }
end
def test_abstract_formula
f=MostlyAbstractFormula.new
assert_equal '__UNKNOWN__', f.name
assert_raises(RuntimeError) { f.prefix }
nostdout { assert_raises(RuntimeError) { f.brew } }
end
def test_mirror_support
HOMEBREW_CACHE.mkpath unless HOMEBREW_CACHE.exist?
f = TestBallWithMirror.new
tarball, downloader = f.fetch
assert_equal f.url, "file:///#{TEST_FOLDER}/bad_url/testball-0.1.tbz"
assert_equal downloader.url, "file:///#{TEST_FOLDER}/tarballs/testball-0.1.tbz"
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 ENV.compiler, case MacOS.clang_build_version
when 0..210 then :gcc
else :clang
end
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
|