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,70 @@
1
+ require 'test/unit'
2
+ require 'testunit_test_util'
3
+
4
+ class TestUnitPending < Test::Unit::TestCase
5
+ include TestUnitTestUtil
6
+
7
+ class TestCase < Test::Unit::TestCase
8
+ class << self
9
+ def suite
10
+ Test::Unit::TestSuite.new(name)
11
+ end
12
+ end
13
+
14
+ def test_pend
15
+ pend("1st pend")
16
+ pend("2nd pend. Should not be reached here.")
17
+ assert(true, "Should not be reached here too.")
18
+ end
19
+
20
+ def test_pend_with_failure_in_block
21
+ pend("Wait a minute") do
22
+ raise "Not implemented yet"
23
+ end
24
+ assert(true, "Reached here.")
25
+ end
26
+
27
+ def test_pend_with_no_failure_in_block
28
+ pend("Wait a minute") do
29
+ "Nothing raised"
30
+ end
31
+ assert(true, "Not reached here.")
32
+ end
33
+ end
34
+
35
+ def test_pend
36
+ test = nil
37
+ result = run_test("test_pend") {|t| test = t}
38
+ assert_equal("1 tests, 0 assertions, 0 failures, 0 errors, 1 pendings, " \
39
+ "0 omissions, 0 notifications",
40
+ result.to_s)
41
+ assert_fault_messages(["1st pend"], result.pendings)
42
+ assert_true(test.interrupted?)
43
+ end
44
+
45
+ def test_pend_with_failure_in_block
46
+ test = nil
47
+ result = run_test("test_pend_with_failure_in_block") {|t| test = t}
48
+ assert_equal("1 tests, 1 assertions, 0 failures, 0 errors, 1 pendings, " \
49
+ "0 omissions, 0 notifications",
50
+ result.to_s)
51
+ assert_fault_messages(["Wait a minute"], result.pendings)
52
+ assert_false(test.interrupted?)
53
+ end
54
+
55
+ def test_pend_with_no_failure_in_block
56
+ test = nil
57
+ result = run_test("test_pend_with_no_failure_in_block") {|t| test = t}
58
+ assert_equal("1 tests, 1 assertions, 1 failures, 0 errors, 0 pendings, " \
59
+ "0 omissions, 0 notifications",
60
+ result.to_s)
61
+ assert_fault_messages(["Pending block should not be passed: Wait a minute."],
62
+ result.failures)
63
+ assert_true(test.interrupted?)
64
+ end
65
+
66
+ private
67
+ def run_test(name, &block)
68
+ super(TestCase, name, &block)
69
+ end
70
+ end
@@ -0,0 +1,89 @@
1
+ require 'test/unit'
2
+
3
+ class TestUnitPriority < Test::Unit::TestCase
4
+ class TestCase < Test::Unit::TestCase
5
+ class << self
6
+ def suite
7
+ Test::Unit::TestSuite.new(name)
8
+ end
9
+ end
10
+
11
+ priority :must
12
+ def test_must
13
+ assert(true)
14
+ end
15
+
16
+ def test_must_inherited
17
+ assert(true)
18
+ end
19
+
20
+ priority :important
21
+ def test_important
22
+ assert(true)
23
+ end
24
+
25
+ def test_important_inherited
26
+ assert(true)
27
+ end
28
+
29
+ priority :high
30
+ def test_high
31
+ assert(true)
32
+ end
33
+
34
+ def test_high_inherited
35
+ assert(true)
36
+ end
37
+
38
+ priority :normal
39
+ def test_normal
40
+ assert(true)
41
+ end
42
+
43
+ def test_normal_inherited
44
+ assert(true)
45
+ end
46
+
47
+ priority :low
48
+ def test_low
49
+ assert(true)
50
+ end
51
+
52
+ def test_low_inherited
53
+ assert(true)
54
+ end
55
+
56
+ priority :never
57
+ def test_never
58
+ assert(true)
59
+ end
60
+
61
+ def test_never_inherited
62
+ assert(true)
63
+ end
64
+ end
65
+
66
+ def test_priority
67
+ assert_priority("must", 1.0, 0.0001)
68
+ assert_priority("important", 0.9, 0.09)
69
+ assert_priority("high", 0.70, 0.1)
70
+ assert_priority("normal", 0.5, 0.1)
71
+ assert_priority("low", 0.25, 0.1)
72
+ assert_priority("never", 0.0, 0.0001)
73
+ end
74
+
75
+ def assert_priority(priority, expected, delta)
76
+ assert_need_to_run("test_#{priority}", expected, delta)
77
+ assert_need_to_run("test_#{priority}_inherited", expected, delta)
78
+ end
79
+
80
+ def assert_need_to_run(test_name, expected, delta)
81
+ test = TestCase.new(test_name)
82
+ n = 1000
83
+ n_need_to_run = 0
84
+ n.times do |i|
85
+ n_need_to_run +=1 if Test::Unit::Priority::Checker.need_to_run?(test)
86
+ end
87
+ assert_in_delta(expected, n_need_to_run.to_f / n, delta)
88
+ end
89
+ end
@@ -263,13 +263,168 @@ module Test
263
263
  check("Should not be equal", test1 != Object.new)
