minitest 5.18.0 → 5.25.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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/History.rdoc +187 -1
- data/Manifest.txt +3 -0
- data/README.rdoc +28 -17
- data/Rakefile +7 -1
- data/lib/hoe/minitest.rb +2 -1
- data/lib/minitest/assertions.rb +77 -80
- data/lib/minitest/autorun.rb +0 -7
- data/lib/minitest/benchmark.rb +6 -9
- data/lib/minitest/compress.rb +94 -0
- data/lib/minitest/error_on_warning.rb +11 -0
- data/lib/minitest/expectations.rb +2 -2
- data/lib/minitest/manual_plugins.rb +16 -0
- data/lib/minitest/mock.rb +39 -19
- data/lib/minitest/parallel.rb +5 -5
- data/lib/minitest/pride_plugin.rb +16 -23
- data/lib/minitest/spec.rb +13 -12
- data/lib/minitest/test.rb +17 -36
- data/lib/minitest/test_task.rb +21 -19
- data/lib/minitest.rb +298 -141
- data/test/minitest/metametameta.rb +32 -18
- data/test/minitest/test_minitest_assertions.rb +159 -140
- data/test/minitest/test_minitest_benchmark.rb +1 -1
- data/test/minitest/test_minitest_mock.rb +151 -79
- data/test/minitest/test_minitest_reporter.rb +143 -19
- data/test/minitest/test_minitest_spec.rb +73 -56
- data/test/minitest/test_minitest_test.rb +218 -116
- data/test/minitest/test_minitest_test_task.rb +18 -7
- data.tar.gz.sig +0 -0
- metadata +21 -20
- metadata.gz.sig +0 -0
@@ -1,21 +1,18 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require "pathname"
|
4
1
|
require "minitest/metametameta"
|
5
2
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
warn ""
|
15
|
-
end
|
3
|
+
e = Encoding.default_external
|
4
|
+
if e != Encoding::UTF_8 then
|
5
|
+
warn ""
|
6
|
+
warn ""
|
7
|
+
warn "NOTE: External encoding #{e} is not UTF-8. Tests WILL fail."
|
8
|
+
warn " Run tests with `RUBYOPT=-Eutf-8 rake` to avoid errors."
|
9
|
+
warn ""
|
10
|
+
warn ""
|
16
11
|
end
|
17
12
|
|
18
13
|
class Minitest::Runnable
|
14
|
+
attr_reader :gc_stats # only needed if running w/ minitest-gcstats
|
15
|
+
|
19
16
|
def whatever # faked for testing
|
20
17
|
assert true
|
21
18
|
end
|
@@ -24,48 +21,45 @@ end
|
|
24
21
|
class TestMinitestUnit < MetaMetaMetaTestCase
|
25
22
|
parallelize_me!
|
26
23
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
"#{MINITEST_BASE_DIR}/test.rb:158:in `each'",
|
33
|
-
"#{MINITEST_BASE_DIR}/test.rb:139:in `run'",
|
34
|
-
"#{MINITEST_BASE_DIR}/test.rb:106:in `run'"]
|
24
|
+
MINITEST_BASE_DIR = "./lib/minitest/mini"
|
25
|
+
BT_MIDDLE = ["#{MINITEST_BASE_DIR}/test.rb:161:in 'each'",
|
26
|
+
"#{MINITEST_BASE_DIR}/test.rb:158:in 'each'",
|
27
|
+
"#{MINITEST_BASE_DIR}/test.rb:139:in 'run'",
|
28
|
+
"#{MINITEST_BASE_DIR}/test.rb:106:in 'run'"]
|
35
29
|
|
36
30
|
def test_filter_backtrace
|
37
31
|
# this is a semi-lame mix of relative paths.
|
38
32
|
# I cheated by making the autotest parts not have ./
|
39
|
-
bt = (["lib/autotest.rb:571:in
|
40
|
-
"test/test_autotest.rb:62:in
|
41
|
-
"#{MINITEST_BASE_DIR}/test.rb:165:in
|
33
|
+
bt = (["lib/autotest.rb:571:in 'add_exception'",
|
34
|
+
"test/test_autotest.rb:62:in 'test_add_exception'",
|
35
|
+
"#{MINITEST_BASE_DIR}/test.rb:165:in '__send__'"] +
|
42
36
|
BT_MIDDLE +
|
43
37
|
["#{MINITEST_BASE_DIR}/test.rb:29",
|
44
38
|
"test/test_autotest.rb:422"])
|
45
39
|
bt = util_expand_bt bt
|
46
40
|
|
47
|
-
ex = ["lib/autotest.rb:571:in
|
48
|
-
"test/test_autotest.rb:62:in
|
41
|
+
ex = ["lib/autotest.rb:571:in 'add_exception'",
|
42
|
+
"test/test_autotest.rb:62:in 'test_add_exception'"]
|
49
43
|
ex = util_expand_bt ex
|
50
44
|
|
51
45
|
Minitest::Test.io_lock.synchronize do # try not to trounce in parallel
|
52
|
-
fu = Minitest.filter_backtrace
|
46
|
+
fu = Minitest.filter_backtrace bt
|
53
47
|
|
54
48
|
assert_equal ex, fu
|
55
49
|
end
|
56
50
|
end
|
57
51
|
|
58
52
|
def test_filter_backtrace_all_unit
|
59
|
-
bt = (["#{MINITEST_BASE_DIR}/test.rb:165:in
|
53
|
+
bt = (["#{MINITEST_BASE_DIR}/test.rb:165:in '__send__'"] +
|
60
54
|
BT_MIDDLE +
|
61
55
|
["#{MINITEST_BASE_DIR}/test.rb:29"])
|
62
56
|
ex = bt.clone
|
63
|
-
fu = Minitest.filter_backtrace
|
57
|
+
fu = Minitest.filter_backtrace bt
|
64
58
|
assert_equal ex, fu
|
65
59
|
end
|
66
60
|
|
67
61
|
def test_filter_backtrace_unit_starts
|
68
|
-
bt = (["#{MINITEST_BASE_DIR}/test.rb:165:in
|
62
|
+
bt = (["#{MINITEST_BASE_DIR}/test.rb:165:in '__send__'"] +
|
69
63
|
BT_MIDDLE +
|
70
64
|
["#{MINITEST_BASE_DIR}/mini/test.rb:29",
|
71
65
|
"-e:1"])
|
@@ -94,24 +88,24 @@ class TestMinitestUnit < MetaMetaMetaTestCase
|
|
94
88
|
end
|
95
89
|
|
96
90
|
def test_this_is_non_ascii_failure_message
|
97
|
-
|
91
|
+
raise "ЁЁЁ".dup.force_encoding(Encoding::BINARY)
|
98
92
|
end
|
99
93
|
end
|
100
94
|
|
101
|
-
expected =
|
95
|
+
expected = <<~EOM
|
102
96
|
FE
|
103
97
|
|
104
98
|
Finished in 0.00
|
105
99
|
|
106
100
|
1) Failure:
|
107
101
|
FakeNamedTestXX#test_this_is_not_ascii_assertion [FILE:LINE]:
|
108
|
-
Expected:
|
109
|
-
Actual:
|
102
|
+
Expected: "ЁЁЁ"
|
103
|
+
Actual: "ёёё"
|
110
104
|
|
111
105
|
2) Error:
|
112
106
|
FakeNamedTestXX#test_this_is_non_ascii_failure_message:
|
113
107
|
RuntimeError: ЁЁЁ
|
114
|
-
FILE:LINE:in
|
108
|
+
FILE:LINE:in 'test_this_is_non_ascii_failure_message'
|
115
109
|
|
116
110
|
2 runs, 1 assertions, 1 failures, 1 errors, 0 skips
|
117
111
|
EOM
|
@@ -163,8 +157,26 @@ class TestMinitestUnit < MetaMetaMetaTestCase
|
|
163
157
|
refute_predicate test, :skipped?
|
164
158
|
end
|
165
159
|
|
160
|
+
def test_skipped_is_reachable
|
161
|
+
test_class = Class.new FakeNamedTest do
|
162
|
+
def test_omg
|
163
|
+
skip
|
164
|
+
ensure
|
165
|
+
flunk unless skipped?
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
test = test_class.new :test_omg
|
170
|
+
test.run
|
171
|
+
|
172
|
+
refute_predicate test, :error?
|
173
|
+
refute_predicate test, :passed?
|
174
|
+
|
175
|
+
assert_predicate test, :skipped?
|
176
|
+
end
|
177
|
+
|
166
178
|
def util_expand_bt bt
|
167
|
-
bt.map { |f| (
|
179
|
+
bt.map { |f| f.start_with?(".") ? File.expand_path(f) : f }
|
168
180
|
end
|
169
181
|
end
|
170
182
|
|
@@ -208,15 +220,14 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
208
220
|
def test_class_runnables
|
209
221
|
@assertion_count = 0
|
210
222
|
|
211
|
-
tc = Class.new
|
223
|
+
tc = Class.new Minitest::Test
|
212
224
|
|
213
225
|
assert_equal 1, Minitest::Test.runnables.size
|
214
226
|
assert_equal [tc], Minitest::Test.runnables
|
215
227
|
end
|
216
228
|
|
217
229
|
def test_run_test
|
218
|
-
@tu =
|
219
|
-
Class.new FakeNamedTest do
|
230
|
+
@tu = Class.new FakeNamedTest do
|
220
231
|
attr_reader :foo
|
221
232
|
|
222
233
|
def run
|
@@ -232,7 +243,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
232
243
|
end
|
233
244
|
end
|
234
245
|
|
235
|
-
expected =
|
246
|
+
expected = <<~EOM
|
236
247
|
.
|
237
248
|
|
238
249
|
Finished in 0.00
|
@@ -244,8 +255,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
244
255
|
end
|
245
256
|
|
246
257
|
def test_run_error
|
247
|
-
@tu =
|
248
|
-
Class.new FakeNamedTest do
|
258
|
+
@tu = Class.new FakeNamedTest do
|
249
259
|
def test_something
|
250
260
|
assert true
|
251
261
|
end
|
@@ -255,7 +265,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
255
265
|
end
|
256
266
|
end
|
257
267
|
|
258
|
-
expected =
|
268
|
+
expected = <<~EOM
|
259
269
|
.E
|
260
270
|
|
261
271
|
Finished in 0.00
|
@@ -263,7 +273,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
263
273
|
1) Error:
|
264
274
|
FakeNamedTestXX#test_error:
|
265
275
|
RuntimeError: unhandled exception
|
266
|
-
FILE:LINE:in
|
276
|
+
FILE:LINE:in 'test_error'
|
267
277
|
|
268
278
|
2 runs, 1 assertions, 0 failures, 1 errors, 0 skips
|
269
279
|
EOM
|
@@ -272,8 +282,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
272
282
|
end
|
273
283
|
|
274
284
|
def test_run_error_teardown
|
275
|
-
@tu =
|
276
|
-
Class.new FakeNamedTest do
|
285
|
+
@tu = Class.new FakeNamedTest do
|
277
286
|
def test_something
|
278
287
|
assert true
|
279
288
|
end
|
@@ -283,7 +292,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
283
292
|
end
|
284
293
|
end
|
285
294
|
|
286
|
-
expected =
|
295
|
+
expected = <<~EOM
|
287
296
|
E
|
288
297
|
|
289
298
|
Finished in 0.00
|
@@ -291,7 +300,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
291
300
|
1) Error:
|
292
301
|
FakeNamedTestXX#test_something:
|
293
302
|
RuntimeError: unhandled exception
|
294
|
-
FILE:LINE:in
|
303
|
+
FILE:LINE:in 'teardown'
|
295
304
|
|
296
305
|
1 runs, 1 assertions, 0 failures, 1 errors, 0 skips
|
297
306
|
EOM
|
@@ -302,7 +311,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
302
311
|
def test_run_failing
|
303
312
|
setup_basic_tu
|
304
313
|
|
305
|
-
expected =
|
314
|
+
expected = <<~EOM
|
306
315
|
.F
|
307
316
|
|
308
317
|
Finished in 0.00
|
@@ -318,8 +327,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
318
327
|
end
|
319
328
|
|
320
329
|
def setup_basic_tu
|
321
|
-
@tu =
|
322
|
-
Class.new FakeNamedTest do
|
330
|
+
@tu = Class.new FakeNamedTest do
|
323
331
|
def test_something
|
324
332
|
assert true
|
325
333
|
end
|
@@ -337,7 +345,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
337
345
|
def test_run_failing_filtered
|
338
346
|
setup_basic_tu
|
339
347
|
|
340
|
-
expected =
|
348
|
+
expected = <<~EOM
|
341
349
|
.
|
342
350
|
|
343
351
|
Finished in 0.00
|
@@ -356,14 +364,14 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
356
364
|
assert a
|
357
365
|
end
|
358
366
|
end
|
359
|
-
Object.const_set
|
367
|
+
Object.const_set :Alpha, alpha
|
360
368
|
|
361
369
|
beta = Class.new FakeNamedTest do
|
362
370
|
define_method :test_something do
|
363
371
|
assert true
|
364
372
|
end
|
365
373
|
end
|
366
|
-
Object.const_set
|
374
|
+
Object.const_set :Beta, beta
|
367
375
|
|
368
376
|
@tus = [alpha, beta]
|
369
377
|
|
@@ -374,7 +382,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
374
382
|
end
|
375
383
|
|
376
384
|
def test_run_filtered_including_suite_name
|
377
|
-
expected =
|
385
|
+
expected = <<~EOM
|
378
386
|
.
|
379
387
|
|
380
388
|
Finished in 0.00
|
@@ -386,7 +394,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
386
394
|
end
|
387
395
|
|
388
396
|
def test_run_filtered_including_suite_name_string
|
389
|
-
expected =
|
397
|
+
expected = <<~EOM
|
390
398
|
.
|
391
399
|
|
392
400
|
Finished in 0.00
|
@@ -398,7 +406,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
398
406
|
end
|
399
407
|
|
400
408
|
def test_run_filtered_string_method_only
|
401
|
-
expected =
|
409
|
+
expected = <<~EOM
|
402
410
|
..
|
403
411
|
|
404
412
|
Finished in 0.00
|
@@ -412,7 +420,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
412
420
|
def test_run_failing_excluded
|
413
421
|
setup_basic_tu
|
414
422
|
|
415
|
-
expected =
|
423
|
+
expected = <<~EOM
|
416
424
|
.
|
417
425
|
|
418
426
|
Finished in 0.00
|
@@ -424,7 +432,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
424
432
|
end
|
425
433
|
|
426
434
|
def test_run_filtered_excluding_suite_name
|
427
|
-
expected =
|
435
|
+
expected = <<~EOM
|
428
436
|
.
|
429
437
|
|
430
438
|
Finished in 0.00
|
@@ -436,7 +444,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
436
444
|
end
|
437
445
|
|
438
446
|
def test_run_filtered_excluding_suite_name_string
|
439
|
-
expected =
|
447
|
+
expected = <<~EOM
|
440
448
|
.
|
441
449
|
|
442
450
|
Finished in 0.00
|
@@ -448,7 +456,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
448
456
|
end
|
449
457
|
|
450
458
|
def test_run_filtered_excluding_string_method_only
|
451
|
-
expected =
|
459
|
+
expected = <<~EOM
|
452
460
|
|
453
461
|
|
454
462
|
Finished in 0.00
|
@@ -460,14 +468,13 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
460
468
|
end
|
461
469
|
|
462
470
|
def test_run_passing
|
463
|
-
@tu =
|
464
|
-
Class.new FakeNamedTest do
|
471
|
+
@tu = Class.new FakeNamedTest do
|
465
472
|
def test_something
|
466
473
|
assert true
|
467
474
|
end
|
468
475
|
end
|
469
476
|
|
470
|
-
expected =
|
477
|
+
expected = <<~EOM
|
471
478
|
.
|
472
479
|
|
473
480
|
Finished in 0.00
|
@@ -479,8 +486,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
479
486
|
end
|
480
487
|
|
481
488
|
def test_run_skip
|
482
|
-
@tu =
|
483
|
-
Class.new FakeNamedTest do
|
489
|
+
@tu = Class.new FakeNamedTest do
|
484
490
|
def test_something
|
485
491
|
assert true
|
486
492
|
end
|
@@ -490,7 +496,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
490
496
|
end
|
491
497
|
end
|
492
498
|
|
493
|
-
expected =
|
499
|
+
expected = <<~EOM
|
494
500
|
.S
|
495
501
|
|
496
502
|
Finished in 0.00
|
@@ -506,8 +512,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
506
512
|
end
|
507
513
|
|
508
514
|
def test_run_skip_verbose
|
509
|
-
@tu =
|
510
|
-
Class.new FakeNamedTest do
|
515
|
+
@tu = Class.new FakeNamedTest do
|
511
516
|
def test_something
|
512
517
|
assert true
|
513
518
|
end
|
@@ -517,7 +522,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
517
522
|
end
|
518
523
|
end
|
519
524
|
|
520
|
-
expected =
|
525
|
+
expected = <<~EOM
|
521
526
|
FakeNamedTestXX#test_something = 0.00 s = .
|
522
527
|
FakeNamedTestXX#test_skip = 0.00 s = S
|
523
528
|
|
@@ -534,8 +539,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
534
539
|
end
|
535
540
|
|
536
541
|
def test_run_skip_show_skips
|
537
|
-
@tu =
|
538
|
-
Class.new FakeNamedTest do
|
542
|
+
@tu = Class.new FakeNamedTest do
|
539
543
|
def test_something
|
540
544
|
assert true
|
541
545
|
end
|
@@ -545,7 +549,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
545
549
|
end
|
546
550
|
end
|
547
551
|
|
548
|
-
expected =
|
552
|
+
expected = <<~EOM
|
549
553
|
.S
|
550
554
|
|
551
555
|
Finished in 0.00
|
@@ -561,8 +565,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
561
565
|
end
|
562
566
|
|
563
567
|
def test_run_with_other_runner
|
564
|
-
@tu =
|
565
|
-
Class.new FakeNamedTest do
|
568
|
+
@tu = Class.new FakeNamedTest do
|
566
569
|
def self.run reporter, options = {}
|
567
570
|
@reporter = reporter
|
568
571
|
before_my_suite
|
@@ -585,7 +588,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
585
588
|
end
|
586
589
|
end
|
587
590
|
|
588
|
-
expected =
|
591
|
+
expected = <<~EOM
|
589
592
|
Running wacky! tests
|
590
593
|
..
|
591
594
|
|
@@ -634,8 +637,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
634
637
|
main_latch.release
|
635
638
|
}
|
636
639
|
|
637
|
-
@tu =
|
638
|
-
Class.new FakeNamedTest do
|
640
|
+
@tu = Class.new FakeNamedTest do
|
639
641
|
parallelize_me!
|
640
642
|
|
641
643
|
test_count.times do |i|
|
@@ -652,7 +654,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
652
654
|
end
|
653
655
|
end
|
654
656
|
|
655
|
-
expected =
|
657
|
+
expected = <<~EOM
|
656
658
|
..
|
657
659
|
|
658
660
|
Finished in 0.00
|
@@ -662,18 +664,18 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
662
664
|
|
663
665
|
skip if Minitest.parallel_executor.size < 2 # locks up test runner if 1 CPU
|
664
666
|
|
665
|
-
assert_report
|
666
|
-
reporter.extend
|
667
|
-
define_method
|
667
|
+
assert_report expected do |reporter|
|
668
|
+
reporter.extend Module.new {
|
669
|
+
define_method :record do |result|
|
668
670
|
super(result)
|
669
671
|
wait_latch.release
|
670
672
|
end
|
671
673
|
|
672
|
-
define_method
|
674
|
+
define_method :report do
|
673
675
|
wait_latch.await
|
674
676
|
super()
|
675
677
|
end
|
676
|
-
}
|
678
|
+
}
|
677
679
|
end
|
678
680
|
assert thread.join
|
679
681
|
end
|
@@ -684,8 +686,8 @@ class TestMinitestUnitOrder < MetaMetaMetaTestCase
|
|
684
686
|
|
685
687
|
def test_before_setup
|
686
688
|
call_order = []
|
687
|
-
|
688
|
-
Class.new FakeNamedTest do
|
689
|
+
|
690
|
+
@tu = Class.new FakeNamedTest do
|
689
691
|
define_method :setup do
|
690
692
|
super()
|
691
693
|
call_order << :setup
|
@@ -700,14 +702,13 @@ class TestMinitestUnitOrder < MetaMetaMetaTestCase
|
|
700
702
|
|
701
703
|
run_tu_with_fresh_reporter
|
702
704
|
|
703
|
-
expected = [
|
705
|
+
expected = %i[before_setup setup]
|
704
706
|
assert_equal expected, call_order
|
705
707
|
end
|
706
708
|
|
707
709
|
def test_after_teardown
|
708
710
|
call_order = []
|
709
|
-
@tu =
|
710
|
-
Class.new FakeNamedTest do
|
711
|
+
@tu = Class.new FakeNamedTest do
|
711
712
|
define_method :teardown do
|
712
713
|
super()
|
713
714
|
call_order << :teardown
|
@@ -722,14 +723,14 @@ class TestMinitestUnitOrder < MetaMetaMetaTestCase
|
|
722
723
|
|
723
724
|
run_tu_with_fresh_reporter
|
724
725
|
|
725
|
-
expected = [
|
726
|
+
expected = %i[teardown after_teardown]
|
726
727
|
assert_equal expected, call_order
|
727
728
|
end
|
728
729
|
|
729
730
|
def test_all_teardowns_are_guaranteed_to_run
|
730
731
|
call_order = []
|
731
|
-
|
732
|
-
Class.new FakeNamedTest do
|
732
|
+
|
733
|
+
@tu = Class.new FakeNamedTest do
|
733
734
|
define_method :after_teardown do
|
734
735
|
super()
|
735
736
|
call_order << :after_teardown
|
@@ -753,7 +754,7 @@ class TestMinitestUnitOrder < MetaMetaMetaTestCase
|
|
753
754
|
|
754
755
|
run_tu_with_fresh_reporter
|
755
756
|
|
756
|
-
expected = [
|
757
|
+
expected = %i[before_teardown teardown after_teardown]
|
757
758
|
assert_equal expected, call_order
|
758
759
|
end
|
759
760
|
|
@@ -780,7 +781,7 @@ class TestMinitestUnitOrder < MetaMetaMetaTestCase
|
|
780
781
|
run_tu_with_fresh_reporter
|
781
782
|
|
782
783
|
# Once for the parent class, once for the child
|
783
|
-
expected = [
|
784
|
+
expected = %i[setup_method test teardown_method] * 2
|
784
785
|
|
785
786
|
assert_equal expected, call_order
|
786
787
|
end
|
@@ -813,6 +814,7 @@ class TestMinitestRunnable < Minitest::Test
|
|
813
814
|
new_tc = Marshal.load Marshal.dump @tc
|
814
815
|
|
815
816
|
ivars = new_tc.instance_variables.map(&:to_s).sort
|
817
|
+
ivars.delete "@gc_stats" # only needed if running w/ minitest-gcstats
|
816
818
|
assert_equal expected_ivars, ivars
|
817
819
|
assert_equal "whatever", new_tc.name
|
818
820
|
assert_equal 42, new_tc.assertions
|
@@ -876,11 +878,11 @@ class TestMinitestRunnable < Minitest::Test
|
|
876
878
|
end
|
877
879
|
|
878
880
|
def test_spec_marshal_with_exception_nameerror
|
879
|
-
klass = describe
|
880
|
-
it
|
881
|
+
klass = describe "whatever" do
|
882
|
+
it "raises NameError" do
|
881
883
|
NOPE::does_not_exist
|
882
|
-
|
883
|
-
|
884
|
+
end
|
885
|
+
end
|
884
886
|
|
885
887
|
rm = klass.runnable_methods.first
|
886
888
|
|
@@ -944,10 +946,9 @@ class TestMinitestRunnable < Minitest::Test
|
|
944
946
|
end
|
945
947
|
|
946
948
|
def test_spec_marshal_with_exception__worse_error_typeerror
|
947
|
-
worse_error_klass = Class.new
|
948
|
-
# problem #1: anonymous subclass can'
|
949
|
-
def initialize
|
950
|
-
|
949
|
+
worse_error_klass = Class.new StandardError do
|
950
|
+
# problem #1: anonymous subclass can't marshal, fails sanitize_exception
|
951
|
+
def initialize record = nil
|
951
952
|
super(record.first)
|
952
953
|
end
|
953
954
|
end
|
@@ -1004,8 +1005,6 @@ class TestMinitestUnitTestCase < Minitest::Test
|
|
1004
1005
|
# which is not threadsafe. Nearly every method in here is an
|
1005
1006
|
# assertion test so it isn't worth splitting it out further.
|
1006
1007
|
|
1007
|
-
RUBY18 = !defined? Encoding
|
1008
|
-
|
1009
1008
|
def setup
|
1010
1009
|
super
|
1011
1010
|
|
@@ -1030,7 +1029,7 @@ class TestMinitestUnitTestCase < Minitest::Test
|
|
1030
1029
|
$VERBOSE = orig_verbose
|
1031
1030
|
end
|
1032
1031
|
|
1033
|
-
def sample_test_case
|
1032
|
+
def sample_test_case rand
|
1034
1033
|
srand rand
|
1035
1034
|
Class.new FakeNamedTest do
|
1036
1035
|
100.times do |i|
|
@@ -1089,17 +1088,27 @@ class TestMinitestUnitTestCase < Minitest::Test
|
|
1089
1088
|
|
1090
1089
|
def test_autorun_does_not_affect_fork_success_status
|
1091
1090
|
@assertion_count = 0
|
1092
|
-
skip "windows doesn't have
|
1091
|
+
skip "windows doesn't have fork" unless Process.respond_to? :fork
|
1093
1092
|
Process.waitpid(fork {})
|
1094
1093
|
assert_equal true, $?.success?
|
1095
1094
|
end
|
1096
1095
|
|
1097
1096
|
def test_autorun_does_not_affect_fork_exit_status
|
1098
1097
|
@assertion_count = 0
|
1099
|
-
skip "windows doesn't have
|
1098
|
+
skip "windows doesn't have fork" unless Process.respond_to? :fork
|
1100
1099
|
Process.waitpid(fork { exit 42 })
|
1101
1100
|
assert_equal 42, $?.exitstatus
|
1102
1101
|
end
|
1102
|
+
|
1103
|
+
def test_autorun_optionally_can_affect_fork_exit_status
|
1104
|
+
@assertion_count = 0
|
1105
|
+
skip "windows doesn't have fork" unless Process.respond_to? :fork
|
1106
|
+
Minitest.allow_fork = true
|
1107
|
+
Process.waitpid(fork { exit 42 })
|
1108
|
+
refute_equal 42, $?.exitstatus
|
1109
|
+
ensure
|
1110
|
+
Minitest.allow_fork = false
|
1111
|
+
end
|
1103
1112
|
end
|
1104
1113
|
|
1105
1114
|
class TestMinitestGuard < Minitest::Test
|
@@ -1116,19 +1125,19 @@ class TestMinitestGuard < Minitest::Test
|
|
1116
1125
|
end
|
1117
1126
|
|
1118
1127
|
def test_rubinius_eh
|
1119
|
-
|
1128
|
+
assert_deprecation do
|
1120
1129
|
assert self.class.rubinius? "rbx"
|
1121
1130
|
end
|
1122
|
-
|
1131
|
+
assert_deprecation do
|
1123
1132
|
assert self.rubinius? "rbx"
|
1124
1133
|
end
|
1125
1134
|
end
|
1126
1135
|
|
1127
1136
|
def test_maglev_eh
|
1128
|
-
|
1137
|
+
assert_deprecation do
|
1129
1138
|
assert self.class.maglev? "maglev"
|
1130
1139
|
end
|
1131
|
-
|
1140
|
+
assert_deprecation do
|
1132
1141
|
assert self.maglev? "maglev"
|
1133
1142
|
end
|
1134
1143
|
end
|
@@ -1169,7 +1178,7 @@ class TestMinitestUnitRecording < MetaMetaMetaTestCase
|
|
1169
1178
|
bogus_reporter = Class.new do # doesn't subclass AbstractReporter
|
1170
1179
|
def start; @success = false; end
|
1171
1180
|
# def prerecord klass, name; end # doesn't define full API
|
1172
|
-
def record
|
1181
|
+
def record _result; @success = true; end
|
1173
1182
|
def report; end
|
1174
1183
|
def passed?; end
|
1175
1184
|
def results; end
|
@@ -1247,17 +1256,17 @@ class TestMinitestUnitRecording < MetaMetaMetaTestCase
|
|
1247
1256
|
|
1248
1257
|
run_tu_with_fresh_reporter
|
1249
1258
|
|
1250
|
-
exp =
|
1259
|
+
exp = <<~EOM
|
1251
1260
|
Error:
|
1252
1261
|
FakeNamedTestXX#test_method:
|
1253
1262
|
AnError: AnError
|
1254
|
-
FILE:LINE:in
|
1263
|
+
FILE:LINE:in 'test_method'
|
1255
1264
|
|
1256
1265
|
Error:
|
1257
1266
|
FakeNamedTestXX#test_method:
|
1258
1267
|
RuntimeError: unhandled exception
|
1259
|
-
FILE:LINE:in
|
1260
|
-
|
1268
|
+
FILE:LINE:in 'teardown'
|
1269
|
+
EOM
|
1261
1270
|
|
1262
1271
|
assert_equal exp.strip, normalize_output(first_reporter.results.first.to_s).strip
|
1263
1272
|
end
|
@@ -1270,3 +1279,96 @@ class TestMinitestUnitRecording < MetaMetaMetaTestCase
|
|
1270
1279
|
end
|
1271
1280
|
end
|
1272
1281
|
end
|
1282
|
+
|
1283
|
+
class TestUnexpectedError < Minitest::Test
|
1284
|
+
def assert_compress exp, input
|
1285
|
+
e = Minitest::UnexpectedError.new RuntimeError.new
|
1286
|
+
|
1287
|
+
exp = exp.lines.map(&:chomp) if String === exp
|
1288
|
+
act = e.compress input
|
1289
|
+
|
1290
|
+
assert_equal exp, act
|
1291
|
+
end
|
1292
|
+
|
1293
|
+
ACT1 = %w[ a b c b c b c b c d ]
|
1294
|
+
|
1295
|
+
def test_normal
|
1296
|
+
assert_compress <<~EXP, %w[ a b c b c b c b c d ]
|
1297
|
+
a
|
1298
|
+
+->> 4 cycles of 2 lines:
|
1299
|
+
| b
|
1300
|
+
| c
|
1301
|
+
+-<<
|
1302
|
+
d
|
1303
|
+
EXP
|
1304
|
+
end
|
1305
|
+
|
1306
|
+
def test_normal2
|
1307
|
+
assert_compress <<~EXP, %w[ a b c b c b c b c ]
|
1308
|
+
a
|
1309
|
+
+->> 4 cycles of 2 lines:
|
1310
|
+
| b
|
1311
|
+
| c
|
1312
|
+
+-<<
|
1313
|
+
EXP
|
1314
|
+
end
|
1315
|
+
|
1316
|
+
def test_longer_c_than_b
|
1317
|
+
# the extra c in the front makes the overall length longer sorting it first
|
1318
|
+
assert_compress <<~EXP, %w[ c a b c b c b c b c b d ]
|
1319
|
+
c
|
1320
|
+
a
|
1321
|
+
b
|
1322
|
+
+->> 4 cycles of 2 lines:
|
1323
|
+
| c
|
1324
|
+
| b
|
1325
|
+
+-<<
|
1326
|
+
d
|
1327
|
+
EXP
|
1328
|
+
end
|
1329
|
+
|
1330
|
+
def test_1_line_cycles
|
1331
|
+
assert_compress <<~EXP, %w[ c a b c b c b c b c b b b d ]
|
1332
|
+
c
|
1333
|
+
a
|
1334
|
+
+->> 4 cycles of 2 lines:
|
1335
|
+
| b
|
1336
|
+
| c
|
1337
|
+
+-<<
|
1338
|
+
+->> 3 cycles of 1 lines:
|
1339
|
+
| b
|
1340
|
+
+-<<
|
1341
|
+
d
|
1342
|
+
EXP
|
1343
|
+
end
|
1344
|
+
|
1345
|
+
def test_sanity3
|
1346
|
+
pre = ("aa".."am").to_a
|
1347
|
+
mid = ("a".."z").to_a * 67
|
1348
|
+
post = ("aa".."am").to_a
|
1349
|
+
ary = pre + mid + post
|
1350
|
+
|
1351
|
+
exp = pre +
|
1352
|
+
[" +->> 67 cycles of 26 lines:"] +
|
1353
|
+
("a".."z").map { |s| " | #{s}" } +
|
1354
|
+
[" +-<<"] +
|
1355
|
+
post
|
1356
|
+
|
1357
|
+
assert_compress exp, ary
|
1358
|
+
end
|
1359
|
+
|
1360
|
+
def test_absurd_patterns
|
1361
|
+
assert_compress <<~EXP, %w[ a b c b c a b c b c a b c ]
|
1362
|
+
+->> 2 cycles of 5 lines:
|
1363
|
+
| a
|
1364
|
+
| +->> 2 cycles of 2 lines:
|
1365
|
+
| | b
|
1366
|
+
| | c
|
1367
|
+
| +-<<
|
1368
|
+
+-<<
|
1369
|
+
a
|
1370
|
+
b
|
1371
|
+
c
|
1372
|
+
EXP
|
1373
|
+
end
|
1374
|
+
end
|