test-unit 1.2.3 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. data/History.txt +27 -0
  2. data/Manifest.txt +30 -8
  3. data/README.txt +9 -4
  4. data/Rakefile +16 -1
  5. data/bin/testrb +0 -0
  6. data/lib/test/unit/assertions.rb +148 -48
  7. data/lib/test/unit/attribute.rb +125 -0
  8. data/lib/test/unit/autorunner.rb +101 -71
  9. data/lib/test/unit/collector/descendant.rb +23 -0
  10. data/lib/test/unit/collector/dir.rb +1 -1
  11. data/lib/test/unit/collector/load.rb +135 -0
  12. data/lib/test/unit/color.rb +61 -0
  13. data/lib/test/unit/diff.rb +524 -0
  14. data/lib/test/unit/error.rb +70 -2
  15. data/lib/test/unit/exceptionhandler.rb +39 -0
  16. data/lib/test/unit/failure.rb +63 -4
  17. data/lib/test/unit/fixture.rb +185 -0
  18. data/lib/test/unit/notification.rb +125 -0
  19. data/lib/test/unit/omission.rb +143 -0
  20. data/lib/test/unit/pending.rb +146 -0
  21. data/lib/test/unit/priority.rb +146 -0
  22. data/lib/test/unit/runner/console.rb +46 -0
  23. data/lib/test/unit/runner/emacs.rb +8 -0
  24. data/lib/test/unit/testcase.rb +193 -76
  25. data/lib/test/unit/testresult.rb +37 -28
  26. data/lib/test/unit/testsuite.rb +35 -1
  27. data/lib/test/unit/ui/console/outputlevel.rb +14 -0
  28. data/lib/test/unit/ui/console/testrunner.rb +96 -28
  29. data/lib/test/unit/ui/emacs/testrunner.rb +49 -0
  30. data/lib/test/unit/ui/testrunner.rb +20 -0
  31. data/lib/test/unit/ui/testrunnermediator.rb +28 -19
  32. data/lib/test/unit/ui/testrunnerutilities.rb +2 -7
  33. data/lib/test/unit/util/backtracefilter.rb +2 -1
  34. data/lib/test/unit/version.rb +1 -1
  35. data/test/collector/test_descendant.rb +135 -0
  36. data/test/collector/test_load.rb +333 -0
  37. data/test/run-test.rb +13 -0
  38. data/test/test_assertions.rb +221 -56
  39. data/test/test_attribute.rb +86 -0
  40. data/test/test_color.rb +37 -0
  41. data/test/test_diff.rb +477 -0
  42. data/test/test_emacs_runner.rb +60 -0
  43. data/test/test_fixture.rb +275 -0
  44. data/test/test_notification.rb +33 -0
  45. data/test/test_omission.rb +81 -0
  46. data/test/test_pending.rb +70 -0
  47. data/test/test_priority.rb +89 -0
  48. data/test/test_testcase.rb +160 -5
  49. data/test/test_testresult.rb +61 -52
  50. data/test/testunit_test_util.rb +14 -0
  51. data/test/ui/test_testrunmediator.rb +20 -0
  52. metadata +53 -23
  53. data/lib/test/unit/ui/fox/testrunner.rb +0 -268
  54. data/lib/test/unit/ui/gtk/testrunner.rb +0 -416
  55. data/lib/test/unit/ui/gtk2/testrunner.rb +0 -465
  56. data/lib/test/unit/ui/tk/testrunner.rb +0 -260
  57. data/test/runit/test_assert.rb +0 -402
  58. data/test/runit/test_testcase.rb +0 -91
  59. data/test/runit/test_testresult.rb +0 -144
  60. data/test/runit/test_testsuite.rb +0 -49
