autotest 4.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,26 @@
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
@@ -0,0 +1,9 @@
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
+
@@ -0,0 +1,22 @@
1
+ module Autotest::RCov
2
+ @@command, @@pattern = "rcov", "test/*.rb"
3
+
4
+ def self.command= o
5
+ @@command = o
6
+ end
7
+
8
+ def self.pattern= o
9
+ @@pattern = o
10
+ end
11
+
12
+ Autotest.add_hook :all_good do |at|
13
+ system "rake #{@@command} PATTERN=#{@@pattern}"
14
+ end
15
+
16
+ Autotest.add_hook :initialize do |at|
17
+ at.add_exception 'coverage'
18
+ at.add_exception 'coverage.info'
19
+ false
20
+ end
21
+ end
22
+
@@ -0,0 +1,11 @@
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 = "autotest"
6
+ cmd << " -v" if $v
7
+
8
+ exec cmd
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
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
@@ -0,0 +1,258 @@
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
+ return data, footer
100
+ end
101
+
102
+ # Parses a single diff recording the header and what
103
+ # was expected, and what was actually obtained.
104
+ def parse_diff(result)
105
+ header = []
106
+ expect = []
107
+ butwas = []
108
+ footer = []
109
+ found = false
110
+ state = :header
111
+
112
+ until result.empty? do
113
+ case state
114
+ when :header then
115
+ header << result.shift
116
+ state = :expect if result.first =~ /^<|^Expected/
117
+ when :expect then
118
+ case result.first
119
+ when /^Expected (.*?) to equal (.*?):$/ then
120
+ expect << $1
121
+ butwas << $2
122
+ state = :footer
123
+ result.shift
124
+ when /^Expected (.*?), not (.*)$/m then
125
+ expect << $1
126
+ butwas << $2
127
+ state = :footer
128
+ result.shift
129
+ when /^Expected (.*?)$/ then
130
+ expect << "#{$1}\n"
131
+ result.shift
132
+ when /^to equal / then
133
+ state = :spec_butwas
134
+ bw = result.shift.sub(/^to equal (.*):?$/, '\1')
135
+ butwas << bw
136
+ else
137
+ state = :butwas if result.first.sub!(/ expected( but was|, not)/, '')
138
+ expect << result.shift
139
+ end
140
+ when :butwas then
141
+ butwas = result[0..-1]
142
+ result.clear
143
+ when :spec_butwas then
144
+ if result.first =~ /^\s+\S+ at |^:\s*$/
145
+ state = :footer
146
+ else
147
+ butwas << result.shift
148
+ end
149
+ when :footer then
150
+ butwas.last.sub!(/:$/, '')
151
+ footer = result.map {|l| l.chomp }
152
+ result.clear
153
+ else
154
+ raise "unknown state #{state}"
155
+ end
156
+ end
157
+
158
+ return header, expect, nil, footer if butwas.empty?
159
+
160
+ expect.last.chomp!
161
+ expect.first.sub!(/^<\"/, '')
162
+ expect.last.sub!(/\">$/, '')
163
+
164
+ butwas.last.chomp!
165
+ butwas.last.chop! if butwas.last =~ /\.$/
166
+ butwas.first.sub!( /^<\"/, '')
167
+ butwas.last.sub!(/\">$/, '')
168
+
169
+ return header, expect, butwas, footer
170
+ end
171
+
172
+ ##
173
+ # Scans Test::Unit output +input+ looking for comparison failures and makes
174
+ # them easily readable by passing them through diff.
175
+
176
+ def unit_diff(input=ARGF, output=$stdout)
177
+ $b = false unless defined? $b
178
+ $c = false unless defined? $c
179
+ $k = false unless defined? $k
180
+ $u = false unless defined? $u
181
+
182
+ data, footer = self.parse_input(input, output)
183
+
184
+ output = []
185
+
186
+ # Output
187
+ data.each do |result|
188
+ first = []
189
+ second = []
190
+
191
+ if result.first =~ /Error/ then
192
+ output.push result.join('')
193
+ next
194
+ end
195
+
196
+ prefix, expect, butwas, result_footer = parse_diff(result)
197
+
198
+ output.push prefix.compact.map {|line| line.strip}.join("\n")
199
+
200
+ if butwas then
201
+ output.push self.diff(expect, butwas)
202
+
203
+ output.push result_footer
204
+ output.push ''
205
+ else
206
+ output.push expect.join('')
207
+ end
208
+ end
209
+
210
+ if footer then
211
+ footer.shift if footer.first.strip.empty?# unless footer.first.nil?
212
+ output.push footer.compact.map {|line| line.strip}.join("\n")
213
+ end
214
+
215
+ return output.flatten.join("\n")
216
+ end
217
+
218
+ def diff expect, butwas
219
+ output = nil
220
+
221
+ Tempfile.open("expect") do |a|
222
+ a.write(massage(expect))
223
+ a.rewind
224
+ Tempfile.open("butwas") do |b|
225
+ b.write(massage(butwas))
226
+ b.rewind
227
+
228
+ diff_flags = $u ? "-u" : $c ? "-c" : ""
229
+ diff_flags += " -b" if $b
230
+
231
+ result = `#{DIFF} #{diff_flags} #{a.path} #{b.path}`
232
+ output = if result.empty? then
233
+ "[no difference--suspect ==]"
234
+ else
235
+ result.split(/\n/)
236
+ end
237
+
238
+ if $k then
239
+ warn "moving #{a.path} to #{a.path}.keep"
240
+ File.rename a.path, a.path + ".keep"
241
+ warn "moving #{b.path} to #{b.path}.keep"
242
+ File.rename b.path, b.path + ".keep"
243
+ end
244
+ end
245
+ end
246
+
247
+ output
248
+ end
249
+
250
+ def massage(data)
251
+ count = 0
252
+ # unescape newlines, strip <> from entire string
253
+ data = data.join
254
+ data = data.gsub(/\\n/, "\n").gsub(/0x[a-f0-9]+/m, '0xXXXXXX') + "\n"
255
+ data += "\n" unless data[-1] == ?\n
256
+ data
257
+ end
258
+ end
@@ -0,0 +1,6 @@
1
+ $LOAD_PATH << File.join(File.dirname('..'),'lib')
2
+ $TESTING = true
3
+
4
+ require 'stringio'
5
+ require 'rubygems'
6
+ require 'test/unit'
@@ -0,0 +1,464 @@
1
+ require '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
+
50
+ @files = {}
51
+ @files[@impl] = Time.at(1)
52
+ @files[@test] = Time.at(2)
53
+
54
+ @a.find_order = @files.keys.sort
55
+ end
56
+
57
+ def test_add_exception
58
+ current = util_exceptions
59
+ @a.add_exception 'blah'
60
+
61
+ actual = util_exceptions
62
+ expect = current + ["blah"]
63
+
64
+ assert_equal expect, actual
65
+ end
66
+
67
+ def test_add_mapping
68
+ current = util_mappings
69
+ @a.add_mapping(/blah/) do 42 end
70
+
71
+ actual = util_mappings
72
+ expect = current + [/blah/]
73
+
74
+ assert_equal expect, actual
75
+ end
76
+
77
+ def test_add_mapping_front
78
+ current = util_mappings
79
+ @a.add_mapping(/blah/, :front) do 42 end
80
+
81
+ actual = util_mappings
82
+ expect = [/blah/] + current
83
+
84
+ assert_equal expect, actual
85
+ end
86
+
87
+ def test_clear_exceptions
88
+ test_add_exception
89
+ @a.clear_exceptions
90
+
91
+ actual = util_exceptions
92
+ expect = []
93
+
94
+ assert_equal expect, actual
95
+ end
96
+
97
+ def test_clear_mapping
98
+ @a.clear_mappings
99
+
100
+ actual = util_mappings
101
+ expect = []
102
+
103
+ assert_equal expect, actual
104
+ end
105
+
106
+ def test_consolidate_failures_experiment
107
+ @files.clear
108
+ @files[@impl] = Time.at(1)
109
+ @files[@test] = Time.at(2)
110
+
111
+ @a.find_order = @files.keys.sort
112
+
113
+ input = [['test_fail1', @test_class], ['test_fail2', @test_class], ['test_error1', @test_class], ['test_error2', @test_class]]
114
+ result = @a.consolidate_failures input
115
+ expected = { @test => %w( test_fail1 test_fail2 test_error1 test_error2 ) }
116
+ assert_equal expected, result
117
+ end
118
+
119
+ def test_consolidate_failures_green
120
+ result = @a.consolidate_failures([])
121
+ expected = {}
122
+ assert_equal expected, result
123
+ end
124
+
125
+ def test_consolidate_failures_multiple_possibilities
126
+ @files[@other_test] = Time.at(42)
127
+ result = @a.consolidate_failures([['test_unmatched', @test_class]])
128
+ expected = { @test => ['test_unmatched']}
129
+ assert_equal expected, result
130
+ expected = ""
131
+ assert_equal expected, @a.output.string
132
+ end
133
+
134
+ def test_consolidate_failures_nested_classes
135
+ @files.clear
136
+ @files['lib/outer.rb'] = Time.at(5)
137
+ @files['lib/outer/inner.rb'] = Time.at(5)
138
+ @files[@inner_test] = Time.at(5)
139
+ @files[@outer_test] = Time.at(5)
140
+
141
+ @a.find_order = @files.keys.sort
142
+
143
+ result = @a.consolidate_failures([['test_blah1', @inner_test_class]])
144
+ expected = { @inner_test => ['test_blah1'] }
145
+ assert_equal expected, result
146
+ expected = ""
147
+ assert_equal expected, @a.output.string
148
+ end
149
+
150
+ def test_consolidate_failures_no_match
151
+ result = @a.consolidate_failures([['test_blah1', @test_class], ['test_blah2', @test_class], ['test_blah1', 'TestUnknown']])
152
+ expected = {@test => ['test_blah1', 'test_blah2']}
153
+ assert_equal expected, result
154
+ expected = "Unable to map class TestUnknown to a file\n"
155
+ assert_equal expected, @a.output.string
156
+ end
157
+
158
+ def test_consolidate_failures_red
159
+ result = @a.consolidate_failures([['test_blah1', @test_class], ['test_blah2', @test_class]])
160
+ expected = {@test => ['test_blah1', 'test_blah2']}
161
+ assert_equal expected, result
162
+ end
163
+
164
+ def test_exceptions
165
+ @a.clear_exceptions
166
+ test_add_exception
167
+ assert_equal(/blah/, @a.exceptions)
168
+ end
169
+
170
+ def test_exceptions_nil
171
+ @a.clear_exceptions
172
+ assert_nil @a.exceptions
173
+ end
174
+
175
+ # TODO: lots of filename edgecases for find_files_to_test
176
+ def test_find_files_to_test
177
+ @a.last_mtime = Time.at(0)
178
+ assert @a.find_files_to_test(@files)
179
+
180
+ @a.last_mtime = @files.values.sort.last + 1
181
+ deny @a.find_files_to_test(@files)
182
+ end
183
+
184
+ def test_find_files_to_test_dunno
185
+ empty = {}
186
+
187
+ files = { "fooby.rb" => Time.at(42) }
188
+ assert @a.find_files_to_test(files) # we find fooby,
189
+ assert_equal empty, @a.files_to_test # but it isn't something to test
190
+ assert_equal "No tests matched fooby.rb\n", @a.output.string
191
+ end
192
+
193
+ def test_find_files_to_test_lib
194
+ # ensure we add test_blah.rb when blah.rb updates
195
+ util_find_files_to_test(@impl, @test => [])
196
+ end
197
+
198
+ def test_find_files_to_test_no_change
199
+ empty = {}
200
+
201
+ # ensure world is virginal
202
+ assert_equal empty, @a.files_to_test
203
+
204
+ # ensure we do nothing when nothing changes...
205
+ files = { @impl => @files[@impl] } # same time
206
+ deny @a.find_files_to_test(files)
207
+ assert_equal empty, @a.files_to_test
208
+ assert_equal "", @a.output.string
209
+
210
+ files = { @impl => @files[@impl] } # same time
211
+ assert(! @a.find_files_to_test(files))
212
+ assert_equal empty, @a.files_to_test
213
+ assert_equal "", @a.output.string
214
+ end
215
+
216
+ def test_find_files_to_test_test
217
+ # ensure we add test_blah.rb when test_blah.rb itself updates
218
+ util_find_files_to_test(@test, @test => [])
219
+ end
220
+
221
+ def test_reorder_alpha
222
+ @a.order = :alpha
223
+ expected = @files.sort
224
+
225
+ assert_equal expected, @a.reorder(@files)
226
+ end
227
+
228
+ def test_reorder_reverse
229
+ @a.order = :reverse
230
+ expected = @files.sort.reverse
231
+
232
+ assert_equal expected, @a.reorder(@files)
233
+ end
234
+
235
+ def test_reorder_random
236
+ @a.order = :random
237
+
238
+ srand 42
239
+ expected, size = @files.dup, @files.size
240
+ expected = expected.sort_by { rand(size) }
241
+
242
+ srand 42
243
+ result = @a.reorder(@files.dup)
244
+
245
+ assert_equal expected, result
246
+ end
247
+
248
+ def test_reorder_natural
249
+ srand 42
250
+
251
+ @files['lib/untested_blah.rb'] = Time.at(2)
252
+ @a.find_order = @files.keys.sort_by { rand }
253
+
254
+ @a.order = :natural
255
+ expected = @a.find_order.map { |f| [f, @files[f]] }
256
+
257
+ assert_equal expected, @a.reorder(@files)
258
+ end
259
+
260
+ def test_handle_results
261
+ @a.files_to_test.clear
262
+ @files.clear
263
+ @files[@impl] = Time.at(1)
264
+ @files[@test] = Time.at(2)
265
+
266
+ @a.find_order = @files.keys.sort
267
+
268
+ empty = {}
269
+ assert_equal empty, @a.files_to_test, "must start empty"
270
+
271
+ s1 = "Loaded suite -e
272
+ Started
273
+ ............
274
+ Finished in 0.001655 seconds.
275
+
276
+ 12 tests, 18 assertions, 0 failures, 0 errors
277
+ "
278
+
279
+ @a.handle_results(s1)
280
+ assert_equal empty, @a.files_to_test, "must stay empty"
281
+
282
+ s2 = "
283
+ 1) Failure:
284
+ test_fail1(#{@test_class}) [#{@test}:59]:
285
+ 2) Failure:
286
+ test_fail2(#{@test_class}) [#{@test}:60]:
287
+ 3) Error:
288
+ test_error1(#{@test_class}):
289
+ 3) Error:
290
+ test_error2(#{@test_class}):
291
+
292
+ 12 tests, 18 assertions, 2 failures, 2 errors
293
+ "
294
+
295
+ @a.handle_results(s2)
296
+ expected = { @test => %w( test_fail1 test_fail2 test_error1 test_error2 ) }
297
+ assert_equal expected, @a.files_to_test
298
+ assert @a.tainted
299
+
300
+ @a.handle_results(s1)
301
+ assert_equal empty, @a.files_to_test
302
+
303
+ s3 = '
304
+ /opt/bin/ruby -I.:lib:test -rubygems -e "%w[test/unit #{@test}].each { |f| require f }" | unit_diff -u
305
+ -e:1:in `require\': ./#{@test}:23: parse error, unexpected tIDENTIFIER, expecting \'}\' (SyntaxError)
306
+ settings_fields.each {|e| assert_equal e, version.send e.intern}
307
+ ^ from -e:1
308
+ from -e:1:in `each\'
309
+ from -e:1
310
+ '
311
+ @a.files_to_test[@test] = Time.at(42)
312
+ @files[@test] = []
313
+ expected = { @test => Time.at(42) }
314
+ assert_equal expected, @a.files_to_test
315
+ @a.handle_results(s3)
316
+ assert_equal expected, @a.files_to_test
317
+ assert @a.tainted
318
+ @a.tainted = false
319
+
320
+ @a.handle_results(s1)
321
+ assert_equal empty, @a.files_to_test
322
+ deny @a.tainted
323
+ end
324
+
325
+ def test_hook_overlap_returning_false
326
+ util_reset_hooks_returning false
327
+
328
+ @a.hook :blah
329
+
330
+ assert @a.instance_variable_get(:@blah1), "Hook1 should work on blah"
331
+ assert @a.instance_variable_get(:@blah2), "Hook2 should work on blah"
332
+ assert @a.instance_variable_get(:@blah3), "Hook3 should work on blah"
333
+ end
334
+
335
+ def test_hook_overlap_returning_true
336
+ util_reset_hooks_returning true
337
+
338
+ @a.hook :blah
339
+
340
+ assert @a.instance_variable_get(:@blah1), "Hook1 should work on blah"
341
+ deny @a.instance_variable_get(:@blah2), "Hook2 should NOT work on blah"
342
+ deny @a.instance_variable_get(:@blah3), "Hook3 should NOT work on blah"
343
+ end
344
+
345
+ def test_hook_response
346
+ Autotest.clear_hooks
347
+ deny @a.hook(:blah)
348
+
349
+ Autotest.add_hook(:blah) { false }
350
+ deny @a.hook(:blah)
351
+
352
+ Autotest.add_hook(:blah) { false }
353
+ deny @a.hook(:blah)
354
+
355
+ Autotest.add_hook(:blah) { true }
356
+ assert @a.hook(:blah)
357
+ end
358
+
359
+ def test_make_test_cmd
360
+ f = {
361
+ @test => [],
362
+ 'test/test_fooby.rb' => [ 'test_something1', 'test_something2' ]
363
+ }
364
+
365
+ expected = [ "#{RUBY} -I.:lib:test -rubygems -e \"%w[test/unit #{@test}].each { |f| require f }\" | unit_diff -u",
366
+ "#{RUBY} -I.:lib:test -rubygems test/test_fooby.rb -n \"/^(test_something1|test_something2)$/\" | unit_diff -u" ].join("; ")
367
+
368
+ result = @a.make_test_cmd f
369
+ assert_equal expected, result
370
+ end
371
+
372
+ def test_path_to_classname
373
+ # non-rails
374
+ util_path_to_classname 'TestBlah', 'test/test_blah.rb'
375
+ util_path_to_classname 'TestOuter::TestInner', 'test/outer/test_inner.rb'
376
+ util_path_to_classname 'TestRuby2Ruby', 'test/test_ruby2ruby.rb'
377
+ end
378
+
379
+ def test_remove_exception
380
+ test_add_exception
381
+ current = util_exceptions
382
+ @a.remove_exception 'blah'
383
+
384
+ actual = util_exceptions
385
+ expect = current - ["blah"]
386
+
387
+ assert_equal expect, actual
388
+ end
389
+
390
+ def test_remove_mapping
391
+ current = util_mappings
392
+ @a.remove_mapping(/^lib\/.*\.rb$/)
393
+
394
+ actual = util_mappings
395
+ expect = current - [/^lib\/.*\.rb$/]
396
+
397
+ assert_equal expect, actual
398
+ end
399
+
400
+ def test_test_files_for
401
+ assert_equal [@test], @a.test_files_for(@impl)
402
+ assert_equal [@test], @a.test_files_for(@test)
403
+
404
+ assert_equal [], @a.test_files_for('test/test_unknown.rb')
405
+ assert_equal [], @a.test_files_for('lib/unknown.rb')
406
+ assert_equal [], @a.test_files_for('unknown.rb')
407
+ assert_equal [], @a.test_files_for('test_unknown.rb')
408
+ end
409
+
410
+ def test_testlib
411
+ assert_equal "test/unit", @a.testlib
412
+
413
+ @a.testlib = "MONKEY"
414
+ assert_equal "MONKEY", @a.testlib
415
+
416
+ f = { @test => [], "test/test_fooby.rb" => %w(first second) }
417
+ assert_match @a.testlib, @a.make_test_cmd(f)
418
+ end
419
+
420
+ def util_exceptions
421
+ @a.exception_list.sort_by { |r| r.to_s }
422
+ end
423
+
424
+ def util_find_files_to_test(f, expected)
425
+ t = @a.last_mtime
426
+ files = { f => t + 1 }
427
+
428
+ assert @a.find_files_to_test(files)
429
+ assert_equal expected, @a.files_to_test
430
+ assert_equal t, @a.last_mtime
431
+ assert_equal "", @a.output.string
432
+ end
433
+
434
+ def util_mappings
435
+ @a.test_mappings.map { |k,v| k }
436
+ end
437
+
438
+ def util_path_to_classname(e,i)
439
+ assert_equal e, @a.path_to_classname(i)
440
+ end
441
+
442
+ def util_reset_hooks_returning val
443
+ Autotest.clear_hooks
444
+
445
+ @a.instance_variable_set :@blah1, false
446
+ @a.instance_variable_set :@blah2, false
447
+ @a.instance_variable_set :@blah3, false
448
+
449
+ Autotest.add_hook(:blah) do |at|
450
+ at.instance_variable_set :@blah1, true
451
+ val
452
+ end
453
+
454
+ Autotest.add_hook(:blah) do |at|
455
+ at.instance_variable_set :@blah2, true
456
+ val
457
+ end
458
+
459
+ Autotest.add_hook(:blah) do |at|
460
+ at.instance_variable_set :@blah3, true
461
+ val
462
+ end
463
+ end
464
+ end