forked from test-unit/test-unit
/
test_testsuite.rb
137 lines (119 loc) · 4.29 KB
/
test_testsuite.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# Author:: Nathaniel Talbott.
# Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved.
# License:: Ruby license.
require 'test/unit'
module Test
module Unit
class TestTestSuite < TestCase
def setup
@testcase1 = Class.new(TestCase) do
def test_succeed1
assert_block { true }
end
def test_fail
assert_block { false }
end
end
@testcase2 = Class.new(TestCase) do
def test_succeed2
assert_block { true }
end
def test_error
raise
end
end
end
def test_add
s = TestSuite.new
assert_equal(s, s << self.class.new("test_add"))
end
def test_delete
s = TestSuite.new
t1 = self.class.new("test_delete")
s << t1
t2 = self.class.new("test_add")
s << t2
assert_equal(t1, s.delete(t1))
assert_nil(s.delete(t1))
assert_equal(TestSuite.new << t2, s)
end
def test_size
suite = TestSuite.new
suite2 = TestSuite.new
suite2 << self.class.new("test_size")
suite << suite2
suite << self.class.new("test_size")
assert_equal(2, suite.size, "The count should be correct")
end
def test_run
progress = []
suite = @testcase1.suite
tests = suite.tests.dup
result = TestResult.new
suite.run(result) { |*values| progress << values }
assert_equal(2, result.run_count, "Should have had four test runs")
assert_equal(1, result.failure_count, "Should have had one test failure")
assert_equal(0, result.error_count, "Should have had one test error")
assert_equal([[TestSuite::STARTED, suite.name],
[TestSuite::STARTED_OBJECT, suite],
[TestCase::STARTED, "test_fail(#{suite.name})"],
[TestCase::STARTED_OBJECT, tests[0]],
[TestCase::FINISHED, "test_fail(#{suite.name})"],
[TestCase::FINISHED_OBJECT, tests[0]],
[TestCase::STARTED, "test_succeed1(#{suite.name})"],
[TestCase::STARTED_OBJECT, tests[1]],
[TestCase::FINISHED, "test_succeed1(#{suite.name})"],
[TestCase::FINISHED_OBJECT, tests[1]],
[TestSuite::FINISHED, suite.name],
[TestSuite::FINISHED_OBJECT, suite]],
progress, "Should have had the correct progress")
suite = TestSuite.new
suite << @testcase1.suite
suite << @testcase2.suite
result = TestResult.new
progress = []
suite.run(result) { |*values| progress << values }
assert_equal(4, result.run_count, "Should have had four test runs")
assert_equal(1, result.failure_count, "Should have had one test failure")
assert_equal(1, result.error_count, "Should have had one test error")
assert_equal(28, progress.size,
"Should have had the correct number of progress calls")
end
def test_empty?
assert(TestSuite.new.empty?, "A new test suite should be empty?")
assert(!@testcase2.suite.empty?, "A test suite with tests should not be empty")
end
def test_equality
suite1 = TestSuite.new
suite2 = TestSuite.new
assert_equal(suite1, suite2)
assert_equal(suite2, suite1)
suite1 = TestSuite.new('name')
assert_not_equal(suite1, suite2)
assert_not_equal(suite2, suite1)
suite2 = TestSuite.new('name')
assert_equal(suite1, suite2)
assert_equal(suite2, suite1)
suite1 << 'test'
assert_not_equal(suite1, suite2)
assert_not_equal(suite2, suite1)
suite2 << 'test'
assert_equal(suite1, suite2)
assert_equal(suite2, suite1)
suite2 = Object.new
class << suite2
def name
'name'
end
def tests
['test']
end
end
assert_not_equal(suite1, suite2)
assert_not_equal(suite2, suite1)
assert_not_equal(suite1, Object.new)
assert_not_equal(Object.new, suite1)
end
end
end
end