aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test/test_external_deps.rb
blob: ed6ce60ba6f0bde23d98ea6f317321fd1b7de2f3 (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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
require 'testing_env'

require 'extend/ARGV' # needs to be after test/unit to avoid conflict with OptionsParser
ARGV.extend(HomebrewArgvExtension)

require 'extend/string'
require 'test/testball'
require 'formula_installer'
require 'utils'


class BadPerlBall <TestBall
  depends_on "notapackage" => :perl

  def initialize name=nil
    super "uses_perl_ball"
  end
end

class GoodPerlBall <TestBall
  depends_on "ENV" => :perl

  def initialize name=nil
    super "uses_perl_ball"
  end
end

class BadPythonBall <TestBall
  depends_on "notapackage" => :python

  def initialize name=nil
    super "uses_python_ball"
  end
end

class GoodPythonBall <TestBall
  depends_on "datetime" => :python

  def initialize name=nil
    super "uses_python_ball"
  end
end

class BadRubyBall <TestBall
  depends_on "notapackage" => :ruby

  def initialize name=nil
    super "uses_ruby_ball"
  end
end

class GoodRubyBall <TestBall
  depends_on "date" => :ruby

  def initialize name=nil
    super "uses_ruby_ball"
  end
end

class BadJRubyBall <TestBall
  depends_on "notapackage" => :jruby

  def initialize name=nil
    super "uses_jruby_ball"
  end
end

class GoodJRubyBall <TestBall
  depends_on "date" => :jruby

  def initialize name=nil
    super "uses_jruby_ball"
  end
end

class BadChickenBall <TestBall
  depends_on "notapackage" => :chicken

  def initialize name=nil
    super "uses_chicken_ball"
  end
end

class GoodChickenBall <TestBall
  depends_on "extras" => :chicken

  def initialize name=nil
    super "uses_chicken_ball"
  end
end

class BadRubiniusBall <TestBall
  depends_on "notapackage" => :rbx

  def initialize name=nil
    super "uses_rubinius_ball"
  end
end

class GoodRubiniusBall <TestBall
  depends_on "date" => :rbx

  def intialize
    super "uses_rubinius_ball"
  end
end

class BadNodeBall <TestBall
  depends_on "notapackage" => :node

  def initialize
    super "uses_node_ball"
  end
end

class GoodNodeBall <TestBall
  depends_on "util" => :node

  def initialize
    super "uses_node_balls"
  end
end


class ExternalDepsTests < Test::Unit::TestCase
  def check_deps_fail f
    assert_raises(UnsatisfiedRequirement) do
      f.new.external_deps.each do |dep|
        raise UnsatisfiedRequirement.new(f, dep) unless dep.satisfied?
      end
    end
  end

  def check_deps_pass f
    assert_nothing_raised do
      f.new.external_deps.each do |dep|
        raise UnsatisfiedRequirement.new(f, dep) unless dep.satisfied?
      end
    end
  end


  def test_bad_perl_deps
    check_deps_fail BadPerlBall
  end

  def test_good_perl_deps
    check_deps_pass GoodPerlBall
  end

  def test_bad_python_deps
    check_deps_fail BadPythonBall
  end

  def test_good_python_deps
    check_deps_pass GoodPythonBall
  end

  def test_bad_ruby_deps
    check_deps_fail BadRubyBall
  end

  def test_good_ruby_deps
    check_deps_pass GoodRubyBall
  end

  # Only run these next two tests if jruby is installed.
  def test_bad_jruby_deps
    check_deps_fail BadJRubyBall unless `/usr/bin/which jruby`.chomp.empty?
  end

  def test_good_jruby_deps
    check_deps_pass GoodJRubyBall unless `/usr/bin/which jruby`.chomp.empty?
  end

  # Only run these next two tests if rubinius is installed.
  def test_bad_rubinius_deps
    check_deps_fail BadRubiniusBall unless `/usr/bin/which rbx`.chomp.empty?
  end

  def test_good_rubinius_deps
    check_deps_pass GoodRubiniusBall unless `/usr/bin/which rbx`.chomp.empty?
  end

  # Only run these next two tests if chicken scheme is installed.
  def test_bad_chicken_deps
    check_deps_fail BadChickenBall unless `/usr/bin/which csc`.chomp.empty?
  end

  def test_good_chicken_deps
    check_deps_pass GoodChickenBall unless `/usr/bin/which csc`.chomp.empty?
  end

  # Only run these next two tests if node.js is installed.
  def test_bad_node_deps
    check_deps_fail BadNodeBall unless `/usr/bin/which node`.chomp.empty?
  end

  def test_good_node_deps
    check_deps_pass GoodNodeBall unless `/usr/bin/which node`.chomp.empty?
  end
end