264
264
  check("Should not be equal", Object.new != test1)
265
265
  end
266
-
267
- def check(message, passed)
268
- @_result.add_assertion
269
- if ! passed
270
- raise AssertionFailedError.new(message)
266
+
267
+ def test_re_raise_exception
268
+ test_case = Class.new(TestCase) do
269
+ def test_raise_interrupt
270
+ raise Interrupt
271
+ end
272
+ end
273
+
274
+ test = test_case.new("test_raise_interrupt")
275
+ begin
276
+ test.run(TestResult.new) {}
277
+ check("Should not be reached", false)
278
+ rescue Exception
279
+ check("Interrupt exception should be re-raised", $!.class == Interrupt)
280
+ end
281
+ end
282
+
283
+ def test_startup_shutdown
284
+ called = []
285
+ test_case = Class.new(TestCase) do
286
+ @@called = called
287
+ class << self
288
+ def startup
289
+ @@called << :startup
290
+ end
291
+
292
+ def shutdown
293
+ @@called << :shutdown
294
+ end
295
+ end
296
+
297
+ def setup
298
+ @@called << :setup
299
+ end
300
+
301
+ def teardown
302
+ @@called << :teardown
303
+ end
304
+
305
+ def test1
306
+ end
307
+
308
+ def test2
309
+ end
310
+ end
311
+
312
+ test_suite = test_case.suite
313
+ test_suite.run(TestResult.new) {}
314
+ check("startup/shutdown should be called once per test case" +
315
+ ": #{called.inspect}",
316
+ called == [:startup,
317
+ :setup, :teardown,
318
+ :setup, :teardown,
319
+ :shutdown])
320
+ end
321
+
322
+ def test_error_on_startup
323
+ test_case = Class.new(TestCase) do
324
+ class << self
325
+ def startup
326
+ raise "from startup"
327
+ end
328
+ end
329
+
330
+ def test_nothing
331
+ end
332
+ end
333
+
334
+ test_suite = test_case.suite
335
+ result = TestResult.new
336
+ test_suite.run(result) {}
337
+ check("Should record an error on startup: #{result}",
338
+ result.error_count == 1)
339
+ end
340
+
341
+ def test_pass_through_error_on_startup
342
+ test_case = Class.new(TestCase) do
343
+ class << self
344
+ def startup
345
+ raise Interrupt
346
+ end
347
+ end
348
+
349
+ def test_nothing
350
+ end
351
+ end
352
+
353
+ test_suite = test_case.suite
354
+ begin
355
+ test_suite.run(TestResult.new) {}
356
+ check("Should not be reached", false)
357
+ rescue Exception
358
+ check("Interrupt should be passed through: #{$!}",
359
+ Interrupt === $!)
271
360
  end
