minitest 5.14.4 → 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 +283 -2
- data/Manifest.txt +5 -0
- data/README.rdoc +78 -36
- data/Rakefile +8 -1
- data/lib/hoe/minitest.rb +2 -5
- data/lib/minitest/assertions.rb +131 -83
- data/lib/minitest/autorun.rb +0 -7
- data/lib/minitest/benchmark.rb +11 -14
- data/lib/minitest/compress.rb +94 -0
- data/lib/minitest/error_on_warning.rb +11 -0
- data/lib/minitest/expectations.rb +18 -0
- data/lib/minitest/manual_plugins.rb +16 -0
- data/lib/minitest/mock.rb +148 -45
- data/lib/minitest/parallel.rb +5 -5
- data/lib/minitest/pride_plugin.rb +17 -24
- data/lib/minitest/spec.rb +20 -12
- data/lib/minitest/test.rb +51 -34
- data/lib/minitest/test_task.rb +307 -0
- data/lib/minitest/unit.rb +5 -8
- data/lib/minitest.rb +333 -154
- data/test/minitest/metametameta.rb +33 -19
- data/test/minitest/test_minitest_assertions.rb +292 -147
- data/test/minitest/test_minitest_benchmark.rb +3 -3
- data/test/minitest/test_minitest_mock.rb +396 -62
- data/test/minitest/test_minitest_reporter.rb +169 -32
- data/test/minitest/test_minitest_spec.rb +174 -72
- data/test/minitest/test_minitest_test.rb +420 -130
- data/test/minitest/test_minitest_test_task.rb +57 -0
- data.tar.gz.sig +0 -0
- metadata +23 -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,46 +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
|
46
|
+
fu = Minitest.filter_backtrace bt
|
52
47
|
|
53
|
-
|
48
|
+
assert_equal ex, fu
|
49
|
+
end
|
54
50
|
end
|
55
51
|
|
56
52
|
def test_filter_backtrace_all_unit
|
57
|
-
bt = (["#{MINITEST_BASE_DIR}/test.rb:165:in
|
53
|
+
bt = (["#{MINITEST_BASE_DIR}/test.rb:165:in '__send__'"] +
|
58
54
|
BT_MIDDLE +
|
59
55
|
["#{MINITEST_BASE_DIR}/test.rb:29"])
|
60
56
|
ex = bt.clone
|
61
|
-
fu = Minitest.filter_backtrace
|
57
|
+
fu = Minitest.filter_backtrace bt
|
62
58
|
assert_equal ex, fu
|
63
59
|
end
|
64
60
|
|
65
61
|
def test_filter_backtrace_unit_starts
|
66
|
-
bt = (["#{MINITEST_BASE_DIR}/test.rb:165:in
|
62
|
+
bt = (["#{MINITEST_BASE_DIR}/test.rb:165:in '__send__'"] +
|
67
63
|
BT_MIDDLE +
|
68
64
|
["#{MINITEST_BASE_DIR}/mini/test.rb:29",
|
69
65
|
"-e:1"])
|
@@ -71,8 +67,10 @@ class TestMinitestUnit < MetaMetaMetaTestCase
|
|
71
67
|
bt = util_expand_bt bt
|
72
68
|
|
73
69
|
ex = ["-e:1"]
|
74
|
-
|
75
|
-
|
70
|
+
Minitest::Test.io_lock.synchronize do # try not to trounce in parallel
|
71
|
+
fu = Minitest.filter_backtrace bt
|
72
|
+
assert_equal ex, fu
|
73
|
+
end
|
76
74
|
end
|
77
75
|
|
78
76
|
def test_filter_backtrace__empty
|
@@ -90,29 +88,31 @@ class TestMinitestUnit < MetaMetaMetaTestCase
|
|
90
88
|
end
|
91
89
|
|
92
90
|
def test_this_is_non_ascii_failure_message
|
93
|
-
|
91
|
+
raise "ЁЁЁ".dup.force_encoding(Encoding::BINARY)
|
94
92
|
end
|
95
93
|
end
|
96
94
|
|
97
|
-
expected =
|
98
|
-
|
95
|
+
expected = <<~EOM
|
96
|
+
FE
|
99
97
|
|
100
98
|
Finished in 0.00
|
101
99
|
|
102
|
-
1)
|
100
|
+
1) Failure:
|
101
|
+
FakeNamedTestXX#test_this_is_not_ascii_assertion [FILE:LINE]:
|
102
|
+
Expected: "ЁЁЁ"
|
103
|
+
Actual: "ёёё"
|
104
|
+
|
105
|
+
2) Error:
|
103
106
|
FakeNamedTestXX#test_this_is_non_ascii_failure_message:
|
104
107
|
RuntimeError: ЁЁЁ
|
105
|
-
FILE:LINE:in
|
106
|
-
|
107
|
-
2) Failure:
|
108
|
-
FakeNamedTestXX#test_this_is_not_ascii_assertion [FILE:LINE]:
|
109
|
-
Expected: \"ЁЁЁ\"
|
110
|
-
Actual: \"ёёё\"
|
108
|
+
FILE:LINE:in 'test_this_is_non_ascii_failure_message'
|
111
109
|
|
112
110
|
2 runs, 1 assertions, 1 failures, 1 errors, 0 skips
|
113
111
|
EOM
|
114
112
|
|
115
|
-
|
113
|
+
Minitest::Test.io_lock.synchronize do # try not to trounce in parallel
|
114
|
+
assert_report expected
|
115
|
+
end
|
116
116
|
end
|
117
117
|
|
118
118
|
def test_passed_eh_teardown_good
|
@@ -157,12 +157,26 @@ class TestMinitestUnit < MetaMetaMetaTestCase
|
|
157
157
|
refute_predicate test, :skipped?
|
158
158
|
end
|
159
159
|
|
160
|
-
def
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
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
|
165
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
|
+
|
178
|
+
def util_expand_bt bt
|
179
|
+
bt.map { |f| f.start_with?(".") ? File.expand_path(f) : f }
|
166
180
|
end
|
167
181
|
end
|
168
182
|
|
@@ -206,15 +220,14 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
206
220
|
def test_class_runnables
|
207
221
|
@assertion_count = 0
|
208
222
|
|
209
|
-
tc = Class.new
|
223
|
+
tc = Class.new Minitest::Test
|
210
224
|
|
211
225
|
assert_equal 1, Minitest::Test.runnables.size
|
212
226
|
assert_equal [tc], Minitest::Test.runnables
|
213
227
|
end
|
214
228
|
|
215
229
|
def test_run_test
|
216
|
-
@tu =
|
217
|
-
Class.new FakeNamedTest do
|
230
|
+
@tu = Class.new FakeNamedTest do
|
218
231
|
attr_reader :foo
|
219
232
|
|
220
233
|
def run
|
@@ -230,7 +243,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
230
243
|
end
|
231
244
|
end
|
232
245
|
|
233
|
-
expected =
|
246
|
+
expected = <<~EOM
|
234
247
|
.
|
235
248
|
|
236
249
|
Finished in 0.00
|
@@ -242,8 +255,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
242
255
|
end
|
243
256
|
|
244
257
|
def test_run_error
|
245
|
-
@tu =
|
246
|
-
Class.new FakeNamedTest do
|
258
|
+
@tu = Class.new FakeNamedTest do
|
247
259
|
def test_something
|
248
260
|
assert true
|
249
261
|
end
|
@@ -253,15 +265,15 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
253
265
|
end
|
254
266
|
end
|
255
267
|
|
256
|
-
expected =
|
257
|
-
E
|
268
|
+
expected = <<~EOM
|
269
|
+
.E
|
258
270
|
|
259
271
|
Finished in 0.00
|
260
272
|
|
261
273
|
1) Error:
|
262
274
|
FakeNamedTestXX#test_error:
|
263
275
|
RuntimeError: unhandled exception
|
264
|
-
FILE:LINE:in
|
276
|
+
FILE:LINE:in 'test_error'
|
265
277
|
|
266
278
|
2 runs, 1 assertions, 0 failures, 1 errors, 0 skips
|
267
279
|
EOM
|
@@ -270,8 +282,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
270
282
|
end
|
271
283
|
|
272
284
|
def test_run_error_teardown
|
273
|
-
@tu =
|
274
|
-
Class.new FakeNamedTest do
|
285
|
+
@tu = Class.new FakeNamedTest do
|
275
286
|
def test_something
|
276
287
|
assert true
|
277
288
|
end
|
@@ -281,7 +292,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
281
292
|
end
|
282
293
|
end
|
283
294
|
|
284
|
-
expected =
|
295
|
+
expected = <<~EOM
|
285
296
|
E
|
286
297
|
|
287
298
|
Finished in 0.00
|
@@ -289,7 +300,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
289
300
|
1) Error:
|
290
301
|
FakeNamedTestXX#test_something:
|
291
302
|
RuntimeError: unhandled exception
|
292
|
-
FILE:LINE:in
|
303
|
+
FILE:LINE:in 'teardown'
|
293
304
|
|
294
305
|
1 runs, 1 assertions, 0 failures, 1 errors, 0 skips
|
295
306
|
EOM
|
@@ -300,8 +311,8 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
300
311
|
def test_run_failing
|
301
312
|
setup_basic_tu
|
302
313
|
|
303
|
-
expected =
|
304
|
-
F
|
314
|
+
expected = <<~EOM
|
315
|
+
.F
|
305
316
|
|
306
317
|
Finished in 0.00
|
307
318
|
|
@@ -316,8 +327,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
316
327
|
end
|
317
328
|
|
318
329
|
def setup_basic_tu
|
319
|
-
@tu =
|
320
|
-
Class.new FakeNamedTest do
|
330
|
+
@tu = Class.new FakeNamedTest do
|
321
331
|
def test_something
|
322
332
|
assert true
|
323
333
|
end
|
@@ -328,10 +338,14 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
328
338
|
end
|
329
339
|
end
|
330
340
|
|
341
|
+
def test_seed # this is set for THIS run, so I'm not testing it's actual value
|
342
|
+
assert_instance_of Integer, Minitest.seed
|
343
|
+
end
|
344
|
+
|
331
345
|
def test_run_failing_filtered
|
332
346
|
setup_basic_tu
|
333
347
|
|
334
|
-
expected =
|
348
|
+
expected = <<~EOM
|
335
349
|
.
|
336
350
|
|
337
351
|
Finished in 0.00
|
@@ -350,14 +364,14 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
350
364
|
assert a
|
351
365
|
end
|
352
366
|
end
|
353
|
-
Object.const_set
|
367
|
+
Object.const_set :Alpha, alpha
|
354
368
|
|
355
369
|
beta = Class.new FakeNamedTest do
|
356
370
|
define_method :test_something do
|
357
371
|
assert true
|
358
372
|
end
|
359
373
|
end
|
360
|
-
Object.const_set
|
374
|
+
Object.const_set :Beta, beta
|
361
375
|
|
362
376
|
@tus = [alpha, beta]
|
363
377
|
|
@@ -368,7 +382,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
368
382
|
end
|
369
383
|
|
370
384
|
def test_run_filtered_including_suite_name
|
371
|
-
expected =
|
385
|
+
expected = <<~EOM
|
372
386
|
.
|
373
387
|
|
374
388
|
Finished in 0.00
|
@@ -380,7 +394,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
380
394
|
end
|
381
395
|
|
382
396
|
def test_run_filtered_including_suite_name_string
|
383
|
-
expected =
|
397
|
+
expected = <<~EOM
|
384
398
|
.
|
385
399
|
|
386
400
|
Finished in 0.00
|
@@ -392,7 +406,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
392
406
|
end
|
393
407
|
|
394
408
|
def test_run_filtered_string_method_only
|
395
|
-
expected =
|
409
|
+
expected = <<~EOM
|
396
410
|
..
|
397
411
|
|
398
412
|
Finished in 0.00
|
@@ -406,7 +420,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
406
420
|
def test_run_failing_excluded
|
407
421
|
setup_basic_tu
|
408
422
|
|
409
|
-
expected =
|
423
|
+
expected = <<~EOM
|
410
424
|
.
|
411
425
|
|
412
426
|
Finished in 0.00
|
@@ -418,7 +432,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
418
432
|
end
|
419
433
|
|
420
434
|
def test_run_filtered_excluding_suite_name
|
421
|
-
expected =
|
435
|
+
expected = <<~EOM
|
422
436
|
.
|
423
437
|
|
424
438
|
Finished in 0.00
|
@@ -430,7 +444,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
430
444
|
end
|
431
445
|
|
432
446
|
def test_run_filtered_excluding_suite_name_string
|
433
|
-
expected =
|
447
|
+
expected = <<~EOM
|
434
448
|
.
|
435
449
|
|
436
450
|
Finished in 0.00
|
@@ -442,7 +456,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
442
456
|
end
|
443
457
|
|
444
458
|
def test_run_filtered_excluding_string_method_only
|
445
|
-
expected =
|
459
|
+
expected = <<~EOM
|
446
460
|
|
447
461
|
|
448
462
|
Finished in 0.00
|
@@ -454,14 +468,13 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
454
468
|
end
|
455
469
|
|
456
470
|
def test_run_passing
|
457
|
-
@tu =
|
458
|
-
Class.new FakeNamedTest do
|
471
|
+
@tu = Class.new FakeNamedTest do
|
459
472
|
def test_something
|
460
473
|
assert true
|
461
474
|
end
|
462
475
|
end
|
463
476
|
|
464
|
-
expected =
|
477
|
+
expected = <<~EOM
|
465
478
|
.
|
466
479
|
|
467
480
|
Finished in 0.00
|
@@ -473,8 +486,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
473
486
|
end
|
474
487
|
|
475
488
|
def test_run_skip
|
476
|
-
@tu =
|
477
|
-
Class.new FakeNamedTest do
|
489
|
+
@tu = Class.new FakeNamedTest do
|
478
490
|
def test_something
|
479
491
|
assert true
|
480
492
|
end
|
@@ -484,8 +496,8 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
484
496
|
end
|
485
497
|
end
|
486
498
|
|
487
|
-
expected =
|
488
|
-
S
|
499
|
+
expected = <<~EOM
|
500
|
+
.S
|
489
501
|
|
490
502
|
Finished in 0.00
|
491
503
|
|
@@ -500,8 +512,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
500
512
|
end
|
501
513
|
|
502
514
|
def test_run_skip_verbose
|
503
|
-
@tu =
|
504
|
-
Class.new FakeNamedTest do
|
515
|
+
@tu = Class.new FakeNamedTest do
|
505
516
|
def test_something
|
506
517
|
assert true
|
507
518
|
end
|
@@ -511,9 +522,9 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
511
522
|
end
|
512
523
|
end
|
513
524
|
|
514
|
-
expected =
|
515
|
-
FakeNamedTestXX#test_skip = 0.00 s = S
|
525
|
+
expected = <<~EOM
|
516
526
|
FakeNamedTestXX#test_something = 0.00 s = .
|
527
|
+
FakeNamedTestXX#test_skip = 0.00 s = S
|
517
528
|
|
518
529
|
Finished in 0.00
|
519
530
|
|
@@ -527,9 +538,34 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
527
538
|
assert_report expected, %w[--seed 42 --verbose]
|
528
539
|
end
|
529
540
|
|
541
|
+
def test_run_skip_show_skips
|
542
|
+
@tu = Class.new FakeNamedTest do
|
543
|
+
def test_something
|
544
|
+
assert true
|
545
|
+
end
|
546
|
+
|
547
|
+
def test_skip
|
548
|
+
skip "not yet"
|
549
|
+
end
|
550
|
+
end
|
551
|
+
|
552
|
+
expected = <<~EOM
|
553
|
+
.S
|
554
|
+
|
555
|
+
Finished in 0.00
|
556
|
+
|
557
|
+
1) Skipped:
|
558
|
+
FakeNamedTestXX#test_skip [FILE:LINE]:
|
559
|
+
not yet
|
560
|
+
|
561
|
+
2 runs, 1 assertions, 0 failures, 0 errors, 1 skips
|
562
|
+
EOM
|
563
|
+
|
564
|
+
assert_report expected, %w[--seed 42 --show-skips]
|
565
|
+
end
|
566
|
+
|
530
567
|
def test_run_with_other_runner
|
531
|
-
@tu =
|
532
|
-
Class.new FakeNamedTest do
|
568
|
+
@tu = Class.new FakeNamedTest do
|
533
569
|
def self.run reporter, options = {}
|
534
570
|
@reporter = reporter
|
535
571
|
before_my_suite
|
@@ -552,7 +588,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
552
588
|
end
|
553
589
|
end
|
554
590
|
|
555
|
-
expected =
|
591
|
+
expected = <<~EOM
|
556
592
|
Running wacky! tests
|
557
593
|
..
|
558
594
|
|
@@ -601,8 +637,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
601
637
|
main_latch.release
|
602
638
|
}
|
603
639
|
|
604
|
-
@tu =
|
605
|
-
Class.new FakeNamedTest do
|
640
|
+
@tu = Class.new FakeNamedTest do
|
606
641
|
parallelize_me!
|
607
642
|
|
608
643
|
test_count.times do |i|
|
@@ -619,7 +654,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
619
654
|
end
|
620
655
|
end
|
621
656
|
|
622
|
-
expected =
|
657
|
+
expected = <<~EOM
|
623
658
|
..
|
624
659
|
|
625
660
|
Finished in 0.00
|
@@ -627,18 +662,20 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
627
662
|
2 runs, 2 assertions, 0 failures, 0 errors, 0 skips
|
628
663
|
EOM
|
629
664
|
|
630
|
-
|
631
|
-
|
632
|
-
|
665
|
+
skip if Minitest.parallel_executor.size < 2 # locks up test runner if 1 CPU
|
666
|
+
|
667
|
+
assert_report expected do |reporter|
|
668
|
+
reporter.extend Module.new {
|
669
|
+
define_method :record do |result|
|
633
670
|
super(result)
|
634
671
|
wait_latch.release
|
635
672
|
end
|
636
673
|
|
637
|
-
define_method
|
674
|
+
define_method :report do
|
638
675
|
wait_latch.await
|
639
676
|
super()
|
640
677
|
end
|
641
|
-
}
|
678
|
+
}
|
642
679
|
end
|
643
680
|
assert thread.join
|
644
681
|
end
|
@@ -649,8 +686,8 @@ class TestMinitestUnitOrder < MetaMetaMetaTestCase
|
|
649
686
|
|
650
687
|
def test_before_setup
|
651
688
|
call_order = []
|
652
|
-
|
653
|
-
Class.new FakeNamedTest do
|
689
|
+
|
690
|
+
@tu = Class.new FakeNamedTest do
|
654
691
|
define_method :setup do
|
655
692
|
super()
|
656
693
|
call_order << :setup
|
@@ -665,14 +702,13 @@ class TestMinitestUnitOrder < MetaMetaMetaTestCase
|
|
665
702
|
|
666
703
|
run_tu_with_fresh_reporter
|
667
704
|
|
668
|
-
expected = [
|
705
|
+
expected = %i[before_setup setup]
|
669
706
|
assert_equal expected, call_order
|
670
707
|
end
|
671
708
|
|
672
709
|
def test_after_teardown
|
673
710
|
call_order = []
|
674
|
-
@tu =
|
675
|
-
Class.new FakeNamedTest do
|
711
|
+
@tu = Class.new FakeNamedTest do
|
676
712
|
define_method :teardown do
|
677
713
|
super()
|
678
714
|
call_order << :teardown
|
@@ -687,14 +723,14 @@ class TestMinitestUnitOrder < MetaMetaMetaTestCase
|
|
687
723
|
|
688
724
|
run_tu_with_fresh_reporter
|
689
725
|
|
690
|
-
expected = [
|
726
|
+
expected = %i[teardown after_teardown]
|
691
727
|
assert_equal expected, call_order
|
692
728
|
end
|
693
729
|
|
694
730
|
def test_all_teardowns_are_guaranteed_to_run
|
695
731
|
call_order = []
|
696
|
-
|
697
|
-
Class.new FakeNamedTest do
|
732
|
+
|
733
|
+
@tu = Class.new FakeNamedTest do
|
698
734
|
define_method :after_teardown do
|
699
735
|
super()
|
700
736
|
call_order << :after_teardown
|
@@ -718,7 +754,7 @@ class TestMinitestUnitOrder < MetaMetaMetaTestCase
|
|
718
754
|
|
719
755
|
run_tu_with_fresh_reporter
|
720
756
|
|
721
|
-
expected = [
|
757
|
+
expected = %i[before_teardown teardown after_teardown]
|
722
758
|
assert_equal expected, call_order
|
723
759
|
end
|
724
760
|
|
@@ -745,12 +781,19 @@ class TestMinitestUnitOrder < MetaMetaMetaTestCase
|
|
745
781
|
run_tu_with_fresh_reporter
|
746
782
|
|
747
783
|
# Once for the parent class, once for the child
|
748
|
-
expected = [
|
784
|
+
expected = %i[setup_method test teardown_method] * 2
|
749
785
|
|
750
786
|
assert_equal expected, call_order
|
751
787
|
end
|
752
788
|
end
|
753
789
|
|
790
|
+
class BetterError < RuntimeError # like better_error w/o infecting RuntimeError
|
791
|
+
def set_backtrace bt
|
792
|
+
super
|
793
|
+
@bad_ivar = binding
|
794
|
+
end
|
795
|
+
end
|
796
|
+
|
754
797
|
class TestMinitestRunnable < Minitest::Test
|
755
798
|
def setup_marshal klass
|
756
799
|
tc = klass.new "whatever"
|
@@ -771,6 +814,7 @@ class TestMinitestRunnable < Minitest::Test
|
|
771
814
|
new_tc = Marshal.load Marshal.dump @tc
|
772
815
|
|
773
816
|
ivars = new_tc.instance_variables.map(&:to_s).sort
|
817
|
+
ivars.delete "@gc_stats" # only needed if running w/ minitest-gcstats
|
774
818
|
assert_equal expected_ivars, ivars
|
775
819
|
assert_equal "whatever", new_tc.name
|
776
820
|
assert_equal 42, new_tc.assertions
|
@@ -803,6 +847,145 @@ class TestMinitestRunnable < Minitest::Test
|
|
803
847
|
assert_equal @tc.failures, over_the_wire.failures
|
804
848
|
assert_equal @tc.klass, over_the_wire.klass
|
805
849
|
end
|
850
|
+
|
851
|
+
def test_spec_marshal_with_exception
|
852
|
+
klass = describe("whatever") {
|
853
|
+
it("raises, badly") {
|
854
|
+
raise Class.new(StandardError), "this is bad!"
|
855
|
+
}
|
856
|
+
}
|
857
|
+
|
858
|
+
rm = klass.runnable_methods.first
|
859
|
+
|
860
|
+
# Run the test
|
861
|
+
@tc = klass.new(rm).run
|
862
|
+
|
863
|
+
assert_kind_of Minitest::Result, @tc
|
864
|
+
assert_instance_of Minitest::UnexpectedError, @tc.failure
|
865
|
+
|
866
|
+
msg = @tc.failure.error.message
|
867
|
+
assert_includes msg, "Neutered Exception #<Class:"
|
868
|
+
assert_includes msg, "this is bad!"
|
869
|
+
|
870
|
+
# Pass it over the wire
|
871
|
+
over_the_wire = Marshal.load Marshal.dump @tc
|
872
|
+
|
873
|
+
assert_equal @tc.time, over_the_wire.time
|
874
|
+
assert_equal @tc.name, over_the_wire.name
|
875
|
+
assert_equal @tc.assertions, over_the_wire.assertions
|
876
|
+
assert_equal @tc.failures, over_the_wire.failures
|
877
|
+
assert_equal @tc.klass, over_the_wire.klass
|
878
|
+
end
|
879
|
+
|
880
|
+
def test_spec_marshal_with_exception_nameerror
|
881
|
+
klass = describe "whatever" do
|
882
|
+
it "raises NameError" do
|
883
|
+
NOPE::does_not_exist
|
884
|
+
end
|
885
|
+
end
|
886
|
+
|
887
|
+
rm = klass.runnable_methods.first
|
888
|
+
|
889
|
+
# Run the test
|
890
|
+
@tc = klass.new(rm).run
|
891
|
+
|
892
|
+
assert_kind_of Minitest::Result, @tc
|
893
|
+
assert_instance_of Minitest::UnexpectedError, @tc.failure
|
894
|
+
|
895
|
+
msg = @tc.failure.error.message
|
896
|
+
assert_includes msg, "uninitialized constant TestMinitestRunnable::NOPE"
|
897
|
+
|
898
|
+
# Pass it over the wire
|
899
|
+
over_the_wire = Marshal.load Marshal.dump @tc
|
900
|
+
|
901
|
+
assert_equal @tc.time, over_the_wire.time
|
902
|
+
assert_equal @tc.name, over_the_wire.name
|
903
|
+
assert_equal @tc.assertions, over_the_wire.assertions
|
904
|
+
assert_equal @tc.failures, over_the_wire.failures
|
905
|
+
assert_equal @tc.klass, over_the_wire.klass
|
906
|
+
end
|
907
|
+
|
908
|
+
def with_runtime_error klass
|
909
|
+
old_runtime = RuntimeError
|
910
|
+
Object.send :remove_const, :RuntimeError
|
911
|
+
Object.const_set :RuntimeError, klass
|
912
|
+
yield
|
913
|
+
ensure
|
914
|
+
Object.send :remove_const, :RuntimeError
|
915
|
+
Object.const_set :RuntimeError, old_runtime
|
916
|
+
end
|
917
|
+
|
918
|
+
def test_spec_marshal_with_exception__better_error_typeerror
|
919
|
+
klass = describe("whatever") {
|
920
|
+
it("raises with binding") {
|
921
|
+
raise BetterError, "boom"
|
922
|
+
}
|
923
|
+
}
|
924
|
+
|
925
|
+
rm = klass.runnable_methods.first
|
926
|
+
|
927
|
+
# Run the test
|
928
|
+
@tc = with_runtime_error BetterError do
|
929
|
+
klass.new(rm).run
|
930
|
+
end
|
931
|
+
|
932
|
+
assert_kind_of Minitest::Result, @tc
|
933
|
+
assert_instance_of Minitest::UnexpectedError, @tc.failure
|
934
|
+
|
935
|
+
msg = @tc.failure.error.message
|
936
|
+
assert_equal "Neutered Exception BetterError: boom", msg
|
937
|
+
|
938
|
+
# Pass it over the wire
|
939
|
+
over_the_wire = Marshal.load Marshal.dump @tc
|
940
|
+
|
941
|
+
assert_equal @tc.time, over_the_wire.time
|
942
|
+
assert_equal @tc.name, over_the_wire.name
|
943
|
+
assert_equal @tc.assertions, over_the_wire.assertions
|
944
|
+
assert_equal @tc.failures, over_the_wire.failures
|
945
|
+
assert_equal @tc.klass, over_the_wire.klass
|
946
|
+
end
|
947
|
+
|
948
|
+
def test_spec_marshal_with_exception__worse_error_typeerror
|
949
|
+
worse_error_klass = Class.new StandardError do
|
950
|
+
# problem #1: anonymous subclass can't marshal, fails sanitize_exception
|
951
|
+
def initialize record = nil
|
952
|
+
super(record.first)
|
953
|
+
end
|
954
|
+
end
|
955
|
+
|
956
|
+
klass = describe("whatever") {
|
957
|
+
it("raises with NoMethodError") {
|
958
|
+
# problem #2: instantiated with a NON-string argument
|
959
|
+
#
|
960
|
+
# problem #3: arg responds to #first, but it becomes message
|
961
|
+
# which gets passed back in via new_exception
|
962
|
+
# that passes a string to worse_error_klass#initialize
|
963
|
+
# which calls first on it, which raises NoMethodError
|
964
|
+
raise worse_error_klass.new(["boom"])
|
965
|
+
}
|
966
|
+
}
|
967
|
+
|
968
|
+
rm = klass.runnable_methods.first
|
969
|
+
|
970
|
+
# Run the test
|
971
|
+
@tc = klass.new(rm).run
|
972
|
+
|
973
|
+
assert_kind_of Minitest::Result, @tc
|
974
|
+
assert_instance_of Minitest::UnexpectedError, @tc.failure
|
975
|
+
|
976
|
+
msg = @tc.failure.error.message.gsub(/0x[A-Fa-f0-9]+/, "0xXXX")
|
977
|
+
|
978
|
+
assert_equal "Neutered Exception #<Class:0xXXX>: boom", msg
|
979
|
+
|
980
|
+
# Pass it over the wire
|
981
|
+
over_the_wire = Marshal.load Marshal.dump @tc
|
982
|
+
|
983
|
+
assert_equal @tc.time, over_the_wire.time
|
984
|
+
assert_equal @tc.name, over_the_wire.name
|
985
|
+
assert_equal @tc.assertions, over_the_wire.assertions
|
986
|
+
assert_equal @tc.failures, over_the_wire.failures
|
987
|
+
assert_equal @tc.klass, over_the_wire.klass
|
988
|
+
end
|
806
989
|
end
|
807
990
|
|
808
991
|
class TestMinitestTest < TestMinitestRunnable
|
@@ -822,8 +1005,6 @@ class TestMinitestUnitTestCase < Minitest::Test
|
|
822
1005
|
# which is not threadsafe. Nearly every method in here is an
|
823
1006
|
# assertion test so it isn't worth splitting it out further.
|
824
1007
|
|
825
|
-
RUBY18 = !defined? Encoding
|
826
|
-
|
827
1008
|
def setup
|
828
1009
|
super
|
829
1010
|
|
@@ -848,19 +1029,25 @@ class TestMinitestUnitTestCase < Minitest::Test
|
|
848
1029
|
$VERBOSE = orig_verbose
|
849
1030
|
end
|
850
1031
|
|
1032
|
+
def sample_test_case rand
|
1033
|
+
srand rand
|
1034
|
+
Class.new FakeNamedTest do
|
1035
|
+
100.times do |i|
|
1036
|
+
define_method("test_#{i}") { assert true }
|
1037
|
+
end
|
1038
|
+
end.runnable_methods
|
1039
|
+
end
|
1040
|
+
|
1041
|
+
# srand varies with OS
|
851
1042
|
def test_runnable_methods_random
|
852
1043
|
@assertion_count = 0
|
853
1044
|
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
def test_test2; assert "does not matter" end
|
858
|
-
def test_test3; assert "does not matter" end
|
859
|
-
end
|
1045
|
+
random_tests_1 = sample_test_case 42
|
1046
|
+
random_tests_2 = sample_test_case 42
|
1047
|
+
random_tests_3 = sample_test_case 1_000
|
860
1048
|
|
861
|
-
|
862
|
-
|
863
|
-
assert_equal expected, sample_test_case.runnable_methods
|
1049
|
+
assert_equal random_tests_1, random_tests_2
|
1050
|
+
assert_equal random_tests_1, random_tests_3
|
864
1051
|
end
|
865
1052
|
|
866
1053
|
def test_runnable_methods_sorted
|
@@ -901,17 +1088,27 @@ class TestMinitestUnitTestCase < Minitest::Test
|
|
901
1088
|
|
902
1089
|
def test_autorun_does_not_affect_fork_success_status
|
903
1090
|
@assertion_count = 0
|
904
|
-
skip "windows doesn't have
|
1091
|
+
skip "windows doesn't have fork" unless Process.respond_to? :fork
|
905
1092
|
Process.waitpid(fork {})
|
906
1093
|
assert_equal true, $?.success?
|
907
1094
|
end
|
908
1095
|
|
909
1096
|
def test_autorun_does_not_affect_fork_exit_status
|
910
1097
|
@assertion_count = 0
|
911
|
-
skip "windows doesn't have
|
1098
|
+
skip "windows doesn't have fork" unless Process.respond_to? :fork
|
912
1099
|
Process.waitpid(fork { exit 42 })
|
913
1100
|
assert_equal 42, $?.exitstatus
|
914
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
|
915
1112
|
end
|
916
1113
|
|
917
1114
|
class TestMinitestGuard < Minitest::Test
|
@@ -928,19 +1125,19 @@ class TestMinitestGuard < Minitest::Test
|
|
928
1125
|
end
|
929
1126
|
|
930
1127
|
def test_rubinius_eh
|
931
|
-
|
1128
|
+
assert_deprecation do
|
932
1129
|
assert self.class.rubinius? "rbx"
|
933
1130
|
end
|
934
|
-
|
1131
|
+
assert_deprecation do
|
935
1132
|
assert self.rubinius? "rbx"
|
936
1133
|
end
|
937
1134
|
end
|
938
1135
|
|
939
1136
|
def test_maglev_eh
|
940
|
-
|
1137
|
+
assert_deprecation do
|
941
1138
|
assert self.class.maglev? "maglev"
|
942
1139
|
end
|
943
|
-
|
1140
|
+
assert_deprecation do
|
944
1141
|
assert self.maglev? "maglev"
|
945
1142
|
end
|
946
1143
|
end
|
@@ -981,7 +1178,7 @@ class TestMinitestUnitRecording < MetaMetaMetaTestCase
|
|
981
1178
|
bogus_reporter = Class.new do # doesn't subclass AbstractReporter
|
982
1179
|
def start; @success = false; end
|
983
1180
|
# def prerecord klass, name; end # doesn't define full API
|
984
|
-
def record
|
1181
|
+
def record _result; @success = true; end
|
985
1182
|
def report; end
|
986
1183
|
def passed?; end
|
987
1184
|
def results; end
|
@@ -1059,17 +1256,17 @@ class TestMinitestUnitRecording < MetaMetaMetaTestCase
|
|
1059
1256
|
|
1060
1257
|
run_tu_with_fresh_reporter
|
1061
1258
|
|
1062
|
-
exp =
|
1259
|
+
exp = <<~EOM
|
1063
1260
|
Error:
|
1064
1261
|
FakeNamedTestXX#test_method:
|
1065
1262
|
AnError: AnError
|
1066
|
-
FILE:LINE:in
|
1263
|
+
FILE:LINE:in 'test_method'
|
1067
1264
|
|
1068
1265
|
Error:
|
1069
1266
|
FakeNamedTestXX#test_method:
|
1070
1267
|
RuntimeError: unhandled exception
|
1071
|
-
FILE:LINE:in
|
1072
|
-
|
1268
|
+
FILE:LINE:in 'teardown'
|
1269
|
+
EOM
|
1073
1270
|
|
1074
1271
|
assert_equal exp.strip, normalize_output(first_reporter.results.first.to_s).strip
|
1075
1272
|
end
|
@@ -1082,3 +1279,96 @@ class TestMinitestUnitRecording < MetaMetaMetaTestCase
|
|
1082
1279
|
end
|
1083
1280
|
end
|
1084
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
|