minitest 5.20.0 → 5.25.1

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.
@@ -13,10 +13,6 @@ class TestMinitestReporter < MetaMetaMetaTestCase
13
13
  attr_accessor :r, :io
14
14
 
15
15
  def new_composite_reporter
16
- # Ruby bug in older versions of 2.2 & 2.3 on all platforms
17
- # Latest Windows builds were 2.2.6 and 2.3.3. Latest Ruby releases were
18
- # 2.2.10 and 2.3.8.
19
- skip if windows? && RUBY_VERSION < '2.4'
20
16
  reporter = Minitest::CompositeReporter.new
21
17
  reporter << Minitest::SummaryReporter.new(self.io)
22
18
  reporter << Minitest::ProgressReporter.new(self.io)
@@ -31,13 +27,13 @@ class TestMinitestReporter < MetaMetaMetaTestCase
31
27
 
32
28
  def setup
33
29
  super
34
- self.io = StringIO.new("")
30
+ self.io = StringIO.new(+"")
35
31
  self.r = new_composite_reporter
36
32
  end
37
33
 
38
34
  def error_test
39
35
  unless defined? @et then
40
- @et = Minitest::Test.new(:woot)
36
+ @et = Minitest::Test.new :woot
41
37
  @et.failures << Minitest::UnexpectedError.new(begin
42
38
  raise "no"
43
39
  rescue => e
@@ -48,9 +44,28 @@ class TestMinitestReporter < MetaMetaMetaTestCase
48
44
  @et
49
45
  end
50
46
 
47
+ def system_stack_error_test
48
+ unless defined? @sse then
49
+
50
+ ex = SystemStackError.new
51
+
52
+ pre = ("a".."c").to_a
53
+ mid = ("aa".."ad").to_a * 67
54
+ post = ("d".."f").to_a
55
+ ary = pre + mid + post
56
+
57
+ ex.set_backtrace ary
58
+
59
+ @sse = Minitest::Test.new :woot
60
+ @sse.failures << Minitest::UnexpectedError.new(ex)
61
+ @sse = Minitest::Result.from @sse
62
+ end
63
+ @sse
64
+ end
65
+
51
66
  def fail_test
52
67
  unless defined? @ft then
53
- @ft = Minitest::Test.new(:woot)
68
+ @ft = Minitest::Test.new :woot
54
69
  @ft.failures << begin
55
70
  raise Minitest::Assertion, "boo"
56
71
  rescue Minitest::Assertion => e
@@ -66,14 +81,14 @@ class TestMinitestReporter < MetaMetaMetaTestCase
66
81
  end
67
82
 
68
83
  def passing_test_with_metadata
69
- test = Minitest::Test.new(:woot)
84
+ test = Minitest::Test.new :woot
70
85
  test.metadata[:meta] = :data
71
86
  @pt ||= Minitest::Result.from test
72
87
  end
73
88
 
74
89
  def skip_test
75
90
  unless defined? @st then
76
- @st = Minitest::Test.new(:woot)
91
+ @st = Minitest::Test.new :woot
77
92
  @st.failures << begin
78
93
  raise Minitest::Skip
79
94
  rescue Minitest::Assertion => e
@@ -229,7 +244,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
229
244
  r.start
230
245
  r.report
231
246
 
232
- exp = clean <<-EOM
247
+ exp = <<~EOM
233
248
  Run options:
234
249
 
235
250
  # Running:
@@ -249,7 +264,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
249
264
  r.record passing_test
250
265
  r.report
251
266
 
252
- exp = clean <<-EOM
267
+ exp = <<~EOM
253
268
  Run options:
254
269
 
255
270
  # Running:
@@ -269,7 +284,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
269
284
  r.record fail_test
270
285
  r.report
271
286
 
272
- exp = clean <<-EOM
287
+ exp = <<~EOM
273
288
  Run options:
274
289
 
275
290
  # Running:
@@ -293,7 +308,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
293
308
  r.record error_test
294
309
  r.report
295
310
 
296
- exp = clean <<-EOM
311
+ exp = <<~EOM
297
312
  Run options:
298
313
 
299
314
  # Running:
@@ -305,8 +320,44 @@ class TestMinitestReporter < MetaMetaMetaTestCase
305
320
  1) Error:
306
321
  Minitest::Test#woot:
307
322
  RuntimeError: no
308
- FILE:LINE:in `error_test'
309
- FILE:LINE:in `test_report_error'
323
+ FILE:LINE:in 'error_test'
324
+ FILE:LINE:in 'test_report_error'
325
+
326
+ 1 runs, 0 assertions, 0 failures, 1 errors, 0 skips
327
+ EOM
328
+
329
+ assert_equal exp, normalize_output(io.string)
330
+ end
331
+
332
+ def test_report_error__sse
333
+ r.start
334
+ r.record system_stack_error_test
335
+ r.report
336
+
337
+ exp = <<~EOM
338
+ Run options:
339
+
340
+ # Running:
341
+
342
+ E
343
+
344
+ Finished in 0.00
345
+
346
+ 1) Error:
347
+ Minitest::Test#woot:
348
+ SystemStackError: 274 -> 12
349
+ a
350
+ b
351
+ c
352
+ +->> 67 cycles of 4 lines:
353
+ | aa
354
+ | ab
355
+ | ac
356
+ | ad
357
+ +-<<
358
+ d
359
+ e
360
+ f
310
361
 
311
362
  1 runs, 0 assertions, 0 failures, 1 errors, 0 skips
312
363
  EOM
@@ -322,7 +373,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
322
373
  r.report
323
374
  end
324
375
 
325
- exp = clean <<-EOM
376
+ exp = <<~EOM
326
377
  Run options:
327
378
 
328
379
  # Running:
@@ -338,4 +389,48 @@ class TestMinitestReporter < MetaMetaMetaTestCase
338
389
 
339
390
  assert_equal exp, normalize_output(io.string)
340
391
  end
392
+
393
+ def test_report_failure_uses_backtrace_filter
394
+ filter = Minitest::BacktraceFilter.new
395
+ def filter.filter _bt
396
+ ["foo.rb:123:in 'foo'"]
397
+ end
398
+
399
+ with_backtrace_filter filter do
400
+ r.start
401
+ r.record fail_test
402
+ r.report
403
+ end
404
+
405
+ exp = "Minitest::Test#woot [foo.rb:123]"
406
+
407
+ assert_includes io.string, exp
408
+ end
409
+
410
+ def test_report_failure_uses_backtrace_filter_complex_sorbet
411
+ backtrace = <<~EOBT
412
+ /Users/user/.gem/ruby/3.2.2/gems/minitest-5.20.0/lib/minitest/assertions.rb:183:in 'assert'
413
+ example_test.rb:9:in 'assert_false'
414
+ /Users/user/.gem/ruby/3.2.2/gems/sorbet-runtime-0.5.11068/lib/types/private/methods/call_validation.rb:256:in 'bind_call'
415
+ /Users/user/.gem/ruby/3.2.2/gems/sorbet-runtime-0.5.11068/lib/types/private/methods/call_validation.rb:256:in 'validate_call'
416
+ /Users/user/.gem/ruby/3.2.2/gems/sorbet-runtime-0.5.11068/lib/types/private/methods/_methods.rb:275:in 'block in _on_method_added'
417
+ example_test.rb:25:in 'test_something'
418
+ /Users/user/.gem/ruby/3.2.2/gems/minitest-5.20.0/lib/minitest/test.rb:94:in 'block (3 levels) in run'
419
+ /Users/user/.gem/ruby/3.2.2/gems/minitest-5.20.0/lib/minitest/test.rb:191:in 'capture_exceptions'
420
+ /Users/user/.gem/ruby/3.2.2/gems/minitest-5.20.0/lib/minitest/test.rb:89:in 'block (2 levels) in run'
421
+ ... so many lines ...
422
+ EOBT
423
+
424
+ filter = Minitest::BacktraceFilter.new %r%lib/minitest|gems/sorbet%
425
+
426
+ with_backtrace_filter filter do
427
+ begin
428
+ assert_equal 1, 2
429
+ rescue Minitest::Assertion => e
430
+ e.set_backtrace backtrace.lines.map(&:chomp)
431
+
432
+ assert_match "example_test.rb:25", e.location
433
+ end
434
+ end
435
+ end
341
436
  end
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  require "minitest/metametameta"
3
2
  require "stringio"
