test-unit 3.2.9 → 3.5.5

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.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/BSDL +24 -0
  3. data/COPYING +41 -44
  4. data/README.md +18 -11
  5. data/Rakefile +0 -23
  6. data/doc/text/getting-started.md +2 -2
  7. data/doc/text/news.md +329 -1
  8. data/lib/test/unit/assertion-failed-error.rb +35 -0
  9. data/lib/test/unit/assertions.rb +453 -161
  10. data/lib/test/unit/attribute.rb +3 -1
  11. data/lib/test/unit/autorunner.rb +78 -30
  12. data/lib/test/unit/code-snippet-fetcher.rb +7 -7
  13. data/lib/test/unit/collector/descendant.rb +1 -0
  14. data/lib/test/unit/collector/dir.rb +4 -2
  15. data/lib/test/unit/collector/load.rb +3 -3
  16. data/lib/test/unit/collector/objectspace.rb +1 -0
  17. data/lib/test/unit/collector.rb +31 -0
  18. data/lib/test/unit/color-scheme.rb +20 -2
  19. data/lib/test/unit/data-sets.rb +26 -15
  20. data/lib/test/unit/data.rb +5 -5
  21. data/lib/test/unit/diff.rb +2 -3
  22. data/lib/test/unit/fixture.rb +6 -0
  23. data/lib/test/unit/notification.rb +9 -7
  24. data/lib/test/unit/omission.rb +34 -31
  25. data/lib/test/unit/pending.rb +12 -11
  26. data/lib/test/unit/priority.rb +7 -5
  27. data/lib/test/unit/runner/console.rb +0 -17
  28. data/lib/test/unit/testcase.rb +222 -146
  29. data/lib/test/unit/testsuite.rb +1 -1
  30. data/lib/test/unit/ui/console/testrunner.rb +58 -49
  31. data/lib/test/unit/util/memory-usage.rb +47 -0
  32. data/lib/test/unit/util/observable.rb +2 -2
  33. data/lib/test/unit/util/output.rb +5 -4
  34. data/lib/test/unit/version.rb +1 -1
  35. data/lib/test/unit/warning.rb +3 -0
  36. data/lib/test/unit.rb +177 -161
  37. data/lib/test-unit.rb +2 -17
  38. metadata +14 -91
  39. data/GPL +0 -339
  40. data/LGPL +0 -502
  41. data/test/collector/test-descendant.rb +0 -182
  42. data/test/collector/test-load.rb +0 -442
  43. data/test/collector/test_dir.rb +0 -407
  44. data/test/collector/test_objectspace.rb +0 -102
  45. data/test/fixtures/header-label.csv +0 -3
  46. data/test/fixtures/header-label.tsv +0 -3
  47. data/test/fixtures/header.csv +0 -3
  48. data/test/fixtures/header.tsv +0 -3
  49. data/test/fixtures/no-header.csv +0 -2
  50. data/test/fixtures/no-header.tsv +0 -2
  51. data/test/fixtures/plus.csv +0 -3
  52. data/test/run-test.rb +0 -22
  53. data/test/test-assertions.rb +0 -2180
  54. data/test/test-attribute-matcher.rb +0 -38
  55. data/test/test-attribute.rb +0 -123
  56. data/test/test-code-snippet.rb +0 -37
  57. data/test/test-color-scheme.rb +0 -82
  58. data/test/test-color.rb +0 -47
  59. data/test/test-data.rb +0 -419
  60. data/test/test-diff.rb +0 -518
  61. data/test/test-emacs-runner.rb +0 -60
  62. data/test/test-error.rb +0 -26
  63. data/test/test-failure.rb +0 -33
  64. data/test/test-fault-location-detector.rb +0 -163
  65. data/test/test-fixture.rb +0 -713
  66. data/test/test-notification.rb +0 -33
  67. data/test/test-omission.rb +0 -81
  68. data/test/test-pending.rb +0 -70
  69. data/test/test-priority.rb +0 -173
  70. data/test/test-test-case.rb +0 -1279
  71. data/test/test-test-result.rb +0 -113
  72. data/test/test-test-suite-creator.rb +0 -97
  73. data/test/test-test-suite.rb +0 -151
  74. data/test/testunit-test-util.rb +0 -31
  75. data/test/ui/test_testrunmediator.rb +0 -20
  76. data/test/util/test-method-owner-finder.rb +0 -38
  77. data/test/util/test-output.rb +0 -11
  78. data/test/util/test_backtracefilter.rb +0 -52
  79. data/test/util/test_observable.rb +0 -102
  80. data/test/util/test_procwrapper.rb +0 -36
