minitest 5.11.3 → 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 +384 -4
- data/Manifest.txt +6 -0
- data/README.rdoc +113 -17
- data/Rakefile +11 -16
- data/lib/hoe/minitest.rb +2 -5
- data/lib/minitest/assertions.rb +255 -93
- data/lib/minitest/autorun.rb +0 -7
- data/lib/minitest/benchmark.rb +13 -16
- data/lib/minitest/compress.rb +94 -0
- data/lib/minitest/error_on_warning.rb +11 -0
- data/lib/minitest/expectations.rb +72 -35
- data/lib/minitest/manual_plugins.rb +16 -0
- data/lib/minitest/mock.rb +151 -44
- data/lib/minitest/parallel.rb +5 -5
- data/lib/minitest/pride_plugin.rb +17 -24
- data/lib/minitest/spec.rb +38 -19
- 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 +414 -166
- data/test/minitest/metametameta.rb +65 -17
- data/test/minitest/test_minitest_assertions.rb +1720 -0
- data/test/minitest/test_minitest_benchmark.rb +3 -3
- data/test/minitest/test_minitest_mock.rb +409 -65
- data/test/minitest/test_minitest_reporter.rb +169 -32
- data/test/minitest/test_minitest_spec.rb +369 -193
- data/test/minitest/test_minitest_test.rb +479 -1247
- data/test/minitest/test_minitest_test_task.rb +57 -0
- data.tar.gz.sig +0 -0
- metadata +37 -23
- metadata.gz.sig +0 -0
|
@@ -1,26 +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
|
-
module MyModule; end
|
|
19
|
-
class AnError < StandardError; include MyModule; end
|
|
20
|
-
class ImmutableString < String; def inspect; super.freeze; end; end
|
|
21
|
-
SomeError = Class.new Exception
|
|
22
|
-
|
|
23
13
|
class Minitest::Runnable
|
|
14
|
+
attr_reader :gc_stats # only needed if running w/ minitest-gcstats
|
|
15
|
+
|
|
24
16
|
def whatever # faked for testing
|
|
25
17
|
assert true
|
|
26
18
|
end
|
|
@@ -29,46 +21,45 @@ end
|
|
|
29
21
|
class TestMinitestUnit < MetaMetaMetaTestCase
|
|
30
22
|
parallelize_me!
|
|
31
23
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"#{MINITEST_BASE_DIR}/test.rb:158:in `each'",
|
|
38
|
-
"#{MINITEST_BASE_DIR}/test.rb:139:in `run'",
|
|
39
|
-
"#{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'"]
|
|
40
29
|
|
|
41
30
|
def test_filter_backtrace
|
|
42
31
|
# this is a semi-lame mix of relative paths.
|
|
43
32
|
# I cheated by making the autotest parts not have ./
|
|
44
|
-
bt = (["lib/autotest.rb:571:in
|
|
45
|
-
"test/test_autotest.rb:62:in
|
|
46
|
-
"#{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__'"] +
|
|
47
36
|
BT_MIDDLE +
|
|
48
37
|
["#{MINITEST_BASE_DIR}/test.rb:29",
|
|
49
38
|
"test/test_autotest.rb:422"])
|
|
50
39
|
bt = util_expand_bt bt
|
|
51
40
|
|
|
52
|
-
ex = ["lib/autotest.rb:571:in
|
|
53
|
-
"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'"]
|
|
54
43
|
ex = util_expand_bt ex
|
|
55
44
|
|
|
56
|
-
|
|
45
|
+
Minitest::Test.io_lock.synchronize do # try not to trounce in parallel
|
|
46
|
+
fu = Minitest.filter_backtrace bt
|
|
57
47
|
|
|
58
|
-
|
|
48
|
+
assert_equal ex, fu
|
|
49
|
+
end
|
|
59
50
|
end
|
|
60
51
|
|
|
61
52
|
def test_filter_backtrace_all_unit
|
|
62
|
-
bt = (["#{MINITEST_BASE_DIR}/test.rb:165:in
|
|
53
|
+
bt = (["#{MINITEST_BASE_DIR}/test.rb:165:in '__send__'"] +
|
|
63
54
|
BT_MIDDLE +
|
|
64
55
|
["#{MINITEST_BASE_DIR}/test.rb:29"])
|
|
65
56
|
ex = bt.clone
|
|
66
|
-
fu = Minitest.filter_backtrace
|
|
57
|
+
fu = Minitest.filter_backtrace bt
|
|
67
58
|
assert_equal ex, fu
|
|
68
59
|
end
|
|
69
60
|
|
|
70
61
|
def test_filter_backtrace_unit_starts
|
|
71
|
-
bt = (["#{MINITEST_BASE_DIR}/test.rb:165:in
|
|
62
|
+
bt = (["#{MINITEST_BASE_DIR}/test.rb:165:in '__send__'"] +
|
|
72
63
|
BT_MIDDLE +
|
|
73
64
|
["#{MINITEST_BASE_DIR}/mini/test.rb:29",
|
|
74
65
|
"-e:1"])
|
|
@@ -76,13 +67,19 @@ class TestMinitestUnit < MetaMetaMetaTestCase
|
|
|
76
67
|
bt = util_expand_bt bt
|
|
77
68
|
|
|
78
69
|
ex = ["-e:1"]
|
|
79
|
-
|
|
80
|
-
|
|
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
|
|
81
74
|
end
|
|
82
75
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
76
|
+
def test_filter_backtrace__empty
|
|
77
|
+
with_empty_backtrace_filter do
|
|
78
|
+
bt = %w[first second third]
|
|
79
|
+
fu = Minitest.filter_backtrace bt.dup
|
|
80
|
+
assert_equal bt, fu
|
|
81
|
+
end
|
|
82
|
+
end
|
|
86
83
|
|
|
87
84
|
def test_infectious_binary_encoding
|
|
88
85
|
@tu = Class.new FakeNamedTest do
|
|
@@ -91,29 +88,31 @@ class TestMinitestUnit < MetaMetaMetaTestCase
|
|
|
91
88
|
end
|
|
92
89
|
|
|
93
90
|
def test_this_is_non_ascii_failure_message
|
|
94
|
-
|
|
91
|
+
raise "ЁЁЁ".dup.force_encoding(Encoding::BINARY)
|
|
95
92
|
end
|
|
96
93
|
end
|
|
97
94
|
|
|
98
|
-
expected =
|
|
99
|
-
|
|
95
|
+
expected = <<~EOM
|
|
96
|
+
FE
|
|
100
97
|
|
|
101
98
|
Finished in 0.00
|
|
102
99
|
|
|
103
|
-
1)
|
|
100
|
+
1) Failure:
|
|
101
|
+
FakeNamedTestXX#test_this_is_not_ascii_assertion [FILE:LINE]:
|
|
102
|
+
Expected: "ЁЁЁ"
|
|
103
|
+
Actual: "ёёё"
|
|
104
|
+
|
|
105
|
+
2) Error:
|
|
104
106
|
FakeNamedTestXX#test_this_is_non_ascii_failure_message:
|
|
105
107
|
RuntimeError: ЁЁЁ
|
|
106
|
-
FILE:LINE:in
|
|
107
|
-
|
|
108
|
-
2) Failure:
|
|
109
|
-
FakeNamedTestXX#test_this_is_not_ascii_assertion [FILE:LINE]:
|
|
110
|
-
Expected: \"ЁЁЁ\"
|
|
111
|
-
Actual: \"ёёё\"
|
|
108
|
+
FILE:LINE:in 'test_this_is_non_ascii_failure_message'
|
|
112
109
|
|
|
113
110
|
2 runs, 1 assertions, 1 failures, 1 errors, 0 skips
|
|
114
111
|
EOM
|
|
115
112
|
|
|
116
|
-
|
|
113
|
+
Minitest::Test.io_lock.synchronize do # try not to trounce in parallel
|
|
114
|
+
assert_report expected
|
|
115
|
+
end
|
|
117
116
|
end
|
|
118
117
|
|
|
119
118
|
def test_passed_eh_teardown_good
|
|
@@ -158,12 +157,26 @@ class TestMinitestUnit < MetaMetaMetaTestCase
|
|
|
158
157
|
refute_predicate test, :skipped?
|
|
159
158
|
end
|
|
160
159
|
|
|
161
|
-
def
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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
|
|
166
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 }
|
|
167
180
|
end
|
|
168
181
|
end
|
|
169
182
|
|
|
@@ -207,15 +220,14 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
|
207
220
|
def test_class_runnables
|
|
208
221
|
@assertion_count = 0
|
|
209
222
|
|
|
210
|
-
tc = Class.new
|
|
223
|
+
tc = Class.new Minitest::Test
|
|
211
224
|
|
|
212
225
|
assert_equal 1, Minitest::Test.runnables.size
|
|
213
226
|
assert_equal [tc], Minitest::Test.runnables
|
|
214
227
|
end
|
|
215
228
|
|
|
216
229
|
def test_run_test
|
|
217
|
-
@tu =
|
|
218
|
-
Class.new FakeNamedTest do
|
|
230
|
+
@tu = Class.new FakeNamedTest do
|
|
219
231
|
attr_reader :foo
|
|
220
232
|
|
|
221
233
|
def run
|
|
@@ -231,7 +243,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
|
231
243
|
end
|
|
232
244
|
end
|
|
233
245
|
|
|
234
|
-
expected =
|
|
246
|
+
expected = <<~EOM
|
|
235
247
|
.
|
|
236
248
|
|
|
237
249
|
Finished in 0.00
|
|
@@ -243,8 +255,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
|
243
255
|
end
|
|
244
256
|
|
|
245
257
|
def test_run_error
|
|
246
|
-
@tu =
|
|
247
|
-
Class.new FakeNamedTest do
|
|
258
|
+
@tu = Class.new FakeNamedTest do
|
|
248
259
|
def test_something
|
|
249
260
|
assert true
|
|
250
261
|
end
|
|
@@ -254,15 +265,15 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
|
254
265
|
end
|
|
255
266
|
end
|
|
256
267
|
|
|
257
|
-
expected =
|
|
258
|
-
E
|
|
268
|
+
expected = <<~EOM
|
|
269
|
+
.E
|
|
259
270
|
|
|
260
271
|
Finished in 0.00
|
|
261
272
|
|
|
262
273
|
1) Error:
|
|
263
274
|
FakeNamedTestXX#test_error:
|
|
264
275
|
RuntimeError: unhandled exception
|
|
265
|
-
FILE:LINE:in
|
|
276
|
+
FILE:LINE:in 'test_error'
|
|
266
277
|
|
|
267
278
|
2 runs, 1 assertions, 0 failures, 1 errors, 0 skips
|
|
268
279
|
EOM
|
|
@@ -271,8 +282,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
|
271
282
|
end
|
|
272
283
|
|
|
273
284
|
def test_run_error_teardown
|
|
274
|
-
@tu =
|
|
275
|
-
Class.new FakeNamedTest do
|
|
285
|
+
@tu = Class.new FakeNamedTest do
|
|
276
286
|
def test_something
|
|
277
287
|
assert true
|
|
278
288
|
end
|
|
@@ -282,7 +292,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
|
282
292
|
end
|
|
283
293
|
end
|
|
284
294
|
|
|
285
|
-
expected =
|
|
295
|
+
expected = <<~EOM
|
|
286
296
|
E
|
|
287
297
|
|
|
288
298
|
Finished in 0.00
|
|
@@ -290,7 +300,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
|
290
300
|
1) Error:
|
|
291
301
|
FakeNamedTestXX#test_something:
|
|
292
302
|
RuntimeError: unhandled exception
|
|
293
|
-
FILE:LINE:in
|
|
303
|
+
FILE:LINE:in 'teardown'
|
|
294
304
|
|
|
295
305
|
1 runs, 1 assertions, 0 failures, 1 errors, 0 skips
|
|
296
306
|
EOM
|
|
@@ -301,8 +311,8 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
|
301
311
|
def test_run_failing
|
|
302
312
|
setup_basic_tu
|
|
303
313
|
|
|
304
|
-
expected =
|
|
305
|
-
F
|
|
314
|
+
expected = <<~EOM
|
|
315
|
+
.F
|
|
306
316
|
|
|
307
317
|
Finished in 0.00
|
|
308
318
|
|
|
@@ -317,8 +327,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
|
317
327
|
end
|
|
318
328
|
|
|
319
329
|
def setup_basic_tu
|
|
320
|
-
@tu =
|
|
321
|
-
Class.new FakeNamedTest do
|
|
330
|
+
@tu = Class.new FakeNamedTest do
|
|
322
331
|
def test_something
|
|
323
332
|
assert true
|
|
324
333
|
end
|
|
@@ -329,10 +338,14 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
|
329
338
|
end
|
|
330
339
|
end
|
|
331
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
|
+
|
|
332
345
|
def test_run_failing_filtered
|
|
333
346
|
setup_basic_tu
|
|
334
347
|
|
|
335
|
-
expected =
|
|
348
|
+
expected = <<~EOM
|
|
336
349
|
.
|
|
337
350
|
|
|
338
351
|
Finished in 0.00
|
|
@@ -351,14 +364,14 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
|
351
364
|
assert a
|
|
352
365
|
end
|
|
353
366
|
end
|
|
354
|
-
Object.const_set
|
|
367
|
+
Object.const_set :Alpha, alpha
|
|
355
368
|
|
|
356
369
|
beta = Class.new FakeNamedTest do
|
|
357
370
|
define_method :test_something do
|
|
358
371
|
assert true
|
|
359
372
|
end
|
|
360
373
|
end
|
|
361
|
-
Object.const_set
|
|
374
|
+
Object.const_set :Beta, beta
|
|
362
375
|
|
|
363
376
|
@tus = [alpha, beta]
|
|
364
377
|
|
|
@@ -369,7 +382,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
|
369
382
|
end
|
|
370
383
|
|
|
371
384
|
def test_run_filtered_including_suite_name
|
|
372
|
-
expected =
|
|
385
|
+
expected = <<~EOM
|
|
373
386
|
.
|
|
374
387
|
|
|
375
388
|
Finished in 0.00
|
|
@@ -381,7 +394,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
|
381
394
|
end
|
|
382
395
|
|
|
383
396
|
def test_run_filtered_including_suite_name_string
|
|
384
|
-
expected =
|
|
397
|
+
expected = <<~EOM
|
|
385
398
|
.
|
|
386
399
|
|
|
387
400
|
Finished in 0.00
|
|
@@ -393,7 +406,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
|
393
406
|
end
|
|
394
407
|
|
|
395
408
|
def test_run_filtered_string_method_only
|
|
396
|
-
expected =
|
|
409
|
+
expected = <<~EOM
|
|
397
410
|
..
|
|
398
411
|
|
|
399
412
|
Finished in 0.00
|
|
@@ -407,7 +420,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
|
407
420
|
def test_run_failing_excluded
|
|
408
421
|
setup_basic_tu
|
|
409
422
|
|
|
410
|
-
expected =
|
|
423
|
+
expected = <<~EOM
|
|
411
424
|
.
|
|
412
425
|
|
|
413
426
|
Finished in 0.00
|
|
@@ -419,7 +432,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
|
419
432
|
end
|
|
420
433
|
|
|
421
434
|
def test_run_filtered_excluding_suite_name
|
|
422
|
-
expected =
|
|
435
|
+
expected = <<~EOM
|
|
423
436
|
.
|
|
424
437
|
|
|
425
438
|
Finished in 0.00
|
|
@@ -431,7 +444,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
|
431
444
|
end
|
|
432
445
|
|
|
433
446
|
def test_run_filtered_excluding_suite_name_string
|
|
434
|
-
expected =
|
|
447
|
+
expected = <<~EOM
|
|
435
448
|
.
|
|
436
449
|
|
|
437
450
|
Finished in 0.00
|
|
@@ -443,7 +456,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
|
443
456
|
end
|
|
444
457
|
|
|
445
458
|
def test_run_filtered_excluding_string_method_only
|
|
446
|
-
expected =
|
|
459
|
+
expected = <<~EOM
|
|
447
460
|
|
|
448
461
|
|
|
449
462
|
Finished in 0.00
|
|
@@ -455,14 +468,13 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
|
455
468
|
end
|
|
456
469
|
|
|
457
470
|
def test_run_passing
|
|
458
|
-
@tu =
|
|
459
|
-
Class.new FakeNamedTest do
|
|
471
|
+
@tu = Class.new FakeNamedTest do
|
|
460
472
|
def test_something
|
|
461
473
|
assert true
|
|
462
474
|
end
|
|
463
475
|
end
|
|
464
476
|
|
|
465
|
-
expected =
|
|
477
|
+
expected = <<~EOM
|
|
466
478
|
.
|
|
467
479
|
|
|
468
480
|
Finished in 0.00
|
|
@@ -474,8 +486,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
|
474
486
|
end
|
|
475
487
|
|
|
476
488
|
def test_run_skip
|
|
477
|
-
@tu =
|
|
478
|
-
Class.new FakeNamedTest do
|
|
489
|
+
@tu = Class.new FakeNamedTest do
|
|
479
490
|
def test_something
|
|
480
491
|
assert true
|
|
481
492
|
end
|
|
@@ -485,8 +496,8 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
|
485
496
|
end
|
|
486
497
|
end
|
|
487
498
|
|
|
488
|
-
expected =
|
|
489
|
-
S
|
|
499
|
+
expected = <<~EOM
|
|
500
|
+
.S
|
|
490
501
|
|
|
491
502
|
Finished in 0.00
|
|
492
503
|
|
|
@@ -501,8 +512,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
|
501
512
|
end
|
|
502
513
|
|
|
503
514
|
def test_run_skip_verbose
|
|
504
|
-
@tu =
|
|
505
|
-
Class.new FakeNamedTest do
|
|
515
|
+
@tu = Class.new FakeNamedTest do
|
|
506
516
|
def test_something
|
|
507
517
|
assert true
|
|
508
518
|
end
|
|
@@ -512,9 +522,9 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
|
512
522
|
end
|
|
513
523
|
end
|
|
514
524
|
|
|
515
|
-
expected =
|
|
516
|
-
FakeNamedTestXX#test_skip = 0.00 s = S
|
|
525
|
+
expected = <<~EOM
|
|
517
526
|
FakeNamedTestXX#test_something = 0.00 s = .
|
|
527
|
+
FakeNamedTestXX#test_skip = 0.00 s = S
|
|
518
528
|
|
|
519
529
|
Finished in 0.00
|
|
520
530
|
|
|
@@ -528,9 +538,34 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
|
528
538
|
assert_report expected, %w[--seed 42 --verbose]
|
|
529
539
|
end
|
|
530
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
|
+
|
|
531
567
|
def test_run_with_other_runner
|
|
532
|
-
@tu =
|
|
533
|
-
Class.new FakeNamedTest do
|
|
568
|
+
@tu = Class.new FakeNamedTest do
|
|
534
569
|
def self.run reporter, options = {}
|
|
535
570
|
@reporter = reporter
|
|
536
571
|
before_my_suite
|
|
@@ -553,7 +588,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
|
553
588
|
end
|
|
554
589
|
end
|
|
555
590
|
|
|
556
|
-
expected =
|
|
591
|
+
expected = <<~EOM
|
|
557
592
|
Running wacky! tests
|
|
558
593
|
..
|
|
559
594
|
|
|
@@ -587,8 +622,6 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
|
587
622
|
end
|
|
588
623
|
|
|
589
624
|
def test_run_parallel
|
|
590
|
-
skip "I don't have ParallelEach debugged yet" if maglev?
|
|
591
|
-
|
|
592
625
|
test_count = 2
|
|
593
626
|
test_latch = Latch.new test_count
|
|
594
627
|
wait_latch = Latch.new test_count
|
|
@@ -604,8 +637,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
|
604
637
|
main_latch.release
|
|
605
638
|
}
|
|
606
639
|
|
|
607
|
-
@tu =
|
|
608
|
-
Class.new FakeNamedTest do
|
|
640
|
+
@tu = Class.new FakeNamedTest do
|
|
609
641
|
parallelize_me!
|
|
610
642
|
|
|
611
643
|
test_count.times do |i|
|
|
@@ -622,7 +654,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
|
622
654
|
end
|
|
623
655
|
end
|
|
624
656
|
|
|
625
|
-
expected =
|
|
657
|
+
expected = <<~EOM
|
|
626
658
|
..
|
|
627
659
|
|
|
628
660
|
Finished in 0.00
|
|
@@ -630,18 +662,20 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
|
630
662
|
2 runs, 2 assertions, 0 failures, 0 errors, 0 skips
|
|
631
663
|
EOM
|
|
632
664
|
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
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|
|
|
636
670
|
super(result)
|
|
637
671
|
wait_latch.release
|
|
638
672
|
end
|
|
639
673
|
|
|
640
|
-
define_method
|
|
674
|
+
define_method :report do
|
|
641
675
|
wait_latch.await
|
|
642
676
|
super()
|
|
643
677
|
end
|
|
644
|
-
}
|
|
678
|
+
}
|
|
645
679
|
end
|
|
646
680
|
assert thread.join
|
|
647
681
|
end
|
|
@@ -652,8 +686,8 @@ class TestMinitestUnitOrder < MetaMetaMetaTestCase
|
|
|
652
686
|
|
|
653
687
|
def test_before_setup
|
|
654
688
|
call_order = []
|
|
655
|
-
|
|
656
|
-
Class.new FakeNamedTest do
|
|
689
|
+
|
|
690
|
+
@tu = Class.new FakeNamedTest do
|
|
657
691
|
define_method :setup do
|
|
658
692
|
super()
|
|
659
693
|
call_order << :setup
|
|
@@ -668,14 +702,13 @@ class TestMinitestUnitOrder < MetaMetaMetaTestCase
|
|
|
668
702
|
|
|
669
703
|
run_tu_with_fresh_reporter
|
|
670
704
|
|
|
671
|
-
expected = [
|
|
705
|
+
expected = %i[before_setup setup]
|
|
672
706
|
assert_equal expected, call_order
|
|
673
707
|
end
|
|
674
708
|
|
|
675
709
|
def test_after_teardown
|
|
676
710
|
call_order = []
|
|
677
|
-
@tu =
|
|
678
|
-
Class.new FakeNamedTest do
|
|
711
|
+
@tu = Class.new FakeNamedTest do
|
|
679
712
|
define_method :teardown do
|
|
680
713
|
super()
|
|
681
714
|
call_order << :teardown
|
|
@@ -690,14 +723,14 @@ class TestMinitestUnitOrder < MetaMetaMetaTestCase
|
|
|
690
723
|
|
|
691
724
|
run_tu_with_fresh_reporter
|
|
692
725
|
|
|
693
|
-
expected = [
|
|
726
|
+
expected = %i[teardown after_teardown]
|
|
694
727
|
assert_equal expected, call_order
|
|
695
728
|
end
|
|
696
729
|
|
|
697
730
|
def test_all_teardowns_are_guaranteed_to_run
|
|
698
731
|
call_order = []
|
|
699
|
-
|
|
700
|
-
Class.new FakeNamedTest do
|
|
732
|
+
|
|
733
|
+
@tu = Class.new FakeNamedTest do
|
|
701
734
|
define_method :after_teardown do
|
|
702
735
|
super()
|
|
703
736
|
call_order << :after_teardown
|
|
@@ -721,7 +754,7 @@ class TestMinitestUnitOrder < MetaMetaMetaTestCase
|
|
|
721
754
|
|
|
722
755
|
run_tu_with_fresh_reporter
|
|
723
756
|
|
|
724
|
-
expected = [
|
|
757
|
+
expected = %i[before_teardown teardown after_teardown]
|
|
725
758
|
assert_equal expected, call_order
|
|
726
759
|
end
|
|
727
760
|
|
|
@@ -748,12 +781,19 @@ class TestMinitestUnitOrder < MetaMetaMetaTestCase
|
|
|
748
781
|
run_tu_with_fresh_reporter
|
|
749
782
|
|
|
750
783
|
# Once for the parent class, once for the child
|
|
751
|
-
expected = [
|
|
784
|
+
expected = %i[setup_method test teardown_method] * 2
|
|
752
785
|
|
|
753
786
|
assert_equal expected, call_order
|
|
754
787
|
end
|
|
755
788
|
end
|
|
756
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
|
+
|
|
757
797
|
class TestMinitestRunnable < Minitest::Test
|
|
758
798
|
def setup_marshal klass
|
|
759
799
|
tc = klass.new "whatever"
|
|
@@ -774,6 +814,7 @@ class TestMinitestRunnable < Minitest::Test
|
|
|
774
814
|
new_tc = Marshal.load Marshal.dump @tc
|
|
775
815
|
|
|
776
816
|
ivars = new_tc.instance_variables.map(&:to_s).sort
|
|
817
|
+
ivars.delete "@gc_stats" # only needed if running w/ minitest-gcstats
|
|
777
818
|
assert_equal expected_ivars, ivars
|
|
778
819
|
assert_equal "whatever", new_tc.name
|
|
779
820
|
assert_equal 42, new_tc.assertions
|
|
@@ -806,6 +847,145 @@ class TestMinitestRunnable < Minitest::Test
|
|
|
806
847
|
assert_equal @tc.failures, over_the_wire.failures
|
|
807
848
|
assert_equal @tc.klass, over_the_wire.klass
|
|
808
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
|
|
809
989
|
end
|
|
810
990
|
|
|
811
991
|
class TestMinitestTest < TestMinitestRunnable
|
|
@@ -825,8 +1005,6 @@ class TestMinitestUnitTestCase < Minitest::Test
|
|
|
825
1005
|
# which is not threadsafe. Nearly every method in here is an
|
|
826
1006
|
# assertion test so it isn't worth splitting it out further.
|
|
827
1007
|
|
|
828
|
-
RUBY18 = !defined? Encoding
|
|
829
|
-
|
|
830
1008
|
def setup
|
|
831
1009
|
super
|
|
832
1010
|
|
|
@@ -851,1168 +1029,129 @@ class TestMinitestUnitTestCase < Minitest::Test
|
|
|
851
1029
|
$VERBOSE = orig_verbose
|
|
852
1030
|
end
|
|
853
1031
|
|
|
854
|
-
def
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
assert_triggered "Expected false to be truthy." do
|
|
862
|
-
@tc.assert false
|
|
863
|
-
end
|
|
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
|
|
864
1039
|
end
|
|
865
1040
|
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
end
|
|
870
|
-
end
|
|
1041
|
+
# srand varies with OS
|
|
1042
|
+
def test_runnable_methods_random
|
|
1043
|
+
@assertion_count = 0
|
|
871
1044
|
|
|
872
|
-
|
|
873
|
-
|
|
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
|
|
874
1048
|
|
|
875
|
-
|
|
1049
|
+
assert_equal random_tests_1, random_tests_2
|
|
1050
|
+
assert_equal random_tests_1, random_tests_3
|
|
876
1051
|
end
|
|
877
1052
|
|
|
878
|
-
def
|
|
879
|
-
@assertion_count =
|
|
1053
|
+
def test_runnable_methods_sorted
|
|
1054
|
+
@assertion_count = 0
|
|
880
1055
|
|
|
881
|
-
|
|
882
|
-
|
|
1056
|
+
sample_test_case = Class.new FakeNamedTest do
|
|
1057
|
+
def self.test_order; :sorted end
|
|
1058
|
+
def test_test3; assert "does not matter" end
|
|
1059
|
+
def test_test2; assert "does not matter" end
|
|
1060
|
+
def test_test1; assert "does not matter" end
|
|
883
1061
|
end
|
|
884
|
-
end
|
|
885
1062
|
|
|
886
|
-
|
|
887
|
-
|
|
1063
|
+
expected = %w[test_test1 test_test2 test_test3]
|
|
1064
|
+
assert_equal expected, sample_test_case.runnable_methods
|
|
888
1065
|
end
|
|
889
1066
|
|
|
890
|
-
def
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
You should look at the implementation of #== on Array or its members.
|
|
895
|
-
[#<Object:0xXXXXXX>]".gsub(/^ +/, "")
|
|
896
|
-
assert_triggered msg do
|
|
897
|
-
@tc.assert_equal [object1], [object2]
|
|
898
|
-
end
|
|
899
|
-
end
|
|
1067
|
+
def test_i_suck_and_my_tests_are_order_dependent_bang_sets_test_order_alpha
|
|
1068
|
+
@assertion_count = 0
|
|
1069
|
+
|
|
1070
|
+
shitty_test_case = Class.new FakeNamedTest
|
|
900
1071
|
|
|
901
|
-
|
|
902
|
-
h1, h2 = {}, {}
|
|
903
|
-
h1[1] = Object.new
|
|
904
|
-
h2[1] = Object.new
|
|
905
|
-
msg = "No visible difference in the Hash#inspect output.
|
|
906
|
-
You should look at the implementation of #== on Hash or its members.
|
|
907
|
-
{1=>#<Object:0xXXXXXX>}".gsub(/^ +/, "")
|
|
1072
|
+
shitty_test_case.i_suck_and_my_tests_are_order_dependent!
|
|
908
1073
|
|
|
909
|
-
|
|
910
|
-
@tc.assert_equal h1, h2
|
|
911
|
-
end
|
|
1074
|
+
assert_equal :alpha, shitty_test_case.test_order
|
|
912
1075
|
end
|
|
913
1076
|
|
|
914
|
-
def
|
|
915
|
-
|
|
916
|
-
--- expected
|
|
917
|
-
+++ actual
|
|
918
|
-
@@ -1 +1,2 @@
|
|
919
|
-
+# encoding: ASCII-8BIT
|
|
920
|
-
"bad-utf8-\\xF1.txt"
|
|
921
|
-
EOM
|
|
922
|
-
|
|
923
|
-
assert_triggered msg do
|
|
924
|
-
x = "bad-utf8-\xF1.txt"
|
|
925
|
-
y = x.dup.force_encoding "binary" # TODO: switch to .b when 1.9 dropped
|
|
926
|
-
@tc.assert_equal x, y
|
|
927
|
-
end
|
|
928
|
-
end unless RUBY18
|
|
929
|
-
|
|
930
|
-
def test_assert_equal_string_encodings_both_different
|
|
931
|
-
msg = <<-EOM.gsub(/^ {10}/, "")
|
|
932
|
-
--- expected
|
|
933
|
-
+++ actual
|
|
934
|
-
@@ -1,2 +1,2 @@
|
|
935
|
-
-# encoding: US-ASCII
|
|
936
|
-
+# encoding: ASCII-8BIT
|
|
937
|
-
"bad-utf8-\\xF1.txt"
|
|
938
|
-
EOM
|
|
939
|
-
|
|
940
|
-
assert_triggered msg do
|
|
941
|
-
x = "bad-utf8-\xF1.txt".force_encoding "ASCII"
|
|
942
|
-
y = x.dup.force_encoding "binary" # TODO: switch to .b when 1.9 dropped
|
|
943
|
-
@tc.assert_equal x, y
|
|
944
|
-
end
|
|
945
|
-
end unless RUBY18
|
|
1077
|
+
def test_i_suck_and_my_tests_are_order_dependent_bang_does_not_warn
|
|
1078
|
+
@assertion_count = 0
|
|
946
1079
|
|
|
947
|
-
|
|
948
|
-
skip "https://github.com/MagLev/maglev/issues/209" if maglev?
|
|
1080
|
+
shitty_test_case = Class.new FakeNamedTest
|
|
949
1081
|
|
|
950
|
-
|
|
951
|
-
assert_triggered util_msg("haha" * 10, "blah" * 10) do
|
|
952
|
-
o1 = "haha" * 10
|
|
953
|
-
o2 = "blah" * 10
|
|
1082
|
+
def shitty_test_case.test_order; :lol end
|
|
954
1083
|
|
|
955
|
-
|
|
956
|
-
|
|
1084
|
+
assert_silent do
|
|
1085
|
+
shitty_test_case.i_suck_and_my_tests_are_order_dependent!
|
|
957
1086
|
end
|
|
958
1087
|
end
|
|
959
1088
|
|
|
960
|
-
def
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
o1 = c.new "a"
|
|
966
|
-
o2 = c.new "b"
|
|
967
|
-
msg = "--- expected
|
|
968
|
-
+++ actual
|
|
969
|
-
@@ -1 +1 @@
|
|
970
|
-
-#<#<Class:0xXXXXXX>:0xXXXXXX @name=\"a\">
|
|
971
|
-
+#<#<Class:0xXXXXXX>:0xXXXXXX @name=\"b\">
|
|
972
|
-
".gsub(/^ +/, "")
|
|
973
|
-
|
|
974
|
-
assert_triggered msg do
|
|
975
|
-
@tc.assert_equal o1, o2
|
|
976
|
-
end
|
|
1089
|
+
def test_autorun_does_not_affect_fork_success_status
|
|
1090
|
+
@assertion_count = 0
|
|
1091
|
+
skip "windows doesn't have fork" unless Process.respond_to? :fork
|
|
1092
|
+
Process.waitpid(fork {})
|
|
1093
|
+
assert_equal true, $?.success?
|
|
977
1094
|
end
|
|
978
1095
|
|
|
979
|
-
def
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
You should look at the implementation of #== on Object or its members.
|
|
985
|
-
#<Object:0xXXXXXX>".gsub(/^ +/, "")
|
|
986
|
-
|
|
987
|
-
assert_triggered msg do
|
|
988
|
-
@tc.assert_equal o1, o2
|
|
989
|
-
end
|
|
1096
|
+
def test_autorun_does_not_affect_fork_exit_status
|
|
1097
|
+
@assertion_count = 0
|
|
1098
|
+
skip "windows doesn't have fork" unless Process.respond_to? :fork
|
|
1099
|
+
Process.waitpid(fork { exit 42 })
|
|
1100
|
+
assert_equal 42, $?.exitstatus
|
|
990
1101
|
end
|
|
991
1102
|
|
|
992
|
-
def
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
assert_triggered msg do
|
|
1001
|
-
o1 = "haha" * 10
|
|
1002
|
-
o2 = "blah" * 10
|
|
1003
|
-
|
|
1004
|
-
@tc.assert_equal o1, o2
|
|
1005
|
-
end
|
|
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
|
|
1006
1111
|
end
|
|
1112
|
+
end
|
|
1007
1113
|
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
You should look at the implementation of #== on String or its members.
|
|
1011
|
-
\"blahblahblahblahblahblahblahblahblahblah\"".gsub(/^ +/, "")
|
|
1114
|
+
class TestMinitestGuard < Minitest::Test
|
|
1115
|
+
parallelize_me!
|
|
1012
1116
|
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
def o1.== _
|
|
1017
|
-
false
|
|
1018
|
-
end
|
|
1019
|
-
@tc.assert_equal o1, o2
|
|
1020
|
-
end
|
|
1117
|
+
def test_mri_eh
|
|
1118
|
+
assert self.class.mri? "ruby blah"
|
|
1119
|
+
assert self.mri? "ruby blah"
|
|
1021
1120
|
end
|
|
1022
1121
|
|
|
1023
|
-
def
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
@@ -1 +1 @@
|
|
1028
|
-
-\"hahahahahahahahahahahahahahahahahahahaha\"
|
|
1029
|
-
+\"blahblahblahblahblahblahblahblahblahblah\"
|
|
1030
|
-
".gsub(/^ +/, "")
|
|
1122
|
+
def test_jruby_eh
|
|
1123
|
+
assert self.class.jruby? "java"
|
|
1124
|
+
assert self.jruby? "java"
|
|
1125
|
+
end
|
|
1031
1126
|
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1127
|
+
def test_rubinius_eh
|
|
1128
|
+
assert_deprecation do
|
|
1129
|
+
assert self.class.rubinius? "rbx"
|
|
1130
|
+
end
|
|
1131
|
+
assert_deprecation do
|
|
1132
|
+
assert self.rubinius? "rbx"
|
|
1036
1133
|
end
|
|
1037
1134
|
end
|
|
1038
1135
|
|
|
1039
|
-
def
|
|
1040
|
-
|
|
1041
|
-
|
|
1136
|
+
def test_maglev_eh
|
|
1137
|
+
assert_deprecation do
|
|
1138
|
+
assert self.class.maglev? "maglev"
|
|
1139
|
+
end
|
|
1140
|
+
assert_deprecation do
|
|
1141
|
+
assert self.maglev? "maglev"
|
|
1042
1142
|
end
|
|
1043
1143
|
end
|
|
1044
1144
|
|
|
1045
|
-
def
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
end
|
|
1145
|
+
def test_osx_eh
|
|
1146
|
+
assert self.class.osx? "darwin"
|
|
1147
|
+
assert self.osx? "darwin"
|
|
1049
1148
|
end
|
|
1050
1149
|
|
|
1051
|
-
def
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
@tc.assert_equal "a\nb", "a\nc"
|
|
1055
|
-
end
|
|
1150
|
+
def test_windows_eh
|
|
1151
|
+
assert self.class.windows? "mswin"
|
|
1152
|
+
assert self.windows? "mswin"
|
|
1056
1153
|
end
|
|
1057
|
-
|
|
1058
|
-
def test_assert_equal_does_not_allow_lhs_nil
|
|
1059
|
-
if Minitest::VERSION =~ /^6/ then
|
|
1060
|
-
warn "Time to strip the MT5 test"
|
|
1061
|
-
|
|
1062
|
-
@assertion_count += 1
|
|
1063
|
-
assert_triggered(/Use assert_nil if expecting nil/) do
|
|
1064
|
-
@tc.assert_equal nil, nil
|
|
1065
|
-
end
|
|
1066
|
-
else
|
|
1067
|
-
err_re = /Use assert_nil if expecting nil from .*test_minitest_test.rb/
|
|
1068
|
-
err_re = "" if $-w.nil?
|
|
1069
|
-
|
|
1070
|
-
assert_output "", err_re do
|
|
1071
|
-
@tc.assert_equal nil, nil
|
|
1072
|
-
end
|
|
1073
|
-
end
|
|
1074
|
-
end
|
|
1075
|
-
|
|
1076
|
-
def test_assert_equal_does_not_allow_lhs_nil_triggered
|
|
1077
|
-
assert_triggered "Expected: nil\n Actual: false" do
|
|
1078
|
-
@tc.assert_equal nil, false
|
|
1079
|
-
end
|
|
1080
|
-
end
|
|
1081
|
-
|
|
1082
|
-
def test_assert_in_delta
|
|
1083
|
-
@tc.assert_in_delta 0.0, 1.0 / 1000, 0.1
|
|
1084
|
-
end
|
|
1085
|
-
|
|
1086
|
-
def test_delta_consistency
|
|
1087
|
-
@assertion_count = 2
|
|
1088
|
-
|
|
1089
|
-
@tc.assert_in_delta 0, 1, 1
|
|
1090
|
-
|
|
1091
|
-
assert_triggered "Expected |0 - 1| (1) to not be <= 1." do
|
|
1092
|
-
@tc.refute_in_delta 0, 1, 1
|
|
1093
|
-
end
|
|
1094
|
-
end
|
|
1095
|
-
|
|
1096
|
-
def test_assert_in_delta_triggered
|
|
1097
|
-
x = maglev? ? "9.999999xxxe-07" : "1.0e-06"
|
|
1098
|
-
assert_triggered "Expected |0.0 - 0.001| (0.001) to be <= #{x}." do
|
|
1099
|
-
@tc.assert_in_delta 0.0, 1.0 / 1000, 0.000001
|
|
1100
|
-
end
|
|
1101
|
-
end
|
|
1102
|
-
|
|
1103
|
-
def test_assert_in_epsilon
|
|
1104
|
-
@assertion_count = 10
|
|
1105
|
-
|
|
1106
|
-
@tc.assert_in_epsilon 10_000, 9991
|
|
1107
|
-
@tc.assert_in_epsilon 9991, 10_000
|
|
1108
|
-
@tc.assert_in_epsilon 1.0, 1.001
|
|
1109
|
-
@tc.assert_in_epsilon 1.001, 1.0
|
|
1110
|
-
|
|
1111
|
-
@tc.assert_in_epsilon 10_000, 9999.1, 0.0001
|
|
1112
|
-
@tc.assert_in_epsilon 9999.1, 10_000, 0.0001
|
|
1113
|
-
@tc.assert_in_epsilon 1.0, 1.0001, 0.0001
|
|
1114
|
-
@tc.assert_in_epsilon 1.0001, 1.0, 0.0001
|
|
1115
|
-
|
|
1116
|
-
@tc.assert_in_epsilon(-1, -1)
|
|
1117
|
-
@tc.assert_in_epsilon(-10_000, -9991)
|
|
1118
|
-
end
|
|
1119
|
-
|
|
1120
|
-
def test_epsilon_consistency
|
|
1121
|
-
@assertion_count = 2
|
|
1122
|
-
|
|
1123
|
-
@tc.assert_in_epsilon 1.0, 1.001
|
|
1124
|
-
|
|
1125
|
-
msg = "Expected |1.0 - 1.001| (0.000999xxx) to not be <= 0.001."
|
|
1126
|
-
assert_triggered msg do
|
|
1127
|
-
@tc.refute_in_epsilon 1.0, 1.001
|
|
1128
|
-
end
|
|
1129
|
-
end
|
|
1130
|
-
|
|
1131
|
-
def test_assert_in_epsilon_triggered
|
|
1132
|
-
assert_triggered "Expected |10000 - 9990| (10) to be <= 9.99." do
|
|
1133
|
-
@tc.assert_in_epsilon 10_000, 9990
|
|
1134
|
-
end
|
|
1135
|
-
end
|
|
1136
|
-
|
|
1137
|
-
def test_assert_in_epsilon_triggered_negative_case
|
|
1138
|
-
x = (RUBY18 and not maglev?) ? "0.1" : "0.100000xxx"
|
|
1139
|
-
y = maglev? ? "0.100000xxx" : "0.1"
|
|
1140
|
-
assert_triggered "Expected |-1.1 - -1| (#{x}) to be <= #{y}." do
|
|
1141
|
-
@tc.assert_in_epsilon(-1.1, -1, 0.1)
|
|
1142
|
-
end
|
|
1143
|
-
end
|
|
1144
|
-
|
|
1145
|
-
def test_assert_includes
|
|
1146
|
-
@assertion_count = 2
|
|
1147
|
-
|
|
1148
|
-
@tc.assert_includes [true], true
|
|
1149
|
-
end
|
|
1150
|
-
|
|
1151
|
-
def test_assert_includes_triggered
|
|
1152
|
-
@assertion_count = 3
|
|
1153
|
-
|
|
1154
|
-
e = @tc.assert_raises Minitest::Assertion do
|
|
1155
|
-
@tc.assert_includes [true], false
|
|
1156
|
-
end
|
|
1157
|
-
|
|
1158
|
-
expected = "Expected [true] to include false."
|
|
1159
|
-
assert_equal expected, e.message
|
|
1160
|
-
end
|
|
1161
|
-
|
|
1162
|
-
def test_assert_instance_of
|
|
1163
|
-
@tc.assert_instance_of String, "blah"
|
|
1164
|
-
end
|
|
1165
|
-
|
|
1166
|
-
def test_assert_instance_of_triggered
|
|
1167
|
-
assert_triggered 'Expected "blah" to be an instance of Array, not String.' do
|
|
1168
|
-
@tc.assert_instance_of Array, "blah"
|
|
1169
|
-
end
|
|
1170
|
-
end
|
|
1171
|
-
|
|
1172
|
-
def test_assert_kind_of
|
|
1173
|
-
@tc.assert_kind_of String, "blah"
|
|
1174
|
-
end
|
|
1175
|
-
|
|
1176
|
-
def test_assert_kind_of_triggered
|
|
1177
|
-
assert_triggered 'Expected "blah" to be a kind of Array, not String.' do
|
|
1178
|
-
@tc.assert_kind_of Array, "blah"
|
|
1179
|
-
end
|
|
1180
|
-
end
|
|
1181
|
-
|
|
1182
|
-
def test_assert_match
|
|
1183
|
-
@assertion_count = 2
|
|
1184
|
-
@tc.assert_match(/\w+/, "blah blah blah")
|
|
1185
|
-
end
|
|
1186
|
-
|
|
1187
|
-
def test_assert_match_matcher_object
|
|
1188
|
-
@assertion_count = 2
|
|
1189
|
-
|
|
1190
|
-
pattern = Object.new
|
|
1191
|
-
def pattern.=~ _; true end
|
|
1192
|
-
|
|
1193
|
-
@tc.assert_match pattern, 5
|
|
1194
|
-
end
|
|
1195
|
-
|
|
1196
|
-
def test_assert_match_matchee_to_str
|
|
1197
|
-
@assertion_count = 2
|
|
1198
|
-
|
|
1199
|
-
obj = Object.new
|
|
1200
|
-
def obj.to_str; "blah" end
|
|
1201
|
-
|
|
1202
|
-
@tc.assert_match "blah", obj
|
|
1203
|
-
end
|
|
1204
|
-
|
|
1205
|
-
def test_assert_match_object_triggered
|
|
1206
|
-
@assertion_count = 2
|
|
1207
|
-
|
|
1208
|
-
pattern = Object.new
|
|
1209
|
-
def pattern.=~ _; false end
|
|
1210
|
-
def pattern.inspect; "[Object]" end
|
|
1211
|
-
|
|
1212
|
-
assert_triggered "Expected [Object] to match 5." do
|
|
1213
|
-
@tc.assert_match pattern, 5
|
|
1214
|
-
end
|
|
1215
|
-
end
|
|
1216
|
-
|
|
1217
|
-
def test_assert_match_triggered
|
|
1218
|
-
@assertion_count = 2
|
|
1219
|
-
assert_triggered 'Expected /\d+/ to match "blah blah blah".' do
|
|
1220
|
-
@tc.assert_match(/\d+/, "blah blah blah")
|
|
1221
|
-
end
|
|
1222
|
-
end
|
|
1223
|
-
|
|
1224
|
-
def test_assert_nil
|
|
1225
|
-
@tc.assert_nil nil
|
|
1226
|
-
end
|
|
1227
|
-
|
|
1228
|
-
def test_assert_nil_triggered
|
|
1229
|
-
assert_triggered "Expected 42 to be nil." do
|
|
1230
|
-
@tc.assert_nil 42
|
|
1231
|
-
end
|
|
1232
|
-
end
|
|
1233
|
-
|
|
1234
|
-
def test_assert_operator
|
|
1235
|
-
@tc.assert_operator 2, :>, 1
|
|
1236
|
-
end
|
|
1237
|
-
|
|
1238
|
-
def test_assert_operator_bad_object
|
|
1239
|
-
bad = Object.new
|
|
1240
|
-
def bad.== _; true end
|
|
1241
|
-
|
|
1242
|
-
@tc.assert_operator bad, :equal?, bad
|
|
1243
|
-
end
|
|
1244
|
-
|
|
1245
|
-
def test_assert_operator_triggered
|
|
1246
|
-
assert_triggered "Expected 2 to be < 1." do
|
|
1247
|
-
@tc.assert_operator 2, :<, 1
|
|
1248
|
-
end
|
|
1249
|
-
end
|
|
1250
|
-
|
|
1251
|
-
def test_assert_output_both
|
|
1252
|
-
@assertion_count = 2
|
|
1253
|
-
|
|
1254
|
-
@tc.assert_output "yay", "blah" do
|
|
1255
|
-
print "yay"
|
|
1256
|
-
$stderr.print "blah"
|
|
1257
|
-
end
|
|
1258
|
-
end
|
|
1259
|
-
|
|
1260
|
-
def test_assert_output_both_regexps
|
|
1261
|
-
@assertion_count = 4
|
|
1262
|
-
|
|
1263
|
-
@tc.assert_output(/y.y/, /bl.h/) do
|
|
1264
|
-
print "yay"
|
|
1265
|
-
$stderr.print "blah"
|
|
1266
|
-
end
|
|
1267
|
-
end
|
|
1268
|
-
|
|
1269
|
-
def test_assert_output_err
|
|
1270
|
-
@tc.assert_output nil, "blah" do
|
|
1271
|
-
$stderr.print "blah"
|
|
1272
|
-
end
|
|
1273
|
-
end
|
|
1274
|
-
|
|
1275
|
-
def test_assert_output_neither
|
|
1276
|
-
@assertion_count = 0
|
|
1277
|
-
|
|
1278
|
-
@tc.assert_output do
|
|
1279
|
-
# do nothing
|
|
1280
|
-
end
|
|
1281
|
-
end
|
|
1282
|
-
|
|
1283
|
-
def test_assert_output_out
|
|
1284
|
-
@tc.assert_output "blah" do
|
|
1285
|
-
print "blah"
|
|
1286
|
-
end
|
|
1287
|
-
end
|
|
1288
|
-
|
|
1289
|
-
def test_assert_output_triggered_both
|
|
1290
|
-
assert_triggered util_msg("blah", "blah blah", "In stderr") do
|
|
1291
|
-
@tc.assert_output "yay", "blah" do
|
|
1292
|
-
print "boo"
|
|
1293
|
-
$stderr.print "blah blah"
|
|
1294
|
-
end
|
|
1295
|
-
end
|
|
1296
|
-
end
|
|
1297
|
-
|
|
1298
|
-
def test_assert_output_triggered_err
|
|
1299
|
-
assert_triggered util_msg("blah", "blah blah", "In stderr") do
|
|
1300
|
-
@tc.assert_output nil, "blah" do
|
|
1301
|
-
$stderr.print "blah blah"
|
|
1302
|
-
end
|
|
1303
|
-
end
|
|
1304
|
-
end
|
|
1305
|
-
|
|
1306
|
-
def test_assert_output_triggered_out
|
|
1307
|
-
assert_triggered util_msg("blah", "blah blah", "In stdout") do
|
|
1308
|
-
@tc.assert_output "blah" do
|
|
1309
|
-
print "blah blah"
|
|
1310
|
-
end
|
|
1311
|
-
end
|
|
1312
|
-
end
|
|
1313
|
-
|
|
1314
|
-
def test_assert_predicate
|
|
1315
|
-
@tc.assert_predicate "", :empty?
|
|
1316
|
-
end
|
|
1317
|
-
|
|
1318
|
-
def test_assert_predicate_triggered
|
|
1319
|
-
assert_triggered 'Expected "blah" to be empty?.' do
|
|
1320
|
-
@tc.assert_predicate "blah", :empty?
|
|
1321
|
-
end
|
|
1322
|
-
end
|
|
1323
|
-
|
|
1324
|
-
def test_assert_raises
|
|
1325
|
-
@tc.assert_raises RuntimeError do
|
|
1326
|
-
raise "blah"
|
|
1327
|
-
end
|
|
1328
|
-
end
|
|
1329
|
-
|
|
1330
|
-
def test_assert_raises_default
|
|
1331
|
-
@tc.assert_raises do
|
|
1332
|
-
raise StandardError, "blah"
|
|
1333
|
-
end
|
|
1334
|
-
end
|
|
1335
|
-
|
|
1336
|
-
def test_assert_raises_default_triggered
|
|
1337
|
-
e = assert_raises Minitest::Assertion do
|
|
1338
|
-
@tc.assert_raises do
|
|
1339
|
-
raise SomeError, "blah"
|
|
1340
|
-
end
|
|
1341
|
-
end
|
|
1342
|
-
|
|
1343
|
-
expected = clean <<-EOM.chomp
|
|
1344
|
-
[StandardError] exception expected, not
|
|
1345
|
-
Class: <SomeError>
|
|
1346
|
-
Message: <\"blah\">
|
|
1347
|
-
---Backtrace---
|
|
1348
|
-
FILE:LINE:in \`test_assert_raises_default_triggered\'
|
|
1349
|
-
---------------
|
|
1350
|
-
EOM
|
|
1351
|
-
|
|
1352
|
-
actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
|
|
1353
|
-
actual.gsub!(/block \(\d+ levels\) in /, "") if RUBY_VERSION >= "1.9.0"
|
|
1354
|
-
|
|
1355
|
-
assert_equal expected, actual
|
|
1356
|
-
end
|
|
1357
|
-
|
|
1358
|
-
def test_assert_raises_module
|
|
1359
|
-
@tc.assert_raises MyModule do
|
|
1360
|
-
raise AnError
|
|
1361
|
-
end
|
|
1362
|
-
end
|
|
1363
|
-
|
|
1364
|
-
##
|
|
1365
|
-
# *sigh* This is quite an odd scenario, but it is from real (albeit
|
|
1366
|
-
# ugly) test code in ruby-core:
|
|
1367
|
-
#
|
|
1368
|
-
# http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29259
|
|
1369
|
-
|
|
1370
|
-
def test_assert_raises_skip
|
|
1371
|
-
@assertion_count = 0
|
|
1372
|
-
|
|
1373
|
-
assert_triggered "skipped", Minitest::Skip do
|
|
1374
|
-
@tc.assert_raises ArgumentError do
|
|
1375
|
-
begin
|
|
1376
|
-
raise "blah"
|
|
1377
|
-
rescue
|
|
1378
|
-
skip "skipped"
|
|
1379
|
-
end
|
|
1380
|
-
end
|
|
1381
|
-
end
|
|
1382
|
-
end
|
|
1383
|
-
|
|
1384
|
-
def test_assert_raises_triggered_different
|
|
1385
|
-
e = assert_raises Minitest::Assertion do
|
|
1386
|
-
@tc.assert_raises RuntimeError do
|
|
1387
|
-
raise SyntaxError, "icky"
|
|
1388
|
-
end
|
|
1389
|
-
end
|
|
1390
|
-
|
|
1391
|
-
expected = clean <<-EOM.chomp
|
|
1392
|
-
[RuntimeError] exception expected, not
|
|
1393
|
-
Class: <SyntaxError>
|
|
1394
|
-
Message: <\"icky\">
|
|
1395
|
-
---Backtrace---
|
|
1396
|
-
FILE:LINE:in \`test_assert_raises_triggered_different\'
|
|
1397
|
-
---------------
|
|
1398
|
-
EOM
|
|
1399
|
-
|
|
1400
|
-
actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
|
|
1401
|
-
actual.gsub!(/block \(\d+ levels\) in /, "") if RUBY_VERSION >= "1.9.0"
|
|
1402
|
-
|
|
1403
|
-
assert_equal expected, actual
|
|
1404
|
-
end
|
|
1405
|
-
|
|
1406
|
-
def test_assert_raises_triggered_different_msg
|
|
1407
|
-
e = assert_raises Minitest::Assertion do
|
|
1408
|
-
@tc.assert_raises RuntimeError, "XXX" do
|
|
1409
|
-
raise SyntaxError, "icky"
|
|
1410
|
-
end
|
|
1411
|
-
end
|
|
1412
|
-
|
|
1413
|
-
expected = clean <<-EOM
|
|
1414
|
-
XXX.
|
|
1415
|
-
[RuntimeError] exception expected, not
|
|
1416
|
-
Class: <SyntaxError>
|
|
1417
|
-
Message: <\"icky\">
|
|
1418
|
-
---Backtrace---
|
|
1419
|
-
FILE:LINE:in \`test_assert_raises_triggered_different_msg\'
|
|
1420
|
-
---------------
|
|
1421
|
-
EOM
|
|
1422
|
-
|
|
1423
|
-
actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
|
|
1424
|
-
actual.gsub!(/block \(\d+ levels\) in /, "") if RUBY_VERSION >= "1.9.0"
|
|
1425
|
-
|
|
1426
|
-
assert_equal expected.chomp, actual
|
|
1427
|
-
end
|
|
1428
|
-
|
|
1429
|
-
def test_assert_raises_triggered_none
|
|
1430
|
-
e = assert_raises Minitest::Assertion do
|
|
1431
|
-
@tc.assert_raises Minitest::Assertion do
|
|
1432
|
-
# do nothing
|
|
1433
|
-
end
|
|
1434
|
-
end
|
|
1435
|
-
|
|
1436
|
-
expected = "Minitest::Assertion expected but nothing was raised."
|
|
1437
|
-
|
|
1438
|
-
assert_equal expected, e.message
|
|
1439
|
-
end
|
|
1440
|
-
|
|
1441
|
-
def test_assert_raises_triggered_none_msg
|
|
1442
|
-
e = assert_raises Minitest::Assertion do
|
|
1443
|
-
@tc.assert_raises Minitest::Assertion, "XXX" do
|
|
1444
|
-
# do nothing
|
|
1445
|
-
end
|
|
1446
|
-
end
|
|
1447
|
-
|
|
1448
|
-
expected = "XXX.\nMinitest::Assertion expected but nothing was raised."
|
|
1449
|
-
|
|
1450
|
-
assert_equal expected, e.message
|
|
1451
|
-
end
|
|
1452
|
-
|
|
1453
|
-
def test_assert_raises_subclass
|
|
1454
|
-
@tc.assert_raises StandardError do
|
|
1455
|
-
raise AnError
|
|
1456
|
-
end
|
|
1457
|
-
end
|
|
1458
|
-
|
|
1459
|
-
def test_assert_raises_subclass_triggered
|
|
1460
|
-
e = assert_raises Minitest::Assertion do
|
|
1461
|
-
@tc.assert_raises SomeError do
|
|
1462
|
-
raise AnError, "some message"
|
|
1463
|
-
end
|
|
1464
|
-
end
|
|
1465
|
-
|
|
1466
|
-
expected = clean <<-EOM
|
|
1467
|
-
[SomeError] exception expected, not
|
|
1468
|
-
Class: <AnError>
|
|
1469
|
-
Message: <\"some message\">
|
|
1470
|
-
---Backtrace---
|
|
1471
|
-
FILE:LINE:in \`test_assert_raises_subclass_triggered\'
|
|
1472
|
-
---------------
|
|
1473
|
-
EOM
|
|
1474
|
-
|
|
1475
|
-
actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
|
|
1476
|
-
actual.gsub!(/block \(\d+ levels\) in /, "") if RUBY_VERSION >= "1.9.0"
|
|
1477
|
-
|
|
1478
|
-
assert_equal expected.chomp, actual
|
|
1479
|
-
end
|
|
1480
|
-
|
|
1481
|
-
def test_assert_raises_exit
|
|
1482
|
-
@tc.assert_raises SystemExit do
|
|
1483
|
-
exit 1
|
|
1484
|
-
end
|
|
1485
|
-
end
|
|
1486
|
-
|
|
1487
|
-
def test_assert_raises_signals
|
|
1488
|
-
@tc.assert_raises SignalException do
|
|
1489
|
-
raise SignalException, :INT
|
|
1490
|
-
end
|
|
1491
|
-
end
|
|
1492
|
-
|
|
1493
|
-
def test_assert_respond_to
|
|
1494
|
-
@tc.assert_respond_to "blah", :empty?
|
|
1495
|
-
end
|
|
1496
|
-
|
|
1497
|
-
def test_assert_respond_to_triggered
|
|
1498
|
-
assert_triggered 'Expected "blah" (String) to respond to #rawr!.' do
|
|
1499
|
-
@tc.assert_respond_to "blah", :rawr!
|
|
1500
|
-
end
|
|
1501
|
-
end
|
|
1502
|
-
|
|
1503
|
-
def test_assert_same
|
|
1504
|
-
@assertion_count = 3
|
|
1505
|
-
|
|
1506
|
-
o = "blah"
|
|
1507
|
-
@tc.assert_same 1, 1
|
|
1508
|
-
@tc.assert_same :blah, :blah
|
|
1509
|
-
@tc.assert_same o, o
|
|
1510
|
-
end
|
|
1511
|
-
|
|
1512
|
-
def test_assert_same_triggered
|
|
1513
|
-
@assertion_count = 2
|
|
1514
|
-
|
|
1515
|
-
assert_triggered "Expected 2 (oid=N) to be the same as 1 (oid=N)." do
|
|
1516
|
-
@tc.assert_same 1, 2
|
|
1517
|
-
end
|
|
1518
|
-
|
|
1519
|
-
s1 = "blah"
|
|
1520
|
-
s2 = "blah"
|
|
1521
|
-
|
|
1522
|
-
assert_triggered 'Expected "blah" (oid=N) to be the same as "blah" (oid=N).' do
|
|
1523
|
-
@tc.assert_same s1, s2
|
|
1524
|
-
end
|
|
1525
|
-
end
|
|
1526
|
-
|
|
1527
|
-
def assert_deprecated name
|
|
1528
|
-
dep = /DEPRECATED: #{name}. From #{__FILE__}:\d+(?::.*)?/
|
|
1529
|
-
dep = "" if $-w.nil?
|
|
1530
|
-
|
|
1531
|
-
assert_output nil, dep do
|
|
1532
|
-
yield
|
|
1533
|
-
end
|
|
1534
|
-
end
|
|
1535
|
-
|
|
1536
|
-
def test_assert_send
|
|
1537
|
-
assert_deprecated :assert_send do
|
|
1538
|
-
@tc.assert_send [1, :<, 2]
|
|
1539
|
-
end
|
|
1540
|
-
end
|
|
1541
|
-
|
|
1542
|
-
def test_assert_send_bad
|
|
1543
|
-
assert_deprecated :assert_send do
|
|
1544
|
-
assert_triggered "Expected 1.>(*[2]) to return true." do
|
|
1545
|
-
@tc.assert_send [1, :>, 2]
|
|
1546
|
-
end
|
|
1547
|
-
end
|
|
1548
|
-
end
|
|
1549
|
-
|
|
1550
|
-
def test_assert_silent
|
|
1551
|
-
@assertion_count = 2
|
|
1552
|
-
|
|
1553
|
-
@tc.assert_silent do
|
|
1554
|
-
# do nothing
|
|
1555
|
-
end
|
|
1556
|
-
end
|
|
1557
|
-
|
|
1558
|
-
def test_assert_silent_triggered_err
|
|
1559
|
-
assert_triggered util_msg("", "blah blah", "In stderr") do
|
|
1560
|
-
@tc.assert_silent do
|
|
1561
|
-
$stderr.print "blah blah"
|
|
1562
|
-
end
|
|
1563
|
-
end
|
|
1564
|
-
end
|
|
1565
|
-
|
|
1566
|
-
def test_assert_silent_triggered_out
|
|
1567
|
-
@assertion_count = 2
|
|
1568
|
-
|
|
1569
|
-
assert_triggered util_msg("", "blah blah", "In stdout") do
|
|
1570
|
-
@tc.assert_silent do
|
|
1571
|
-
print "blah blah"
|
|
1572
|
-
end
|
|
1573
|
-
end
|
|
1574
|
-
end
|
|
1575
|
-
|
|
1576
|
-
def test_assert_throws
|
|
1577
|
-
@tc.assert_throws :blah do
|
|
1578
|
-
throw :blah
|
|
1579
|
-
end
|
|
1580
|
-
end
|
|
1581
|
-
|
|
1582
|
-
def test_assert_throws_name_error
|
|
1583
|
-
@tc.assert_raises NameError do
|
|
1584
|
-
@tc.assert_throws :blah do
|
|
1585
|
-
raise NameError
|
|
1586
|
-
end
|
|
1587
|
-
end
|
|
1588
|
-
end
|
|
1589
|
-
|
|
1590
|
-
def test_assert_throws_argument_exception
|
|
1591
|
-
@tc.assert_raises ArgumentError do
|
|
1592
|
-
@tc.assert_throws :blah do
|
|
1593
|
-
raise ArgumentError
|
|
1594
|
-
end
|
|
1595
|
-
end
|
|
1596
|
-
end
|
|
1597
|
-
|
|
1598
|
-
def test_assert_throws_different
|
|
1599
|
-
assert_triggered "Expected :blah to have been thrown, not :not_blah." do
|
|
1600
|
-
@tc.assert_throws :blah do
|
|
1601
|
-
throw :not_blah
|
|
1602
|
-
end
|
|
1603
|
-
end
|
|
1604
|
-
end
|
|
1605
|
-
|
|
1606
|
-
def test_assert_throws_unthrown
|
|
1607
|
-
assert_triggered "Expected :blah to have been thrown." do
|
|
1608
|
-
@tc.assert_throws :blah do
|
|
1609
|
-
# do nothing
|
|
1610
|
-
end
|
|
1611
|
-
end
|
|
1612
|
-
end
|
|
1613
|
-
|
|
1614
|
-
def test_capture_io
|
|
1615
|
-
@assertion_count = 0
|
|
1616
|
-
|
|
1617
|
-
non_verbose do
|
|
1618
|
-
out, err = capture_io do
|
|
1619
|
-
puts "hi"
|
|
1620
|
-
$stderr.puts "bye!"
|
|
1621
|
-
end
|
|
1622
|
-
|
|
1623
|
-
assert_equal "hi\n", out
|
|
1624
|
-
assert_equal "bye!\n", err
|
|
1625
|
-
end
|
|
1626
|
-
end
|
|
1627
|
-
|
|
1628
|
-
def test_capture_subprocess_io
|
|
1629
|
-
@assertion_count = 0
|
|
1630
|
-
|
|
1631
|
-
non_verbose do
|
|
1632
|
-
out, err = capture_subprocess_io do
|
|
1633
|
-
system("echo hi")
|
|
1634
|
-
system("echo bye! 1>&2")
|
|
1635
|
-
end
|
|
1636
|
-
|
|
1637
|
-
assert_equal "hi\n", out
|
|
1638
|
-
assert_equal "bye!", err.strip
|
|
1639
|
-
end
|
|
1640
|
-
end
|
|
1641
|
-
|
|
1642
|
-
def test_class_asserts_match_refutes
|
|
1643
|
-
@assertion_count = 0
|
|
1644
|
-
|
|
1645
|
-
methods = Minitest::Assertions.public_instance_methods
|
|
1646
|
-
methods.map!(&:to_s) if Symbol === methods.first
|
|
1647
|
-
|
|
1648
|
-
# These don't have corresponding refutes _on purpose_. They're
|
|
1649
|
-
# useless and will never be added, so don't bother.
|
|
1650
|
-
ignores = %w[assert_output assert_raises assert_send
|
|
1651
|
-
assert_silent assert_throws assert_mock]
|
|
1652
|
-
|
|
1653
|
-
# These are test/unit methods. I'm not actually sure why they're still here
|
|
1654
|
-
ignores += %w[assert_no_match assert_not_equal assert_not_nil
|
|
1655
|
-
assert_not_same assert_nothing_raised
|
|
1656
|
-
assert_nothing_thrown assert_raise]
|
|
1657
|
-
|
|
1658
|
-
asserts = methods.grep(/^assert/).sort - ignores
|
|
1659
|
-
refutes = methods.grep(/^refute/).sort - ignores
|
|
1660
|
-
|
|
1661
|
-
assert_empty refutes.map { |n| n.sub(/^refute/, "assert") } - asserts
|
|
1662
|
-
assert_empty asserts.map { |n| n.sub(/^assert/, "refute") } - refutes
|
|
1663
|
-
end
|
|
1664
|
-
|
|
1665
|
-
def test_flunk
|
|
1666
|
-
assert_triggered "Epic Fail!" do
|
|
1667
|
-
@tc.flunk
|
|
1668
|
-
end
|
|
1669
|
-
end
|
|
1670
|
-
|
|
1671
|
-
def test_flunk_message
|
|
1672
|
-
assert_triggered @zomg do
|
|
1673
|
-
@tc.flunk @zomg
|
|
1674
|
-
end
|
|
1675
|
-
end
|
|
1676
|
-
|
|
1677
|
-
def test_message
|
|
1678
|
-
@assertion_count = 0
|
|
1679
|
-
|
|
1680
|
-
assert_equal "blah2.", @tc.message { "blah2" }.call
|
|
1681
|
-
assert_equal "blah2.", @tc.message("") { "blah2" }.call
|
|
1682
|
-
assert_equal "blah1.\nblah2.", @tc.message(:blah1) { "blah2" }.call
|
|
1683
|
-
assert_equal "blah1.\nblah2.", @tc.message("blah1") { "blah2" }.call
|
|
1684
|
-
|
|
1685
|
-
message = proc { "blah1" }
|
|
1686
|
-
assert_equal "blah1.\nblah2.", @tc.message(message) { "blah2" }.call
|
|
1687
|
-
|
|
1688
|
-
message = @tc.message { "blah1" }
|
|
1689
|
-
assert_equal "blah1.\nblah2.", @tc.message(message) { "blah2" }.call
|
|
1690
|
-
end
|
|
1691
|
-
|
|
1692
|
-
def test_message_message
|
|
1693
|
-
assert_triggered "whoops.\nExpected: 1\n Actual: 2" do
|
|
1694
|
-
@tc.assert_equal 1, 2, message { "whoops" }
|
|
1695
|
-
end
|
|
1696
|
-
end
|
|
1697
|
-
|
|
1698
|
-
def test_message_lambda
|
|
1699
|
-
assert_triggered "whoops.\nExpected: 1\n Actual: 2" do
|
|
1700
|
-
@tc.assert_equal 1, 2, lambda { "whoops" }
|
|
1701
|
-
end
|
|
1702
|
-
end
|
|
1703
|
-
|
|
1704
|
-
def test_message_deferred
|
|
1705
|
-
@assertion_count, var = 0, nil
|
|
1706
|
-
|
|
1707
|
-
msg = message { var = "blah" }
|
|
1708
|
-
|
|
1709
|
-
assert_nil var
|
|
1710
|
-
|
|
1711
|
-
msg.call
|
|
1712
|
-
|
|
1713
|
-
assert_equal "blah", var
|
|
1714
|
-
end
|
|
1715
|
-
|
|
1716
|
-
def test_pass
|
|
1717
|
-
@tc.pass
|
|
1718
|
-
end
|
|
1719
|
-
|
|
1720
|
-
def test_prints
|
|
1721
|
-
printer = Class.new { extend Minitest::Assertions }
|
|
1722
|
-
@tc.assert_equal '"test"', printer.mu_pp(ImmutableString.new "test")
|
|
1723
|
-
end
|
|
1724
|
-
|
|
1725
|
-
def test_refute
|
|
1726
|
-
@assertion_count = 2
|
|
1727
|
-
|
|
1728
|
-
@tc.assert_equal false, @tc.refute(false), "returns false on success"
|
|
1729
|
-
end
|
|
1730
|
-
|
|
1731
|
-
def test_refute_empty
|
|
1732
|
-
@assertion_count = 2
|
|
1733
|
-
|
|
1734
|
-
@tc.refute_empty [1]
|
|
1735
|
-
end
|
|
1736
|
-
|
|
1737
|
-
def test_refute_empty_triggered
|
|
1738
|
-
@assertion_count = 2
|
|
1739
|
-
|
|
1740
|
-
assert_triggered "Expected [] to not be empty." do
|
|
1741
|
-
@tc.refute_empty []
|
|
1742
|
-
end
|
|
1743
|
-
end
|
|
1744
|
-
|
|
1745
|
-
def test_refute_equal
|
|
1746
|
-
@tc.refute_equal "blah", "yay"
|
|
1747
|
-
end
|
|
1748
|
-
|
|
1749
|
-
def test_refute_equal_triggered
|
|
1750
|
-
assert_triggered 'Expected "blah" to not be equal to "blah".' do
|
|
1751
|
-
@tc.refute_equal "blah", "blah"
|
|
1752
|
-
end
|
|
1753
|
-
end
|
|
1754
|
-
|
|
1755
|
-
def test_refute_in_delta
|
|
1756
|
-
@tc.refute_in_delta 0.0, 1.0 / 1000, 0.000001
|
|
1757
|
-
end
|
|
1758
|
-
|
|
1759
|
-
def test_refute_in_delta_triggered
|
|
1760
|
-
x = maglev? ? "0.100000xxx" : "0.1"
|
|
1761
|
-
assert_triggered "Expected |0.0 - 0.001| (0.001) to not be <= #{x}." do
|
|
1762
|
-
@tc.refute_in_delta 0.0, 1.0 / 1000, 0.1
|
|
1763
|
-
end
|
|
1764
|
-
end
|
|
1765
|
-
|
|
1766
|
-
def test_refute_in_epsilon
|
|
1767
|
-
@tc.refute_in_epsilon 10_000, 9990-1
|
|
1768
|
-
end
|
|
1769
|
-
|
|
1770
|
-
def test_refute_in_epsilon_triggered
|
|
1771
|
-
assert_triggered "Expected |10000 - 9990| (10) to not be <= 10.0." do
|
|
1772
|
-
@tc.refute_in_epsilon 10_000, 9990
|
|
1773
|
-
flunk
|
|
1774
|
-
end
|
|
1775
|
-
end
|
|
1776
|
-
|
|
1777
|
-
def test_refute_includes
|
|
1778
|
-
@assertion_count = 2
|
|
1779
|
-
|
|
1780
|
-
@tc.refute_includes [true], false
|
|
1781
|
-
end
|
|
1782
|
-
|
|
1783
|
-
def test_refute_includes_triggered
|
|
1784
|
-
@assertion_count = 3
|
|
1785
|
-
|
|
1786
|
-
e = @tc.assert_raises Minitest::Assertion do
|
|
1787
|
-
@tc.refute_includes [true], true
|
|
1788
|
-
end
|
|
1789
|
-
|
|
1790
|
-
expected = "Expected [true] to not include true."
|
|
1791
|
-
assert_equal expected, e.message
|
|
1792
|
-
end
|
|
1793
|
-
|
|
1794
|
-
def test_refute_instance_of
|
|
1795
|
-
@tc.refute_instance_of Array, "blah"
|
|
1796
|
-
end
|
|
1797
|
-
|
|
1798
|
-
def test_refute_instance_of_triggered
|
|
1799
|
-
assert_triggered 'Expected "blah" to not be an instance of String.' do
|
|
1800
|
-
@tc.refute_instance_of String, "blah"
|
|
1801
|
-
end
|
|
1802
|
-
end
|
|
1803
|
-
|
|
1804
|
-
def test_refute_kind_of
|
|
1805
|
-
@tc.refute_kind_of Array, "blah"
|
|
1806
|
-
end
|
|
1807
|
-
|
|
1808
|
-
def test_refute_kind_of_triggered
|
|
1809
|
-
assert_triggered 'Expected "blah" to not be a kind of String.' do
|
|
1810
|
-
@tc.refute_kind_of String, "blah"
|
|
1811
|
-
end
|
|
1812
|
-
end
|
|
1813
|
-
|
|
1814
|
-
def test_refute_match
|
|
1815
|
-
@assertion_count = 2
|
|
1816
|
-
@tc.refute_match(/\d+/, "blah blah blah")
|
|
1817
|
-
end
|
|
1818
|
-
|
|
1819
|
-
def test_refute_match_matcher_object
|
|
1820
|
-
@assertion_count = 2
|
|
1821
|
-
@tc.refute_match Object.new, 5 # default #=~ returns false
|
|
1822
|
-
end
|
|
1823
|
-
|
|
1824
|
-
def test_refute_match_object_triggered
|
|
1825
|
-
@assertion_count = 2
|
|
1826
|
-
|
|
1827
|
-
pattern = Object.new
|
|
1828
|
-
def pattern.=~ _; true end
|
|
1829
|
-
def pattern.inspect; "[Object]" end
|
|
1830
|
-
|
|
1831
|
-
assert_triggered "Expected [Object] to not match 5." do
|
|
1832
|
-
@tc.refute_match pattern, 5
|
|
1833
|
-
end
|
|
1834
|
-
end
|
|
1835
|
-
|
|
1836
|
-
def test_refute_match_triggered
|
|
1837
|
-
@assertion_count = 2
|
|
1838
|
-
assert_triggered 'Expected /\w+/ to not match "blah blah blah".' do
|
|
1839
|
-
@tc.refute_match(/\w+/, "blah blah blah")
|
|
1840
|
-
end
|
|
1841
|
-
end
|
|
1842
|
-
|
|
1843
|
-
def test_refute_nil
|
|
1844
|
-
@tc.refute_nil 42
|
|
1845
|
-
end
|
|
1846
|
-
|
|
1847
|
-
def test_refute_nil_triggered
|
|
1848
|
-
assert_triggered "Expected nil to not be nil." do
|
|
1849
|
-
@tc.refute_nil nil
|
|
1850
|
-
end
|
|
1851
|
-
end
|
|
1852
|
-
|
|
1853
|
-
def test_refute_predicate
|
|
1854
|
-
@tc.refute_predicate "42", :empty?
|
|
1855
|
-
end
|
|
1856
|
-
|
|
1857
|
-
def test_refute_predicate_triggered
|
|
1858
|
-
assert_triggered 'Expected "" to not be empty?.' do
|
|
1859
|
-
@tc.refute_predicate "", :empty?
|
|
1860
|
-
end
|
|
1861
|
-
end
|
|
1862
|
-
|
|
1863
|
-
def test_refute_operator
|
|
1864
|
-
@tc.refute_operator 2, :<, 1
|
|
1865
|
-
end
|
|
1866
|
-
|
|
1867
|
-
def test_refute_operator_bad_object
|
|
1868
|
-
bad = Object.new
|
|
1869
|
-
def bad.== _; true end
|
|
1870
|
-
|
|
1871
|
-
@tc.refute_operator true, :equal?, bad
|
|
1872
|
-
end
|
|
1873
|
-
|
|
1874
|
-
def test_refute_operator_triggered
|
|
1875
|
-
assert_triggered "Expected 2 to not be > 1." do
|
|
1876
|
-
@tc.refute_operator 2, :>, 1
|
|
1877
|
-
end
|
|
1878
|
-
end
|
|
1879
|
-
|
|
1880
|
-
def test_refute_respond_to
|
|
1881
|
-
@tc.refute_respond_to "blah", :rawr!
|
|
1882
|
-
end
|
|
1883
|
-
|
|
1884
|
-
def test_refute_respond_to_triggered
|
|
1885
|
-
assert_triggered 'Expected "blah" to not respond to empty?.' do
|
|
1886
|
-
@tc.refute_respond_to "blah", :empty?
|
|
1887
|
-
end
|
|
1888
|
-
end
|
|
1889
|
-
|
|
1890
|
-
def test_refute_same
|
|
1891
|
-
@tc.refute_same 1, 2
|
|
1892
|
-
end
|
|
1893
|
-
|
|
1894
|
-
def test_refute_same_triggered
|
|
1895
|
-
assert_triggered "Expected 1 (oid=N) to not be the same as 1 (oid=N)." do
|
|
1896
|
-
@tc.refute_same 1, 1
|
|
1897
|
-
end
|
|
1898
|
-
end
|
|
1899
|
-
|
|
1900
|
-
def test_skip
|
|
1901
|
-
@assertion_count = 0
|
|
1902
|
-
|
|
1903
|
-
assert_triggered "haha!", Minitest::Skip do
|
|
1904
|
-
@tc.skip "haha!"
|
|
1905
|
-
end
|
|
1906
|
-
end
|
|
1907
|
-
|
|
1908
|
-
def test_runnable_methods_random
|
|
1909
|
-
@assertion_count = 0
|
|
1910
|
-
|
|
1911
|
-
sample_test_case = Class.new FakeNamedTest do
|
|
1912
|
-
def self.test_order; :random; end
|
|
1913
|
-
def test_test1; assert "does not matter" end
|
|
1914
|
-
def test_test2; assert "does not matter" end
|
|
1915
|
-
def test_test3; assert "does not matter" end
|
|
1916
|
-
end
|
|
1917
|
-
|
|
1918
|
-
srand 42
|
|
1919
|
-
expected = case
|
|
1920
|
-
when maglev? then
|
|
1921
|
-
%w[test_test2 test_test3 test_test1]
|
|
1922
|
-
else
|
|
1923
|
-
%w[test_test2 test_test1 test_test3]
|
|
1924
|
-
end
|
|
1925
|
-
assert_equal expected, sample_test_case.runnable_methods
|
|
1926
|
-
end
|
|
1927
|
-
|
|
1928
|
-
def test_runnable_methods_sorted
|
|
1929
|
-
@assertion_count = 0
|
|
1930
|
-
|
|
1931
|
-
sample_test_case = Class.new FakeNamedTest do
|
|
1932
|
-
def self.test_order; :sorted end
|
|
1933
|
-
def test_test3; assert "does not matter" end
|
|
1934
|
-
def test_test2; assert "does not matter" end
|
|
1935
|
-
def test_test1; assert "does not matter" end
|
|
1936
|
-
end
|
|
1937
|
-
|
|
1938
|
-
expected = %w[test_test1 test_test2 test_test3]
|
|
1939
|
-
assert_equal expected, sample_test_case.runnable_methods
|
|
1940
|
-
end
|
|
1941
|
-
|
|
1942
|
-
def test_i_suck_and_my_tests_are_order_dependent_bang_sets_test_order_alpha
|
|
1943
|
-
@assertion_count = 0
|
|
1944
|
-
|
|
1945
|
-
shitty_test_case = Class.new FakeNamedTest
|
|
1946
|
-
|
|
1947
|
-
shitty_test_case.i_suck_and_my_tests_are_order_dependent!
|
|
1948
|
-
|
|
1949
|
-
assert_equal :alpha, shitty_test_case.test_order
|
|
1950
|
-
end
|
|
1951
|
-
|
|
1952
|
-
def test_i_suck_and_my_tests_are_order_dependent_bang_does_not_warn
|
|
1953
|
-
@assertion_count = 0
|
|
1954
|
-
|
|
1955
|
-
shitty_test_case = Class.new FakeNamedTest
|
|
1956
|
-
|
|
1957
|
-
def shitty_test_case.test_order; :lol end
|
|
1958
|
-
|
|
1959
|
-
assert_silent do
|
|
1960
|
-
shitty_test_case.i_suck_and_my_tests_are_order_dependent!
|
|
1961
|
-
end
|
|
1962
|
-
end
|
|
1963
|
-
|
|
1964
|
-
def assert_triggered expected, klass = Minitest::Assertion
|
|
1965
|
-
e = assert_raises klass do
|
|
1966
|
-
yield
|
|
1967
|
-
end
|
|
1968
|
-
|
|
1969
|
-
msg = e.message.sub(/(---Backtrace---).*/m, '\1')
|
|
1970
|
-
msg.gsub!(/\(oid=[-0-9]+\)/, "(oid=N)")
|
|
1971
|
-
msg.gsub!(/(\d\.\d{6})\d+/, '\1xxx') # normalize: ruby version, impl, platform
|
|
1972
|
-
|
|
1973
|
-
assert_msg = Regexp === expected ? :assert_match : :assert_equal
|
|
1974
|
-
self.send assert_msg, expected, msg
|
|
1975
|
-
end
|
|
1976
|
-
|
|
1977
|
-
def util_msg exp, act, msg = nil
|
|
1978
|
-
s = "Expected: #{exp.inspect}\n Actual: #{act.inspect}"
|
|
1979
|
-
s = "#{msg}.\n#{s}" if msg
|
|
1980
|
-
s
|
|
1981
|
-
end
|
|
1982
|
-
|
|
1983
|
-
def without_diff
|
|
1984
|
-
old_diff = Minitest::Assertions.diff
|
|
1985
|
-
Minitest::Assertions.diff = nil
|
|
1986
|
-
|
|
1987
|
-
yield
|
|
1988
|
-
ensure
|
|
1989
|
-
Minitest::Assertions.diff = old_diff
|
|
1990
|
-
end
|
|
1991
|
-
end
|
|
1992
|
-
|
|
1993
|
-
class TestMinitestGuard < Minitest::Test
|
|
1994
|
-
parallelize_me!
|
|
1995
|
-
|
|
1996
|
-
def test_mri_eh
|
|
1997
|
-
assert self.class.mri? "ruby blah"
|
|
1998
|
-
assert self.mri? "ruby blah"
|
|
1999
|
-
end
|
|
2000
|
-
|
|
2001
|
-
def test_jruby_eh
|
|
2002
|
-
assert self.class.jruby? "java"
|
|
2003
|
-
assert self.jruby? "java"
|
|
2004
|
-
end
|
|
2005
|
-
|
|
2006
|
-
def test_rubinius_eh
|
|
2007
|
-
assert self.class.rubinius? "rbx"
|
|
2008
|
-
assert self.rubinius? "rbx"
|
|
2009
|
-
end
|
|
2010
|
-
|
|
2011
|
-
def test_windows_eh
|
|
2012
|
-
assert self.class.windows? "mswin"
|
|
2013
|
-
assert self.windows? "mswin"
|
|
2014
|
-
end
|
|
2015
|
-
end
|
|
1154
|
+
end
|
|
2016
1155
|
|
|
2017
1156
|
class TestMinitestUnitRecording < MetaMetaMetaTestCase
|
|
2018
1157
|
# do not parallelize this suite... it just can't handle it.
|
|
@@ -2039,7 +1178,7 @@ class TestMinitestUnitRecording < MetaMetaMetaTestCase
|
|
|
2039
1178
|
bogus_reporter = Class.new do # doesn't subclass AbstractReporter
|
|
2040
1179
|
def start; @success = false; end
|
|
2041
1180
|
# def prerecord klass, name; end # doesn't define full API
|
|
2042
|
-
def record
|
|
1181
|
+
def record _result; @success = true; end
|
|
2043
1182
|
def report; end
|
|
2044
1183
|
def passed?; end
|
|
2045
1184
|
def results; end
|
|
@@ -2117,17 +1256,17 @@ class TestMinitestUnitRecording < MetaMetaMetaTestCase
|
|
|
2117
1256
|
|
|
2118
1257
|
run_tu_with_fresh_reporter
|
|
2119
1258
|
|
|
2120
|
-
exp =
|
|
1259
|
+
exp = <<~EOM
|
|
2121
1260
|
Error:
|
|
2122
1261
|
FakeNamedTestXX#test_method:
|
|
2123
1262
|
AnError: AnError
|
|
2124
|
-
FILE:LINE:in
|
|
1263
|
+
FILE:LINE:in 'test_method'
|
|
2125
1264
|
|
|
2126
1265
|
Error:
|
|
2127
1266
|
FakeNamedTestXX#test_method:
|
|
2128
1267
|
RuntimeError: unhandled exception
|
|
2129
|
-
FILE:LINE:in
|
|
2130
|
-
|
|
1268
|
+
FILE:LINE:in 'teardown'
|
|
1269
|
+
EOM
|
|
2131
1270
|
|
|
2132
1271
|
assert_equal exp.strip, normalize_output(first_reporter.results.first.to_s).strip
|
|
2133
1272
|
end
|
|
@@ -2140,3 +1279,96 @@ class TestMinitestUnitRecording < MetaMetaMetaTestCase
|
|
|
2140
1279
|
end
|
|
2141
1280
|
end
|
|
2142
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
|