@@ -0,0 +1,135 @@
1
+ require 'test/unit'
2
+ require 'test/unit/collector/descendant'
3
+
4
+ class TestUnitCollectorDescendant < Test::Unit::TestCase
5
+ def setup
6
+ @previous_descendants = Test::Unit::TestCase::DESCENDANTS.dup
7
+ Test::Unit::TestCase::DESCENDANTS.clear
8
+
9
+ @test_case1 = Class.new(Test::Unit::TestCase) do
10
+ def self.name
11
+ "test-case1"
12
+ end
13
+
14
+ def test_1
15
+ end
16
+
17
+ def test_2
18
+ end
19
+ end
20
+
21
+ @test_case2 = Class.new(Test::Unit::TestCase) do
22
+ def self.name
23
+ "test-case2"
24
+ end
25
+
26
+ def test_0
27
+ end
28
+ end
29
+
30
+ @no_test_case = Class.new do
31
+ def self.name
32
+ "no-test-case"
33
+ end
34
+
35
+ def test_4
36
+ end
37
+ end
38
+ end
39
+
40
+ def teardown
41
+ Test::Unit::TestCase::DESCENDANTS.replace(@previous_descendants)
42
+ end
43
+
44
+ def test_basic_collection
45
+ assert_collect(full_suite("name"), "name")
46
+
47
+ assert_collect(full_suite("name"), "name") do |collector|
48
+ collector.filter = []
49
+ end
50
+ end
51
+
52
+ def test_filtered_collection
53
+ assert_collect(empty_suite) do |collector|
54
+ collector.filter = Proc.new {false}
55
+ end
56
+
57
+ assert_collect(full_suite) do |collector|
58
+ collector.filter = Proc.new {true}
59
+ end
60
+
61
+ assert_collect(full_suite) do |collector|
62
+ collector.filter = Proc.new {nil}
63
+ end
64
+
65
+ assert_collect(empty_suite) do |collector|
66
+ collector.filter = [Proc.new {false}, Proc.new {true}]
67
+ end
68
+
69
+ assert_collect(full_suite) do |collector|
70
+ collector.filter = [Proc.new {true}, Proc.new {false}]
71
+ end
72
+
73
+ assert_collect(empty_suite) do |collector|
74
+ collector.filter = [Proc.new {nil}, Proc.new {false}]
75
+ end
76
+
77
+ assert_collect(full_suite) do |collector|
78
+ collector.filter = [Proc.new {nil}, Proc.new {true}]
79
+ end
80
+
81
+ expected = empty_suite
82
+ suite1 = Test::Unit::TestSuite.new(@test_case1.name)
83
+ suite1 << @test_case1.new("test_1")
84
+ suite2 = Test::Unit::TestSuite.new(@test_case2.name)
85
+ suite2 << @test_case2.new("test_0")
86
+ expected << suite1 << suite2
87
+ assert_collect(expected) do |collector|
88
+ collector.filter = Proc.new do |test|
89
+ ['test_1', 'test_0'].include?(test.method_name)
90
+ end
91
+ end
92
+
93
+ expected = empty_suite
94
+ suite1 = Test::Unit::TestSuite.new(@test_case1.name)
95
+ suite1 << @test_case1.new("test_1")
96
+ suite2 = Test::Unit::TestSuite.new(@test_case2.name)
97
+ suite2 << @test_case2.new("test_0")
98
+ expected << suite1 << suite2
99
+ assert_collect(expected) do |collector|
100
+ filters = [Proc.new {|test| test.method_name == 'test_1' ? true : nil},
101
+ Proc.new {|test| test.method_name == 'test_0' ? true : nil},
102
+ Proc.new {false}]
103
+ collector.filter = filters
104
+ end
105
+ end
106
+
107
+ private
108
+ def assert_collect(expected, *collect_args)
109
+ collector = Test::Unit::Collector::Descendant.new
110
+ yield(collector) if block_given?
111
+ assert_equal(expected, collector.send(:collect, *collect_args))
112
+ end
113
+
114
+ def default_name
115
+ Test::Unit::Collector::Descendant::NAME
116
+ end
117
+
118
+ def empty_suite(name=nil)
119
+ Test::Unit::TestSuite.new(name || default_name)
120
+ end
121
+
122
+ def full_suite(name=nil)
123
+ sub_suite1 = Test::Unit::TestSuite.new(@test_case1.name)
124
+ sub_suite1 << @test_case1.new('test_1')
125
+ sub_suite1 << @test_case1.new('test_2')
126
+
127
+ sub_suite2 = Test::Unit::TestSuite.new(@test_case2.name)
128
+ sub_suite2 << @test_case2.new('test_0')
129
+
130
+ suite = empty_suite(name)
131
+ suite << sub_suite1
132
+ suite << sub_suite2
133
+ suite
134
+ end
135
+ end
@@ -0,0 +1,333 @@
1
+ require 'tmpdir'
2
+ require 'pathname'
3
+
4
+ require 'test/unit'
5
+ require 'test/unit/collector/load'
6
+
7
+ class TestUnitCollectorLoad < Test::Unit::TestCase
8
+ def setup
9
+ @previous_descendants = Test::Unit::TestCase::DESCENDANTS.dup
10
+ Test::Unit::TestCase::DESCENDANTS.clear
11
+
12
+ @temporary_test_cases_module_name = "TempTestCases"
13
+ ::Object.const_set(@temporary_test_cases_module_name, Module.new)
14
+
15
+ @test_dir = Pathname(Dir.tmpdir) + "test-unit"
16
+ @test_dir.rmtree if @test_dir.exist?
17
+ @test_dir.mkpath
18
+ end
19
+
20
+ setup
21
+ def setup_top_level_test_cases
22
+ @test_case1 = @test_dir + "test_case1.rb"
23
+ @test_case2 = @test_dir + "test_case2.rb"
24
+ @no_load_test_case3 = @test_dir + "case3.rb"
25
+
26
+ @test_case1.open("w") do |test_case|
27
+ test_case.puts(<<-EOT)
28
+ module #{@temporary_test_cases_module_name}
29
+ class TestCase1 < Test::Unit::TestCase
30
+ def test1_1
31
+ end
32
+
33
+ def test1_2
34
+ end
35
+ end
36
+ end
37
+ EOT
38
+ end
39
+
40
+ @test_case2.open("w") do |test_case|
41
+ test_case.puts(<<-EOT)
42
+ module #{@temporary_test_cases_module_name}
43
+ class TestCase2 < Test::Unit::TestCase
44
+ def test2
45
+ end
46
+ end
47
+ end
48
+ EOT
49
+ end
50
+
51
+ @no_load_test_case3.open("w") do |test_case|
52
+ test_case.puts(<<-EOT)
53
+ module #{@temporary_test_cases_module_name}
54
+ class NoLoadTestCase3 < Test::Unit::TestCase
55
+ def test3
56
+ end
57
+ end
58
+ end
59
+ EOT
60
+ end
61
+ end
62
+
63
+ setup
64
+ def setup_sub_level_test_cases
65
+ @sub_test_dir = @test_dir + "sub"
66
+ @sub_test_dir.mkpath
67
+
68
+ @sub_test_case4 = @sub_test_dir + "test_case4.rb"
69
+ @no_load_sub_test_case5 = @sub_test_dir + "case5.rb"
70
+ @sub_test_case6 = @sub_test_dir + "test_case6.rb"
71
+
72
+ @sub_test_case4.open("w") do |test_case|
73
+ test_case.puts(<<-EOT)
74
+ module #{@temporary_test_cases_module_name}
75
+ class SubTestCase4 < Test::Unit::TestCase
76
+ def test4_1
77
+ end
78
+
79
+ def test4_2
80
+ end
81
+ end
82
+ end
83
+ EOT
84
+ end
85
+
86
+ @no_load_sub_test_case5.open("w") do |test_case|
87
+ test_case.puts(<<-EOT)
88
+ module #{@temporary_test_cases_module_name}
89
+ class NoLoadSubTestCase5 < Test::Unit::TestCase
90
+ def test5_1
91
+ end
92
+
93
+ def test5_2
94
+ end
95
+ end
96
+ end
97
+ EOT
98
+ end
99
+
100
+ @sub_test_case6.open("w") do |test_case|
101
+ test_case.puts(<<-EOT)
102
+ module #{@temporary_test_cases_module_name}
103
+ class SubTestCase6 < Test::Unit::TestCase
104
+ def test6
105
+ end
106
+ end
107
+ end
108
+ EOT
109
+ end
110
+ end
111
+
112
+ setup
113
+ def setup_sub_level_test_cases2
114
+ @sub2_test_dir = @test_dir + "sub2"
115
+ @sub2_test_dir.mkpath
116
+
117
+ @no_load_sub2_test_case7 = @sub2_test_dir + "case7.rb"
118
+ @sub2_test_case8 = @sub2_test_dir + "test_case8.rb"
119
+ @sub2_test_case9 = @sub2_test_dir + "test_case9.rb"
120
+
121
+ @no_load_sub2_test_case7.open("w") do |test_case|
122
+ test_case.puts(<<-EOT)
123
+ module #{@temporary_test_cases_module_name}
124
+ class NoLoadSub2TestCase7 < Test::Unit::TestCase
125
+ def test7_1
126
+ end
127
+
128
+ def test7_2
129
+ end
130
+ end
131
+ end
132
+ EOT
133
+ end
134
+
135
+ @sub2_test_case8.open("w") do |test_case|
136
+ test_case.puts(<<-EOT)
137
+ module #{@temporary_test_cases_module_name}
138
+ class Sub2TestCase8 < Test::Unit::TestCase
139
+ def test8_1
140
+ end
141
+
142
+ def test8_2
143
+ end
144
+ end
145
+ end
146
+ EOT
147
+ end
148
+
149
+ @sub2_test_case9.open("w") do |test_case|
150
+ test_case.puts(<<-EOT)
151
+ module #{@temporary_test_cases_module_name}
152
+ class Sub2TestCase9 < Test::Unit::TestCase
153
+ def test9
154
+ end
155
+ end
156
+ end
157
+ EOT
158
+ end
159
+ end
160
+
161
+ setup
162
+ def setup_svn_test_cases
163
+ @svn_test_dir = @test_dir + ".svn"
164
+ @svn_test_dir.mkpath
165
+
166
+ @svn_test_case10 = @svn_test_dir + "test_case10.rb"
167
+
168
+ @svn_test_case10.open("w") do |test_case|
169
+ test_case.puts(<<-EOT)
170
+ module #{@temporary_test_cases_module_name}
171
+ class SvnTestCase10 < Test::Unit::TestCase
172
+ def test7
173
+ end
174
+ end
175
+ end
176
+ EOT
177
+ end
178
+ end
179
+
180
+ setup
181
+ def setup_sub_cvs_test_cases
182
+ @sub_cvs_test_dir = @sub_test_dir + "CVS"
183
+ @sub_cvs_test_dir.mkpath
184
+
185
+ @sub_cvs_test_case11 = @sub_cvs_test_dir + "test_case11.rb"
186
+
187
+ @sub_cvs_test_case11.open("w") do |test_case|
188
+ test_case.puts(<<-EOT)
189
+ module #{@temporary_test_cases_module_name}
190
+ class SubCVSTestCase11 < Test::Unit::TestCase
191
+ def test11
192
+ end
193
+ end
194
+ end
195
+ EOT
196
+ end
197
+ end
198
+
199
+ def teardown
200
+ @test_dir.rmtree if @test_dir.exist?
201
+ ::Object.send(:remove_const, @temporary_test_cases_module_name)
202
+ Test::Unit::TestCase::DESCENDANTS.replace(@previous_descendants)
203
+ end
204
+
205
+ def test_simple_collect
206
+ assert_collect([:suite, {:name => @sub_test_dir.basename.to_s},
207
+ [:suite, {:name => _test_case_name("SubTestCase4")},
208
+ [:test, {:name => "test4_1"}],
209
+ [:test, {:name => "test4_2"}]],
210
+ [:suite, {:name => _test_case_name("SubTestCase6")},
211
+ [:test, {:name => "test6"}]]],
212
+ @sub_test_dir.to_s)
213
+ end
214
+
215
+ def test_multilevel_collect
216
+ assert_collect([:suite, {:name => "."},
217
+ [:suite, {:name => _test_case_name("TestCase1")},
218
+ [:test, {:name => "test1_1"}],
219
+ [:test, {:name => "test1_2"}]],
220
+ [:suite, {:name => _test_case_name("TestCase2")},
221
+ [:test, {:name => "test2"}]],
222
+ [:suite, {:name => @sub_test_dir.basename.to_s},
223
+ [:suite, {:name => _test_case_name("SubTestCase4")},
224
+ [:test, {:name => "test4_1"}],
225
+ [:test, {:name => "test4_2"}]],
226
+ [:suite, {:name => _test_case_name("SubTestCase6")},
227
+ [:test, {:name => "test6"}]]],
228
+ [:suite, {:name => @sub2_test_dir.basename.to_s},
229
+ [:suite, {:name => _test_case_name("Sub2TestCase8")},
230
+ [:test, {:name => "test8_1"}],
231
+ [:test, {:name => "test8_2"}]],
232
+ [:suite, {:name => _test_case_name("Sub2TestCase9")},
233
+ [:test, {:name => "test9"}]]]])
234
+ end
235
+
236
+ def test_collect_file
237
+ assert_collect([:suite, {:name => @test_case1.basename.to_s},
238
+ [:suite, {:name => _test_case_name("TestCase1")},
239
+ [:test, {:name => "test1_1"}],
240
+ [:test, {:name => "test1_2"}]]],
241
+ @test_case1.to_s)
242
+
243
+ assert_collect([:suite, {:name => @no_load_sub_test_case5.basename.to_s},
244
+ [:suite, {:name => _test_case_name("NoLoadSubTestCase5")},
245
+ [:test, {:name => "test5_1"}],
246
+ [:test, {:name => "test5_2"}]]],
247
+ @no_load_sub_test_case5.to_s)
248
+ end
249
+
250
+ def test_nil_pattern
251
+ assert_collect([:suite, {:name => @sub_test_dir.basename.to_s},
252
+ [:suite, {:name => _test_case_name("NoLoadSubTestCase5")},
253
+ [:test, {:name => "test5_1"}],
254
+ [:test, {:name => "test5_2"}]],
255
+ [:suite, {:name => _test_case_name("SubTestCase4")},
256
+ [:test, {:name => "test4_1"}],
257
+ [:test, {:name => "test4_2"}]],
258
+ [:suite, {:name => _test_case_name("SubTestCase6")},
259
+ [:test, {:name => "test6"}]]],
260
+ @sub_test_dir.to_s) do |collector|
261
+ collector.patterns.clear
262
+ end
263
+ end
264
+
265
+ def test_filtering
266
+ assert_collect([:suite, {:name => "."},
267
+ [:suite, {:name => _test_case_name("TestCase1")},
268
+ [:test, {:name => "test1_1"}],
269
+ [:test, {:name => "test1_2"}]]]) do |collector|
270
+ collector.filter = Proc.new do |test|
271
+ not /\Atest1/.match(test.method_name).nil?
272
+ end
273
+ end
274
+ end
275
+
276
+ def test_collect_multi
277
+ test_dirs = [@sub_test_dir.to_s, @sub2_test_dir.to_s]
278
+ assert_collect([:suite, {:name => "[#{test_dirs.join(', ')}]"},
279
+ [:suite, {:name => @sub_test_dir.basename.to_s},
280
+ [:suite, {:name => _test_case_name("SubTestCase4")},
281
+ [:test, {:name => "test4_1"}],
282
+ [:test, {:name => "test4_2"}]],
283
+ [:suite, {:name => _test_case_name("SubTestCase6")},
284
+ [:test, {:name => "test6"}]]],
285
+ [:suite, {:name => @sub2_test_dir.basename.to_s},
286
+ [:suite, {:name => _test_case_name("Sub2TestCase8")},
287
+ [:test, {:name => "test8_1"}],
288
+ [:test, {:name => "test8_2"}]],
289
+ [:suite, {:name => _test_case_name("Sub2TestCase9")},
290
+ [:test, {:name => "test9"}]]]],
291
+ *test_dirs)
292
+ end
293
+
294
+ private
295
+ def assert_collect(expected, *collect_args)
296
+ keep_required_files do
297
+ Dir.chdir(@test_dir.to_s) do
298
+ collector = Test::Unit::Collector::Load.new
299
+ yield(collector) if block_given?
300
+ actual = inspect_test_object(collector.send(:collect, *collect_args))
301
+ assert_equal(expected, actual)
302
+ end
303
+ end
304
+ end
305
+
306
+ def keep_required_files
307
+ required_files = $".dup
308
+ yield
309
+ ensure
310
+ $".replace(required_files)
311
+ end
312
+
313
+ def _test_case_name(test_case_class_name)
314
+ "#{@temporary_test_cases_module_name}::#{test_case_class_name}"
315
+ end
316
+
317
+ def inspect_test_object(test_object)
318
+ return nil if test_object.nil?
319
+ case test_object
320
+ when Test::Unit::TestSuite
321
+ sub_tests = test_object.tests.collect do |test|
322
+ inspect_test_object(test)
323
+ end.sort_by do |type, attributes, *children|
324
+ attributes[:name]
325
+ end
326
+ [:suite, {:name => test_object.name}, *sub_tests]
327
+ when Test::Unit::TestCase
328
+ [:test, {:name => test_object.method_name}]
329
+ else
330
+ raise "unexpected test object: #{test_object.inspect}"
331
+ end
332
+ end
333
+ end