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.
- data/History.txt +27 -0
- data/Manifest.txt +30 -8
- data/README.txt +9 -4
- data/Rakefile +16 -1
- data/bin/testrb +0 -0
- data/lib/test/unit/assertions.rb +148 -48
- data/lib/test/unit/attribute.rb +125 -0
- data/lib/test/unit/autorunner.rb +101 -71
- data/lib/test/unit/collector/descendant.rb +23 -0
- data/lib/test/unit/collector/dir.rb +1 -1
- data/lib/test/unit/collector/load.rb +135 -0
- data/lib/test/unit/color.rb +61 -0
- data/lib/test/unit/diff.rb +524 -0
- data/lib/test/unit/error.rb +70 -2
- data/lib/test/unit/exceptionhandler.rb +39 -0
- data/lib/test/unit/failure.rb +63 -4
- data/lib/test/unit/fixture.rb +185 -0
- data/lib/test/unit/notification.rb +125 -0
- data/lib/test/unit/omission.rb +143 -0
- data/lib/test/unit/pending.rb +146 -0
- data/lib/test/unit/priority.rb +146 -0
- data/lib/test/unit/runner/console.rb +46 -0
- data/lib/test/unit/runner/emacs.rb +8 -0
- data/lib/test/unit/testcase.rb +193 -76
- data/lib/test/unit/testresult.rb +37 -28
- data/lib/test/unit/testsuite.rb +35 -1
- data/lib/test/unit/ui/console/outputlevel.rb +14 -0
- data/lib/test/unit/ui/console/testrunner.rb +96 -28
- data/lib/test/unit/ui/emacs/testrunner.rb +49 -0
- data/lib/test/unit/ui/testrunner.rb +20 -0
- data/lib/test/unit/ui/testrunnermediator.rb +28 -19
- data/lib/test/unit/ui/testrunnerutilities.rb +2 -7
- data/lib/test/unit/util/backtracefilter.rb +2 -1
- data/lib/test/unit/version.rb +1 -1
- data/test/collector/test_descendant.rb +135 -0
- data/test/collector/test_load.rb +333 -0
- data/test/run-test.rb +13 -0
- data/test/test_assertions.rb +221 -56
- data/test/test_attribute.rb +86 -0
- data/test/test_color.rb +37 -0
- data/test/test_diff.rb +477 -0
- data/test/test_emacs_runner.rb +60 -0
- data/test/test_fixture.rb +275 -0
- data/test/test_notification.rb +33 -0
- data/test/test_omission.rb +81 -0
- data/test/test_pending.rb +70 -0
- data/test/test_priority.rb +89 -0
- data/test/test_testcase.rb +160 -5
- data/test/test_testresult.rb +61 -52
- data/test/testunit_test_util.rb +14 -0
- data/test/ui/test_testrunmediator.rb +20 -0
- metadata +53 -23
- data/lib/test/unit/ui/fox/testrunner.rb +0 -268
- data/lib/test/unit/ui/gtk/testrunner.rb +0 -416
- data/lib/test/unit/ui/gtk2/testrunner.rb +0 -465
- data/lib/test/unit/ui/tk/testrunner.rb +0 -260
- data/test/runit/test_assert.rb +0 -402
- data/test/runit/test_testcase.rb +0 -91
- data/test/runit/test_testresult.rb +0 -144
- data/test/runit/test_testsuite.rb +0 -49
data/test/run-test.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$VERBOSE = true
|
4
|
+
|
5
|
+
base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
6
|
+
lib_dir = File.join(base_dir, "lib")
|
7
|
+
test_dir = File.join(base_dir, "test")
|
8
|
+
|
9
|
+
$LOAD_PATH.unshift(lib_dir)
|
10
|
+
|
11
|
+
require 'test/unit'
|
12
|
+
|
13
|
+
exit Test::Unit::AutoRunner.run(true, test_dir)
|
data/test/test_assertions.rb
CHANGED
@@ -9,12 +9,11 @@ module Test
|
|
9
9
|
class TC_Assertions < TestCase
|
10
10
|
def check(value, message="")
|
11
11
|
add_assertion
|
12
|
-
|
13
|
-
raise AssertionFailedError.new(message)
|
14
|
-
end
|
12
|
+
raise AssertionFailedError.new(message) unless value
|
15
13
|
end
|
16
14
|
|
17
|
-
def check_assertions(expect_fail, expected_message="",
|
15
|
+
def check_assertions(expect_fail, expected_message="",
|
16
|
+
return_value_expected=false)
|
18
17
|
@actual_assertion_count = 0
|
19
18
|
failed = true
|
20
19
|
actual_message = nil
|
@@ -27,35 +26,65 @@ module Test
|
|
27
26
|
actual_message = error.message
|
28
27
|
end
|
29
28
|
@catch_assertions = false
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
|
30
|
+
if expect_fail
|
31
|
+
message = "Should have failed, but didn't"
|
32
|
+
else
|
33
|
+
message = "Should not have failed, but did with message\n" +
|
34
|
+
"<#{actual_message}>"
|
35
|
+
end
|
36
|
+
check(expect_fail == failed, message)
|
37
|
+
|
38
|
+
message = "Should have made one assertion but made\n" +
|
39
|
+
"<#{@actual_assertion_count}>"
|
40
|
+
check(1 == @actual_assertion_count, message)
|
41
|
+
|
42
|
+
if expect_fail
|
33
43
|
case expected_message
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
44
|
+
when String
|
45
|
+
check(actual_message == expected_message,
|
46
|
+
"Should have the correct message.\n" +
|
47
|
+
"<#{expected_message.inspect}> expected but was\n" +
|
48
|
+
"<#{actual_message.inspect}>")
|
49
|
+
when Regexp
|
50
|
+
check(actual_message =~ expected_message,
|
51
|
+
"The message should match correctly.\n" +
|
52
|
+
"</#{expected_message.source}/> expected to match\n" +
|
53
|
+
"<#{actual_message.inspect}>")
|
54
|
+
else
|
55
|
+
check(false,
|
56
|
+
"Incorrect expected message type in assert_nothing_failed")
|
40
57
|
end
|
41
58
|
else
|
42
|
-
if
|
43
|
-
check(return_value.nil?, "Should not return a value but returned <#{return_value}>")
|
44
|
-
else
|
59
|
+
if return_value_expected
|
45
60
|
check(!return_value.nil?, "Should return a value")
|
61
|
+
else
|
62
|
+
check(return_value.nil?,
|
63
|
+
"Should not return a value but returned <#{return_value}>")
|
46
64
|
end
|
47
65
|
end
|
48
|
-
|
66
|
+
|
67
|
+
return_value
|
49
68
|
end
|
50
|
-
|
69
|
+
|
51
70
|
def check_nothing_fails(return_value_expected=false, &proc)
|
52
71
|
check_assertions(false, "", return_value_expected, &proc)
|
53
72
|
end
|
54
|
-
|
73
|
+
|
55
74
|
def check_fails(expected_message="", &proc)
|
56
75
|
check_assertions(true, expected_message, &proc)
|
57
76
|
end
|
58
|
-
|
77
|
+
|
78
|
+
def inspect_tag(tag)
|
79
|
+
begin
|
80
|
+
throw tag
|
81
|
+
rescue NameError
|
82
|
+
tag.to_s.inspect
|
83
|
+
rescue ArgumentError
|
84
|
+
tag.inspect
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
59
88
|
def test_assert_block
|
60
89
|
check_nothing_fails {
|
61
90
|
assert_block {true}
|
@@ -93,17 +122,87 @@ module Test
|
|
93
122
|
check_nothing_fails {
|
94
123
|
assert_equal("string1", "string1", "successful assert_equal")
|
95
124
|
}
|
96
|
-
|
125
|
+
|
126
|
+
message = <<-EOM.chomp
|
127
|
+
<"string1"> expected but was
|
128
|
+
<"string2">.
|
129
|
+
|
130
|
+
diff:
|
131
|
+
- string1
|
132
|
+
? ^
|
133
|
+
+ string2
|
134
|
+
? ^
|
135
|
+
EOM
|
136
|
+
check_fails(message) {
|
97
137
|
assert_equal("string1", "string2")
|
98
138
|
}
|
99
|
-
|
139
|
+
|
140
|
+
message = <<-EOM.chomp
|
141
|
+
failed assert_equal.
|
142
|
+
<"string1"> expected but was
|
143
|
+
<"string2">.
|
144
|
+
|
145
|
+
diff:
|
146
|
+
- string1
|
147
|
+
? ^
|
148
|
+
+ string2
|
149
|
+
? ^
|
150
|
+
EOM
|
151
|
+
check_fails(message) {
|
100
152
|
assert_equal("string1", "string2", "failed assert_equal")
|
101
153
|
}
|
102
|
-
|
103
|
-
|
154
|
+
|
155
|
+
message = <<-EOM.chomp
|
156
|
+
<"111111"> expected but was
|
157
|
+
<111111>.
|
158
|
+
|
159
|
+
diff:
|
160
|
+
- "111111"
|
161
|
+
? - -
|
162
|
+
+ 111111
|
163
|
+
EOM
|
164
|
+
check_fails(message) do
|
165
|
+
assert_equal("111111", 111111)
|
104
166
|
end
|
105
167
|
end
|
106
|
-
|
168
|
+
|
169
|
+
def test_assert_equal_for_too_small_difference
|
170
|
+
message = <<-EOM.chomp
|
171
|
+
<1> expected but was
|
172
|
+
<2>.
|
173
|
+
EOM
|
174
|
+
check_fails(message) do
|
175
|
+
assert_equal(1, 2)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_assert_equal_for_same_inspected_objects
|
180
|
+
now = Time.now
|
181
|
+
now_without_usec = Time.at(now.to_i)
|
182
|
+
message = <<-EOM.chomp
|
183
|
+
<#{now.inspect}> expected but was
|
184
|
+
<#{now.inspect}>.
|
185
|
+
EOM
|
186
|
+
check_fails(message) do
|
187
|
+
assert_equal(now, now_without_usec)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_assert_equal_with_multi_lines_result
|
192
|
+
message = <<-EOM.chomp
|
193
|
+
<#{"a\nb".inspect}> expected but was
|
194
|
+
<#{"x".inspect}>.
|
195
|
+
|
196
|
+
diff:
|
197
|
+
+ x
|
198
|
+
- a
|
199
|
+
- b
|
200
|
+
EOM
|
201
|
+
check_fails(message) do
|
202
|
+
assert_equal("a\nb", "x")
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
107
206
|
def test_assert_raise
|
108
207
|
return_value = nil
|
109
208
|
check_nothing_fails(true) {
|
@@ -211,10 +310,10 @@ Message: <"Error">
|
|
211
310
|
check_nothing_fails {
|
212
311
|
assert_nil(nil, "successful assert_nil")
|
213
312
|
}
|
214
|
-
check_fails(%Q{<
|
313
|
+
check_fails(%Q{<"string"> expected to be nil.}) {
|
215
314
|
assert_nil("string")
|
216
315
|
}
|
217
|
-
check_fails(%Q{failed assert_nil.\n<
|
316
|
+
check_fails(%Q{failed assert_nil.\n<"string"> expected to be nil.}) {
|
218
317
|
assert_nil("string", "failed assert_nil")
|
219
318
|
}
|
220
319
|
end
|
@@ -398,34 +497,43 @@ Message: <"Error">
|
|
398
497
|
end
|
399
498
|
|
400
499
|
def test_assert_throws
|
401
|
-
check_nothing_fails
|
402
|
-
assert_throws(:thing, "message")
|
500
|
+
check_nothing_fails do
|
501
|
+
assert_throws(:thing, "message") do
|
403
502
|
throw :thing
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
503
|
+
end
|
504
|
+
end
|
505
|
+
|
506
|
+
tag = :thing2
|
507
|
+
check_fails("message.\n" +
|
508
|
+
"<:thing> expected to be thrown but\n" +
|
509
|
+
"<#{inspect_tag(tag)}> was thrown.") do
|
510
|
+
assert_throws(:thing, "message") do
|
408
511
|
throw :thing2
|
409
|
-
|
410
|
-
|
411
|
-
check_fails("message.\n
|
412
|
-
|
512
|
+
end
|
513
|
+
end
|
514
|
+
check_fails("message.\n" +
|
515
|
+
"<:thing> should have been thrown.") do
|
516
|
+
assert_throws(:thing, "message") do
|
413
517
|
1 + 1
|
414
|
-
|
415
|
-
|
518
|
+
end
|
519
|
+
end
|
416
520
|
end
|
417
521
|
|
418
522
|
def test_assert_nothing_thrown
|
419
|
-
check_nothing_fails
|
420
|
-
assert_nothing_thrown("message")
|
523
|
+
check_nothing_fails do
|
524
|
+
assert_nothing_thrown("message") do
|
421
525
|
1 + 1
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
526
|
+
end
|
527
|
+
end
|
528
|
+
|
529
|
+
tag = :thing
|
530
|
+
inspected = inspect_tag(tag)
|
531
|
+
check_fails("message.\n" +
|
532
|
+
"<#{inspected}> was thrown when nothing was expected.") do
|
533
|
+
assert_nothing_thrown("message") do
|
534
|
+
throw tag
|
535
|
+
end
|
536
|
+
end
|
429
537
|
end
|
430
538
|
|
431
539
|
def test_assert_operator
|
@@ -505,22 +613,79 @@ Message: <"Error">
|
|
505
613
|
@changed ||= false
|
506
614
|
return (!@changed)
|
507
615
|
end
|
508
|
-
check_nothing_fails
|
616
|
+
check_nothing_fails do
|
509
617
|
assert_equal(object, object, "message")
|
510
|
-
|
618
|
+
end
|
619
|
+
end
|
620
|
+
|
621
|
+
def test_assert_boolean
|
622
|
+
check_nothing_fails do
|
623
|
+
assert_boolean(true)
|
624
|
+
end
|
625
|
+
check_nothing_fails do
|
626
|
+
assert_boolean(false)
|
627
|
+
end
|
628
|
+
|
629
|
+
check_fails("<true> or <false> expected but was\n<1>") do
|
630
|
+
assert_boolean(1)
|
631
|
+
end
|
632
|
+
|
633
|
+
check_fails("<true> or <false> expected but was\n<nil>") do
|
634
|
+
assert_boolean(nil)
|
635
|
+
end
|
636
|
+
|
637
|
+
check_fails("message.\n<true> or <false> expected but was\n<\"XXX\">") do
|
638
|
+
assert_boolean("XXX", "message")
|
639
|
+
end
|
511
640
|
end
|
512
|
-
|
641
|
+
|
642
|
+
def test_assert_true
|
643
|
+
check_nothing_fails do
|
644
|
+
assert_true(true)
|
645
|
+
end
|
646
|
+
|
647
|
+
check_fails("<true> expected but was\n<false>") do
|
648
|
+
assert_true(false)
|
649
|
+
end
|
650
|
+
|
651
|
+
check_fails("<true> expected but was\n<1>") do
|
652
|
+
assert_true(1)
|
653
|
+
end
|
654
|
+
|
655
|
+
check_fails("message.\n<true> expected but was\n<nil>") do
|
656
|
+
assert_true(nil, "message")
|
657
|
+
end
|
658
|
+
end
|
659
|
+
|
660
|
+
def test_assert_false
|
661
|
+
check_nothing_fails do
|
662
|
+
assert_false(false)
|
663
|
+
end
|
664
|
+
|
665
|
+
check_fails("<false> expected but was\n<true>") do
|
666
|
+
assert_false(true)
|
667
|
+
end
|
668
|
+
|
669
|
+
check_fails("<false> expected but was\n<nil>") do
|
670
|
+
assert_false(nil)
|
671
|
+
end
|
672
|
+
|
673
|
+
check_fails("message.\n<false> expected but was\n<:false>") do
|
674
|
+
assert_false(:false, "message")
|
675
|
+
end
|
676
|
+
end
|
677
|
+
|
513
678
|
def add_failure(message, location=caller)
|
514
|
-
|
679
|
+
unless @catch_assertions
|
515
680
|
super
|
516
681
|
end
|
517
682
|
end
|
518
|
-
|
683
|
+
|
519
684
|
def add_assertion
|
520
|
-
if
|
521
|
-
super
|
522
|
-
else
|
685
|
+
if @catch_assertions
|
523
686
|
@actual_assertion_count += 1
|
687
|
+
else
|
688
|
+
super
|
524
689
|
end
|
525
690
|
end
|
526
691
|
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
class TestUnitAttribute < Test::Unit::TestCase
|
2
|
+
class TestStack < Test::Unit::TestCase
|
3
|
+
class << self
|
4
|
+
def suite
|
5
|
+
Test::Unit::TestSuite.new(name)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class Stack
|
10
|
+
def initialize
|
11
|
+
@data = []
|
12
|
+
end
|
13
|
+
|
14
|
+
def push(data)
|
15
|
+
@data.push(data)
|
16
|
+
end
|
17
|
+
|
18
|
+
def peek
|
19
|
+
@data[-2]
|
20
|
+
end
|
21
|
+
|
22
|
+
def empty?
|
23
|
+
@data.empty?
|
24
|
+
end
|
25
|
+
|
26
|
+
def size
|
27
|
+
@data.size + 11
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def setup
|
32
|
+
@stack = Stack.new
|
33
|
+
end
|
34
|
+
|
35
|
+
attribute :category, :accessor
|
36
|
+
def test_peek
|
37
|
+
@stack.push(1)
|
38
|
+
@stack.push(2)
|
39
|
+
assert_equal(2, @stack.peek)
|
40
|
+
end
|
41
|
+
|
42
|
+
attribute :bug, 1234
|
43
|
+
def test_bug_1234
|
44
|
+
assert_equal(0, @stack.size)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_no_attributes
|
48
|
+
assert(@stack.empty?)
|
49
|
+
@stack.push(1)
|
50
|
+
assert(!@stack.empty?)
|
51
|
+
assert_equal(1, @stack.size)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_set_attributes
|
56
|
+
test_for_accessor_category = TestStack.new("test_peek")
|
57
|
+
assert_equal({"category" => :accessor},
|
58
|
+
test_for_accessor_category.attributes)
|
59
|
+
|
60
|
+
test_for_bug_1234 = TestStack.new("test_bug_1234")
|
61
|
+
assert_equal({"bug" => 1234}, test_for_bug_1234.attributes)
|
62
|
+
|
63
|
+
test_no_attributes = TestStack.new("test_no_attributes")
|
64
|
+
assert_equal({}, test_no_attributes.attributes)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_callback
|
68
|
+
changed_attributes = []
|
69
|
+
observer = Proc.new do |test_case, key, old_value, value, method_name|
|
70
|
+
changed_attributes << [test_case, key, old_value, value, method_name]
|
71
|
+
end
|
72
|
+
|
73
|
+
test_case = Class.new(TestStack) do
|
74
|
+
register_attribute_observer(:bug, &observer)
|
75
|
+
attribute("bug", 9876, "test_bug_1234")
|
76
|
+
attribute(:description, "Test for peek", "test_peek")
|
77
|
+
attribute(:bug, 29, "test_peek")
|
78
|
+
end
|
79
|
+
|
80
|
+
assert_equal([
|
81
|
+
[test_case, "bug", 1234, 9876, "test_bug_1234"],
|
82
|
+
[test_case, "bug", nil, 29, "test_peek"],
|
83
|
+
],
|
84
|
+
changed_attributes)
|
85
|
+
end
|
86
|
+
end
|