@@ -65,19 +65,20 @@ module Test
65
65
  # Marks the test or part of the test is pending.
66
66
  #
67
67
  # Example:
68
- # def test_pending
69
- # pend
70
- # # Not reached here
71
- # end
72
68
  #
73
- # def test_pending_with_here
74
- # pend do
75
- # # Ran here
76
- # # Fails if the block doesn't raise any error.
77
- # # Because it means the block is passed unexpectedly.
69
+ # def test_pending
70
+ # pend
71
+ # # Not reached here
72
+ # end
73
+ #
74
+ # def test_pending_with_here
75
+ # pend do
76
+ # # Ran here
77
+ # # Fails if the block doesn't raise any error.
78
+ # # Because it means the block is passed unexpectedly.
79
+ # end
80
+ # # Reached here
78
81
  # end
79
- # # Reached here
80
- # end
81
82
  def pend(message=nil, &block)
82
83
  message ||= "pended."
83
84
  if block_given?
@@ -1,5 +1,3 @@
1
- require "fileutils"
2
-
3
1
  module Test
4
2
  module Unit
5
3
  module Priority
@@ -148,15 +146,19 @@ module Test
148
146
  end
149
147
 
150
148
  def escape_class_name(class_name)
151
- class_name.gsub(/(?:[: \\\/])/, "_")
149
+ escape_name(class_name)
152
150
  end
153
151
 
154
152
  def escaped_method_name
155
- @test.method_name.to_s.gsub(/(?:[: ]|[!?=]$)/) do |matched|
153
+ escape_name(@test.method_name.to_s)
154
+ end
155
+
156
+ def escape_name(name)
157
+ name.gsub(/(?:[: \/!?=])/) do |matched|
156
158
  case matched
157
159
  when ":"
158
160
  "_colon_"
159
- when " "
161
+ when " ", "/"
160
162
  "_"
161
163
  when "!"
162
164
  ".destructive"
@@ -1,21 +1,4 @@
1
1
  # Copyright (C) 2008-2017 Kouhei Sutou <kou@clear-code.com>
2
- #
3
- # License: Ruby OR LGPL-2.1+
4
- #
5
- # This library is free software; you can redistribute it and/or
6
- # modify it under the terms of the GNU Lesser General Public
7
- # License as published by the Free Software Foundation; either
8
- # version 2.1 of the License, or (at your option) any later version.
9
- #
10
- # This library is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
- # Lesser General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU Lesser General Public
16
- # License along with this library; if not, write to the Free Software
17
- # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18
- # 02110-1301 USA
19
2
 
20
3
  module Test
21
4
  module Unit
