test-unit 3.1.4 → 3.6.2
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 +824 -54
- 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 +200 -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/fault-location-detector.rb +1 -1
- 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 +10 -23
- metadata +21 -95
- 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/lib/test/unit/testcase.rb
CHANGED
@@ -20,6 +20,7 @@ require 'test/unit/data'
|
|
20
20
|
require 'test/unit/testsuite'
|
21
21
|
require 'test/unit/test-suite-creator'
|
22
22
|
require 'test/unit/assertion-failed-error'
|
23
|
+
require 'test/unit/auto-runner-loader'
|
23
24
|
require 'test/unit/util/backtracefilter'
|
24
25
|
require 'test/unit/util/output'
|
25
26
|
require 'test/unit/util/method-owner-finder'
|
@@ -36,49 +37,70 @@ module Test
|
|
36
37
|
# You can run two hooks before/after a TestCase run.
|
37
38
|
#
|
38
39
|
# Example:
|
39
|
-
#
|
40
|
-
# class
|
41
|
-
#
|
40
|
+
#
|
41
|
+
# class TestMyClass < Test::Unit::TestCase
|
42
|
+
# class << self
|
43
|
+
# def startup
|
44
|
+
# ...
|
45
|
+
# end
|
46
|
+
#
|
47
|
+
# def shutdown
|
48
|
+
# ...
|
49
|
+
# end
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
# def setup
|
42
53
|
# ...
|
43
54
|
# end
|
44
55
|
#
|
45
|
-
# def
|
56
|
+
# def cleanup
|
46
57
|
# ...
|
47
58
|
# end
|
48
|
-
# end
|
49
59
|
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
60
|
+
# def teardown
|
61
|
+
# ...
|
62
|
+
# end
|
53
63
|
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
64
|
+
# def test_my_method1
|
65
|
+
# ...
|
66
|
+
# end
|
57
67
|
#
|
58
|
-
#
|
59
|
-
#
|
68
|
+
# def test_my_method2
|
69
|
+
# ...
|
70
|
+
# end
|
60
71
|
# end
|
61
72
|
#
|
62
|
-
#
|
63
|
-
# ...
|
64
|
-
# end
|
73
|
+
# Here is a call order:
|
65
74
|
#
|
66
|
-
#
|
67
|
-
#
|
68
|
-
#
|
69
|
-
#
|
75
|
+
# 1. startup
|
76
|
+
# 1. setup
|
77
|
+
# 1. test_my_method1
|
78
|
+
# 1. cleanup
|
79
|
+
# 1. teardown
|
80
|
+
# 1. setup
|
81
|
+
# 1. test_my_method2
|
82
|
+
# 1. cleanup
|
83
|
+
# 1. teardown
|
84
|
+
# 1. shutdown
|
70
85
|
#
|
71
|
-
#
|
72
|
-
#
|
73
|
-
#
|
74
|
-
#
|
75
|
-
#
|
76
|
-
#
|
77
|
-
#
|
78
|
-
#
|
79
|
-
#
|
80
|
-
#
|
81
|
-
#
|
86
|
+
# You can set an attribute to each test.
|
87
|
+
#
|
88
|
+
# Example:
|
89
|
+
#
|
90
|
+
# class TestMyClass < Test::Unit::TestCase
|
91
|
+
# attribute :speed, :fast
|
92
|
+
# def test_my_fast_method
|
93
|
+
# # You can get the attribute via `self[]`
|
94
|
+
# self[:speed] # => :fast
|
95
|
+
# ...
|
96
|
+
# end
|
97
|
+
#
|
98
|
+
# attribute :speed, :slow
|
99
|
+
# def test_my_slow_method
|
100
|
+
# self[:speed] # => :slow
|
101
|
+
# ...
|
102
|
+
# end
|
103
|
+
# end
|
82
104
|
class TestCase
|
83
105
|
include Attribute
|
84
106
|
include Fixture
|
@@ -104,11 +126,20 @@ module Test
|
|
104
126
|
|
105
127
|
class << self
|
106
128
|
def inherited(sub_class) # :nodoc:
|
107
|
-
require "test/unit"
|
108
129
|
DESCENDANTS << sub_class
|
109
130
|
super
|
110
131
|
end
|
111
132
|
|
133
|
+
def include(*modules, &block) # :nodoc:
|
134
|
+
result = super
|
135
|
+
modules.each do |mod|
|
136
|
+
mod.public_instance_methods(false).each do |method_name|
|
137
|
+
AutoRunnerLoader.check(self, method_name.to_s)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
result
|
141
|
+
end
|
142
|
+
|
112
143
|
@@added_method_names = {}
|
113
144
|
def method_added(name) # :nodoc:
|
114
145
|
super
|
@@ -120,16 +151,23 @@ module Test
|
|
120
151
|
source_location = find_attribute(stringified_name, :source_location)
|
121
152
|
if source_location
|
122
153
|
path, line = source_location
|
154
|
+
elsif respond_to?(:caller_locations, true)
|
155
|
+
location = caller_locations(1, 1)[0]
|
156
|
+
path = location.absolute_path || location.path
|
157
|
+
line = location.lineno
|
123
158
|
else
|
159
|
+
# TODO: Remove me when Ruby 1.9 support is dropped
|
124
160
|
path, line, = caller[0].split(/:(\d+)/, 2)
|
125
161
|
line = line.to_i if line
|
126
162
|
end
|
127
|
-
|
163
|
+
location = {
|
128
164
|
:method_name => stringified_name,
|
129
165
|
:path => File.expand_path(path),
|
130
166
|
:line => line,
|
131
167
|
}
|
168
|
+
add_method_location(location)
|
132
169
|
added_method_names[stringified_name] = true
|
170
|
+
AutoRunnerLoader.check(self, stringified_name)
|
133
171
|
end
|
134
172
|
|
135
173
|
def added_method_names # :nodoc:
|
@@ -149,27 +187,29 @@ module Test
|
|
149
187
|
# scope.
|
150
188
|
#
|
151
189
|
# Here is an example test case:
|
152
|
-
#
|
153
|
-
# class
|
154
|
-
#
|
155
|
-
#
|
190
|
+
#
|
191
|
+
# class TestMyClass < Test::Unit::TestCase
|
192
|
+
# class << self
|
193
|
+
# def startup
|
194
|
+
# ...
|
195
|
+
# end
|
156
196
|
# end
|
157
|
-
# end
|
158
197
|
#
|
159
|
-
#
|
160
|
-
#
|
161
|
-
#
|
198
|
+
# def setup
|
199
|
+
# ...
|
200
|
+
# end
|
162
201
|
#
|
163
|
-
#
|
164
|
-
#
|
165
|
-
#
|
202
|
+
# def test_my_class1
|
203
|
+
# ...
|
204
|
+
# end
|
166
205
|
#
|
167
|
-
#
|
168
|
-
#
|
206
|
+
# def test_my_class2
|
207
|
+
# ...
|
208
|
+
# end
|
169
209
|
# end
|
170
|
-
# end
|
171
210
|
#
|
172
211
|
# Here is a call order:
|
212
|
+
#
|
173
213
|
# * startup
|
174
214
|
# * setup
|
175
215
|
# * test_my_class1 (or test_my_class2)
|
@@ -185,27 +225,29 @@ module Test
|
|
185
225
|
# down fixture information used in test case scope.
|
186
226
|
#
|
187
227
|
# Here is an example test case:
|
188
|
-
#
|
189
|
-
# class
|
190
|
-
#
|
191
|
-
#
|
228
|
+
#
|
229
|
+
# class TestMyClass < Test::Unit::TestCase
|
230
|
+
# class << self
|
231
|
+
# def shutdown
|
232
|
+
# ...
|
233
|
+
# end
|
192
234
|
# end
|
193
|
-
# end
|
194
235
|
#
|
195
|
-
#
|
196
|
-
#
|
197
|
-
#
|
236
|
+
# def teardown
|
237
|
+
# ...
|
238
|
+
# end
|
198
239
|
#
|
199
|
-
#
|
200
|
-
#
|
201
|
-
#
|
240
|
+
# def test_my_class1
|
241
|
+
# ...
|
242
|
+
# end
|
202
243
|
#
|
203
|
-
#
|
204
|
-
#
|
244
|
+
# def test_my_class2
|
245
|
+
# ...
|
246
|
+
# end
|
205
247
|
# end
|
206
|
-
# end
|
207
248
|
#
|
208
249
|
# Here is a call order:
|
250
|
+
#
|
209
251
|
# * test_my_class1 (or test_my_class2)
|
210
252
|
# * teardown
|
211
253
|
# * test_my_class2 (or test_my_class1)
|
@@ -220,20 +262,27 @@ module Test
|
|
220
262
|
@@test_orders = {}
|
221
263
|
|
222
264
|
# Returns the current test order. This returns
|
223
|
-
#
|
265
|
+
# `:alphabetic` by default.
|
224
266
|
def test_order
|
225
|
-
|
267
|
+
ancestors.each do |ancestor|
|
268
|
+
order = @@test_orders[ancestor]
|
269
|
+
return order if order
|
270
|
+
end
|
271
|
+
AVAILABLE_ORDERS.first
|
226
272
|
end
|
227
273
|
|
228
274
|
# Sets the current test order.
|
229
275
|
#
|
230
276
|
# Here are the available _order_:
|
231
|
-
#
|
232
|
-
#
|
233
|
-
#
|
234
|
-
#
|
235
|
-
#
|
236
|
-
#
|
277
|
+
#
|
278
|
+
# :alphabetic
|
279
|
+
# : Default. Tests are sorted in alphabetic order.
|
280
|
+
#
|
281
|
+
# :random
|
282
|
+
# : Tests are sorted in random order.
|
283
|
+
#
|
284
|
+
# :defined
|
285
|
+
# : Tests are sorted in defined order.
|
237
286
|
def test_order=(order)
|
238
287
|
@@test_orders[self] = order
|
239
288
|
end
|
@@ -244,22 +293,22 @@ module Test
|
|
244
293
|
# In declarative syntax usage, the following two
|
245
294
|
# test definitions are the almost same:
|
246
295
|
#
|
247
|
-
#
|
248
|
-
#
|
249
|
-
#
|
250
|
-
#
|
296
|
+
# description "register user"
|
297
|
+
# def test_register_user
|
298
|
+
# ...
|
299
|
+
# end
|
251
300
|
#
|
252
|
-
#
|
253
|
-
#
|
254
|
-
#
|
301
|
+
# test "register user" do
|
302
|
+
# ...
|
303
|
+
# end
|
255
304
|
#
|
256
305
|
# In test method mark usage, the "my_test_method" is
|
257
306
|
# treated as a test method:
|
258
307
|
#
|
259
|
-
#
|
260
|
-
#
|
261
|
-
#
|
262
|
-
#
|
308
|
+
# test
|
309
|
+
# def my_test_method
|
310
|
+
# assert_equal("call me", ...)
|
311
|
+
# end
|
263
312
|
def test(*test_description_or_targets, &block)
|
264
313
|
if block_given?
|
265
314
|
test_description = test_description_or_targets.first
|
@@ -281,6 +330,9 @@ module Test
|
|
281
330
|
else
|
282
331
|
targets = test_description_or_targets
|
283
332
|
attribute(:test, true, {}, *targets)
|
333
|
+
targets.each do |target|
|
334
|
+
AutoRunnerLoader.check(self, target)
|
335
|
+
end
|
284
336
|
end
|
285
337
|
end
|
286
338
|
|
@@ -290,35 +342,67 @@ module Test
|
|
290
342
|
# normal user" description with "test_register"
|
291
343
|
# test.
|
292
344
|
#
|
293
|
-
#
|
294
|
-
#
|
295
|
-
#
|
296
|
-
#
|
345
|
+
# description "register a normal user"
|
346
|
+
# def test_register
|
347
|
+
# ...
|
348
|
+
# end
|
297
349
|
def description(value, target=nil)
|
298
350
|
targets = [target].compact
|
299
351
|
attribute(:description, value, {}, *targets)
|
300
352
|
end
|
301
353
|
|
354
|
+
# Declares that the following test uses Ractor.
|
355
|
+
#
|
356
|
+
# Tests that use Ractor are executed at the end. Because multi
|
357
|
+
# Ractor mode is enabled in the current process and it's not
|
358
|
+
# disabled even when only one Ractor is running after running
|
359
|
+
# a test that uses Ractor on Ruby 3.0. It will be solved in
|
360
|
+
# the future.
|
361
|
+
#
|
362
|
+
# This is implemented by setting the `:ractor` attribute of
|
363
|
+
# the test to `true`.
|
364
|
+
#
|
365
|
+
# @param options [Hash] See {Attribute::ClassMethods#attribute}
|
366
|
+
# for details.
|
367
|
+
#
|
368
|
+
# @return [void]
|
369
|
+
#
|
370
|
+
# @example Declares that test_do_something_with_ractor uses Ractor
|
371
|
+
#
|
372
|
+
# ractor
|
373
|
+
# def test_do_something_with_ractor
|
374
|
+
# Ractor.new do
|
375
|
+
# # ...
|
376
|
+
# end
|
377
|
+
# end
|
378
|
+
#
|
379
|
+
# @since 3.4.6
|
380
|
+
def ractor(options={})
|
381
|
+
attribute(:ractor, true, options)
|
382
|
+
end
|
383
|
+
|
302
384
|
# Defines a sub test case.
|
303
385
|
#
|
304
386
|
# This is a syntax sugar. The both of the following codes are
|
305
387
|
# the same in meaning:
|
306
388
|
#
|
307
389
|
# Standard:
|
308
|
-
#
|
309
|
-
# class
|
310
|
-
#
|
390
|
+
#
|
391
|
+
# class TestParent < Test::Unit::TestCase
|
392
|
+
# class TestChild < self
|
393
|
+
# def test_in_child
|
394
|
+
# end
|
311
395
|
# end
|
312
396
|
# end
|
313
|
-
# end
|
314
397
|
#
|
315
398
|
# Syntax sugar:
|
316
|
-
#
|
317
|
-
#
|
318
|
-
#
|
399
|
+
#
|
400
|
+
# class TestParent < Test::Unit::TestCase
|
401
|
+
# sub_test_case("TestChild") do
|
402
|
+
# def test_in_child
|
403
|
+
# end
|
319
404
|
# end
|
320
405
|
# end
|
321
|
-
# end
|
322
406
|
#
|
323
407
|
# The difference of them are the following:
|
324
408
|
#
|
@@ -335,13 +419,7 @@ module Test
|
|
335
419
|
# case class context.
|
336
420
|
# @return [Test::Unit::TestCase] Created sub test case class.
|
337
421
|
def sub_test_case(name, &block)
|
338
|
-
|
339
|
-
sub_test_case = Class.new(self) do
|
340
|
-
singleton_class = class << self; self; end
|
341
|
-
singleton_class.__send__(:define_method, :name) do
|
342
|
-
[parent_test_case.name, name].compact.join("::")
|
343
|
-
end
|
344
|
-
end
|
422
|
+
sub_test_case = sub_test_case_class(name)
|
345
423
|
sub_test_case.class_eval(&block)
|
346
424
|
sub_test_case
|
347
425
|
end
|
@@ -356,6 +434,11 @@ module Test
|
|
356
434
|
# @option query [String] :method_name (nil)
|
357
435
|
# the method name for a test.
|
358
436
|
def test_defined?(query)
|
437
|
+
locations = find_locations(query)
|
438
|
+
not locations.empty?
|
439
|
+
end
|
440
|
+
|
441
|
+
def find_locations(query)
|
359
442
|
query_path = query[:path]
|
360
443
|
query_line = query[:line]
|
361
444
|
query_method_name = query[:method_name]
|
@@ -368,49 +451,73 @@ module Test
|
|
368
451
|
available_location = available_locations.find do |location|
|
369
452
|
query_line >= location[:line]
|
370
453
|
end
|
371
|
-
return
|
372
|
-
return
|
454
|
+
return [] if available_location.nil?
|
455
|
+
return [] if available_location[:test_case] != self
|
373
456
|
available_locations = [available_location]
|
374
457
|
end
|
375
458
|
if query_method_name
|
376
459
|
available_location = available_locations.find do |location|
|
377
|
-
|
460
|
+
location[:test_case] == self and
|
461
|
+
query_method_name == location[:method_name]
|
378
462
|
end
|
379
|
-
return
|
463
|
+
return [] if available_location.nil?
|
380
464
|
available_locations = [available_location]
|
381
465
|
end
|
382
466
|
|
383
|
-
|
467
|
+
available_locations
|
384
468
|
end
|
385
469
|
|
386
470
|
private
|
387
471
|
# @private
|
388
472
|
@@method_locations = {}
|
473
|
+
# @private
|
474
|
+
@@method_location_mutex = Thread::Mutex.new
|
475
|
+
|
389
476
|
# @private
|
390
477
|
def method_locations
|
391
478
|
@@method_locations[self] ||= []
|
392
479
|
end
|
393
480
|
|
394
481
|
# @private
|
395
|
-
def
|
396
|
-
|
397
|
-
|
398
|
-
path = self_location[:path] if self_location
|
482
|
+
def add_method_location(location)
|
483
|
+
@@method_location_mutex.synchronize do
|
484
|
+
method_locations << location
|
399
485
|
end
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
486
|
+
end
|
487
|
+
|
488
|
+
# @private
|
489
|
+
def target_method_locations(path)
|
490
|
+
@@method_location_mutex.synchronize do
|
491
|
+
if path.nil?
|
492
|
+
self_location = method_locations.first
|
493
|
+
path = self_location[:path] if self_location
|
494
|
+
end
|
495
|
+
return [] if path.nil?
|
496
|
+
|
497
|
+
target_locations = []
|
498
|
+
@@method_locations.each do |test_case, locations|
|
499
|
+
locations.each do |location|
|
500
|
+
absolete_path = File.expand_path(path)
|
501
|
+
location_path = location[:path]
|
502
|
+
location_basename = File.basename(location_path)
|
503
|
+
if location_path == absolete_path or location_basename == path
|
504
|
+
target_locations << location.merge(:test_case => test_case)
|
505
|
+
end
|
410
506
|
end
|
411
507
|
end
|
508
|
+
target_locations
|
509
|
+
end
|
510
|
+
end
|
511
|
+
|
512
|
+
# @private
|
513
|
+
def sub_test_case_class(name)
|
514
|
+
parent_test_case = self
|
515
|
+
Class.new(self) do
|
516
|
+
singleton_class = class << self; self; end
|
517
|
+
singleton_class.__send__(:define_method, :name) do
|
518
|
+
[parent_test_case.name, name].compact.join("::")
|
519
|
+
end
|
412
520
|
end
|
413
|
-
target_locations
|
414
521
|
end
|
415
522
|
end
|
416
523
|
|
@@ -432,9 +539,7 @@ module Test
|
|
432
539
|
def valid? # :nodoc:
|
433
540
|
return false unless respond_to?(@method_name)
|
434
541
|
test_method = method(@method_name)
|
435
|
-
|
436
|
-
return false unless test_method.arity == 1
|
437
|
-
else
|
542
|
+
unless @internal_data.have_test_data?
|
438
543
|
return false unless test_method.arity <= 0
|
439
544
|
end
|
440
545
|
owner = Util::MethodOwnerFinder.find(self, @method_name)
|
@@ -453,14 +558,31 @@ module Test
|
|
453
558
|
@internal_data.test_started
|
454
559
|
yield(STARTED, name)
|
455
560
|
yield(STARTED_OBJECT, self)
|
561
|
+
processed_exception_in_setup = false
|
456
562
|
begin
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
563
|
+
catch do |tag|
|
564
|
+
run_setup do
|
565
|
+
begin
|
566
|
+
run_test
|
567
|
+
run_cleanup
|
568
|
+
add_pass
|
569
|
+
rescue Exception
|
570
|
+
@internal_data.interrupted
|
571
|
+
unless handle_exception($!)
|
572
|
+
processed_exception_in_setup = true
|
573
|
+
raise
|
574
|
+
end
|
575
|
+
throw(tag)
|
576
|
+
end
|
577
|
+
end
|
578
|
+
end
|
461
579
|
rescue Exception
|
462
|
-
|
463
|
-
|
580
|
+
if processed_exception_in_setup
|
581
|
+
raise
|
582
|
+
else
|
583
|
+
@internal_data.interrupted
|
584
|
+
raise unless handle_exception($!)
|
585
|
+
end
|
464
586
|
ensure
|
465
587
|
begin
|
466
588
|
run_teardown
|
@@ -482,35 +604,37 @@ module Test
|
|
482
604
|
#
|
483
605
|
# You can add additional setup tasks by the following
|
484
606
|
# code:
|
485
|
-
# class TestMyClass < Test::Unit::TestCase
|
486
|
-
# def setup
|
487
|
-
# ...
|
488
|
-
# end
|
489
607
|
#
|
490
|
-
#
|
491
|
-
#
|
492
|
-
#
|
493
|
-
#
|
608
|
+
# class TestMyClass < Test::Unit::TestCase
|
609
|
+
# def setup
|
610
|
+
# ...
|
611
|
+
# end
|
494
612
|
#
|
495
|
-
#
|
496
|
-
#
|
497
|
-
#
|
613
|
+
# setup
|
614
|
+
# def my_setup1
|
615
|
+
# ...
|
616
|
+
# end
|
498
617
|
#
|
499
|
-
#
|
500
|
-
#
|
501
|
-
#
|
502
|
-
# end
|
618
|
+
# setup do
|
619
|
+
# ... # setup callback1
|
620
|
+
# end
|
503
621
|
#
|
504
|
-
#
|
505
|
-
#
|
506
|
-
#
|
622
|
+
# setup
|
623
|
+
# def my_setup2
|
624
|
+
# ...
|
625
|
+
# end
|
626
|
+
#
|
627
|
+
# setup do
|
628
|
+
# ... # setup callback2
|
629
|
+
# end
|
507
630
|
#
|
508
|
-
#
|
509
|
-
#
|
631
|
+
# def test_my_class
|
632
|
+
# ...
|
633
|
+
# end
|
510
634
|
# end
|
511
|
-
# end
|
512
635
|
#
|
513
636
|
# Here is a call order:
|
637
|
+
#
|
514
638
|
# * setup
|
515
639
|
# * my_setup1
|
516
640
|
# * setup callback1
|
@@ -527,35 +651,37 @@ module Test
|
|
527
651
|
#
|
528
652
|
# You can add additional cleanup tasks by the following
|
529
653
|
# code:
|
530
|
-
# class TestMyClass < Test::Unit::TestCase
|
531
|
-
# def cleanup
|
532
|
-
# ...
|
533
|
-
# end
|
534
654
|
#
|
535
|
-
#
|
536
|
-
#
|
537
|
-
#
|
538
|
-
#
|
655
|
+
# class TestMyClass < Test::Unit::TestCase
|
656
|
+
# def cleanup
|
657
|
+
# ...
|
658
|
+
# end
|
539
659
|
#
|
540
|
-
#
|
541
|
-
#
|
542
|
-
#
|
660
|
+
# cleanup
|
661
|
+
# def my_cleanup1
|
662
|
+
# ...
|
663
|
+
# end
|
543
664
|
#
|
544
|
-
#
|
545
|
-
#
|
546
|
-
#
|
547
|
-
# end
|
665
|
+
# cleanup do
|
666
|
+
# ... # cleanup callback1
|
667
|
+
# end
|
548
668
|
#
|
549
|
-
#
|
550
|
-
#
|
551
|
-
#
|
669
|
+
# cleanup
|
670
|
+
# def my_cleanup2
|
671
|
+
# ...
|
672
|
+
# end
|
673
|
+
#
|
674
|
+
# cleanup do
|
675
|
+
# ... # cleanup callback2
|
676
|
+
# end
|
552
677
|
#
|
553
|
-
#
|
554
|
-
#
|
678
|
+
# def test_my_class
|
679
|
+
# ...
|
680
|
+
# end
|
555
681
|
# end
|
556
|
-
# end
|
557
682
|
#
|
558
683
|
# Here is a call order:
|
684
|
+
#
|
559
685
|
# * test_my_class
|
560
686
|
# * cleanup callback2
|
561
687
|
# * my_cleanup2
|
@@ -570,35 +696,37 @@ module Test
|
|
570
696
|
#
|
571
697
|
# You can add additional teardown tasks by the following
|
572
698
|
# code:
|
573
|
-
# class TestMyClass < Test::Unit::TestCase
|
574
|
-
# def teardown
|
575
|
-
# ...
|
576
|
-
# end
|
577
699
|
#
|
578
|
-
#
|
579
|
-
#
|
580
|
-
#
|
581
|
-
#
|
700
|
+
# class TestMyClass < Test::Unit::TestCase
|
701
|
+
# def teardown
|
702
|
+
# ...
|
703
|
+
# end
|
582
704
|
#
|
583
|
-
#
|
584
|
-
#
|
585
|
-
#
|
705
|
+
# teardown
|
706
|
+
# def my_teardown1
|
707
|
+
# ...
|
708
|
+
# end
|
586
709
|
#
|
587
|
-
#
|
588
|
-
#
|
589
|
-
#
|
590
|
-
# end
|
710
|
+
# teardown do
|
711
|
+
# ... # teardown callback1
|
712
|
+
# end
|
591
713
|
#
|
592
|
-
#
|
593
|
-
#
|
594
|
-
#
|
714
|
+
# teardown
|
715
|
+
# def my_teardown2
|
716
|
+
# ...
|
717
|
+
# end
|
718
|
+
#
|
719
|
+
# teardown do
|
720
|
+
# ... # teardown callback2
|
721
|
+
# end
|
595
722
|
#
|
596
|
-
#
|
597
|
-
#
|
723
|
+
# def test_my_class
|
724
|
+
# ...
|
725
|
+
# end
|
598
726
|
# end
|
599
|
-
# end
|
600
727
|
#
|
601
728
|
# Here is a call order:
|
729
|
+
#
|
602
730
|
# * test_my_class
|
603
731
|
# * teardown callback2
|
604
732
|
# * my_teardown2
|
@@ -618,18 +746,33 @@ module Test
|
|
618
746
|
|
619
747
|
# Returns a label of test data for the test. If the
|
620
748
|
# test isn't associated with any test data, it returns
|
621
|
-
#
|
749
|
+
# `nil`.
|
622
750
|
def data_label
|
623
751
|
@internal_data.test_data_label
|
624
752
|
end
|
625
753
|
|
754
|
+
# Returns test data for the test. If the test isn't associated
|
755
|
+
# with any test data, it returns `nil`.
|
756
|
+
def data
|
757
|
+
@internal_data.test_data
|
758
|
+
end
|
759
|
+
|
626
760
|
# Returns a human-readable name for the specific test that
|
627
761
|
# this instance of TestCase represents.
|
628
762
|
def name
|
763
|
+
"#{local_name}(#{self.class.name})"
|
764
|
+
end
|
765
|
+
|
766
|
+
# Returns a human-readable name for the specific test that this
|
767
|
+
# instance of TestCase represents.
|
768
|
+
#
|
769
|
+
# `#local_name` doesn't include class name. `#name` includes
|
770
|
+
# class name.
|
771
|
+
def local_name
|
629
772
|
if @internal_data.have_test_data?
|
630
|
-
"#{@method_name}[#{data_label}]
|
773
|
+
"#{@method_name}[#{data_label}]"
|
631
774
|
else
|
632
|
-
|
775
|
+
@method_name.to_s
|
633
776
|
end
|
634
777
|
end
|
635
778
|
|
@@ -707,13 +850,23 @@ module Test
|
|
707
850
|
end
|
708
851
|
|
709
852
|
def run_test
|
853
|
+
signature = "#{self.class}\##{@method_name}"
|
710
854
|
redefined_info = self[:redefined]
|
711
855
|
if redefined_info
|
712
|
-
notify("
|
856
|
+
notify("<#{signature}> was redefined",
|
713
857
|
:backtrace => redefined_info[:backtrace])
|
714
858
|
end
|
859
|
+
if self[:ractor] and not defined?(::Ractor)
|
860
|
+
omit("<#{signature}> requires Ractor")
|
861
|
+
end
|
715
862
|
if @internal_data.have_test_data?
|
716
|
-
|
863
|
+
test_method = method(@method_name)
|
864
|
+
arity = test_method.arity
|
865
|
+
if arity.zero?
|
866
|
+
__send__(@method_name)
|
867
|
+
else
|
868
|
+
__send__(@method_name, @internal_data.test_data)
|
869
|
+
end
|
717
870
|
else
|
718
871
|
__send__(@method_name)
|
719
872
|
end
|