test-unit 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/Manifest.txt +48 -0
- data/README.txt +27 -0
- data/Rakefile +15 -0
- data/bin/testrb +5 -0
- data/lib/test/unit.rb +280 -0
- data/lib/test/unit/assertionfailederror.rb +14 -0
- data/lib/test/unit/assertions.rb +622 -0
- data/lib/test/unit/autorunner.rb +220 -0
- data/lib/test/unit/collector.rb +43 -0
- data/lib/test/unit/collector/dir.rb +108 -0
- data/lib/test/unit/collector/objectspace.rb +34 -0
- data/lib/test/unit/error.rb +56 -0
- data/lib/test/unit/failure.rb +51 -0
- data/lib/test/unit/testcase.rb +160 -0
- data/lib/test/unit/testresult.rb +80 -0
- data/lib/test/unit/testsuite.rb +76 -0
- data/lib/test/unit/ui/console/testrunner.rb +127 -0
- data/lib/test/unit/ui/fox/testrunner.rb +268 -0
- data/lib/test/unit/ui/gtk/testrunner.rb +416 -0
- data/lib/test/unit/ui/gtk2/testrunner.rb +465 -0
- data/lib/test/unit/ui/testrunnermediator.rb +68 -0
- data/lib/test/unit/ui/testrunnerutilities.rb +46 -0
- data/lib/test/unit/ui/tk/testrunner.rb +260 -0
- data/lib/test/unit/util/backtracefilter.rb +40 -0
- data/lib/test/unit/util/observable.rb +90 -0
- data/lib/test/unit/util/procwrapper.rb +48 -0
- data/lib/test/unit/version.rb +7 -0
- data/sample/adder.rb +13 -0
- data/sample/subtracter.rb +12 -0
- data/sample/tc_adder.rb +18 -0
- data/sample/tc_subtracter.rb +18 -0
- data/sample/ts_examples.rb +7 -0
- data/test/collector/test_dir.rb +406 -0
- data/test/collector/test_objectspace.rb +98 -0
- data/test/runit/test_assert.rb +402 -0
- data/test/runit/test_testcase.rb +91 -0
- data/test/runit/test_testresult.rb +144 -0
- data/test/runit/test_testsuite.rb +49 -0
- data/test/test_assertions.rb +528 -0
- data/test/test_error.rb +26 -0
- data/test/test_failure.rb +33 -0
- data/test/test_testcase.rb +275 -0
- data/test/test_testresult.rb +104 -0
- data/test/test_testsuite.rb +129 -0
- data/test/util/test_backtracefilter.rb +41 -0
- data/test/util/test_observable.rb +102 -0
- data/test/util/test_procwrapper.rb +36 -0
- metadata +128 -0
@@ -0,0 +1,98 @@
|
|
1
|
+
# Author:: Nathaniel Talbott.
|
2
|
+
# Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved.
|
3
|
+
# License:: Ruby license.
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
require 'test/unit/collector/objectspace'
|
7
|
+
|
8
|
+
module Test
|
9
|
+
module Unit
|
10
|
+
module Collector
|
11
|
+
class TC_ObjectSpace < TestCase
|
12
|
+
def setup
|
13
|
+
@tc1 = Class.new(TestCase) do
|
14
|
+
def self.name
|
15
|
+
"tc_1"
|
16
|
+
end
|
17
|
+
def test_1
|
18
|
+
end
|
19
|
+
def test_2
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
@tc2 = Class.new(TestCase) do
|
24
|
+
def self.name
|
25
|
+
"tc_2"
|
26
|
+
end
|
27
|
+
def test_0
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
@no_tc = Class.new do
|
32
|
+
def test_4
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
@object_space = {Class => [@tc1, @tc2, @no_tc], String => ['']}
|
37
|
+
def @object_space.each_object(type)
|
38
|
+
self[type].each{|item| yield(item) }
|
39
|
+
end
|
40
|
+
|
41
|
+
@c = ObjectSpace.new(@object_space)
|
42
|
+
end
|
43
|
+
|
44
|
+
def full_suite(name=ObjectSpace::NAME)
|
45
|
+
expected = TestSuite.new(name)
|
46
|
+
expected << (TestSuite.new(@tc1.name) << @tc1.new('test_1') << @tc1.new('test_2'))
|
47
|
+
expected << (TestSuite.new(@tc2.name) << @tc2.new('test_0'))
|
48
|
+
end
|
49
|
+
|
50
|
+
def empty_suite
|
51
|
+
TestSuite.new(ObjectSpace::NAME)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_basic_collection
|
55
|
+
assert_equal(full_suite("name"), @c.collect("name"))
|
56
|
+
|
57
|
+
@c.filter = []
|
58
|
+
assert_equal(full_suite("name"), @c.collect("name"))
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_filtered_collection
|
62
|
+
@c.filter = proc{false}
|
63
|
+
assert_equal(empty_suite, @c.collect)
|
64
|
+
|
65
|
+
@c.filter = proc{true}
|
66
|
+
assert_equal(full_suite, @c.collect)
|
67
|
+
|
68
|
+
@c.filter = proc{nil}
|
69
|
+
assert_equal(full_suite, @c.collect)
|
70
|
+
|
71
|
+
@c.filter = [proc{false}, proc{true}]
|
72
|
+
assert_equal(empty_suite, @c.collect)
|
73
|
+
|
74
|
+
@c.filter = [proc{true}, proc{false}]
|
75
|
+
assert_equal(full_suite, @c.collect)
|
76
|
+
|
77
|
+
@c.filter = [proc{nil}, proc{false}]
|
78
|
+
assert_equal(empty_suite, @c.collect)
|
79
|
+
|
80
|
+
@c.filter = [proc{nil}, proc{true}]
|
81
|
+
assert_equal(full_suite, @c.collect)
|
82
|
+
|
83
|
+
expected = TestSuite.new(ObjectSpace::NAME)
|
84
|
+
expected << (TestSuite.new(@tc1.name) << @tc1.new('test_1'))
|
85
|
+
expected << (TestSuite.new(@tc2.name) << @tc2.new('test_0'))
|
86
|
+
@c.filter = proc{|test| ['test_1', 'test_0'].include?(test.method_name)}
|
87
|
+
assert_equal(expected, @c.collect)
|
88
|
+
|
89
|
+
expected = TestSuite.new(ObjectSpace::NAME)
|
90
|
+
expected << (TestSuite.new(@tc1.name) << @tc1.new('test_1'))
|
91
|
+
expected << (TestSuite.new(@tc2.name) << @tc2.new('test_0'))
|
92
|
+
@c.filter = [proc{|t| t.method_name == 'test_1' ? true : nil}, proc{|t| t.method_name == 'test_0' ? true : nil}, proc{false}]
|
93
|
+
assert_equal(expected, @c.collect)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,402 @@
|
|
1
|
+
# Author:: Masaki Suketa.
|
2
|
+
# Adapted by:: Nathaniel Talbott.
|
3
|
+
# Copyright:: Copyright (c) Masaki Suketa. All rights reserved.
|
4
|
+
# Copyright:: Copyright (c) 2002 Nathaniel Talbott. All rights reserved.
|
5
|
+
# License:: Ruby license.
|
6
|
+
|
7
|
+
require 'rubyunit'
|
8
|
+
|
9
|
+
module RUNIT
|
10
|
+
class TargetAssert
|
11
|
+
include RUNIT::Assert
|
12
|
+
end
|
13
|
+
|
14
|
+
class TestAssert < RUNIT::TestCase
|
15
|
+
def setup
|
16
|
+
@assert = TargetAssert.new
|
17
|
+
@e = nil
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_assert
|
21
|
+
sub_test_assert_pass(true)
|
22
|
+
sub_test_assert_pass(TRUE)
|
23
|
+
sub_test_assert_failure(false)
|
24
|
+
sub_test_assert_failure(FALSE)
|
25
|
+
sub_test_assert_failure(nil)
|
26
|
+
sub_test_assert_pass("")
|
27
|
+
sub_test_assert_pass("ok")
|
28
|
+
sub_test_assert_pass(0)
|
29
|
+
sub_test_assert_pass(1)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_assert_with_2_argument
|
33
|
+
assert_no_exception {
|
34
|
+
assert(true, "3")
|
35
|
+
}
|
36
|
+
assert_no_exception {
|
37
|
+
assert(true)
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_assert_equal_float_0_1
|
42
|
+
assert_proc = Proc.new {
|
43
|
+
@assert.assert_equal_float(1.4, 1.35, 0.1)
|
44
|
+
}
|
45
|
+
sub_assert_pass(assert_proc)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_assert_equal_float_0_5
|
49
|
+
assert_proc = Proc.new {
|
50
|
+
@assert.assert_equal_float(1.4, 1.34, 0.5)
|
51
|
+
}
|
52
|
+
sub_assert_pass(assert_proc)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_assert_equal_float_0
|
56
|
+
assert_proc = Proc.new {
|
57
|
+
@assert.assert_equal_float(1.4, 1.4, 0)
|
58
|
+
}
|
59
|
+
sub_assert_pass(assert_proc)
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_assert_equal_float_0_raise
|
63
|
+
assert_proc = Proc.new {
|
64
|
+
@assert.assert_equal_float(1.4, 1.34, 0)
|
65
|
+
}
|
66
|
+
sub_assert_raise_fail(assert_proc)
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_assert_equal_float_0_01
|
70
|
+
assert_proc = Proc.new {
|
71
|
+
@assert.assert_equal_float(1.4, 1.35, 0.01)
|
72
|
+
}
|
73
|
+
sub_assert_raise_fail(assert_proc)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_assert_equal_float_0_001
|
77
|
+
assert_proc = Proc.new {
|
78
|
+
@assert.assert_equal_float(Math.sqrt(2), 1.414, 0.001)
|
79
|
+
}
|
80
|
+
sub_assert_pass(assert_proc)
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_assert_equal_float_minus_1_0
|
84
|
+
assert_proc = Proc.new {
|
85
|
+
@assert.assert_equal_float(1.4, 1.35, -1.0)
|
86
|
+
}
|
87
|
+
sub_assert_raise_fail(assert_proc)
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_assert_fail
|
91
|
+
except = nil
|
92
|
+
begin
|
93
|
+
@assert.assert_fail("failure")
|
94
|
+
rescue Exception
|
95
|
+
except = $!
|
96
|
+
end
|
97
|
+
assert_not_nil(except)
|
98
|
+
end
|
99
|
+
|
100
|
+
def sub_test_assert_pass(obj)
|
101
|
+
assert_proc = Proc.new {
|
102
|
+
@assert.assert(obj)
|
103
|
+
}
|
104
|
+
sub_assert_pass(assert_proc)
|
105
|
+
end
|
106
|
+
|
107
|
+
def sub_test_assert_failure(obj)
|
108
|
+
assert_proc = Proc.new {
|
109
|
+
@assert.assert(obj)
|
110
|
+
}
|
111
|
+
sub_assert_raise_fail(assert_proc)
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_assert_equal
|
115
|
+
assert_proc = Proc.new {
|
116
|
+
@assert.assert_equal(2, 2)
|
117
|
+
}
|
118
|
+
sub_assert_pass(assert_proc)
|
119
|
+
assert_proc = Proc.new {
|
120
|
+
@assert.assert_equal(2, 3)
|
121
|
+
}
|
122
|
+
sub_assert_raise_fail(assert_proc)
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_assert_nil
|
126
|
+
obj = nil
|
127
|
+
assert_proc = Proc.new {
|
128
|
+
@assert.assert_nil(obj)
|
129
|
+
}
|
130
|
+
sub_assert_pass(assert_proc)
|
131
|
+
obj = 'string'
|
132
|
+
sub_assert_raise_fail(assert_proc)
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_assert_not_nil
|
136
|
+
obj = 'string'
|
137
|
+
assert_proc = Proc.new {
|
138
|
+
@assert.assert_not_nil(obj)
|
139
|
+
}
|
140
|
+
sub_assert_pass(assert_proc)
|
141
|
+
|
142
|
+
obj = nil
|
143
|
+
sub_assert_raise_fail(assert_proc)
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_assert_operator
|
147
|
+
assert_proc = Proc.new {
|
148
|
+
@assert.assert_operator(2, :<, 3)
|
149
|
+
}
|
150
|
+
sub_assert_pass(assert_proc)
|
151
|
+
assert_proc = Proc.new {
|
152
|
+
@assert.assert_operator(2, :>, 3)
|
153
|
+
}
|
154
|
+
sub_assert_raise_fail(assert_proc)
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_assert_respond_to
|
158
|
+
sub_test_assert_respond_to('string', 'sub', 'foo')
|
159
|
+
sub_test_assert_respond_to('string', :sub, :foo)
|
160
|
+
end
|
161
|
+
|
162
|
+
def sub_test_assert_respond_to(obj, msg, dummy_msg)
|
163
|
+
assert_proc = Proc.new {
|
164
|
+
@assert.assert_respond_to(msg, obj)
|
165
|
+
}
|
166
|
+
sub_assert_pass(assert_proc)
|
167
|
+
assert_proc = Proc.new {
|
168
|
+
@assert.assert_respond_to(dummy_msg, obj)
|
169
|
+
}
|
170
|
+
sub_assert_raise_fail(assert_proc)
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_assert_send
|
174
|
+
assert_proc = Proc.new {
|
175
|
+
ary = []
|
176
|
+
@assert.assert_send ary, :empty?
|
177
|
+
}
|
178
|
+
sub_assert_pass(assert_proc)
|
179
|
+
assert_proc = Proc.new {
|
180
|
+
ary = [2,3]
|
181
|
+
@assert.assert_send ary, :empty?
|
182
|
+
}
|
183
|
+
sub_assert_raise_fail(assert_proc)
|
184
|
+
assert_proc = Proc.new {
|
185
|
+
str = "abc"
|
186
|
+
@assert.assert_send str, :sub!, "z", "y"
|
187
|
+
}
|
188
|
+
sub_assert_raise_fail(assert_proc)
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_assert_kind_of
|
192
|
+
assert_proc = Proc.new {
|
193
|
+
@assert.assert_kind_of(String, "string")
|
194
|
+
}
|
195
|
+
sub_assert_pass(assert_proc)
|
196
|
+
assert_proc = Proc.new {
|
197
|
+
@assert.assert_kind_of(Regexp, "string")
|
198
|
+
}
|
199
|
+
sub_assert_raise_fail(assert_proc)
|
200
|
+
end
|
201
|
+
|
202
|
+
def test_assert_instance_of
|
203
|
+
assert_proc = Proc.new {
|
204
|
+
@assert.assert_instance_of(String, "string")
|
205
|
+
}
|
206
|
+
sub_assert_pass(assert_proc)
|
207
|
+
assert_proc = Proc.new {
|
208
|
+
@assert.assert_instance_of(Object, "string")
|
209
|
+
}
|
210
|
+
sub_assert_raise_fail(assert_proc)
|
211
|
+
end
|
212
|
+
|
213
|
+
def test_assert_match
|
214
|
+
assert_proc = Proc.new{
|
215
|
+
@assert.assert_match('foostring', /foo/)
|
216
|
+
}
|
217
|
+
sub_assert_pass(assert_proc)
|
218
|
+
assert_proc = Proc.new {
|
219
|
+
@assert.assert_match('barstring', /foo/)
|
220
|
+
}
|
221
|
+
sub_assert_raise_fail(assert_proc)
|
222
|
+
match = @assert.assert_match('foostring', /foo/)
|
223
|
+
assert_instance_of(MatchData, match)
|
224
|
+
assert_equal('foo', match[0])
|
225
|
+
end
|
226
|
+
|
227
|
+
def test_assert_matches
|
228
|
+
assert_proc = Proc.new{
|
229
|
+
@assert.assert_matches('foostring', /foo/)
|
230
|
+
}
|
231
|
+
sub_assert_pass(assert_proc)
|
232
|
+
assert_proc = Proc.new {
|
233
|
+
@assert.assert_matches('barstring', /foo/)
|
234
|
+
}
|
235
|
+
sub_assert_raise_fail(assert_proc)
|
236
|
+
end
|
237
|
+
|
238
|
+
def test_assert_not_match
|
239
|
+
assert_proc = Proc.new{
|
240
|
+
@assert.assert_not_match('barstring', /foo/)
|
241
|
+
}
|
242
|
+
sub_assert_pass(assert_proc)
|
243
|
+
assert_proc = Proc.new {
|
244
|
+
@assert.assert_not_match('foostring', /foo/)
|
245
|
+
}
|
246
|
+
sub_assert_raise_fail(assert_proc)
|
247
|
+
assert_proc = Proc.new {
|
248
|
+
@assert.assert_not_match('foobarbaz', /ba.+/)
|
249
|
+
}
|
250
|
+
sub_assert_raise_fail(assert_proc)
|
251
|
+
end
|
252
|
+
|
253
|
+
def test_assert_same
|
254
|
+
flag = false
|
255
|
+
e = "foo"
|
256
|
+
a = e
|
257
|
+
assert_proc = Proc.new {@assert.assert_same(e, a)}
|
258
|
+
sub_assert_pass(assert_proc)
|
259
|
+
|
260
|
+
a = "foo"
|
261
|
+
sub_assert_raise_fail(assert_proc)
|
262
|
+
end
|
263
|
+
|
264
|
+
def test_assert_exception
|
265
|
+
assert_proc = Proc.new{
|
266
|
+
@assert.assert_exception(IOError) {
|
267
|
+
raise IOError
|
268
|
+
}
|
269
|
+
}
|
270
|
+
sub_assert_pass(assert_proc)
|
271
|
+
|
272
|
+
assert_proc = Proc.new{
|
273
|
+
@assert.assert_exception(StandardError) {
|
274
|
+
raise IOError
|
275
|
+
}
|
276
|
+
}
|
277
|
+
sub_assert_raise_fail(assert_proc)
|
278
|
+
|
279
|
+
assert_proc = Proc.new{
|
280
|
+
@assert.assert_exception(IOError, "Exception") {
|
281
|
+
raise StandardError
|
282
|
+
}
|
283
|
+
}
|
284
|
+
sub_assert_raise_fail(assert_proc)
|
285
|
+
|
286
|
+
assert_proc = Proc.new {
|
287
|
+
@assert.assert_exception(StandardError) {
|
288
|
+
"No Exception raised in this block"
|
289
|
+
}
|
290
|
+
}
|
291
|
+
sub_assert_raise_fail(assert_proc)
|
292
|
+
|
293
|
+
assert_proc = Proc.new {
|
294
|
+
@assert.assert_exception(StandardError) {
|
295
|
+
exit(33)
|
296
|
+
}
|
297
|
+
}
|
298
|
+
sub_assert_raise_fail(assert_proc)
|
299
|
+
|
300
|
+
t = @assert.assert_exception(IOError) {
|
301
|
+
raise IOError
|
302
|
+
}
|
303
|
+
assert_instance_of(IOError, t)
|
304
|
+
t = @assert.assert_exception(NameError) {
|
305
|
+
non_existent_method
|
306
|
+
}
|
307
|
+
assert_instance_of(NameError, t)
|
308
|
+
t = @assert.assert_exception(SystemExit) {
|
309
|
+
exit(33)
|
310
|
+
}
|
311
|
+
assert_instance_of(SystemExit, t)
|
312
|
+
end
|
313
|
+
|
314
|
+
def test_assert_no_exception
|
315
|
+
assert_proc = Proc.new{
|
316
|
+
@assert.assert_no_exception(IOError, ArgumentError) {
|
317
|
+
"No Exception raised in this block"
|
318
|
+
}
|
319
|
+
}
|
320
|
+
sub_assert_pass(assert_proc)
|
321
|
+
|
322
|
+
assert_proc = Proc.new{
|
323
|
+
@assert.assert_no_exception(IOError, ArgumentError) {
|
324
|
+
raise StandardError, "Standard Error raised"
|
325
|
+
}
|
326
|
+
}
|
327
|
+
sub_assert_raise_error(assert_proc)
|
328
|
+
|
329
|
+
assert_proc = Proc.new{
|
330
|
+
@assert.assert_no_exception(IOError, ArgumentError) {
|
331
|
+
raise ArgumentError, "Bad Argument"
|
332
|
+
}
|
333
|
+
}
|
334
|
+
sub_assert_raise_fail(assert_proc)
|
335
|
+
|
336
|
+
assert_proc = Proc.new{
|
337
|
+
@assert.assert_no_exception {
|
338
|
+
raise ArgumentError, "Bad Argument"
|
339
|
+
}
|
340
|
+
}
|
341
|
+
sub_assert_raise_fail(assert_proc)
|
342
|
+
|
343
|
+
assert_proc = Proc.new{
|
344
|
+
@assert.assert_no_exception {
|
345
|
+
raise NameError, "Bad Name"
|
346
|
+
}
|
347
|
+
}
|
348
|
+
sub_assert_raise_fail(assert_proc)
|
349
|
+
assert_proc = Proc.new {
|
350
|
+
@assert.assert_no_exception {
|
351
|
+
raise NoMemoryError
|
352
|
+
}
|
353
|
+
}
|
354
|
+
sub_assert_raise_fail(assert_proc)
|
355
|
+
end
|
356
|
+
|
357
|
+
def sub_assert_pass(p)
|
358
|
+
flag = false
|
359
|
+
err = nil
|
360
|
+
begin
|
361
|
+
p.call
|
362
|
+
flag = true
|
363
|
+
rescue
|
364
|
+
err = $!
|
365
|
+
flag = false
|
366
|
+
end
|
367
|
+
assert(flag, err.to_s)
|
368
|
+
end
|
369
|
+
|
370
|
+
def sub_assert_raise_fail(p)
|
371
|
+
flag = false
|
372
|
+
err = nil
|
373
|
+
begin
|
374
|
+
p.call
|
375
|
+
flag = false
|
376
|
+
rescue RUNIT::AssertionFailedError
|
377
|
+
flag = true
|
378
|
+
err = $!
|
379
|
+
rescue Exception
|
380
|
+
flag = false
|
381
|
+
err = $!
|
382
|
+
end
|
383
|
+
assert(flag, err.to_s)
|
384
|
+
end
|
385
|
+
|
386
|
+
def sub_assert_raise_error(p)
|
387
|
+
flag = false
|
388
|
+
err = nil
|
389
|
+
begin
|
390
|
+
p.call
|
391
|
+
flag = false
|
392
|
+
rescue RUNIT::AssertionFailedError
|
393
|
+
flag = false
|
394
|
+
err = $!
|
395
|
+
rescue Exception
|
396
|
+
flag = true
|
397
|
+
err = $!
|
398
|
+
end
|
399
|
+
assert(flag, err.to_s)
|
400
|
+
end
|
401
|
+
end
|
402
|
+
end
|