@@ -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
- method_locations << {
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
- # class TestMyClass < Test::Unit::TestCase
180
- # class << self
181
- # def startup
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
- # def setup
187
- # ...
188
- # end
198
+ # def setup
199
+ # ...
200
+ # end
189
201
  #
190
- # def test_my_class1
191
- # ...
192
- # end
202
+ # def test_my_class1
203
+ # ...
204
+ # end
193
205
  #
194
- # def test_my_class2
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
- # class TestMyClass < Test::Unit::TestCase
216
- # class << self
217
- # def shutdown
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
- # def teardown
223
- # ...
224
- # end
236
+ # def teardown
237
+ # ...
238
+ # end
225
239
  #
226
- # def test_my_class1
227
- # ...
228
- # end
240
+ # def test_my_class1
241
+ # ...
242
+ # end
229
243
  #
230
- # def test_my_class2
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
- # +:alphabetic+ by default.
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
- # [:alphabetic]
263
- # Default. Tests are sorted in alphabetic order.
264
- # [:random]
265
- # Tests are sorted in random order.
266
- # [:defined]
267
- # Tests are sorted in defined order.
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
- # description "register user"
279
- # def test_register_user
280
- # ...
281
- # end
296
+ # description "register user"
297
+ # def test_register_user
298
+ # ...
299
+ # end
282
300
  #
283
- # test "register user" do
284
- # ...
285
- # end
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
- # test
291
- # def my_test_method
292
- # assert_equal("call me", ...)
293
- # end
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
- # description "register a normal user"
328
- # def test_register
329
- # ...
330
- # end
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
- # class TestParent < Test::Unit::TestCase
343
- # class TestChild < self
344
- # def test_in_child
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
- # class TestParent < Test::Unit::TestCase
351
- # sub_test_case("TestChild") do
352
- # def test_in_child
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
  #
@@ -369,13 +419,7 @@ module Test
369
419
  # case class context.
370
420
  # @return [Test::Unit::TestCase] Created sub test case class.
371
421
  def sub_test_case(name, &block)
372
- parent_test_case = self
373
- sub_test_case = Class.new(self) do
374
- singleton_class = class << self; self; end
375
- singleton_class.__send__(:define_method, :name) do
376
- [parent_test_case.name, name].compact.join("::")
377
- end
378
- end
422
+ sub_test_case = sub_test_case_class(name)
379
423
  sub_test_case.class_eval(&block)
380
424
  sub_test_case
381
425
  end
@@ -426,31 +470,54 @@ module Test
426
470
  private
427
471
  # @private
428
472
  @@method_locations = {}
473
+ # @private
474
+ @@method_location_mutex = Thread::Mutex.new
475
+
429
476
  # @private
430
477
  def method_locations
431
478
  @@method_locations[self] ||= []
432
479
  end
433
480
 
434
481
  # @private
435
- def target_method_locations(path)
436
- if path.nil?
437
- self_location = method_locations.first
438
- path = self_location[:path] if self_location
482
+ def add_method_location(location)
483
+ @@method_location_mutex.synchronize do
484
+ method_locations << location
439
485
  end
440
- return [] if path.nil?
441
-
442
- target_locations = []
443
- @@method_locations.each do |test_case, locations|
444
- locations.each do |location|
445
- absolete_path = File.expand_path(path)
446
- location_path = location[:path]
447
- location_basename = File.basename(location_path)
448
- if location_path == absolete_path or location_basename == path
449
- target_locations << location.merge(:test_case => test_case)
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
450
506
  end
451
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
452
520
  end
453
- target_locations
454
521
  end
455
522
  end
456
523
 
@@ -537,35 +604,37 @@ module Test
537
604
  #
538
605
  # You can add additional setup tasks by the following
539
606
  # code:
540
- # class TestMyClass < Test::Unit::TestCase
541
- # def setup
542
- # ...
543
- # end
544
607
  #
545
- # setup
546
- # def my_setup1
547
- # ...
548
- # end
608
+ # class TestMyClass < Test::Unit::TestCase
609
+ # def setup
610
+ # ...
611
+ # end
549
612
  #
550
- # setup do
551
- # ... # setup callback1
552
- # end
613
+ # setup
614
+ # def my_setup1
615
+ # ...
616
+ # end
553
617
  #
554
- # setup
555
- # def my_setup2
556
- # ...
557
- # end
618
+ # setup do
619
+ # ... # setup callback1
620
+ # end
558
621
  #
559
- # setup do
560
- # ... # setup callback2
561
- # end
622
+ # setup
623
+ # def my_setup2
624
+ # ...
625
+ # end
626
+ #
627
+ # setup do
628
+ # ... # setup callback2
629
+ # end
562
630
  #
563
- # def test_my_class
564
- # ...
631
+ # def test_my_class
632
+ # ...
633
+ # end
565
634
  # end
566
- # end
567
635
  #
568
636
  # Here is a call order:
637
+ #
569
638
  # * setup
570
639
  # * my_setup1
571
640
  # * setup callback1
@@ -582,35 +651,37 @@ module Test
582
651
  #
583
652
  # You can add additional cleanup tasks by the following
584
653
  # code:
585
- # class TestMyClass < Test::Unit::TestCase
586
- # def cleanup
587
- # ...
588
- # end
589
654
  #
590
- # cleanup
591
- # def my_cleanup1
592
- # ...
593
- # end
655
+ # class TestMyClass < Test::Unit::TestCase
656
+ # def cleanup
657
+ # ...
658
+ # end
594
659
  #
595
- # cleanup do
596
- # ... # cleanup callback1
597
- # end
660
+ # cleanup
661
+ # def my_cleanup1
662
+ # ...
663
+ # end
598
664
  #
599
- # cleanup
600
- # def my_cleanup2
601
- # ...
602
- # end
665
+ # cleanup do
666
+ # ... # cleanup callback1
667
+ # end
603
668
  #
604
- # cleanup do
605
- # ... # cleanup callback2
606
- # end
669
+ # cleanup
670
+ # def my_cleanup2
671
+ # ...
672
+ # end
673
+ #
674
+ # cleanup do
675
+ # ... # cleanup callback2
676
+ # end
607
677
  #
608
- # def test_my_class
609
- # ...
678
+ # def test_my_class
679
+ # ...
680
+ # end
610
681
  # end
611
- # end
612
682
  #
613
683
  # Here is a call order:
684
+ #
614
685
  # * test_my_class
615
686
  # * cleanup callback2
616
687
  # * my_cleanup2
@@ -625,35 +696,37 @@ module Test
625
696
  #
626
697
  # You can add additional teardown tasks by the following
627
698
  # code:
628
- # class TestMyClass < Test::Unit::TestCase
629
- # def teardown
630
- # ...
631
- # end
632
699
  #
633
- # teardown
634
- # def my_teardown1
635
- # ...
636
- # end
700
+ # class TestMyClass < Test::Unit::TestCase
701
+ # def teardown
702
+ # ...
703
+ # end
637
704
  #
638
- # teardown do
639
- # ... # teardown callback1
640
- # end
705
+ # teardown
706
+ # def my_teardown1
707
+ # ...
708
+ # end
641
709
  #
642
- # teardown
643
- # def my_teardown2
644
- # ...
645
- # end
710
+ # teardown do
711
+ # ... # teardown callback1
712
+ # end
646
713
  #
647
- # teardown do
648
- # ... # teardown callback2
649
- # end
714
+ # teardown
715
+ # def my_teardown2
716
+ # ...
717
+ # end
650
718
  #
651
- # def test_my_class
652
- # ...
719
+ # teardown do
720
+ # ... # teardown callback2
721
+ # end
722
+ #
723
+ # def test_my_class
724
+ # ...
725
+ # end
653
726
  # end
654
- # end
655
727
  #
656
728
  # Here is a call order:
729
+ #
657
730
  # * test_my_class
658
731
  # * teardown callback2
659
732
  # * my_teardown2
@@ -673,13 +746,13 @@ module Test
673
746
 
674
747
  # Returns a label of test data for the test. If the
675
748
  # test isn't associated with any test data, it returns
676
- # +nil+.
749
+ # `nil`.
677
750
  def data_label
678
751
  @internal_data.test_data_label
679
752
  end
680
753
 
681
754
  # Returns test data for the test. If the test isn't associated
682
- # with any test data, it returns +nil+.
755
+ # with any test data, it returns `nil`.
683
756
  def data
684
757
  @internal_data.test_data
685
758
  end
@@ -783,6 +856,9 @@ module Test
783
856
  notify("<#{signature}> was redefined",
784
857
  :backtrace => redefined_info[:backtrace])
785
858
  end
859
+ if self[:ractor] and not defined?(::Ractor)
860
+ omit("<#{signature}> requires Ractor")
861
+ end
786
862
  if @internal_data.have_test_data?
787
863
  test_method = method(@method_name)
788
864
  arity = test_method.arity
@@ -77,7 +77,7 @@ module Test
77
77
  @tests -= tests
78
78
  end
79
79
 
80
- # Retuns the rolled up number of tests in this suite;
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