272
361
  end
362
+
363
+ def test_error_on_shutdown
364
+ test_case = Class.new(TestCase) do
365
+ class << self
366
+ def shutdown
367
+ raise "from shutdown"
368
+ end
369
+ end
370
+
371
+ def test_nothing
372
+ end
373
+ end
374
+
375
+ test_suite = test_case.suite
376
+ result = TestResult.new
377
+ test_suite.run(result) {}
378
+ check("Should record an error on shutdown: #{result}",
379
+ result.error_count == 1)
380
+ end
381
+
382
+ def test_pass_through_error_on_shutdown
383
+ test_case = Class.new(TestCase) do
384
+ class << self
385
+ def shutdown
386
+ raise Interrupt
387
+ end
388
+ end
389
+
390
+ def test_nothing
391
+ end
392
+ end
393
+
394
+ test_suite = test_case.suite
395
+ begin
396
+ test_suite.run(TestResult.new) {}
397
+ check("Should not be reached", false)
398
+ rescue Exception
399
+ check("Interrupt should be passed through: #{$!}",
400
+ Interrupt === $!)
401
+ end
402
+ end
403
+
404
+ def test_interrupted
405
+ test_case = Class.new(TestCase) do
406
+ def test_fail
407
+ flunk
408
+ end
409
+
410
+ def test_nothing
411
+ end
412
+ end
413
+
414
+ failed_test = test_case.new(:test_fail)
415
+ failed_test.run(TestResult.new) {}
416
+ check("Should be interrupted", failed_test.interrupted?)
417
+
418
+ success_test = test_case.new(:test_nothing)
419
+ success_test.run(TestResult.new) {}
420
+ check("Should not be interrupted", !success_test.interrupted?)
421
+ end
422
+
423
+ private
424
+ def check(message, passed)
425
+ add_assertion
426
+ raise AssertionFailedError.new(message) unless passed
427
+ end
273
428
  end
274
429
  end
275
430
  end
@@ -11,93 +11,102 @@ module Test
11
11
  def setup
12
12
  @my_result = TestResult.new
13
13
  @my_result.add_assertion()
14
- @my_result.add_failure("")
15
- @my_result.add_error("")
14
+ @failure = "failure"
15
+ @my_result.add_failure(@failure)
16
+ @error = "error"
17
+ @my_result.add_error(@error)
16
18
  end
19
+
17
20
  def test_result_changed_notification
18
21
  called1 = false
19
- @my_result.add_listener( TestResult::CHANGED) {
20
- |result|
21
- assert_block("The result should be correct") { result == @my_result }
22
+ @my_result.add_listener(TestResult::CHANGED) do |result|
23
+ assert_equal(@my_result, result)
22
24
  called1 = true
23
- }
25
+ end
24
26
  @my_result.add_assertion
25
- assert_block("Should have been notified when the assertion happened") { called1 }
26
-
27
+ assert_true(called1)
28
+
27
29
  called1, called2 = false, false
28
- @my_result.add_listener( TestResult::CHANGED) {
29
- |result|
30
- assert_block("The result should be correct") { result == @my_result }
30
+ @my_result.add_listener(TestResult::CHANGED) do |result|
31
+ assert_equal(@my_result, result)
31
32
  called2 = true
32
- }
33
+ end
33
34
  @my_result.add_assertion
34
- assert_block("Both listeners should have been notified for a success") { called1 && called2 }
35
-
35
+ assert_equal([true, true], [called1, called2])
36
+
36
37
  called1, called2 = false, false
37
38
  @my_result.add_failure("")
38
- assert_block("Both listeners should have been notified for a failure") { called1 && called2 }
39
-
40
- called1, called2 = false, false
39
+ assert_equal([true, true], [called1, called2])
40
+
41
+ called1, called2 = false, false
41
42
  @my_result.add_error("")
