test-unit 3.1.5 → 3.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/BSDL +24 -0
- data/COPYING +41 -41
- data/README.md +24 -17
- data/Rakefile +21 -24
- data/doc/text/getting-started.md +246 -0
- data/doc/text/news.md +797 -56
- data/lib/test/unit/assertion-failed-error.rb +35 -0
- data/lib/test/unit/assertions.rb +542 -220
- data/lib/test/unit/attribute.rb +78 -4
- data/lib/test/unit/auto-runner-loader.rb +17 -0
- data/lib/test/unit/autorunner.rb +175 -78
- data/lib/test/unit/code-snippet-fetcher.rb +7 -7
- data/lib/test/unit/collector/descendant.rb +1 -0
- data/lib/test/unit/collector/dir.rb +4 -2
- data/lib/test/unit/collector/load.rb +25 -15
- data/lib/test/unit/collector/objectspace.rb +1 -0
- data/lib/test/unit/collector.rb +31 -0
- data/lib/test/unit/color-scheme.rb +29 -2
- data/lib/test/unit/data-sets.rb +127 -0
- data/lib/test/unit/data.rb +121 -12
- data/lib/test/unit/diff.rb +10 -11
- data/lib/test/unit/fixture.rb +77 -27
- data/lib/test/unit/notification.rb +9 -7
- data/lib/test/unit/omission.rb +34 -31
- data/lib/test/unit/pending.rb +12 -11
- data/lib/test/unit/priority.rb +7 -5
- data/lib/test/unit/runner/console.rb +20 -1
- data/lib/test/unit/test-suite-creator.rb +30 -9
- data/lib/test/unit/testcase.rb +349 -196
- data/lib/test/unit/testresult.rb +7 -0
- data/lib/test/unit/testsuite.rb +1 -1
- data/lib/test/unit/ui/console/testrunner.rb +171 -60
- data/lib/test/unit/ui/emacs/testrunner.rb +5 -5
- data/lib/test/unit/ui/testrunnermediator.rb +9 -7
- data/lib/test/unit/util/backtracefilter.rb +17 -5
- data/lib/test/unit/util/memory-usage.rb +47 -0
- data/lib/test/unit/util/observable.rb +2 -2
- data/lib/test/unit/util/output.rb +5 -4
- data/lib/test/unit/util/procwrapper.rb +4 -4
- data/lib/test/unit/version.rb +1 -1
- data/lib/test/unit/warning.rb +3 -0
- data/lib/test/unit.rb +177 -161
- data/lib/test-unit.rb +2 -17
- metadata +20 -94
- data/GPL +0 -339
- data/LGPL +0 -502
- data/test/collector/test-descendant.rb +0 -178
- data/test/collector/test-load.rb +0 -442
- data/test/collector/test_dir.rb +0 -406
- data/test/collector/test_objectspace.rb +0 -100
- data/test/fixtures/header-label.csv +0 -3
- data/test/fixtures/header-label.tsv +0 -3
- data/test/fixtures/header.csv +0 -3
- data/test/fixtures/header.tsv +0 -3
- data/test/fixtures/no-header.csv +0 -2
- data/test/fixtures/no-header.tsv +0 -2
- data/test/fixtures/plus.csv +0 -3
- data/test/run-test.rb +0 -22
- data/test/test-assertions.rb +0 -2157
- data/test/test-attribute-matcher.rb +0 -38
- data/test/test-attribute.rb +0 -123
- data/test/test-code-snippet.rb +0 -37
- data/test/test-color-scheme.rb +0 -82
- data/test/test-color.rb +0 -47
- data/test/test-data.rb +0 -281
- data/test/test-diff.rb +0 -518
- data/test/test-emacs-runner.rb +0 -60
- data/test/test-error.rb +0 -26
- data/test/test-failure.rb +0 -33
- data/test/test-fault-location-detector.rb +0 -163
- data/test/test-fixture.rb +0 -659
- data/test/test-notification.rb +0 -33
- data/test/test-omission.rb +0 -81
- data/test/test-pending.rb +0 -70
- data/test/test-priority.rb +0 -173
- data/test/test-test-case.rb +0 -1171
- data/test/test-test-result.rb +0 -113
- data/test/test-test-suite-creator.rb +0 -97
- data/test/test-test-suite.rb +0 -150
- data/test/testunit-test-util.rb +0 -31
- data/test/ui/test_testrunmediator.rb +0 -20
- data/test/util/test-method-owner-finder.rb +0 -38
- data/test/util/test-output.rb +0 -11
- data/test/util/test_backtracefilter.rb +0 -41
- data/test/util/test_observable.rb +0 -102
- data/test/util/test_procwrapper.rb +0 -36
data/test/test-test-case.rb
DELETED
@@ -1,1171 +0,0 @@
|
|
1
|
-
# Author:: Nathaniel Talbott.
|
2
|
-
# Copyright:: Copyright (c) 2008-2014 Kouhei Sutou <kou@clear-code.com>
|
3
|
-
# Copyright:: Copyright (c) 2011 Haruka Yoshihara <yoshihara@clear-code.com>
|
4
|
-
# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott
|
5
|
-
# License:: Ruby license.
|
6
|
-
|
7
|
-
require 'test/unit'
|
8
|
-
|
9
|
-
module Test
|
10
|
-
module Unit
|
11
|
-
class TestTestCase < TestCase
|
12
|
-
self.test_order = :random
|
13
|
-
def test_creation
|
14
|
-
test_case = Class.new(TestCase) do
|
15
|
-
def test_with_arguments(arg1, arg2)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
test = test_case.new(:test_with_arguments)
|
20
|
-
check("Should have caught an invalid test when there are arguments",
|
21
|
-
!test.valid?)
|
22
|
-
|
23
|
-
test = test_case.new(:non_existent_test)
|
24
|
-
check("Should have caught an invalid test when the method does not exist",
|
25
|
-
!test.valid?)
|
26
|
-
end
|
27
|
-
|
28
|
-
def setup
|
29
|
-
@tc_failure_error = Class.new(TestCase) do
|
30
|
-
def test_failure
|
31
|
-
assert_block("failure") do
|
32
|
-
false
|
33
|
-
end
|
34
|
-
end
|
35
|
-
def test_error
|
36
|
-
1 / 0
|
37
|
-
end
|
38
|
-
def test_nested_failure
|
39
|
-
nested
|
40
|
-
end
|
41
|
-
def nested
|
42
|
-
assert_block("nested") do
|
43
|
-
false
|
44
|
-
end
|
45
|
-
end
|
46
|
-
def return_passed?
|
47
|
-
return passed?
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def @tc_failure_error.name
|
52
|
-
"TC_FailureError"
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def jruby_backtrace_entry?(entry)
|
57
|
-
entry.start_with?("org/jruby/")
|
58
|
-
end
|
59
|
-
|
60
|
-
def rubinius_backtrace_entry?(entry)
|
61
|
-
entry.start_with?("kernel/")
|
62
|
-
end
|
63
|
-
|
64
|
-
def normalize_location(location)
|
65
|
-
filtered_location = location.reject do |entry|
|
66
|
-
jruby_backtrace_entry?(entry) or
|
67
|
-
rubinius_backtrace_entry?(entry)
|
68
|
-
end
|
69
|
-
filtered_location.collect do |entry|
|
70
|
-
entry.sub(/:\d+:/, ":0:")
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_add_failed_assertion
|
75
|
-
test_case = @tc_failure_error.new(:test_failure)
|
76
|
-
assert do
|
77
|
-
test_case.passed?
|
78
|
-
end
|
79
|
-
|
80
|
-
result = TestResult.new
|
81
|
-
faults = []
|
82
|
-
result.add_listener(TestResult::FAULT) do |fault|
|
83
|
-
faults << fault
|
84
|
-
end
|
85
|
-
progress = []
|
86
|
-
test_case.run(result) do |*arguments|
|
87
|
-
progress << arguments
|
88
|
-
end
|
89
|
-
fault_details = faults.collect do |fault|
|
90
|
-
{
|
91
|
-
:class => fault.class,
|
92
|
-
:message => fault.message,
|
93
|
-
:test_name => fault.test_name,
|
94
|
-
:location => normalize_location(fault.location),
|
95
|
-
}
|
96
|
-
end
|
97
|
-
assert_equal([
|
98
|
-
{
|
99
|
-
:class => Failure,
|
100
|
-
:message => "failure",
|
101
|
-
:test_name => "test_failure(TC_FailureError)",
|
102
|
-
:location => [
|
103
|
-
"#{__FILE__}:0:in `test_failure'",
|
104
|
-
"#{__FILE__}:0:in `#{__method__}'",
|
105
|
-
],
|
106
|
-
},
|
107
|
-
],
|
108
|
-
fault_details)
|
109
|
-
|
110
|
-
assert do
|
111
|
-
not test_case.passed?
|
112
|
-
end
|
113
|
-
assert_equal([
|
114
|
-
[TestCase::STARTED, test_case.name],
|
115
|
-
[TestCase::STARTED_OBJECT, test_case],
|
116
|
-
[TestCase::FINISHED, test_case.name],
|
117
|
-
[TestCase::FINISHED_OBJECT, test_case],
|
118
|
-
],
|
119
|
-
progress)
|
120
|
-
end
|
121
|
-
|
122
|
-
def test_add_failure_nested
|
123
|
-
test_case = @tc_failure_error.new(:test_nested_failure)
|
124
|
-
assert do
|
125
|
-
test_case.passed?
|
126
|
-
end
|
127
|
-
|
128
|
-
result = TestResult.new
|
129
|
-
faults = []
|
130
|
-
result.add_listener(TestResult::FAULT) do |fault|
|
131
|
-
faults << fault
|
132
|
-
end
|
133
|
-
test_case.run(result) do
|
134
|
-
end
|
135
|
-
fault_details = faults.collect do |fault|
|
136
|
-
{
|
137
|
-
:class => fault.class,
|
138
|
-
:message => fault.message,
|
139
|
-
:test_name => fault.test_name,
|
140
|
-
:location => normalize_location(fault.location),
|
141
|
-
}
|
142
|
-
end
|
143
|
-
assert_equal([
|
144
|
-
{
|
145
|
-
:class => Failure,
|
146
|
-
:message => "nested",
|
147
|
-
:test_name => "test_nested_failure(TC_FailureError)",
|
148
|
-
:location => [
|
149
|
-
"#{__FILE__}:0:in `nested'",
|
150
|
-
"#{__FILE__}:0:in `test_nested_failure'",
|
151
|
-
"#{__FILE__}:0:in `#{__method__}'",
|
152
|
-
],
|
153
|
-
},
|
154
|
-
],
|
155
|
-
fault_details)
|
156
|
-
|
157
|
-
assert do
|
158
|
-
not test_case.passed?
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
def jruby?
|
163
|
-
defined?(JRUBY_VERSION)
|
164
|
-
end
|
165
|
-
|
166
|
-
def rubinius?
|
167
|
-
false # TODO
|
168
|
-
end
|
169
|
-
|
170
|
-
def cruby?
|
171
|
-
(not jruby?) and (not rubinius?)
|
172
|
-
end
|
173
|
-
|
174
|
-
def test_add_error
|
175
|
-
test_case = @tc_failure_error.new(:test_error)
|
176
|
-
assert do
|
177
|
-
test_case.passed?
|
178
|
-
end
|
179
|
-
|
180
|
-
result = TestResult.new
|
181
|
-
faults = []
|
182
|
-
result.add_listener(TestResult::FAULT) do |fault|
|
183
|
-
faults << fault
|
184
|
-
end
|
185
|
-
test_case.run(result) do
|
186
|
-
end
|
187
|
-
fault_details = faults.collect do |fault|
|
188
|
-
{
|
189
|
-
:class => fault.class,
|
190
|
-
:message => fault.message,
|
191
|
-
:test_name => fault.test_name,
|
192
|
-
:location => normalize_location(fault.location),
|
193
|
-
}
|
194
|
-
end
|
195
|
-
location = []
|
196
|
-
location << "#{__FILE__}:0:in `/'" if cruby?
|
197
|
-
location << "#{__FILE__}:0:in `test_error'"
|
198
|
-
location << "#{__FILE__}:0:in `#{__method__}'"
|
199
|
-
assert_equal([
|
200
|
-
{
|
201
|
-
:class => Error,
|
202
|
-
:message => "ZeroDivisionError: divided by 0",
|
203
|
-
:test_name => "test_error(TC_FailureError)",
|
204
|
-
:location => location,
|
205
|
-
},
|
206
|
-
],
|
207
|
-
fault_details)
|
208
|
-
|
209
|
-
assert do
|
210
|
-
not test_case.passed?
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
def test_no_tests
|
215
|
-
suite = TestCase.suite
|
216
|
-
check("Should have a test suite", suite.instance_of?(TestSuite))
|
217
|
-
check("Should have one test", suite.size == 1)
|
218
|
-
check("Should have the default test", suite.tests.first.name == "default_test(Test::Unit::TestCase)")
|
219
|
-
|
220
|
-
result = TestResult.new
|
221
|
-
suite.run(result) {}
|
222
|
-
check("Should have had one test run", result.run_count == 1)
|
223
|
-
check("Should have had one test failure", result.failure_count == 1)
|
224
|
-
check("Should have had no errors", result.error_count == 0)
|
225
|
-
end
|
226
|
-
|
227
|
-
def test_suite
|
228
|
-
tc = Class.new(TestCase) do
|
229
|
-
def test_succeed
|
230
|
-
assert_block {true}
|
231
|
-
end
|
232
|
-
def test_fail
|
233
|
-
assert_block {false}
|
234
|
-
end
|
235
|
-
def test_error
|
236
|
-
1/0
|
237
|
-
end
|
238
|
-
def dont_run
|
239
|
-
assert_block {true}
|
240
|
-
end
|
241
|
-
def test_dont_run(argument)
|
242
|
-
assert_block {true}
|
243
|
-
end
|
244
|
-
def test
|
245
|
-
assert_block {true}
|
246
|
-
end
|
247
|
-
end
|
248
|
-
|
249
|
-
suite = tc.suite
|
250
|
-
check("Should have a test suite", suite.instance_of?(TestSuite))
|
251
|
-
check("Should have three tests", suite.size == 3)
|
252
|
-
|
253
|
-
result = TestResult.new
|
254
|
-
suite.run(result) {}
|
255
|
-
check("Should have had three test runs", result.run_count == 3)
|
256
|
-
check("Should have had one test failure", result.failure_count == 1)
|
257
|
-
check("Should have had one test error", result.error_count == 1)
|
258
|
-
end
|
259
|
-
|
260
|
-
def test_setup_teardown
|
261
|
-
tc = Class.new(TestCase) do
|
262
|
-
attr_reader(:setup_called, :teardown_called)
|
263
|
-
def initialize(test)
|
264
|
-
super(test)
|
265
|
-
@setup_called = false
|
266
|
-
@teardown_called = false
|
267
|
-
end
|
268
|
-
def setup
|
269
|
-
@setup_called = true
|
270
|
-
end
|
271
|
-
def teardown
|
272
|
-
@teardown_called = true
|
273
|
-
end
|
274
|
-
def test_succeed
|
275
|
-
assert_block {true}
|
276
|
-
end
|
277
|
-
def test_fail
|
278
|
-
assert_block {false}
|
279
|
-
end
|
280
|
-
def test_error
|
281
|
-
raise "Error!"
|
282
|
-
end
|
283
|
-
end
|
284
|
-
result = TestResult.new
|
285
|
-
|
286
|
-
test = tc.new(:test_succeed)
|
287
|
-
test.run(result) {}
|
288
|
-
check("Should have called setup the correct number of times", test.setup_called)
|
289
|
-
check("Should have called teardown the correct number of times", test.teardown_called)
|
290
|
-
|
291
|
-
test = tc.new(:test_fail)
|
292
|
-
test.run(result) {}
|
293
|
-
check("Should have called setup the correct number of times", test.setup_called)
|
294
|
-
check("Should have called teardown the correct number of times", test.teardown_called)
|
295
|
-
|
296
|
-
test = tc.new(:test_error)
|
297
|
-
test.run(result) {}
|
298
|
-
check("Should have called setup the correct number of times", test.setup_called)
|
299
|
-
check("Should have called teardown the correct number of times", test.teardown_called)
|
300
|
-
|
301
|
-
check("Should have had two test runs", result.run_count == 3)
|
302
|
-
check("Should have had a test failure", result.failure_count == 1)
|
303
|
-
check("Should have had a test error", result.error_count == 1)
|
304
|
-
end
|
305
|
-
|
306
|
-
def test_assertion_failed_not_called
|
307
|
-
tc = Class.new(TestCase) do
|
308
|
-
def test_thing
|
309
|
-
raise AssertionFailedError.new
|
310
|
-
end
|
311
|
-
end
|
312
|
-
|
313
|
-
suite = tc.suite
|
314
|
-
check("Should have one test", suite.size == 1)
|
315
|
-
result = TestResult.new
|
316
|
-
suite.run(result) {}
|
317
|
-
check("Should have had one test run", result.run_count == 1)
|
318
|
-
check("Should have had one assertion failure", result.failure_count == 1)
|
319
|
-
check("Should not have any assertion errors but had #{result.error_count}", result.error_count == 0)
|
320
|
-
end
|
321
|
-
|
322
|
-
def test_equality
|
323
|
-
tc1 = Class.new(TestCase) do
|
324
|
-
def test_1
|
325
|
-
end
|
326
|
-
def test_2
|
327
|
-
end
|
328
|
-
end
|
329
|
-
|
330
|
-
tc2 = Class.new(TestCase) do
|
331
|
-
def test_1
|
332
|
-
end
|
333
|
-
end
|
334
|
-
|
335
|
-
test1 = tc1.new('test_1')
|
336
|
-
test2 = tc1.new('test_1')
|
337
|
-
check("Should be equal", test1 == test2)
|
338
|
-
check("Should be equal", test2 == test1)
|
339
|
-
|
340
|
-
test1 = tc1.new('test_2')
|
341
|
-
check("Should not be equal", test1 != test2)
|
342
|
-
check("Should not be equal", test2 != test1)
|
343
|
-
|
344
|
-
test2 = tc1.new('test_2')
|
345
|
-
check("Should be equal", test1 == test2)
|
346
|
-
check("Should be equal", test2 == test1)
|
347
|
-
|
348
|
-
test1 = tc1.new('test_1')
|
349
|
-
test2 = tc2.new('test_1')
|
350
|
-
check("Should not be equal", test1 != test2)
|
351
|
-
check("Should not be equal", test2 != test1)
|
352
|
-
|
353
|
-
check("Should not be equal", test1 != Object.new)
|
354
|
-
check("Should not be equal", Object.new != test1)
|
355
|
-
end
|
356
|
-
|
357
|
-
def test_re_raise_exception
|
358
|
-
test_case = Class.new(TestCase) do
|
359
|
-
def test_raise_interrupt
|
360
|
-
raise Interrupt, "from test"
|
361
|
-
end
|
362
|
-
end
|
363
|
-
|
364
|
-
test = test_case.new("test_raise_interrupt")
|
365
|
-
begin
|
366
|
-
test.run(TestResult.new) {}
|
367
|
-
check("Should not be reached", false)
|
368
|
-
rescue Exception
|
369
|
-
check("Interrupt exception should be re-raised", $!.class == Interrupt)
|
370
|
-
end
|
371
|
-
end
|
372
|
-
|
373
|
-
def test_timeout_error
|
374
|
-
test_case = Class.new(TestCase) do
|
375
|
-
def test_raise_timeout_error
|
376
|
-
require "timeout"
|
377
|
-
raise Timeout::Error
|
378
|
-
end
|
379
|
-
end
|
380
|
-
|
381
|
-
test_suite = test_case.suite
|
382
|
-
result = TestResult.new
|
383
|
-
begin
|
384
|
-
test_suite.run(result) {}
|
385
|
-
check("Timeout::Error should be handled as error",
|
386
|
-
result.error_count == 1)
|
387
|
-
rescue Exception
|
388
|
-
check("Timeout::Error should not be passed through: #{$!}", false)
|
389
|
-
end
|
390
|
-
end
|
391
|
-
|
392
|
-
def test_interrupted
|
393
|
-
test_case = Class.new(TestCase) do
|
394
|
-
def test_fail
|
395
|
-
flunk
|
396
|
-
end
|
397
|
-
|
398
|
-
def test_nothing
|
399
|
-
end
|
400
|
-
end
|
401
|
-
|
402
|
-
failed_test = test_case.new(:test_fail)
|
403
|
-
failed_test.run(TestResult.new) {}
|
404
|
-
check("Should be interrupted", failed_test.interrupted?)
|
405
|
-
|
406
|
-
success_test = test_case.new(:test_nothing)
|
407
|
-
success_test.run(TestResult.new) {}
|
408
|
-
check("Should not be interrupted", !success_test.interrupted?)
|
409
|
-
end
|
410
|
-
|
411
|
-
def test_inherited_test_should_be_ignored
|
412
|
-
test_case = Class.new(TestCase) do
|
413
|
-
def test_nothing
|
414
|
-
end
|
415
|
-
end
|
416
|
-
|
417
|
-
sub_test_case = Class.new(test_case) do
|
418
|
-
def test_fail
|
419
|
-
flunk
|
420
|
-
end
|
421
|
-
end
|
422
|
-
|
423
|
-
test = test_case.new("test_nothing")
|
424
|
-
assert_predicate(test, :valid?)
|
425
|
-
|
426
|
-
test = sub_test_case.new("test_fail")
|
427
|
-
assert_predicate(test, :valid?)
|
428
|
-
|
429
|
-
test = sub_test_case.new("test_nothing")
|
430
|
-
assert_not_predicate(test, :valid?)
|
431
|
-
end
|
432
|
-
|
433
|
-
def test_mixin_test_should_not_be_ignored
|
434
|
-
test_module = Module.new do
|
435
|
-
def test_nothing
|
436
|
-
end
|
437
|
-
end
|
438
|
-
|
439
|
-
test_case = Class.new(Test::Unit::TestCase) do
|
440
|
-
include test_module
|
441
|
-
|
442
|
-
def test_fail
|
443
|
-
flunk
|
444
|
-
end
|
445
|
-
end
|
446
|
-
|
447
|
-
assert_nothing_thrown do
|
448
|
-
test_case.new("test_nothing")
|
449
|
-
end
|
450
|
-
|
451
|
-
assert_nothing_thrown do
|
452
|
-
test_case.new("test_fail")
|
453
|
-
end
|
454
|
-
end
|
455
|
-
|
456
|
-
def test_defined_order
|
457
|
-
test_case = Class.new(Test::Unit::TestCase) do
|
458
|
-
def test_z
|
459
|
-
end
|
460
|
-
|
461
|
-
def test_1
|
462
|
-
end
|
463
|
-
|
464
|
-
def test_a
|
465
|
-
end
|
466
|
-
end
|
467
|
-
|
468
|
-
assert_equal(["test_1", "test_a", "test_z"],
|
469
|
-
test_case.suite.tests.collect {|test| test.method_name})
|
470
|
-
|
471
|
-
test_case.test_order = :defined
|
472
|
-
assert_equal(["test_z", "test_1", "test_a"],
|
473
|
-
test_case.suite.tests.collect {|test| test.method_name})
|
474
|
-
end
|
475
|
-
|
476
|
-
def test_declarative_style
|
477
|
-
test_case = Class.new(Test::Unit::TestCase) do
|
478
|
-
test "declarative style test definition" do
|
479
|
-
end
|
480
|
-
|
481
|
-
test "include parenthesis" do
|
482
|
-
end
|
483
|
-
|
484
|
-
test "1 + 2 = 3" do
|
485
|
-
end
|
486
|
-
end
|
487
|
-
|
488
|
-
test_case.test_order = :defined
|
489
|
-
|
490
|
-
assert_equal(["test: declarative style test definition",
|
491
|
-
"test: include parenthesis",
|
492
|
-
"test: 1 + 2 = 3"],
|
493
|
-
test_case.suite.tests.collect {|test| test.method_name})
|
494
|
-
|
495
|
-
assert_equal(["declarative style test definition",
|
496
|
-
"include parenthesis",
|
497
|
-
"1 + 2 = 3"],
|
498
|
-
test_case.suite.tests.collect {|test| test.description})
|
499
|
-
end
|
500
|
-
|
501
|
-
def test_test_mark
|
502
|
-
test_case = Class.new(Test::Unit::TestCase) do
|
503
|
-
test
|
504
|
-
def my_test_method
|
505
|
-
end
|
506
|
-
end
|
507
|
-
|
508
|
-
test_case.test_order = :defined
|
509
|
-
|
510
|
-
assert_equal(["my_test_method"],
|
511
|
-
test_case.suite.tests.collect {|test| test.method_name})
|
512
|
-
end
|
513
|
-
|
514
|
-
def test_redefine_method
|
515
|
-
test_case = Class.new(Test::Unit::TestCase) do
|
516
|
-
def test_name
|
517
|
-
end
|
518
|
-
alias_method :test_name2, :test_name
|
519
|
-
|
520
|
-
def test_name
|
521
|
-
end
|
522
|
-
end
|
523
|
-
|
524
|
-
suite = test_case.suite
|
525
|
-
assert_equal(["test_name", "test_name2"],
|
526
|
-
suite.tests.collect {|test| test.method_name})
|
527
|
-
result = TestResult.new
|
528
|
-
suite.run(result) {}
|
529
|
-
assert_equal("2 tests, 0 assertions, 0 failures, " +
|
530
|
-
"0 errors, 0 pendings, 0 omissions, 1 notifications",
|
531
|
-
result.summary)
|
532
|
-
end
|
533
|
-
|
534
|
-
def test_data_driven_test
|
535
|
-
test_case = Class.new(TestCase) do
|
536
|
-
def test_with_data(data)
|
537
|
-
end
|
538
|
-
end
|
539
|
-
|
540
|
-
test = test_case.new("test_with_data")
|
541
|
-
assert_not_predicate(test, :valid?)
|
542
|
-
test.assign_test_data("label1", :test_data1)
|
543
|
-
assert_predicate(test, :valid?)
|
544
|
-
end
|
545
|
-
|
546
|
-
private
|
547
|
-
def check(message, passed)
|
548
|
-
add_assertion
|
549
|
-
raise AssertionFailedError.new(message) unless passed
|
550
|
-
end
|
551
|
-
|
552
|
-
class TestTestDefined < self
|
553
|
-
class TestNoQuery < self
|
554
|
-
def test_no_test
|
555
|
-
test_case = Class.new(TestCase) do
|
556
|
-
end
|
557
|
-
assert_false(test_case.test_defined?({}))
|
558
|
-
end
|
559
|
-
|
560
|
-
def test_have_def_style_test
|
561
|
-
test_case = Class.new(TestCase) do
|
562
|
-
def test_nothing
|
563
|
-
end
|
564
|
-
end
|
565
|
-
assert_true(test_case.test_defined?({}))
|
566
|
-
end
|
567
|
-
|
568
|
-
def test_have_method_style_test
|
569
|
-
test_case = Class.new(TestCase) do
|
570
|
-
test "nothing" do
|
571
|
-
end
|
572
|
-
end
|
573
|
-
assert_true(test_case.test_defined?({}))
|
574
|
-
end
|
575
|
-
end
|
576
|
-
|
577
|
-
class TestPath < self
|
578
|
-
class TestDefStyle < self
|
579
|
-
def test_base_name
|
580
|
-
test_case = Class.new(TestCase) do
|
581
|
-
def test_nothing
|
582
|
-
end
|
583
|
-
end
|
584
|
-
base_name = File.basename(__FILE__)
|
585
|
-
assert_true(test_case.test_defined?(:path => base_name))
|
586
|
-
end
|
587
|
-
|
588
|
-
def test_absolute_path
|
589
|
-
test_case = Class.new(TestCase) do
|
590
|
-
def test_nothing
|
591
|
-
end
|
592
|
-
end
|
593
|
-
assert_true(test_case.test_defined?(:path => __FILE__))
|
594
|
-
end
|
595
|
-
|
596
|
-
def test_not_match
|
597
|
-
test_case = Class.new(TestCase) do
|
598
|
-
def test_nothing
|
599
|
-
end
|
600
|
-
end
|
601
|
-
assert_false(test_case.test_defined?(:path => "nonexistent.rb"))
|
602
|
-
end
|
603
|
-
end
|
604
|
-
|
605
|
-
class TestMethodStyle < self
|
606
|
-
def test_base_name
|
607
|
-
test_case = Class.new(TestCase) do
|
608
|
-
test "nothing" do
|
609
|
-
end
|
610
|
-
end
|
611
|
-
base_name = File.basename(__FILE__)
|
612
|
-
assert_true(test_case.test_defined?(:path => base_name))
|
613
|
-
end
|
614
|
-
|
615
|
-
def test_absolute_path
|
616
|
-
test_case = Class.new(TestCase) do
|
617
|
-
test "nothing" do
|
618
|
-
end
|
619
|
-
end
|
620
|
-
assert_true(test_case.test_defined?(:path => __FILE__))
|
621
|
-
end
|
622
|
-
|
623
|
-
def test_not_match
|
624
|
-
test_case = Class.new(TestCase) do
|
625
|
-
test "nothing" do
|
626
|
-
end
|
627
|
-
end
|
628
|
-
assert_false(test_case.test_defined?(:path => "nonexistent.rb"))
|
629
|
-
end
|
630
|
-
end
|
631
|
-
end
|
632
|
-
|
633
|
-
class TestLine < self
|
634
|
-
class TestDefStyle < self
|
635
|
-
def test_before
|
636
|
-
line_before = nil
|
637
|
-
test_case = Class.new(TestCase) do
|
638
|
-
line_before = __LINE__
|
639
|
-
def test_nothing
|
640
|
-
end
|
641
|
-
end
|
642
|
-
assert_false(test_case.test_defined?(:line => line_before))
|
643
|
-
end
|
644
|
-
|
645
|
-
def test_def
|
646
|
-
line_def = nil
|
647
|
-
test_case = Class.new(TestCase) do
|
648
|
-
line_def = __LINE__; def test_nothing
|
649
|
-
end
|
650
|
-
end
|
651
|
-
assert_true(test_case.test_defined?(:line => line_def))
|
652
|
-
end
|
653
|
-
|
654
|
-
def test_after
|
655
|
-
line_after = nil
|
656
|
-
test_case = Class.new(TestCase) do
|
657
|
-
def test_nothing
|
658
|
-
end
|
659
|
-
line_after = __LINE__
|
660
|
-
end
|
661
|
-
assert_true(test_case.test_defined?(:line => line_after))
|
662
|
-
end
|
663
|
-
|
664
|
-
def test_child
|
665
|
-
child_test_case = nil
|
666
|
-
line_child = nil
|
667
|
-
parent_test_case = Class.new(TestCase) do
|
668
|
-
test "parent" do
|
669
|
-
end
|
670
|
-
|
671
|
-
child_test_case = Class.new(self) do
|
672
|
-
line_child = __LINE__; test "child" do
|
673
|
-
end
|
674
|
-
end
|
675
|
-
end
|
676
|
-
assert_equal([
|
677
|
-
false,
|
678
|
-
true,
|
679
|
-
],
|
680
|
-
[
|
681
|
-
parent_test_case.test_defined?(:line => line_child),
|
682
|
-
child_test_case.test_defined?(:line => line_child),
|
683
|
-
])
|
684
|
-
end
|
685
|
-
end
|
686
|
-
|
687
|
-
class TestMethodStyle < self
|
688
|
-
def test_before
|
689
|
-
line_before = nil
|
690
|
-
test_case = Class.new(TestCase) do
|
691
|
-
line_before = __LINE__
|
692
|
-
test "nothing" do
|
693
|
-
end
|
694
|
-
end
|
695
|
-
assert_false(test_case.test_defined?(:line => line_before))
|
696
|
-
end
|
697
|
-
|
698
|
-
def test_method
|
699
|
-
line_method = nil
|
700
|
-
test_case = Class.new(TestCase) do
|
701
|
-
line_method = __LINE__; test "nothing" do
|
702
|
-
end
|
703
|
-
end
|
704
|
-
assert_true(test_case.test_defined?(:line => line_method))
|
705
|
-
end
|
706
|
-
|
707
|
-
def test_after
|
708
|
-
line_after = nil
|
709
|
-
test_case = Class.new(TestCase) do
|
710
|
-
test "nothing" do
|
711
|
-
end
|
712
|
-
line_after = __LINE__
|
713
|
-
end
|
714
|
-
assert_true(test_case.test_defined?(:line => line_after))
|
715
|
-
end
|
716
|
-
|
717
|
-
def test_child
|
718
|
-
child_test_case = nil
|
719
|
-
line_child = nil
|
720
|
-
parent_test_case = Class.new(TestCase) do
|
721
|
-
test "parent" do
|
722
|
-
end
|
723
|
-
|
724
|
-
child_test_case = Class.new(self) do
|
725
|
-
line_child = __LINE__; test "child" do
|
726
|
-
end
|
727
|
-
end
|
728
|
-
end
|
729
|
-
assert_equal([
|
730
|
-
false,
|
731
|
-
true,
|
732
|
-
],
|
733
|
-
[
|
734
|
-
parent_test_case.test_defined?(:line => line_child),
|
735
|
-
child_test_case.test_defined?(:line => line_child),
|
736
|
-
])
|
737
|
-
end
|
738
|
-
end
|
739
|
-
end
|
740
|
-
|
741
|
-
class TestMethodName < self
|
742
|
-
class TestDefStyle < self
|
743
|
-
def test_match
|
744
|
-
test_case = Class.new(TestCase) do
|
745
|
-
def test_nothing
|
746
|
-
end
|
747
|
-
end
|
748
|
-
query = {:method_name => "test_nothing"}
|
749
|
-
assert_true(test_case.test_defined?(query))
|
750
|
-
end
|
751
|
-
|
752
|
-
def test_not_match
|
753
|
-
test_case = Class.new(TestCase) do
|
754
|
-
def test_nothing
|
755
|
-
end
|
756
|
-
end
|
757
|
-
query = {:method_name => "test_nonexistent"}
|
758
|
-
assert_false(test_case.test_defined?(query))
|
759
|
-
end
|
760
|
-
end
|
761
|
-
|
762
|
-
class TestMethodStyle < self
|
763
|
-
def test_match
|
764
|
-
test_case = Class.new(TestCase) do
|
765
|
-
test "nothing" do
|
766
|
-
end
|
767
|
-
end
|
768
|
-
query = {:method_name => "test: nothing"}
|
769
|
-
assert_true(test_case.test_defined?(query))
|
770
|
-
end
|
771
|
-
|
772
|
-
def test_not_match
|
773
|
-
test_case = Class.new(TestCase) do
|
774
|
-
test "nothing" do
|
775
|
-
end
|
776
|
-
end
|
777
|
-
query = {:method_name => "test: nonexistent"}
|
778
|
-
assert_false(test_case.test_defined?(query))
|
779
|
-
end
|
780
|
-
end
|
781
|
-
end
|
782
|
-
|
783
|
-
class TestCombine < self
|
784
|
-
class TestDefStyle < self
|
785
|
-
def test_line_middle
|
786
|
-
line_middle = nil
|
787
|
-
test_case = Class.new(TestCase) do
|
788
|
-
def test_before
|
789
|
-
end
|
790
|
-
line_middle = __LINE__
|
791
|
-
def test_after
|
792
|
-
end
|
793
|
-
end
|
794
|
-
query = {
|
795
|
-
:path => __FILE__,
|
796
|
-
:line => line_middle,
|
797
|
-
:method_name => "test_before",
|
798
|
-
}
|
799
|
-
assert_true(test_case.test_defined?(query))
|
800
|
-
end
|
801
|
-
|
802
|
-
def test_line_after_def
|
803
|
-
line_after_def = nil
|
804
|
-
test_case = Class.new(TestCase) do
|
805
|
-
def test_before
|
806
|
-
end
|
807
|
-
|
808
|
-
line_after_def = __LINE__; def test_after
|
809
|
-
end
|
810
|
-
end
|
811
|
-
query = {
|
812
|
-
:path => __FILE__,
|
813
|
-
:line => line_after_def,
|
814
|
-
:method_name => "test_before",
|
815
|
-
}
|
816
|
-
assert_false(test_case.test_defined?(query))
|
817
|
-
end
|
818
|
-
end
|
819
|
-
|
820
|
-
class TestMethodStyle < self
|
821
|
-
def test_line_middle
|
822
|
-
line_middle = nil
|
823
|
-
test_case = Class.new(TestCase) do
|
824
|
-
test "before" do
|
825
|
-
end
|
826
|
-
line_middle = __LINE__
|
827
|
-
test "after" do
|
828
|
-
end
|
829
|
-
end
|
830
|
-
query = {
|
831
|
-
:path => __FILE__,
|
832
|
-
:line => line_middle,
|
833
|
-
:method_name => "test: before",
|
834
|
-
}
|
835
|
-
assert_true(test_case.test_defined?(query))
|
836
|
-
end
|
837
|
-
|
838
|
-
def test_line_after_method
|
839
|
-
line_after_method = nil
|
840
|
-
test_case = Class.new(TestCase) do
|
841
|
-
test "before" do
|
842
|
-
end
|
843
|
-
|
844
|
-
line_after_method = __LINE__; test "after" do
|
845
|
-
end
|
846
|
-
end
|
847
|
-
query = {
|
848
|
-
:path => __FILE__,
|
849
|
-
:line => line_after_method,
|
850
|
-
:method_name => "test: before",
|
851
|
-
}
|
852
|
-
assert_false(test_case.test_defined?(query))
|
853
|
-
end
|
854
|
-
end
|
855
|
-
end
|
856
|
-
end
|
857
|
-
|
858
|
-
class TestSubTestCase < self
|
859
|
-
class TestName < self
|
860
|
-
def test_anonymous
|
861
|
-
test_case = Class.new(TestCase)
|
862
|
-
sub_test_case = test_case.sub_test_case("sub test case") do
|
863
|
-
end
|
864
|
-
assert_equal("sub test case", sub_test_case.name)
|
865
|
-
end
|
866
|
-
|
867
|
-
def test_named
|
868
|
-
test_case = Class.new(TestCase)
|
869
|
-
def test_case.name
|
870
|
-
"ParentTestCase"
|
871
|
-
end
|
872
|
-
sub_test_case = test_case.sub_test_case("sub test case") do
|
873
|
-
end
|
874
|
-
assert_equal("ParentTestCase::sub test case", sub_test_case.name)
|
875
|
-
end
|
876
|
-
end
|
877
|
-
|
878
|
-
def test_suite
|
879
|
-
test_case = Class.new(TestCase)
|
880
|
-
sub_test_case = test_case.sub_test_case("sub test case") do
|
881
|
-
def test_nothing
|
882
|
-
end
|
883
|
-
end
|
884
|
-
test_method_names = sub_test_case.suite.tests.collect do |test|
|
885
|
-
test.method_name
|
886
|
-
end
|
887
|
-
assert_equal(["test_nothing"], test_method_names)
|
888
|
-
end
|
889
|
-
|
890
|
-
def test_duplicated_name
|
891
|
-
test_case = Class.new(TestCase) do
|
892
|
-
def test_nothing
|
893
|
-
end
|
894
|
-
end
|
895
|
-
sub_test_case = test_case.sub_test_case("sub test case") do
|
896
|
-
def test_nothing
|
897
|
-
end
|
898
|
-
end
|
899
|
-
|
900
|
-
test_method_names = test_case.suite.tests.collect do |test|
|
901
|
-
test.method_name
|
902
|
-
end
|
903
|
-
sub_test_method_names = sub_test_case.suite.tests.collect do |test|
|
904
|
-
test.method_name
|
905
|
-
end
|
906
|
-
|
907
|
-
assert_equal([
|
908
|
-
["test_nothing"],
|
909
|
-
["test_nothing"],
|
910
|
-
],
|
911
|
-
[
|
912
|
-
test_method_names,
|
913
|
-
sub_test_method_names,
|
914
|
-
])
|
915
|
-
end
|
916
|
-
end
|
917
|
-
|
918
|
-
class TestStartupShutdown < self
|
919
|
-
class TestOrder < self
|
920
|
-
module CallLogger
|
921
|
-
def called
|
922
|
-
@@called ||= []
|
923
|
-
end
|
924
|
-
end
|
925
|
-
|
926
|
-
def call_order(test_case)
|
927
|
-
test_case.called.clear
|
928
|
-
test_suite = test_case.suite
|
929
|
-
test_suite.run(TestResult.new) {}
|
930
|
-
test_case.called
|
931
|
-
end
|
932
|
-
|
933
|
-
class TestNoInheritance < self
|
934
|
-
def setup
|
935
|
-
@test_case = Class.new(TestCase) do
|
936
|
-
extend CallLogger
|
937
|
-
|
938
|
-
class << self
|
939
|
-
def startup
|
940
|
-
called << :startup
|
941
|
-
end
|
942
|
-
|
943
|
-
def shutdown
|
944
|
-
called << :shutdown
|
945
|
-
end
|
946
|
-
end
|
947
|
-
|
948
|
-
def setup
|
949
|
-
self.class.called << :setup
|
950
|
-
end
|
951
|
-
|
952
|
-
def teardown
|
953
|
-
self.class.called << :teardown
|
954
|
-
end
|
955
|
-
|
956
|
-
def test1
|
957
|
-
end
|
958
|
-
|
959
|
-
def test2
|
960
|
-
end
|
961
|
-
end
|
962
|
-
end
|
963
|
-
|
964
|
-
def test_call_order
|
965
|
-
assert_equal([
|
966
|
-
:startup,
|
967
|
-
:setup, :teardown,
|
968
|
-
:setup, :teardown,
|
969
|
-
:shutdown,
|
970
|
-
],
|
971
|
-
call_order(@test_case))
|
972
|
-
end
|
973
|
-
end
|
974
|
-
|
975
|
-
class TestInheritance < self
|
976
|
-
def setup
|
977
|
-
@original_descendants = TestCase::DESCENDANTS.dup
|
978
|
-
TestCase::DESCENDANTS.clear
|
979
|
-
|
980
|
-
@parent_test_case = Class.new(TestCase) do
|
981
|
-
extend CallLogger
|
982
|
-
|
983
|
-
class << self
|
984
|
-
def startup
|
985
|
-
called << :startup_parent
|
986
|
-
end
|
987
|
-
|
988
|
-
def shutdown
|
989
|
-
called << :shutdown_parent
|
990
|
-
end
|
991
|
-
end
|
992
|
-
|
993
|
-
def setup
|
994
|
-
self.class.called << :setup_parent
|
995
|
-
end
|
996
|
-
|
997
|
-
def teardown
|
998
|
-
self.class.called << :teardown_parent
|
999
|
-
end
|
1000
|
-
|
1001
|
-
def test1_parent
|
1002
|
-
self.class.called << :test1_parent
|
1003
|
-
end
|
1004
|
-
|
1005
|
-
def test2_parent
|
1006
|
-
self.class.called << :test2_parent
|
1007
|
-
end
|
1008
|
-
end
|
1009
|
-
|
1010
|
-
@child_test_case = Class.new(@parent_test_case) do
|
1011
|
-
class << self
|
1012
|
-
def startup
|
1013
|
-
called << :startup_child
|
1014
|
-
end
|
1015
|
-
|
1016
|
-
def shutdown
|
1017
|
-
called << :shutdown_child
|
1018
|
-
end
|
1019
|
-
end
|
1020
|
-
|
1021
|
-
def setup
|
1022
|
-
self.class.called << :setup_child
|
1023
|
-
end
|
1024
|
-
|
1025
|
-
def teardown
|
1026
|
-
self.class.called << :teardown_child
|
1027
|
-
end
|
1028
|
-
|
1029
|
-
def test1_child
|
1030
|
-
self.class.called << :test1_child
|
1031
|
-
end
|
1032
|
-
|
1033
|
-
def test2_child
|
1034
|
-
self.class.called << :test2_child
|
1035
|
-
end
|
1036
|
-
end
|
1037
|
-
end
|
1038
|
-
|
1039
|
-
def teardown
|
1040
|
-
TestCase::DESCENDANTS.replace(@original_descendants)
|
1041
|
-
end
|
1042
|
-
|
1043
|
-
def test_call_order
|
1044
|
-
collector = Collector::Descendant.new
|
1045
|
-
test_suite = collector.collect
|
1046
|
-
test_suite.run(TestResult.new) {}
|
1047
|
-
called = @parent_test_case.called
|
1048
|
-
assert_equal([
|
1049
|
-
:startup_parent,
|
1050
|
-
:setup_parent, :test1_parent, :teardown_parent,
|
1051
|
-
:setup_parent, :test2_parent, :teardown_parent,
|
1052
|
-
:startup_child,
|
1053
|
-
:setup_child, :test1_child, :teardown_child,
|
1054
|
-
:setup_child, :test2_child, :teardown_child,
|
1055
|
-
:shutdown_child,
|
1056
|
-
:shutdown_parent,
|
1057
|
-
],
|
1058
|
-
called)
|
1059
|
-
end
|
1060
|
-
end
|
1061
|
-
end
|
1062
|
-
|
1063
|
-
class TestError < self
|
1064
|
-
def run_test_case(test_case)
|
1065
|
-
test_suite = test_case.suite
|
1066
|
-
result = TestResult.new
|
1067
|
-
test_suite.run(result) {}
|
1068
|
-
result
|
1069
|
-
end
|
1070
|
-
|
1071
|
-
def error_count(test_case)
|
1072
|
-
run_test_case(test_case).error_count
|
1073
|
-
end
|
1074
|
-
|
1075
|
-
def test_on_startup
|
1076
|
-
test_case = Class.new(TestCase) do
|
1077
|
-
class << self
|
1078
|
-
def startup
|
1079
|
-
raise "from startup"
|
1080
|
-
end
|
1081
|
-
end
|
1082
|
-
|
1083
|
-
def test_nothing
|
1084
|
-
end
|
1085
|
-
end
|
1086
|
-
|
1087
|
-
assert_equal(1, error_count(test_case))
|
1088
|
-
end
|
1089
|
-
|
1090
|
-
def test_pass_through_on_startup
|
1091
|
-
test_case = Class.new(TestCase) do
|
1092
|
-
class << self
|
1093
|
-
def startup
|
1094
|
-
raise Interrupt, "from startup"
|
1095
|
-
end
|
1096
|
-
end
|
1097
|
-
|
1098
|
-
def test_nothing
|
1099
|
-
end
|
1100
|
-
end
|
1101
|
-
|
1102
|
-
assert_raise(Interrupt) do
|
1103
|
-
run_test_case(test_case)
|
1104
|
-
end
|
1105
|
-
end
|
1106
|
-
|
1107
|
-
def test_on_shutdown
|
1108
|
-
test_case = Class.new(TestCase) do
|
1109
|
-
class << self
|
1110
|
-
def shutdown
|
1111
|
-
raise "from shutdown"
|
1112
|
-
end
|
1113
|
-
end
|
1114
|
-
|
1115
|
-
def test_nothing
|
1116
|
-
end
|
1117
|
-
end
|
1118
|
-
|
1119
|
-
assert_equal(1, error_count(test_case))
|
1120
|
-
end
|
1121
|
-
|
1122
|
-
def test_pass_through_on_shutdown
|
1123
|
-
test_case = Class.new(TestCase) do
|
1124
|
-
class << self
|
1125
|
-
def shutdown
|
1126
|
-
raise Interrupt, "from shutdown"
|
1127
|
-
end
|
1128
|
-
end
|
1129
|
-
|
1130
|
-
def test_nothing
|
1131
|
-
end
|
1132
|
-
end
|
1133
|
-
|
1134
|
-
assert_raise(Interrupt) do
|
1135
|
-
run_test_case(test_case)
|
1136
|
-
end
|
1137
|
-
end
|
1138
|
-
|
1139
|
-
def test_pass_through_in_test
|
1140
|
-
test_case = Class.new(TestCase) do
|
1141
|
-
@called = []
|
1142
|
-
class << self
|
1143
|
-
def called
|
1144
|
-
@called
|
1145
|
-
end
|
1146
|
-
|
1147
|
-
def startup
|
1148
|
-
@called << :startup
|
1149
|
-
end
|
1150
|
-
|
1151
|
-
def shutdown
|
1152
|
-
@called << :shutdown
|
1153
|
-
end
|
1154
|
-
end
|
1155
|
-
|
1156
|
-
def test_error
|
1157
|
-
raise Interrupt, "from test"
|
1158
|
-
end
|
1159
|
-
end
|
1160
|
-
|
1161
|
-
assert_raise(Interrupt) do
|
1162
|
-
run_test_case(test_case)
|
1163
|
-
end
|
1164
|
-
assert_equal([:startup, :shutdown],
|
1165
|
-
test_case.called)
|
1166
|
-
end
|
1167
|
-
end
|
1168
|
-
end
|
1169
|
-
end
|
1170
|
-
end
|
1171
|
-
end
|