4
3
 
@@ -12,15 +11,12 @@ class ExampleA; end
12
11
  class ExampleB < ExampleA; end
13
12
 
14
13
  describe Minitest::Spec do
15
- # helps to deal with 2.4 deprecation of Fixnum for Integer
16
- Int = 1.class
17
-
18
14
  # do not parallelize this suite... it just can"t handle it.
19
15
 
20
16
  def assert_triggered expected = "blah", klass = Minitest::Assertion
21
17
  @assertion_count += 1
22
18
 
23
- e = assert_raises(klass) do
19
+ e = assert_raises klass do
24
20
  yield
25
21
  end
26
22
 
@@ -29,17 +25,17 @@ describe Minitest::Spec do
29
25
  msg.gsub!(/(\d\.\d{6})\d+/, '\1xxx') # normalize: ruby version, impl, platform
30
26
  msg.gsub!(/:0x[Xa-fA-F0-9]{4,}[ @].+?>/, ":0xXXXXXX@PATH>")
31
27
 
32
- if expected
28
+ return unless expected
29
+
30
+ @assertion_count += 1
31
+ case expected
32
+ when String then
33
+ assert_equal expected, msg
34
+ when Regexp then
33
35
  @assertion_count += 1
34
- case expected
35
- when String then
36
- assert_equal expected, msg
37
- when Regexp then
38
- @assertion_count += 1
39
- assert_match expected, msg
40
- else
41
- flunk "Unknown: #{expected.inspect}"
42
- end
36
+ assert_match expected, msg
37
+ else
38
+ flunk "Unknown: #{expected.inspect}"
43
39
  end
44
40
  end
45
41
 
@@ -196,7 +192,7 @@ describe Minitest::Spec do
196
192
  methods = Minitest::Expectations.public_instance_methods.grep(/must|wont/)
197
193
  methods.map!(&:to_s) if Symbol === methods.first
198
194
 
199
- musts, wonts = methods.sort.partition { |m| m =~ /must/ }
195
+ musts, wonts = methods.sort.partition { |m| m.include? "must" }
200
196
 
