autotest 4.4.5 → 4.4.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,26 +0,0 @@
1
- module Autotest::AutoUpdate
2
- @@sleep_time, @@update_cmd, @@updater = 60, "svn up", nil
3
-
4
- def self.sleep_time= o
5
- @@sleep_time = o
6
- end
7
-
8
- def self.update_cmd= o
9
- @@update_cmd = o
10
- end
11
-
12
- Autotest.add_hook :run_command do |at|
13
- @@updater.kill if @@updater
14
- end
15
-
16
- Autotest.add_hook :ran_command do |at|
17
- @@updater = Thread.start do
18
- loop do
19
- puts "# Waiting for #{@@sleep_time} seconds before updating"
20
- sleep @@sleep_time
21
- puts "# Running #{@@update_cmd}"
22
- system @@update_cmd
23
- end
24
- end
25
- end
26
- end
@@ -1,9 +0,0 @@
1
- ##
2
- # this is for autotest plugin developers only...
3
-
4
- module Autotest::Once
5
- Autotest.add_hook :ran_command do |at|
6
- exit 0
7
- end
8
- end
9
-
@@ -1,27 +0,0 @@
1
- module Autotest::RCov
2
- @@command, @@options = "rcov", nil
3
-
4
- def self.command= o
5
- @@command = o
6
- end
7
-
8
- def self.pattern= o
9
- warn "RCov.pattern= no longer has any functionality. please remove."
10
- end
11
-
12
- def self.options= o
13
- @@options = o
14
- end
15
-
16
- Autotest.add_hook :all_good do |at|
17
- options = @@options ? "RCOVOPTS=\"#{@@options}\"" : ""
18
- system "rake #{@@command} #{options}"
19
- false
20
- end
21
-
22
- Autotest.add_hook :initialize do |at|
23
- at.add_exception 'coverage'
24
- at.add_exception 'coverage.info'
25
- false
26
- end
27
- end
@@ -1,12 +0,0 @@
1
- module Autotest::Restart
2
- Autotest.add_hook :updated do |at, *args|
3
- if args.flatten.include? ".autotest" then
4
- warn "Detected change to .autotest, restarting"
5
- cmd = %w(autotest)
6
- cmd << " -v" if $v
7
- cmd += ARGV
8
-
9
- exec(*cmd)
10
- end
11
- end
12
- end
@@ -1,9 +0,0 @@
1
- # -*- ruby -*-
2
-
3
- module Autotest::Timestamp
4
- Autotest.add_hook :waiting do
5
- puts
6
- puts "# Waiting since #{Time.now.strftime "%Y-%m-%d %H:%M:%S"}"
7
- puts
8
- end
9
- end
@@ -1,274 +0,0 @@
1
- require 'tempfile'
2
-
3
- ##
4
- # UnitDiff makes reading Test::Unit output easy and fun. Instead of a
5
- # confusing jumble of text with nearly unnoticable changes like this:
6
- #
7
- # 1) Failure:
8
- # test_to_gpoints(RouteTest) [test/unit/route_test.rb:29]:
9
- # <"new GPolyline([\n new GPoint( 47.00000, -122.00000),\n new GPoint( 46.5000
10
- # 0, -122.50000),\n new GPoint( 46.75000, -122.75000),\n new GPoint( 46.00000,
11
- # -123.00000)])"> expected but was
12
- # <"new Gpolyline([\n new GPoint( 47.00000, -122.00000),\n new GPoint( 46.5000
13
- # 0, -122.50000),\n new GPoint( 46.75000, -122.75000),\n new GPoint( 46.00000,
14
- # -123.00000)])">.
15
- #
16
- #
17
- # You get an easy-to-read diff output like this:
18
- #
19
- # 1) Failure:
20
- # test_to_gpoints(RouteTest) [test/unit/route_test.rb:29]:
21
- # 1c1
22
- # < new GPolyline([
23
- # ---
24
- # > new Gpolyline([
25
- #
26
- # == Usage
27
- #
28
- # test.rb | unit_diff [options]
29
- # options:
30
- # -b ignore whitespace differences
31
- # -c contextual diff
32
- # -h show usage
33
- # -k keep temp diff files around
34
- # -l prefix line numbers on the diffs
35
- # -u unified diff
36
- # -v display version
37
-
38
- class UnitDiff
39
-
40
- WINDOZE = /win32/ =~ RUBY_PLATFORM unless defined? WINDOZE
41
- DIFF = if WINDOZE
42
- 'diff.exe'
43
- else
44
- if system("gdiff", __FILE__, __FILE__)
45
- 'gdiff' # solaris and kin suck
46
- else
47
- 'diff'
48
- end
49
- end unless defined? DIFF
50
-
51
- ##
52
- # Handy wrapper for UnitDiff#unit_diff.
53
-
54
- def self.unit_diff
55
- trap 'INT' do exit 1 end
56
- puts UnitDiff.new.unit_diff
57
- end
58
-
59
- def parse_input(input, output)
60
- current = []
61
- data = []
62
- data << current
63
- print_lines = true
64
-
65
- term = "\nFinished".split(//).map { |c| c[0] }
66
- term_length = term.size
67
-
68
- old_sync = output.sync
69
- output.sync = true
70
- while line = input.gets
71
- case line
72
- when /^(Loaded suite|Started)/ then
73
- print_lines = true
74
- output.puts line
75
- chars = []
76
- while c = input.getc do
77
- output.putc c
78
- chars << c
79
- tail = chars[-term_length..-1]
80
- break if chars.size >= term_length and tail == term
81
- end
82
- output.puts input.gets # the rest of "Finished in..."
83
- output.puts
84
- next
85
- when /^\s*$/, /^\(?\s*\d+\) (Failure|Error):/, /^\d+\)/ then
86
- print_lines = false
87
- current = []
88
- data << current
89
- when /^Finished in \d/ then
90
- print_lines = false
91
- end
92
- output.puts line if print_lines
93
- current << line
94
- end
95
- output.sync = old_sync
96
- data = data.reject { |o| o == ["\n"] or o.empty? }
97
- footer = data.pop
98
-
99
- data.map do |result|
100
- break if result.find do |result_line|
101
- result_line =~ / expected( but was|, not)/
102
- end
103
-
104
- header = result.find do |result_line|
105
- result_line =~ /^\(?\s*\d+\) (Failure|Error):/
106
- end
107
-
108
- break unless header
109
-
110
- message_index = result.index(header) + 2
111
-
112
- result[message_index..-1] = result[message_index..-1].join
113
- end
114
-
115
- return data, footer
116
- end
117
-
118
- # Parses a single diff recording the header and what
119
- # was expected, and what was actually obtained.
120
- def parse_diff(result)
121
- header = []
122
- expect = []
123
- butwas = []
124
- footer = []
125
- found = false
126
- state = :header
127
-
128
- until result.empty? do
129
- case state
130
- when :header then
131
- header << result.shift
132
- state = :expect if result.first =~ /^<|^Expected/
133
- when :expect then
134
- case result.first
135
- when /^Expected (.*?) to equal (.*?):$/ then
136
- expect << $1
137
- butwas << $2
138
- state = :footer
139
- result.shift
140
- when /^Expected (.*?), not (.*)$/m then
141
- expect << $1
142
- butwas << $2
143
- state = :footer
144
- result.shift
145
- when /^Expected (.*?)$/ then
146
- expect << "#{$1}\n"
147
- result.shift
148
- when /^to equal / then
149
- state = :spec_butwas
150
- bw = result.shift.sub(/^to equal (.*):?$/, '\1')
151
- butwas << bw
152
- else
153
- state = :butwas if result.first.sub!(/ expected( but was|, not)/, '')
154
- expect << result.shift
155
- end
156
- when :butwas then
157
- butwas = result[0..-1]
158
- result.clear
159
- when :spec_butwas then
160
- if result.first =~ /^\s+\S+ at |^:\s*$/
161
- state = :footer
162
- else
163
- butwas << result.shift
164
- end
165
- when :footer then
166
- butwas.last.sub!(/:$/, '')
167
- footer = result.map {|l| l.chomp }
168
- result.clear
169
- else
170
- raise "unknown state #{state}"
171
- end
172
- end
173
-
174
- return header, expect, nil, footer if butwas.empty?
175
-
176
- expect.last.chomp!
177
- expect.first.sub!(/^<\"/, '')
178
- expect.last.sub!(/\">$/, '')
179
-
180
- butwas.last.chomp!
181
- butwas.last.chop! if butwas.last =~ /\.$/
182
- butwas.first.sub!( /^<\"/, '')
183
- butwas.last.sub!(/\">$/, '')
184
-
185
- return header, expect, butwas, footer
186
- end
187
-
188
- ##
189
- # Scans Test::Unit output +input+ looking for comparison failures and makes
190
- # them easily readable by passing them through diff.
191
-
192
- def unit_diff(input=ARGF, output=$stdout)
193
- $b = false unless defined? $b
194
- $c = false unless defined? $c
195
- $k = false unless defined? $k
196
- $u = false unless defined? $u
197
-
198
- data, footer = self.parse_input(input, output)
199
-
200
- output = []
201
-
202
- # Output
203
- data.each do |result|
204
- first = []
205
- second = []
206
-
207
- if result.first =~ /Error/ then
208
- output.push result.join('')
209
- next
210
- end
211
-
212
- prefix, expect, butwas, result_footer = parse_diff(result)
213
-
214
- output.push prefix.compact.map {|line| line.strip}.join("\n")
215
-
216
- if butwas then
217
- output.push self.diff(expect, butwas)
218
-
219
- output.push result_footer
220
- output.push ''
221
- else
222
- output.push expect.join('')
223
- end
224
- end
225
-
226
- if footer then
227
- footer.shift if footer.first.strip.empty?# unless footer.first.nil?
228
- output.push footer.compact.map {|line| line.strip}.join("\n")
229
- end
230
-
231
- return output.flatten.join("\n")
232
- end
233
-
234
- def diff expect, butwas
235
- output = nil
236
-
237
- Tempfile.open("expect") do |a|
238
- a.write(massage(expect))
239
- a.rewind
240
- Tempfile.open("butwas") do |b|
241
- b.write(massage(butwas))
242
- b.rewind
243
-
244
- diff_flags = $u ? "-u" : $c ? "-c" : ""
245
- diff_flags += " -b" if $b
246
-
247
- result = `#{DIFF} #{diff_flags} #{a.path} #{b.path}`
248
- output = if result.empty? then
249
- "[no difference--suspect ==]"
250
- else
251
- result.split(/\n/)
252
- end
253
-
254
- if $k then
255
- warn "moving #{a.path} to #{a.path}.keep"
256
- File.rename a.path, a.path + ".keep"
257
- warn "moving #{b.path} to #{b.path}.keep"
258
- File.rename b.path, b.path + ".keep"
259
- end
260
- end
261
- end
262
-
263
- output
264
- end
265
-
266
- def massage(data)
267
- count = 0
268
- # unescape newlines, strip <> from entire string
269
- data = data.join
270
- data = data.gsub(/\\n/, "\n").gsub(/0x[a-f0-9]+/m, '0xXXXXXX') + "\n"
271
- data += "\n" unless data[-1] == ?\n
272
- data
273
- end
274
- end
@@ -1,6 +0,0 @@
1
- $LOAD_PATH << File.join(File.dirname('..'), 'lib')
2
- $TESTING = true
3
-
4
- require 'stringio'
5
- require 'rubygems'
6
- require 'test/unit'
@@ -1,515 +0,0 @@
1
- require File.expand_path('test/helper')
2
- require 'autotest'
3
-
4
-
5
- # NOT TESTED:
6
- # class_run
7
- # add_sigint_handler
8
- # all_good
9
- # get_to_green
10
- # reset
11
- # ruby
12
- # run
13
- # run_tests
14
-
15
- class Autotest
16
- attr_reader :test_mappings, :exception_list
17
-
18
- def self.clear_hooks
19
- HOOKS.clear
20
- end
21
- end
22
-
23
- class TestAutotest < Test::Unit::TestCase
24
-
25
- def deny test, msg=nil
26
- if msg then
27
- assert ! test, msg
28
- else
29
- assert ! test
30
- end
31
- end unless respond_to? :deny
32
-
33
- RUBY = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']) unless defined? RUBY
34
-
35
- def setup
36
- @test_class = 'TestBlah'
37
- @test = 'test/test_blah.rb'
38
- @other_test = 'test/test_blah_other.rb'
39
- @impl = 'lib/blah.rb'
40
- @inner_test = 'test/outer/test_inner.rb'
41
- @outer_test = 'test/test_outer.rb'
42
- @inner_test_class = "TestOuter::TestInner"
43
-
44
- klassname = self.class.name.sub(/^Test/, '')
45
- klassname.sub!(/^(\w+)(Autotest)$/, '\2::\1') unless klassname == "Autotest"
46
- @a = klassname.split(/::/).inject(Object) { |k,n| k.const_get(n) }.new
47
- @a.output = StringIO.new
48
- @a.last_mtime = Time.at(2)
49
- @a.options[:bundle_exec] = nil
50
- @a.options[:parallel] = nil
51
-
52
- @files = {}
53
- @files[@impl] = Time.at(1)
54
- @files[@test] = Time.at(2)
55
-
56
- @a.find_order = @files.keys.sort
57
- end
58
-
59
- def test_add_exception
60
- current = util_exceptions
61
- @a.add_exception 'blah'
62
-
63
- actual = util_exceptions
64
- expect = current + ["blah"]
65
-
66
- assert_equal expect, actual
67
- end
68
-
69
- def test_add_mapping
70
- current = util_mappings
71
- @a.add_mapping(/blah/) do 42 end
72
-
73
- actual = util_mappings
74
- expect = current + [/blah/]
75
-
76
- assert_equal expect, actual
77
- end
78
-
79
- def test_add_mapping_front
80
- current = util_mappings
81
- @a.add_mapping(/blah/, :front) do 42 end
82
-
83
- actual = util_mappings
84
- expect = [/blah/] + current
85
-
86
- assert_equal expect, actual
87
- end
88
-
89
- def test_clear_exceptions
90
- test_add_exception
91
- @a.clear_exceptions
92
-
93
- actual = util_exceptions
94
- expect = []
95
-
96
- assert_equal expect, actual
97
- end
98
-
99
- def test_clear_mapping
100
- @a.clear_mappings
101
-
102
- actual = util_mappings
103
- expect = []
104
-
105
- assert_equal expect, actual
106
- end
107
-
108
- def test_consolidate_failures_experiment
109
- @files.clear
110
- @files[@impl] = Time.at(1)
111
- @files[@test] = Time.at(2)
112
-
113
- @a.find_order = @files.keys.sort
114
-
115
- input = [['test_fail1', @test_class],
116
- ['test_fail2', @test_class],
117
- ['test_error1', @test_class],
118
- ['test_error2', @test_class]]
119
- result = @a.consolidate_failures input
120
- expected = { @test => %w( test_fail1 test_fail2 test_error1 test_error2 ) }
121
- assert_equal expected, result
122
- end
123
-
124
- def test_consolidate_failures_green
125
- result = @a.consolidate_failures([])
126
- expected = {}
127
- assert_equal expected, result
128
- end
129
-
130
- def test_consolidate_failures_multiple_possibilities
131
- @files[@other_test] = Time.at(42)
132
- result = @a.consolidate_failures([['test_unmatched', @test_class]])
133
- expected = { @test => ['test_unmatched']}
134
- assert_equal expected, result
135
- expected = ""
136
- assert_equal expected, @a.output.string
137
- end
138
-
139
- def test_consolidate_failures_nested_classes
140
- @files.clear
141
- @files['lib/outer.rb'] = Time.at(5)
142
- @files['lib/outer/inner.rb'] = Time.at(5)
143
- @files[@inner_test] = Time.at(5)
144
- @files[@outer_test] = Time.at(5)
145
-
146
- @a.find_order = @files.keys.sort
147
-
148
- result = @a.consolidate_failures([['test_blah1', @inner_test_class]])
149
- expected = { @inner_test => ['test_blah1'] }
150
- assert_equal expected, result
151
- expected = ""
152
- assert_equal expected, @a.output.string
153
- end
154
-
155
- def test_consolidate_failures_no_match
156
- result = @a.consolidate_failures([['test_blah1', @test_class], ['test_blah2', @test_class], ['test_blah1', 'TestUnknown']])
157
- expected = {@test => ['test_blah1', 'test_blah2']}
158
- assert_equal expected, result
159
- expected = "Unable to map class TestUnknown to a file\n"
160
- assert_equal expected, @a.output.string
161
- end
162
-
163
- def test_consolidate_failures_red
164
- result = @a.consolidate_failures([['test_blah1', @test_class], ['test_blah2', @test_class]])
165
- expected = {@test => ['test_blah1', 'test_blah2']}
166
- assert_equal expected, result
167
- end
168
-
169
- def test_exceptions
170
- @a.clear_exceptions
171
- test_add_exception
172
- assert_equal(/blah/, @a.exceptions)
173
- end
174
-
175
- def test_exceptions_nil
176
- @a.clear_exceptions
177
- assert_nil @a.exceptions
178
- end
179
-
180
- # TODO: lots of filename edgecases for find_files_to_test
181
- def test_find_files_to_test
182
- @a.last_mtime = Time.at(0)
183
- assert @a.find_files_to_test(@files)
184
-
185
- @a.last_mtime = @files.values.sort.last + 1
186
- deny @a.find_files_to_test(@files)
187
- end
188
-
189
- def test_find_files_to_test_dunno
190
- empty = {}
191
-
192
- files = { "fooby.rb" => Time.at(42) }
193
- assert @a.find_files_to_test(files) # we find fooby,
194
- assert_equal empty, @a.files_to_test # but it isn't something to test
195
- assert_equal "No tests matched fooby.rb\n", @a.output.string
196
- end
197
-
198
- def test_find_files_to_test_lib
199
- # ensure we add test_blah.rb when blah.rb updates
200
- util_find_files_to_test(@impl, @test => [])
201
- end
202
-
203
- def test_find_files_to_test_no_change
204
- empty = {}
205
-
206
- # ensure world is virginal
207
- assert_equal empty, @a.files_to_test
208
-
209
- # ensure we do nothing when nothing changes...
210
- files = { @impl => @files[@impl] } # same time
211
- deny @a.find_files_to_test(files)
212
- assert_equal empty, @a.files_to_test
213
- assert_equal "", @a.output.string
214
-
215
- files = { @impl => @files[@impl] } # same time
216
- assert(! @a.find_files_to_test(files))
217
- assert_equal empty, @a.files_to_test
218
- assert_equal "", @a.output.string
219
- end
220
-
221
- def test_find_files_to_test_test
222
- # ensure we add test_blah.rb when test_blah.rb itself updates
223
- util_find_files_to_test(@test, @test => [])
224
- end
225
-
226
- def test_reorder_alpha
227
- @a.order = :alpha
228
- expected = @files.sort
229
-
230
- assert_equal expected, @a.reorder(@files)
231
- end
232
-
233
- def test_reorder_reverse
234
- @a.order = :reverse
235
- expected = @files.sort.reverse
236
-
237
- assert_equal expected, @a.reorder(@files)
238
- end
239
-
240
- def test_reorder_random
241
- @a.order = :random
242
-
243
- srand 42
244
- expected, size = @files.dup, @files.size
245
- expected = expected.sort_by { rand(size) }
246
-
247
- srand 42
248
- result = @a.reorder(@files.dup)
249
-
250
- assert_equal expected, result
251
- end
252
-
253
- def test_reorder_natural
254
- srand 42
255
-
256
- @files['lib/untested_blah.rb'] = Time.at(2)
257
- @a.find_order = @files.keys.sort_by { rand }
258
-
259
- @a.order = :natural
260
- expected = @a.find_order.map { |f| [f, @files[f]] }
261
-
262
- assert_equal expected, @a.reorder(@files)
263
- end
264
-
265
- def test_handle_results
266
- @a.files_to_test.clear
267
- @files.clear
268
- @files[@impl] = Time.at(1)
269
- @files[@test] = Time.at(2)
270
-
271
- @a.find_order = @files.keys.sort
272
-
273
- empty = {}
274
- assert_equal empty, @a.files_to_test, "must start empty"
275
-
276
- s1 = "Loaded suite -e
277
- Started
278
- ............
279
- Finished in 0.001655 seconds.
280
-
281
- 12 tests, 18 assertions, 0 failures, 0 errors
282
- "
283
-
284
- @a.handle_results(s1)
285
- assert_equal empty, @a.files_to_test, "must stay empty"
286
-
287
- s2 = "
288
- 1) Failure:
289
- test_fail1(#{@test_class}) [#{@test}:59]:
290
- 2) Failure:
291
- test_fail2(#{@test_class}) [#{@test}:60]:
292
- 3) Error:
293
- test_error1(#{@test_class}):
294
- 3) Error:
295
- test_error2(#{@test_class}):
296
-
297
- 12 tests, 18 assertions, 2 failures, 2 errors
298
- "
299
-
300
- @a.handle_results(s2)
301
- expected = { @test => %w( test_fail1 test_fail2 test_error1 test_error2 ) }
302
- assert_equal expected, @a.files_to_test
303
- assert @a.tainted
304
-
305
- @a.handle_results(s1)
306
- assert_equal empty, @a.files_to_test
307
-
308
- s3 = '
309
- /opt/bin/ruby -I.:lib:test -rubygems -e "%w[test/unit #{@test}].each { |f| require f }" | unit_diff -u
310
- -e:1:in `require\': ./#{@test}:23: parse error, unexpected tIDENTIFIER, expecting \'}\' (SyntaxError)
311
- settings_fields.each {|e| assert_equal e, version.send e.intern}
312
- ^ from -e:1
313
- from -e:1:in `each\'
314
- from -e:1
315
- '
316
- @a.files_to_test[@test] = Time.at(42)
317
- @files[@test] = []
318
- expected = { @test => Time.at(42) }
319
- assert_equal expected, @a.files_to_test
320
- @a.handle_results(s3)
321
- assert_equal expected, @a.files_to_test
322
- assert @a.tainted
323
- @a.tainted = false
324
-
325
- @a.handle_results(s1)
326
- assert_equal empty, @a.files_to_test
327
- deny @a.tainted
328
- end
329
-
330
- def test_hook_overlap_returning_false
331
- util_reset_hooks_returning false
332
-
333
- @a.hook :blah
334
-
335
- assert @a.instance_variable_get(:@blah1), "Hook1 should work on blah"
336
- assert @a.instance_variable_get(:@blah2), "Hook2 should work on blah"
337
- assert @a.instance_variable_get(:@blah3), "Hook3 should work on blah"
338
- end
339
-
340
- def test_hook_overlap_returning_true
341
- util_reset_hooks_returning true
342
-
343
- @a.hook :blah
344
-
345
- assert @a.instance_variable_get(:@blah1), "Hook1 should work on blah"
346
- deny @a.instance_variable_get(:@blah2), "Hook2 should NOT work on blah"
347
- deny @a.instance_variable_get(:@blah3), "Hook3 should NOT work on blah"
348
- end
349
-
350
- def test_hook_response
351
- Autotest.clear_hooks
352
- deny @a.hook(:blah)
353
-
354
- Autotest.add_hook(:blah) { false }
355
- deny @a.hook(:blah)
356
-
357
- Autotest.add_hook(:blah) { false }
358
- deny @a.hook(:blah)
359
-
360
- Autotest.add_hook(:blah) { true }
361
- assert @a.hook(:blah)
362
- end
363
-
364
- def test_make_test_cmd_basics
365
- f = {
366
- @test => [],
367
- 'test/test_fooby.rb' => [ 'test_something1', 'test_something2' ]
368
- }
369
-
370
- unit_diff = File.expand_path("#{File.dirname(__FILE__)}/../bin/unit_diff")
371
- pre = "#{RUBY} -I.:lib:test -rubygems"
372
- req = ".each { |f| require f }\""
373
- post = "| #{unit_diff} -u"
374
-
375
- expected = [
376
- "#{pre} -e \"['test/unit', '#{@test}']#{req} #{post}",
377
- "#{pre} test/test_fooby.rb -n \"/^(test_something1|test_something2)$/\" #{post}"
378
- ].join("; ")
379
-
380
- result = @a.make_test_cmd f
381
- assert_equal expected, result
382
- end
383
-
384
- def test_make_test_cmd_uses_bundle_exec_when_given
385
- @a.options[:bundle_exec] = true
386
- f = {
387
- @test => []
388
- }
389
- result = @a.make_test_cmd f
390
- assert_match /^bundle exec \//,result
391
- end
392
-
393
- def test_make_test_cmd_uses_bundle_exec_with_parallel_test
394
- @a.options[:bundle_exec] = true
395
- @a.options[:parallel] = true
396
- f = {
397
- 'test/a.rb' => [],
398
- 'test/b.rb' => []
399
- }
400
- result = @a.make_test_cmd f
401
- assert_match /^bundle exec parallel_test/, result
402
- end
403
-
404
- def test_make_test_cmd_uses_parallel_with_multiple_files
405
- @a.options[:parallel] = true
406
- f = {
407
- 'test/a.rb' => [],
408
- 'test/b.rb' => []
409
- }
410
- result = @a.make_test_cmd f
411
- assert_match /^parallel_test/, result
412
- end
413
-
414
- def test_make_test_cmd_does_not_use_parallel_for_single_file
415
- @a.options[:parallel] = true
416
- f = {
417
- 'test/a.rb' => []
418
- }
419
- result = @a.make_test_cmd f
420
- assert_equal nil, (/^parallel_test/ =~ result)
421
- end
422
-
423
- def test_path_to_classname
424
- # non-rails
425
- util_path_to_classname 'TestBlah', 'test/test_blah.rb'
426
- util_path_to_classname 'TestOuter::TestInner', 'test/outer/test_inner.rb'
427
- util_path_to_classname 'TestRuby2Ruby', 'test/test_ruby2ruby.rb'
428
- end
429
-
430
- def test_remove_exception
431
- test_add_exception
432
- current = util_exceptions
433
- @a.remove_exception 'blah'
434
-
435
- actual = util_exceptions
436
- expect = current - ["blah"]
437
-
438
- assert_equal expect, actual
439
- end
440
-
441
- def test_remove_mapping
442
- current = util_mappings
443
- @a.remove_mapping(/^lib\/.*\.rb$/)
444
-
445
- actual = util_mappings
446
- expect = current - [/^lib\/.*\.rb$/]
447
-
448
- assert_equal expect, actual
449
- end
450
-
451
- def test_test_files_for
452
- assert_equal [@test], @a.test_files_for(@impl)
453
- assert_equal [@test], @a.test_files_for(@test)
454
-
455
- assert_equal [], @a.test_files_for('test/test_unknown.rb')
456
- assert_equal [], @a.test_files_for('lib/unknown.rb')
457
- assert_equal [], @a.test_files_for('unknown.rb')
458
- assert_equal [], @a.test_files_for('test_unknown.rb')
459
- end
460
-
461
- def test_testlib
462
- assert_equal "test/unit", @a.testlib
463
-
464
- @a.testlib = "MONKEY"
465
- assert_equal "MONKEY", @a.testlib
466
-
467
- f = { @test => [], "test/test_fooby.rb" => %w(first second) }
468
- assert_match @a.testlib, @a.make_test_cmd(f)
469
- end
470
-
471
- def util_exceptions
472
- @a.exception_list.sort_by { |r| r.to_s }
473
- end
474
-
475
- def util_find_files_to_test(f, expected)
476
- t = @a.last_mtime
477
- files = { f => t + 1 }
478
-
479
- assert @a.find_files_to_test(files)
480
- assert_equal expected, @a.files_to_test
481
- assert_equal t, @a.last_mtime
482
- assert_equal "", @a.output.string
483
- end
484
-
485
- def util_mappings
486
- @a.test_mappings.map { |k,v| k }
487
- end
488
-
489
- def util_path_to_classname(e,i)
490
- assert_equal e, @a.path_to_classname(i)
491
- end
492
-
493
- def util_reset_hooks_returning val
494
- Autotest.clear_hooks
495
-
496
- @a.instance_variable_set :@blah1, false
497
- @a.instance_variable_set :@blah2, false
498
- @a.instance_variable_set :@blah3, false
499
-
500
- Autotest.add_hook(:blah) do |at|
501
- at.instance_variable_set :@blah1, true
502
- val
503
- end
504
-
505
- Autotest.add_hook(:blah) do |at|
506
- at.instance_variable_set :@blah2, true
507
- val
508
- end
509
-
510
- Autotest.add_hook(:blah) do |at|
511
- at.instance_variable_set :@blah3, true
512
- val
513
- end
514
- end
515
- end