test-unit 3.2.5 → 3.4.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/BSDL +24 -0
- data/COPYING +41 -44
- data/README.md +8 -11
- data/Rakefile +0 -23
- data/doc/text/getting-started.md +1 -1
- data/doc/text/news.md +366 -0
- data/lib/test/unit/assertion-failed-error.rb +35 -0
- data/lib/test/unit/assertions.rb +312 -112
- data/lib/test/unit/attribute.rb +7 -2
- data/lib/test/unit/autorunner.rb +79 -31
- 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 +10 -13
- data/lib/test/unit/collector/objectspace.rb +1 -0
- data/lib/test/unit/collector.rb +31 -0
- data/lib/test/unit/color-scheme.rb +20 -2
- data/lib/test/unit/data-sets.rb +116 -0
- data/lib/test/unit/data.rb +121 -12
- data/lib/test/unit/diff.rb +2 -3
- data/lib/test/unit/fixture.rb +6 -0
- 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 -3
- data/lib/test/unit/runner/console.rb +8 -0
- data/lib/test/unit/test-suite-creator.rb +22 -8
- data/lib/test/unit/testcase.rb +216 -146
- data/lib/test/unit/testsuite.rb +1 -1
- data/lib/test/unit/ui/console/testrunner.rb +92 -32
- 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 +13 -88
- data/GPL +0 -339
- data/LGPL +0 -502
- data/test/collector/test-descendant.rb +0 -182
- data/test/collector/test-load.rb +0 -442
- data/test/collector/test_dir.rb +0 -407
- data/test/collector/test_objectspace.rb +0 -102
- 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 -2180
- 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 -303
- 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 -713
- 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 -1278
- data/test/test-test-result.rb +0 -113
- data/test/test-test-suite-creator.rb +0 -97
- data/test/test-test-suite.rb +0 -151
- 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 -52
- data/test/util/test_observable.rb +0 -102
- data/test/util/test_procwrapper.rb +0 -36
data/lib/test/unit/testcase.rb
CHANGED
@@ -130,6 +130,16 @@ module Test
|
|
130
130
|
super
|
131
131
|
end
|
132
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
|
+
|
133
143
|
@@added_method_names = {}
|
134
144
|
def method_added(name) # :nodoc:
|
135
145
|
super
|
@@ -150,11 +160,12 @@ module Test
|
|
150
160
|
path, line, = caller[0].split(/:(\d+)/, 2)
|
151
161
|
line = line.to_i if line
|
152
162
|
end
|
153
|
-
|
163
|
+
location = {
|
154
164
|
:method_name => stringified_name,
|
155
165
|
:path => File.expand_path(path),
|
156
166
|
:line => line,
|
157
167
|
}
|
168
|
+
add_method_location(location)
|
158
169
|
added_method_names[stringified_name] = true
|
159
170
|
AutoRunnerLoader.check(self, stringified_name)
|
160
171
|
end
|
@@ -176,27 +187,29 @@ module Test
|
|
176
187
|
# scope.
|
177
188
|
#
|
178
189
|
# Here is an example test case:
|
179
|
-
#
|
180
|
-
# class
|
181
|
-
#
|
182
|
-
#
|
190
|
+
#
|
191
|
+
# class TestMyClass < Test::Unit::TestCase
|
192
|
+
# class << self
|
193
|
+
# def startup
|
194
|
+
# ...
|
195
|
+
# end
|
183
196
|
# end
|
184
|
-
# end
|
185
197
|
#
|
186
|
-
#
|
187
|
-
#
|
188
|
-
#
|
198
|
+
# def setup
|
199
|
+
# ...
|
200
|
+
# end
|
189
201
|
#
|
190
|
-
#
|
191
|
-
#
|
192
|
-
#
|
202
|
+
# def test_my_class1
|
203
|
+
# ...
|
204
|
+
# end
|
193
205
|
#
|
194
|
-
#
|
195
|
-
#
|
206
|
+
# def test_my_class2
|
207
|
+
# ...
|
208
|
+
# end
|
196
209
|
# end
|
197
|
-
# end
|
198
210
|
#
|
199
211
|
# Here is a call order:
|
212
|
+
#
|
200
213
|
# * startup
|
201
214
|
# * setup
|
202
215
|
# * test_my_class1 (or test_my_class2)
|
@@ -212,27 +225,29 @@ module Test
|
|
212
225
|
# down fixture information used in test case scope.
|
213
226
|
#
|
214
227
|
# Here is an example test case:
|
215
|
-
#
|
216
|
-
# class
|
217
|
-
#
|
218
|
-
#
|
228
|
+
#
|
229
|
+
# class TestMyClass < Test::Unit::TestCase
|
230
|
+
# class << self
|
231
|
+
# def shutdown
|
232
|
+
# ...
|
233
|
+
# end
|
219
234
|
# end
|
220
|
-
# end
|
221
235
|
#
|
222
|
-
#
|
223
|
-
#
|
224
|
-
#
|
236
|
+
# def teardown
|
237
|
+
# ...
|
238
|
+
# end
|
225
239
|
#
|
226
|
-
#
|
227
|
-
#
|
228
|
-
#
|
240
|
+
# def test_my_class1
|
241
|
+
# ...
|
242
|
+
# end
|
229
243
|
#
|
230
|
-
#
|
231
|
-
#
|
244
|
+
# def test_my_class2
|
245
|
+
# ...
|
246
|
+
# end
|
232
247
|
# end
|
233
|
-
# end
|
234
248
|
#
|
235
249
|
# Here is a call order:
|
250
|
+
#
|
236
251
|
# * test_my_class1 (or test_my_class2)
|
237
252
|
# * teardown
|
238
253
|
# * test_my_class2 (or test_my_class1)
|
@@ -247,7 +262,7 @@ module Test
|
|
247
262
|
@@test_orders = {}
|
248
263
|
|
249
264
|
# Returns the current test order. This returns
|
250
|
-
#
|
265
|
+
# `:alphabetic` by default.
|
251
266
|
def test_order
|
252
267
|
ancestors.each do |ancestor|
|
253
268
|
order = @@test_orders[ancestor]
|
@@ -259,12 +274,15 @@ module Test
|
|
259
274
|
# Sets the current test order.
|
260
275
|
#
|
261
276
|
# Here are the available _order_:
|
262
|
-
#
|
263
|
-
#
|
264
|
-
#
|
265
|
-
#
|
266
|
-
#
|
267
|
-
#
|
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.
|
268
286
|
def test_order=(order)
|
269
287
|
@@test_orders[self] = order
|
270
288
|
end
|
@@ -275,22 +293,22 @@ module Test
|
|
275
293
|
# In declarative syntax usage, the following two
|
276
294
|
# test definitions are the almost same:
|
277
295
|
#
|
278
|
-
#
|
279
|
-
#
|
280
|
-
#
|
281
|
-
#
|
296
|
+
# description "register user"
|
297
|
+
# def test_register_user
|
298
|
+
# ...
|
299
|
+
# end
|
282
300
|
#
|
283
|
-
#
|
284
|
-
#
|
285
|
-
#
|
301
|
+
# test "register user" do
|
302
|
+
# ...
|
303
|
+
# end
|
286
304
|
#
|
287
305
|
# In test method mark usage, the "my_test_method" is
|
288
306
|
# treated as a test method:
|
289
307
|
#
|
290
|
-
#
|
291
|
-
#
|
292
|
-
#
|
293
|
-
#
|
308
|
+
# test
|
309
|
+
# def my_test_method
|
310
|
+
# assert_equal("call me", ...)
|
311
|
+
# end
|
294
312
|
def test(*test_description_or_targets, &block)
|
295
313
|
if block_given?
|
296
314
|
test_description = test_description_or_targets.first
|
@@ -324,35 +342,67 @@ module Test
|
|
324
342
|
# normal user" description with "test_register"
|
325
343
|
# test.
|
326
344
|
#
|
327
|
-
#
|
328
|
-
#
|
329
|
-
#
|
330
|
-
#
|
345
|
+
# description "register a normal user"
|
346
|
+
# def test_register
|
347
|
+
# ...
|
348
|
+
# end
|
331
349
|
def description(value, target=nil)
|
332
350
|
targets = [target].compact
|
333
351
|
attribute(:description, value, {}, *targets)
|
334
352
|
end
|
335
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
|
+
# Ruby 3.1.
|
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
|
+
|
336
384
|
# Defines a sub test case.
|
337
385
|
#
|
338
386
|
# This is a syntax sugar. The both of the following codes are
|
339
387
|
# the same in meaning:
|
340
388
|
#
|
341
389
|
# Standard:
|
342
|
-
#
|
343
|
-
# class
|
344
|
-
#
|
390
|
+
#
|
391
|
+
# class TestParent < Test::Unit::TestCase
|
392
|
+
# class TestChild < self
|
393
|
+
# def test_in_child
|
394
|
+
# end
|
345
395
|
# end
|
346
396
|
# end
|
347
|
-
# end
|
348
397
|
#
|
349
398
|
# Syntax sugar:
|
350
|
-
#
|
351
|
-
#
|
352
|
-
#
|
399
|
+
#
|
400
|
+
# class TestParent < Test::Unit::TestCase
|
401
|
+
# sub_test_case("TestChild") do
|
402
|
+
# def test_in_child
|
403
|
+
# end
|
353
404
|
# end
|
354
405
|
# end
|
355
|
-
# end
|
356
406
|
#
|
357
407
|
# The difference of them are the following:
|
358
408
|
#
|
@@ -426,31 +476,43 @@ module Test
|
|
426
476
|
private
|
427
477
|
# @private
|
428
478
|
@@method_locations = {}
|
479
|
+
# @private
|
480
|
+
@@method_location_mutex = Thread::Mutex.new
|
481
|
+
|
429
482
|
# @private
|
430
483
|
def method_locations
|
431
484
|
@@method_locations[self] ||= []
|
432
485
|
end
|
433
486
|
|
434
487
|
# @private
|
435
|
-
def
|
436
|
-
|
437
|
-
|
438
|
-
path = self_location[:path] if self_location
|
488
|
+
def add_method_location(location)
|
489
|
+
@@method_location_mutex.synchronize do
|
490
|
+
method_locations << location
|
439
491
|
end
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
492
|
+
end
|
493
|
+
|
494
|
+
# @private
|
495
|
+
def target_method_locations(path)
|
496
|
+
@@method_location_mutex.synchronize do
|
497
|
+
if path.nil?
|
498
|
+
self_location = method_locations.first
|
499
|
+
path = self_location[:path] if self_location
|
500
|
+
end
|
501
|
+
return [] if path.nil?
|
502
|
+
|
503
|
+
target_locations = []
|
504
|
+
@@method_locations.each do |test_case, locations|
|
505
|
+
locations.each do |location|
|
506
|
+
absolete_path = File.expand_path(path)
|
507
|
+
location_path = location[:path]
|
508
|
+
location_basename = File.basename(location_path)
|
509
|
+
if location_path == absolete_path or location_basename == path
|
510
|
+
target_locations << location.merge(:test_case => test_case)
|
511
|
+
end
|
450
512
|
end
|
451
513
|
end
|
514
|
+
target_locations
|
452
515
|
end
|
453
|
-
target_locations
|
454
516
|
end
|
455
517
|
end
|
456
518
|
|
@@ -537,35 +599,37 @@ module Test
|
|
537
599
|
#
|
538
600
|
# You can add additional setup tasks by the following
|
539
601
|
# code:
|
540
|
-
# class TestMyClass < Test::Unit::TestCase
|
541
|
-
# def setup
|
542
|
-
# ...
|
543
|
-
# end
|
544
602
|
#
|
545
|
-
#
|
546
|
-
#
|
547
|
-
#
|
548
|
-
#
|
603
|
+
# class TestMyClass < Test::Unit::TestCase
|
604
|
+
# def setup
|
605
|
+
# ...
|
606
|
+
# end
|
549
607
|
#
|
550
|
-
#
|
551
|
-
#
|
552
|
-
#
|
608
|
+
# setup
|
609
|
+
# def my_setup1
|
610
|
+
# ...
|
611
|
+
# end
|
553
612
|
#
|
554
|
-
#
|
555
|
-
#
|
556
|
-
#
|
557
|
-
# end
|
613
|
+
# setup do
|
614
|
+
# ... # setup callback1
|
615
|
+
# end
|
558
616
|
#
|
559
|
-
#
|
560
|
-
#
|
561
|
-
#
|
617
|
+
# setup
|
618
|
+
# def my_setup2
|
619
|
+
# ...
|
620
|
+
# end
|
562
621
|
#
|
563
|
-
#
|
564
|
-
#
|
622
|
+
# setup do
|
623
|
+
# ... # setup callback2
|
624
|
+
# end
|
625
|
+
#
|
626
|
+
# def test_my_class
|
627
|
+
# ...
|
628
|
+
# end
|
565
629
|
# end
|
566
|
-
# end
|
567
630
|
#
|
568
631
|
# Here is a call order:
|
632
|
+
#
|
569
633
|
# * setup
|
570
634
|
# * my_setup1
|
571
635
|
# * setup callback1
|
@@ -582,35 +646,37 @@ module Test
|
|
582
646
|
#
|
583
647
|
# You can add additional cleanup tasks by the following
|
584
648
|
# code:
|
585
|
-
# class TestMyClass < Test::Unit::TestCase
|
586
|
-
# def cleanup
|
587
|
-
# ...
|
588
|
-
# end
|
589
649
|
#
|
590
|
-
#
|
591
|
-
#
|
592
|
-
#
|
593
|
-
#
|
650
|
+
# class TestMyClass < Test::Unit::TestCase
|
651
|
+
# def cleanup
|
652
|
+
# ...
|
653
|
+
# end
|
594
654
|
#
|
595
|
-
#
|
596
|
-
#
|
597
|
-
#
|
655
|
+
# cleanup
|
656
|
+
# def my_cleanup1
|
657
|
+
# ...
|
658
|
+
# end
|
598
659
|
#
|
599
|
-
#
|
600
|
-
#
|
601
|
-
#
|
602
|
-
# end
|
660
|
+
# cleanup do
|
661
|
+
# ... # cleanup callback1
|
662
|
+
# end
|
603
663
|
#
|
604
|
-
#
|
605
|
-
#
|
606
|
-
#
|
664
|
+
# cleanup
|
665
|
+
# def my_cleanup2
|
666
|
+
# ...
|
667
|
+
# end
|
668
|
+
#
|
669
|
+
# cleanup do
|
670
|
+
# ... # cleanup callback2
|
671
|
+
# end
|
607
672
|
#
|
608
|
-
#
|
609
|
-
#
|
673
|
+
# def test_my_class
|
674
|
+
# ...
|
675
|
+
# end
|
610
676
|
# end
|
611
|
-
# end
|
612
677
|
#
|
613
678
|
# Here is a call order:
|
679
|
+
#
|
614
680
|
# * test_my_class
|
615
681
|
# * cleanup callback2
|
616
682
|
# * my_cleanup2
|
@@ -625,35 +691,37 @@ module Test
|
|
625
691
|
#
|
626
692
|
# You can add additional teardown tasks by the following
|
627
693
|
# code:
|
628
|
-
# class TestMyClass < Test::Unit::TestCase
|
629
|
-
# def teardown
|
630
|
-
# ...
|
631
|
-
# end
|
632
694
|
#
|
633
|
-
#
|
634
|
-
#
|
635
|
-
#
|
636
|
-
#
|
695
|
+
# class TestMyClass < Test::Unit::TestCase
|
696
|
+
# def teardown
|
697
|
+
# ...
|
698
|
+
# end
|
637
699
|
#
|
638
|
-
#
|
639
|
-
#
|
640
|
-
#
|
700
|
+
# teardown
|
701
|
+
# def my_teardown1
|
702
|
+
# ...
|
703
|
+
# end
|
641
704
|
#
|
642
|
-
#
|
643
|
-
#
|
644
|
-
#
|
645
|
-
# end
|
705
|
+
# teardown do
|
706
|
+
# ... # teardown callback1
|
707
|
+
# end
|
646
708
|
#
|
647
|
-
#
|
648
|
-
#
|
649
|
-
#
|
709
|
+
# teardown
|
710
|
+
# def my_teardown2
|
711
|
+
# ...
|
712
|
+
# end
|
713
|
+
#
|
714
|
+
# teardown do
|
715
|
+
# ... # teardown callback2
|
716
|
+
# end
|
650
717
|
#
|
651
|
-
#
|
652
|
-
#
|
718
|
+
# def test_my_class
|
719
|
+
# ...
|
720
|
+
# end
|
653
721
|
# end
|
654
|
-
# end
|
655
722
|
#
|
656
723
|
# Here is a call order:
|
724
|
+
#
|
657
725
|
# * test_my_class
|
658
726
|
# * teardown callback2
|
659
727
|
# * my_teardown2
|
@@ -673,11 +741,17 @@ module Test
|
|
673
741
|
|
674
742
|
# Returns a label of test data for the test. If the
|
675
743
|
# test isn't associated with any test data, it returns
|
676
|
-
#
|
744
|
+
# `nil`.
|
677
745
|
def data_label
|
678
746
|
@internal_data.test_data_label
|
679
747
|
end
|
680
748
|
|
749
|
+
# Returns test data for the test. If the test isn't associated
|
750
|
+
# with any test data, it returns `nil`.
|
751
|
+
def data
|
752
|
+
@internal_data.test_data
|
753
|
+
end
|
754
|
+
|
681
755
|
# Returns a human-readable name for the specific test that
|
682
756
|
# this instance of TestCase represents.
|
683
757
|
def name
|
@@ -779,15 +853,11 @@ module Test
|
|
779
853
|
end
|
780
854
|
if @internal_data.have_test_data?
|
781
855
|
test_method = method(@method_name)
|
782
|
-
|
783
|
-
|
856
|
+
arity = test_method.arity
|
857
|
+
if arity.zero?
|
858
|
+
__send__(@method_name)
|
784
859
|
else
|
785
|
-
|
786
|
-
backtrace = locations.collect do |location|
|
787
|
-
"#{location[:path]}:#{location[:line]}"
|
788
|
-
end
|
789
|
-
notify("<#{signature}> misses a parameter to take test data",
|
790
|
-
:backtrace => backtrace)
|
860
|
+
__send__(@method_name, @internal_data.test_data)
|
791
861
|
end
|
792
862
|
else
|
793
863
|
__send__(@method_name)
|
data/lib/test/unit/testsuite.rb
CHANGED
@@ -77,7 +77,7 @@ module Test
|
|
77
77
|
@tests -= tests
|
78
78
|
end
|
79
79
|
|
80
|
-
#
|
80
|
+
# Returns the rolled up number of tests in this suite;
|
81
81
|
# i.e. if the suite contains other suites, it counts the
|
82
82
|
# tests within those suites, not the suites themselves.
|
83
83
|
def size
|