201
197
  expected_musts = %w[must_be
202
198
  must_be_close_to
@@ -220,7 +216,7 @@ describe Minitest::Spec do
220
216
 
221
217
  bad = %w[not raise throw send output be_silent]
222
218
 
223
- expected_wonts = expected_musts.map { |m| m.sub(/must/, "wont") }.sort
219
+ expected_wonts = expected_musts.map { |m| m.sub("must", "wont") }.sort
224
220
  expected_wonts.reject! { |m| m =~ /wont_#{Regexp.union(*bad)}/ }
225
221
 
226
222
  _(musts).must_equal expected_musts
@@ -284,18 +280,14 @@ describe Minitest::Spec do
284
280
  end
285
281
 
286
282
  it "needs to warn on equality with nil" do
287
- @assertion_count += 1 # extra test
283
+ @assertion_count = 3
284
+ @assertion_count += 2 unless error_on_warn? # 2 extra assertions
288
285
 
289
- out, err = capture_io do
286
+ exp = /DEPRECATED: Use assert_nil if expecting nil from .* This will fail in Minitest 6./
287
+
288
+ assert_deprecation exp do
290
289
  assert_success _(nil).must_equal(nil)
291
290
  end
292
-
293
- exp = "DEPRECATED: Use assert_nil if expecting nil from #{__FILE__}:#{__LINE__-3}. " \
294
- "This will fail in Minitest 6.\n"
295
- exp = "" if $-w.nil?
296
-
297
- assert_empty out
298
- assert_equal exp, err
299
291
  end
300
292
 
301
293
  it "needs to verify floats outside a delta" do
@@ -403,12 +395,12 @@ describe Minitest::Spec do
403
395
  it "needs to verify instances of a class" do
404
396
  assert_success _(42).wont_be_instance_of(String)
405
397
 
406
- assert_triggered "Expected 42 to not be a kind of #{Int.name}." do
407
- _(42).wont_be_kind_of Int
398
+ assert_triggered "Expected 42 to not be a kind of Integer." do
399
+ _(42).wont_be_kind_of Integer
408
400
  end
409
401
 
410
- assert_triggered "msg.\nExpected 42 to not be an instance of #{Int.name}." do
411
- _(42).wont_be_instance_of Int, "msg"
402
+ assert_triggered "msg.\nExpected 42 to not be an instance of Integer." do
403
+ _(42).wont_be_instance_of Integer, "msg"
412
404
  end
413
405
  end
414
406
 
@@ -418,26 +410,26 @@ describe Minitest::Spec do
418
410
  assert_success _(42).wont_be_kind_of(String)
419
411
  assert_success _(proc {}).wont_be_kind_of(String)
420
412
 
421
- assert_triggered "Expected 42 to not be a kind of #{Int.name}." do
422
- _(42).wont_be_kind_of Int
413
+ assert_triggered "Expected 42 to not be a kind of Integer." do
414
+ _(42).wont_be_kind_of Integer
423
415
  end
424
416
 
425
- assert_triggered "msg.\nExpected 42 to not be a kind of #{Int.name}." do
426
- _(42).wont_be_kind_of Int, "msg"
417
+ assert_triggered "msg.\nExpected 42 to not be a kind of Integer." do
418
+ _(42).wont_be_kind_of Integer, "msg"
427
419
  end
428
420
  end
429
421
 
430
422
  it "needs to verify kinds of objects" do
431
423
  @assertion_count += 3 # extra test
432
424
 
433
- assert_success _(6 * 7).must_be_kind_of(Int)
425
+ assert_success _(6 * 7).must_be_kind_of(Integer)
434
426
  assert_success _(6 * 7).must_be_kind_of(Numeric)
435
427
 
436
- assert_triggered "Expected 42 to be a kind of String, not #{Int.name}." do
428
+ assert_triggered "Expected 42 to be a kind of String, not Integer." do
437
429
  _(6 * 7).must_be_kind_of String
438
430
  end
439
431
 
440
- assert_triggered "msg.\nExpected 42 to be a kind of String, not #{Int.name}." do
432
+ assert_triggered "msg.\nExpected 42 to be a kind of String, not Integer." do
441
433
  _(6 * 7).must_be_kind_of String, "msg"
442
434
  end
443
435
 
@@ -576,7 +568,8 @@ describe Minitest::Spec do
576
568
 
577
569
  it "can NOT use must_equal in a thread. It must use expect in a thread" do
578
570
  skip "N/A" if ENV["MT_NO_EXPECTATIONS"]
579
- assert_raises RuntimeError do
571
+
572
+ assert_raises RuntimeError, Minitest::UnexpectedWarning do
580
573
  capture_io do
581
574
  Thread.new { (1 + 1).must_equal 2 }.join
582
575
  end
@@ -586,29 +579,33 @@ describe Minitest::Spec do
586
579
  it "fails gracefully when expectation used outside of `it`" do
587
580
  skip "N/A" if ENV["MT_NO_EXPECTATIONS"]
588
581
 
589
- @assertion_count += 1
582
+ @assertion_count += 2 # assert_match is compound
590
583
 
591
- e = assert_raises RuntimeError do
584
+ e = assert_raises RuntimeError, Minitest::UnexpectedWarning do
592
585
  capture_io do
593
586
  Thread.new { # forces ctx to be nil
594
- describe("woot") do
587
+ describe "woot" do
595
588
  (1 + 1).must_equal 2
596
589
  end
597
590
  }.join
598
591
  end
599
592
  end
600
593
 
601
- assert_equal "Calling #must_equal outside of test.", e.message
594
+ exp = "Calling #must_equal outside of test."
595
+ exp = "DEPRECATED: global use of must_equal from" if error_on_warn?
596
+
597
+ assert_match exp, e.message
602
598
  end
603
599
 
604
600
  it "deprecates expectation used without _" do
605
601
  skip "N/A" if ENV["MT_NO_EXPECTATIONS"]
606
602
 
607
- @assertion_count += 3
603
+ @assertion_count += 1
604
+ @assertion_count += 2 unless error_on_warn?
608
605
 
609
606
  exp = /DEPRECATED: global use of must_equal from/
610
607
 
611
- assert_output "", exp do
608
+ assert_deprecation exp do
612
609
  (1 + 1).must_equal 2
613
610
  end
614
611
  end
@@ -618,12 +615,13 @@ describe Minitest::Spec do
618
615
  it "deprecates expectation used without _ with empty backtrace_filter" do
619
616
  skip "N/A" if ENV["MT_NO_EXPECTATIONS"]
620
617
 
621
- @assertion_count += 3
618
+ @assertion_count += 1
619
+ @assertion_count += 2 unless error_on_warn?
622
620
 
623
621
  exp = /DEPRECATED: global use of must_equal from/
624
622
 
625
623
  with_empty_backtrace_filter do
626
- assert_output "", exp do
624
+ assert_deprecation exp do
627
625
  (1 + 1).must_equal 2
628
626
  end
629
627
  end
@@ -654,9 +652,9 @@ describe Minitest::Spec do
654
652
  end
655
653
 
656
654
  it "needs to verify types of objects" do
657
- assert_success _(6 * 7).must_be_instance_of(Int)
655
+ assert_success _(6 * 7).must_be_instance_of(Integer)
658
656
 
659
- exp = "Expected 42 to be an instance of String, not #{Int.name}."
657
+ exp = "Expected 42 to be an instance of String, not Integer."
660
658
 
661
659
  assert_triggered exp do
662
660
  _(6 * 7).must_be_instance_of String
@@ -683,7 +681,7 @@ describe Minitest::Spec do
683
681
  assert_success _(41).must_be(:<, 42)
684
682
 
685
683
  assert_triggered "Expected 42 to be < 41." do
686
- _(42).must_be(:<, 41)
684
+ _(42).must_be :<, 41
687
685
  end
688
686
  end
689
687
 
@@ -700,11 +698,11 @@ describe Minitest::Spec do
700
698
  it "needs to verify using respond_to" do
701
699
  assert_success _(42).must_respond_to(:+)
702
700
 
703
- assert_triggered "Expected 42 (#{Int.name}) to respond to #clear." do
701
+ assert_triggered "Expected 42 (Integer) to respond to #clear." do
704
702
  _(42).must_respond_to :clear
705
703
  end
706
704
 
707
- assert_triggered "msg.\nExpected 42 (#{Int.name}) to respond to #clear." do
705
+ assert_triggered "msg.\nExpected 42 (Integer) to respond to #clear." do
708
706
  _(42).must_respond_to :clear, "msg"
709
707
  end
710
708
  end
@@ -751,9 +749,9 @@ describe Minitest::Spec, :let do
751
749
  it "doesn't raise an error if it is just another let" do
752
750
  v = proc do
753
751
  describe :outer do
754
- let(:bar)
752
+ let :bar
755
753
  describe :inner do
756
- let(:bar)
754
+ let :bar
757
755
  end
758
756
  end
759
757
  :good
@@ -1016,8 +1014,9 @@ class TestMeta < MetaMetaMetaTestCase
1016
1014
  z = describe "second thingy" do end
1017
1015
  end
1018
1016
 
1019
- test_methods = ["test_0001_top level it",
1020
- "test_0002_не латинские &いった α, β, γ, δ, ε hello!!! world",
1017
+ test_methods = [
1018
+ "test_0001_top level it",
1019
+ "test_0002_не латинские &いった α, β, γ, δ, ε hello!!! world",
1021
1020
  ].sort
1022
1021
 
1023
1022
  assert_equal test_methods, [x1, x2]