42
- assert_block("Both listeners should have been notified for an error") { called1 && called2 }
43
-
44
- called1, called2 = false, false
43
+ assert_equal([true, true], [called1, called2])
44
+
45
+ called1, called2 = false, false
45
46
  @my_result.add_run
46
- assert_block("Both listeners should have been notified for a run") { called1 && called2 }
47
+ assert_equal([true, true], [called1, called2])
47
48
  end
49
+
48
50
  def test_fault_notification
49
51
  called1 = false
50
52
  fault = "fault"
51
- @my_result.add_listener(TestResult::FAULT) {
52
- | passed_fault |
53
- assert_block("The fault should be correct") { passed_fault == fault }
53
+ @my_result.add_listener(TestResult::FAULT) do |passed_fault|
54
+ assert_equal(fault, passed_fault)
54
55
  called1 = true
55
- }
56
-
56
+ end
57
+
57
58
  @my_result.add_assertion
58
- assert_block("Should not have been notified when the assertion happened") { !called1 }
59
-
59
+ assert_false(called1)
60
+
60
61
  @my_result.add_failure(fault)
61
- assert_block("Should have been notified when the failure happened") { called1 }
62
-
62
+ assert_true(called1)
63
+
63
64
  called1, called2 = false, false
64
- @my_result.add_listener(TestResult::FAULT) {
65
- | passed_fault |
66
- assert_block("The fault should be correct") { passed_fault == fault }
65
+ @my_result.add_listener(TestResult::FAULT) do |passed_fault|
66
+ assert_equal(fault, passed_fault)
67
67
  called2 = true
68
- }
69
-
68
+ end
69
+
70
70
  @my_result.add_assertion
71
- assert_block("Neither listener should have been notified for a success") { !(called1 || called2) }
72
-
71
+ assert_equal([false, false], [called1, called2])
72
+
73
73
  called1, called2 = false, false
74
74
  @my_result.add_failure(fault)
75
- assert_block("Both listeners should have been notified for a failure") { called1 && called2 }
76
-
77
- called1, called2 = false, false
75
+ assert_equal([true, true], [called1, called2])
76
+
77
+ called1, called2 = false, false
78
78
  @my_result.add_error(fault)
79
- assert_block("Both listeners should have been notified for an error") { called1 && called2 }
80
-
79
+ assert_equal([true, true], [called1, called2])
80
+
81
81
  called1, called2 = false, false
82
82
  @my_result.add_run
83
- assert_block("Neither listener should have been notified for a run") { !(called1 || called2) }
83
+ assert_equal([false, false], [called1, called2])
84
84
  end
85
+
85
86
  def test_passed?
86
87
  result = TestResult.new
87
- assert(result.passed?, "An empty result should have passed")
88
-
88
+ assert_true(result.passed?)
89
+
89
90
  result.add_assertion
90
- assert(result.passed?, "Adding an assertion should not cause the result to not pass")
91
-
91
+ assert_true(result.passed?)
92
+
92
93
  result.add_run
93
- assert(result.passed?, "Adding a run should not cause the result to not pass")
94
-
94
+ assert_true(result.passed?)
95
+
95
96
  result.add_failure("")
96
- assert(!result.passed?, "Adding a failed assertion should cause the result to not pass")
97
-
97
+ assert_false(result.passed?)
98
+
98
99
  result = TestResult.new
99
100
  result.add_error("")
100
- assert(!result.passed?, "Adding an error should cause the result to not pass")
101
+ assert_false(result.passed?)
102
+ end
103
+
104
+ def test_faults
105
+ assert_equal([@failure, @error], @my_result.faults)
106
+
107
+ notification = "notification"
108
+ @my_result.add_notification(notification)
109
+ assert_equal([@failure, @error, notification], @my_result.faults)
101
110
  end
102
111
  end
103
112
  end