minitest 5.18.1 → 5.23.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.
@@ -423,10 +423,12 @@ class TestMinitestMock < Minitest::Test
423
423
  arg1, arg2, arg3 = :bar, [1, 2, 3], { :a => "a" }
424
424
  mock = Minitest::Mock.new
425
425
 
426
- assert_output nil, /Using MT_KWARGS_HAC. yet passing kwargs/ do
426
+ assert_deprecation(/Using MT_KWARGS_HAC. yet passing kwargs/) do
427
427
  mock.expect :foo, nil, [{}], k1: arg1, k2: arg2, k3: arg3
428
428
  end
429
429
 
430
+ skip "-Werror" if error_on_warn? # mock above raised, so this is dead
431
+
430
432
  mock.foo({}, k1: arg1, k2: arg2, k3: arg3)
431
433
 
432
434
  assert_mock mock
@@ -686,7 +688,7 @@ class TestMinitestStub < Minitest::Test
686
688
  end
687
689
 
688
690
  def test_stub_yield_self
689
- obj = "foo"
691
+ obj = +"foo"
690
692
 
691
693
  val = obj.stub :to_s, "bar" do |s|
692
694
  s.to_s
@@ -728,7 +730,7 @@ class TestMinitestStub < Minitest::Test
728
730
  end
729
731
 
730
732
  exp = jruby? ? /Undefined method nope_nope_nope for '#{self.class}::Time'/ :
731
- /undefined method `nope_nope_nope' for( class)? `#{self.class}::Time'/
733
+ /undefined method [`']nope_nope_nope' for( class)? [`']#{self.class}::Time'/
732
734
  assert_match exp, e.message
733
735
  end
734
736
 
@@ -816,7 +818,7 @@ class TestMinitestStub < Minitest::Test
816
818
  # [:value, :block_call, :args] => N/A
817
819
 
818
820
  class Bar
819
- def call
821
+ def call(&_) # to ignore unused block
820
822
  puts "hi"
821
823
  end
822
824
  end
@@ -956,7 +958,7 @@ class TestMinitestStub < Minitest::Test
956
958
  def test_stub_lambda_block_call_5
957
959
  @assertion_count += 1
958
960
  rs = nil
959
- io = StringIO.new "", "w"
961
+ io = StringIO.new(+"", "w")
960
962
  File.stub5 :open, lambda { |p, m, &blk| blk and blk.call io } do
961
963
  File.open "foo.txt", "r" do |f|
962
964
  rs = f && f.write("woot")
@@ -971,7 +973,7 @@ class TestMinitestStub < Minitest::Test
971
973
 
972
974
  @assertion_count += 1
973
975
  rs = nil
974
- io = StringIO.new "", "w"
976
+ io = StringIO.new(+"", "w")
975
977
  File.stub6 :open, lambda { |p, m, &blk| blk.call io } do
976
978
  File.open "foo.txt", "r" do |f|
977
979
  rs = f.write("woot")
@@ -984,7 +986,7 @@ class TestMinitestStub < Minitest::Test
984
986
  def test_stub_lambda_block_call_args_5
985
987
  @assertion_count += 1
986
988
  rs = nil
987
- io = StringIO.new "", "w"
989
+ io = StringIO.new(+"", "w")
988
990
  File.stub5(:open, lambda { |p, m, &blk| blk and blk.call io }, :WTF?) do
989
991
  File.open "foo.txt", "r" do |f|
990
992
  rs = f.write("woot")
@@ -999,7 +1001,7 @@ class TestMinitestStub < Minitest::Test
999
1001
 
1000
1002
  @assertion_count += 1
1001
1003
  rs = nil
1002
- io = StringIO.new "", "w"
1004
+ io = StringIO.new(+"", "w")
1003
1005
  File.stub6(:open, lambda { |p, m, &blk| blk.call io }, :WTF?) do
1004
1006
  File.open "foo.txt", "r" do |f|
1005
1007
  rs = f.write("woot")
@@ -1014,7 +1016,7 @@ class TestMinitestStub < Minitest::Test
1014
1016
 
1015
1017
  @assertion_count += 2
1016
1018
  rs = nil
1017
- io = StringIO.new "", "w"
1019
+ io = StringIO.new(+"", "w")
1018
1020
  @tc.assert_raises ArgumentError do
1019
1021
  File.stub6_2(:open, lambda { |p, m, &blk| blk.call io }, :WTF?) do
1020
1022
  File.open "foo.txt", "r" do |f|
@@ -1064,7 +1066,7 @@ class TestMinitestStub < Minitest::Test
1064
1066
  def test_stub_value_block_args_5
1065
1067
  @assertion_count += 2
1066
1068
  rs = nil
1067
- io = StringIO.new "", "w"
1069
+ io = StringIO.new(+"", "w")
1068
1070
  File.stub5 :open, :value, io do
1069
1071
  result = File.open "foo.txt", "r" do |f|
1070
1072
  rs = f.write("woot")
@@ -1083,7 +1085,7 @@ class TestMinitestStub < Minitest::Test
1083
1085
  end
1084
1086
  end
1085
1087
  end
1086
- exp = /undefined method `write' for nil/
1088
+ exp = /undefined method [`']write' for nil/
1087
1089
  assert_match exp, e.message
1088
1090
  end
1089
1091
 
@@ -1092,7 +1094,7 @@ class TestMinitestStub < Minitest::Test
1092
1094
 
1093
1095
  @assertion_count += 2
1094
1096
  rs = nil
1095
- io = StringIO.new "", "w"
1097
+ io = StringIO.new(+"", "w")
1096
1098
  assert_deprecated do
1097
1099
  File.stub6 :open, :value, io do
1098
1100
  result = File.open "foo.txt", "r" do |f|
@@ -1110,7 +1112,7 @@ class TestMinitestStub < Minitest::Test
1110
1112
 
1111
1113
  @assertion_count += 2
1112
1114
  rs = nil
1113
- io = StringIO.new "", "w"
1115
+ io = StringIO.new(+"", "w")
1114
1116
  @tc.assert_raises ArgumentError do
1115
1117
  File.stub6_2 :open, :value, io do
1116
1118
  result = File.open "foo.txt", "r" do |f|
@@ -31,7 +31,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
31
31
 
32
32
  def setup
33
33
  super
34
- self.io = StringIO.new("")
34
+ self.io = StringIO.new(+"")
35
35
  self.r = new_composite_reporter
36
36
  end
37
37
 
@@ -48,6 +48,25 @@ class TestMinitestReporter < MetaMetaMetaTestCase
48
48
  @et
49
49
  end
50
50
 
51
+ def system_stack_error_test
52
+ unless defined? @sse then
53
+
54
+ ex = SystemStackError.new
55
+
56
+ pre = ("a".."c").to_a
57
+ mid = ("aa".."ad").to_a * 67
58
+ post = ("d".."f").to_a
59
+ ary = pre + mid + post
60
+
61
+ ex.set_backtrace ary
62
+
63
+ @sse = Minitest::Test.new(:woot)
64
+ @sse.failures << Minitest::UnexpectedError.new(ex)
65
+ @sse = Minitest::Result.from @sse
66
+ end
67
+ @sse
68
+ end
69
+
51
70
  def fail_test
52
71
  unless defined? @ft then
53
72
  @ft = Minitest::Test.new(:woot)
@@ -65,6 +84,12 @@ class TestMinitestReporter < MetaMetaMetaTestCase
65
84
  @pt ||= Minitest::Result.from Minitest::Test.new(:woot)
66
85
  end
67
86
 
87
+ def passing_test_with_metadata
88
+ test = Minitest::Test.new(:woot)
89
+ test.metadata[:meta] = :data
90
+ @pt ||= Minitest::Result.from test
91
+ end
92
+
68
93
  def skip_test
69
94
  unless defined? @st then
70
95
  @st = Minitest::Test.new(:woot)
@@ -166,6 +191,29 @@ class TestMinitestReporter < MetaMetaMetaTestCase
166
191
  assert_equal 0, r.assertions
167
192
  end
168
193
 
194
+ def test_record_pass_with_metadata
195
+ reporter = self.r
196
+
197
+ def reporter.metadata
198
+ @metadata
199
+ end
200
+
201
+ def reporter.record result
202
+ super
203
+ @metadata = result.metadata if result.metadata?
204
+ end
205
+
206
+ r.record passing_test_with_metadata
207
+
208
+ exp = { :meta => :data }
209
+ assert_equal exp, reporter.metadata
210
+
211
+ assert_equal ".", io.string
212
+ assert_empty r.results
213
+ assert_equal 1, r.count
214
+ assert_equal 0, r.assertions
215
+ end
216
+
169
217
  def test_record_fail
170
218
  fail_test = self.fail_test
171
219
  r.record fail_test
@@ -276,8 +324,44 @@ class TestMinitestReporter < MetaMetaMetaTestCase
276
324
  1) Error:
277
325
  Minitest::Test#woot:
278
326
  RuntimeError: no
279
- FILE:LINE:in `error_test'
280
- FILE:LINE:in `test_report_error'
327
+ FILE:LINE:in 'error_test'
328
+ FILE:LINE:in 'test_report_error'
329
+
330
+ 1 runs, 0 assertions, 0 failures, 1 errors, 0 skips
331
+ EOM
332
+
333
+ assert_equal exp, normalize_output(io.string)
334
+ end
335
+
336
+ def test_report_error__sse
337
+ r.start
338
+ r.record system_stack_error_test
339
+ r.report
340
+
341
+ exp = clean <<-EOM
342
+ Run options:
343
+
344
+ # Running:
345
+
346
+ E
347
+
348
+ Finished in 0.00
349
+
350
+ 1) Error:
351
+ Minitest::Test#woot:
352
+ SystemStackError: 274 -> 12
353
+ a
354
+ b
355
+ c
356
+ +->> 67 cycles of 4 lines:
357
+ | aa
358
+ | ab
359
+ | ac
360
+ | ad
361
+ +-<<
362
+ d
363
+ e
364
+ f
281
365
 
282
366
  1 runs, 0 assertions, 0 failures, 1 errors, 0 skips
283
367
  EOM
@@ -309,4 +393,48 @@ class TestMinitestReporter < MetaMetaMetaTestCase
309
393
 
310
394
  assert_equal exp, normalize_output(io.string)
311
395
  end
396
+
397
+ def test_report_failure_uses_backtrace_filter
398
+ filter = Minitest::BacktraceFilter.new
399
+ def filter.filter _bt
400
+ ["foo.rb:123:in 'foo'"]
401
+ end
402
+
403
+ with_backtrace_filter filter do
404
+ r.start
405
+ r.record fail_test
406
+ r.report
407
+ end
408
+
409
+ exp = "Minitest::Test#woot [foo.rb:123]"
410
+
411
+ assert_includes io.string, exp
412
+ end
413
+
414
+ def test_report_failure_uses_backtrace_filter_complex_sorbet
415
+ backtrace = <<~EOBT
416
+ /Users/user/.gem/ruby/3.2.2/gems/minitest-5.20.0/lib/minitest/assertions.rb:183:in 'assert'
417
+ example_test.rb:9:in 'assert_false'
418
+ /Users/user/.gem/ruby/3.2.2/gems/sorbet-runtime-0.5.11068/lib/types/private/methods/call_validation.rb:256:in 'bind_call'
419
+ /Users/user/.gem/ruby/3.2.2/gems/sorbet-runtime-0.5.11068/lib/types/private/methods/call_validation.rb:256:in 'validate_call'
420
+ /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'
421
+ example_test.rb:25:in 'test_something'
422
+ /Users/user/.gem/ruby/3.2.2/gems/minitest-5.20.0/lib/minitest/test.rb:94:in 'block (3 levels) in run'
423
+ /Users/user/.gem/ruby/3.2.2/gems/minitest-5.20.0/lib/minitest/test.rb:191:in 'capture_exceptions'
424
+ /Users/user/.gem/ruby/3.2.2/gems/minitest-5.20.0/lib/minitest/test.rb:89:in 'block (2 levels) in run'
425
+ ... so many lines ...
426
+ EOBT
427
+
428
+ filter = Minitest::BacktraceFilter.new %r%lib/minitest|gems/sorbet%
429
+
430
+ with_backtrace_filter filter do
431
+ begin
432
+ assert_equal 1, 2
433
+ rescue Minitest::Assertion => e
434
+ e.set_backtrace backtrace.lines.map(&:chomp)
435
+
436
+ assert_match "example_test.rb:25", e.location
437
+ end
438
+ end
439
+ end
312
440
  end
@@ -284,18 +284,14 @@ describe Minitest::Spec do
284
284
  end
285
285
 
286
286
  it "needs to warn on equality with nil" do
287
- @assertion_count += 1 # extra test
287
+ @assertion_count = 3
288
+ @assertion_count += 2 unless error_on_warn? # 2 extra assertions
289
+
290
+ exp = /DEPRECATED: Use assert_nil if expecting nil from .* This will fail in Minitest 6./
288
291
 
289
- out, err = capture_io do
292
+ assert_deprecation exp do
290
293
  assert_success _(nil).must_equal(nil)
291
294
  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
295
  end
300
296
 
301
297
  it "needs to verify floats outside a delta" do
@@ -576,7 +572,8 @@ describe Minitest::Spec do
576
572
 
577
573
  it "can NOT use must_equal in a thread. It must use expect in a thread" do
578
574
  skip "N/A" if ENV["MT_NO_EXPECTATIONS"]
579
- assert_raises RuntimeError do
575
+
576
+ assert_raises RuntimeError, Minitest::UnexpectedWarning do
580
577
  capture_io do
581
578
  Thread.new { (1 + 1).must_equal 2 }.join
582
579
  end
@@ -586,9 +583,9 @@ describe Minitest::Spec do
586
583
  it "fails gracefully when expectation used outside of `it`" do
587
584
  skip "N/A" if ENV["MT_NO_EXPECTATIONS"]
588
585
 
589
- @assertion_count += 1
586
+ @assertion_count += 2 # assert_match is compound
590
587
 
591
- e = assert_raises RuntimeError do
588
+ e = assert_raises RuntimeError, Minitest::UnexpectedWarning do
592
589
  capture_io do
593
590
  Thread.new { # forces ctx to be nil
594
591
  describe("woot") do
@@ -598,17 +595,21 @@ describe Minitest::Spec do
598
595
  end
599
596
  end
600
597
 
601
- assert_equal "Calling #must_equal outside of test.", e.message
598
+ exp = "Calling #must_equal outside of test."
599
+ exp = "DEPRECATED: global use of must_equal from" if error_on_warn?
600
+
601
+ assert_match exp, e.message
602
602
  end
603
603
 
604
604
  it "deprecates expectation used without _" do
605
605
  skip "N/A" if ENV["MT_NO_EXPECTATIONS"]
606
606
 
607
- @assertion_count += 3
607
+ @assertion_count += 1
608
+ @assertion_count += 2 unless error_on_warn?
608
609
 
609
610
  exp = /DEPRECATED: global use of must_equal from/
610
611
 
611
- assert_output "", exp do
612
+ assert_deprecation exp do
612
613
  (1 + 1).must_equal 2
613
614
  end
614
615
  end
@@ -618,12 +619,13 @@ describe Minitest::Spec do
618
619
  it "deprecates expectation used without _ with empty backtrace_filter" do
619
620
  skip "N/A" if ENV["MT_NO_EXPECTATIONS"]
620
621
 
621
- @assertion_count += 3
622
+ @assertion_count += 1
623
+ @assertion_count += 2 unless error_on_warn?
622
624
 
623
625
  exp = /DEPRECATED: global use of must_equal from/
624
626
 
625
627
  with_empty_backtrace_filter do
626
- assert_output "", exp do
628
+ assert_deprecation exp do
627
629
  (1 + 1).must_equal 2
628
630
  end
629
631
  end
@@ -28,24 +28,24 @@ class TestMinitestUnit < MetaMetaMetaTestCase
28
28
  basedir = Pathname.new(File.expand_path "lib/minitest") + "mini"
29
29
  basedir = basedir.relative_path_from(pwd).to_s
30
30
  MINITEST_BASE_DIR = basedir[/\A\./] ? basedir : "./#{basedir}"
31
- BT_MIDDLE = ["#{MINITEST_BASE_DIR}/test.rb:161:in `each'",
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'"]
31
+ BT_MIDDLE = ["#{MINITEST_BASE_DIR}/test.rb:161:in 'each'",
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'"]
35
35
 
36
36
  def test_filter_backtrace
37
37
  # this is a semi-lame mix of relative paths.
38
38
  # I cheated by making the autotest parts not have ./
39
- bt = (["lib/autotest.rb:571:in `add_exception'",
40
- "test/test_autotest.rb:62:in `test_add_exception'",
41
- "#{MINITEST_BASE_DIR}/test.rb:165:in `__send__'"] +
39
+ bt = (["lib/autotest.rb:571:in 'add_exception'",
40
+ "test/test_autotest.rb:62:in 'test_add_exception'",
41
+ "#{MINITEST_BASE_DIR}/test.rb:165:in '__send__'"] +
42
42
  BT_MIDDLE +
43
43
  ["#{MINITEST_BASE_DIR}/test.rb:29",
44
44
  "test/test_autotest.rb:422"])
45
45
  bt = util_expand_bt bt
46
46
 
47
- ex = ["lib/autotest.rb:571:in `add_exception'",
48
- "test/test_autotest.rb:62:in `test_add_exception'"]
47
+ ex = ["lib/autotest.rb:571:in 'add_exception'",
48
+ "test/test_autotest.rb:62:in 'test_add_exception'"]
49
49
  ex = util_expand_bt ex
50
50
 
51
51
  Minitest::Test.io_lock.synchronize do # try not to trounce in parallel
@@ -56,7 +56,7 @@ class TestMinitestUnit < MetaMetaMetaTestCase
56
56
  end
57
57
 
58
58
  def test_filter_backtrace_all_unit
59
- bt = (["#{MINITEST_BASE_DIR}/test.rb:165:in `__send__'"] +
59
+ bt = (["#{MINITEST_BASE_DIR}/test.rb:165:in '__send__'"] +
60
60
  BT_MIDDLE +
61
61
  ["#{MINITEST_BASE_DIR}/test.rb:29"])
62
62
  ex = bt.clone
@@ -65,7 +65,7 @@ class TestMinitestUnit < MetaMetaMetaTestCase
65
65
  end
66
66
 
67
67
  def test_filter_backtrace_unit_starts
68
- bt = (["#{MINITEST_BASE_DIR}/test.rb:165:in `__send__'"] +
68
+ bt = (["#{MINITEST_BASE_DIR}/test.rb:165:in '__send__'"] +
69
69
  BT_MIDDLE +
70
70
  ["#{MINITEST_BASE_DIR}/mini/test.rb:29",
71
71
  "-e:1"])
@@ -94,7 +94,7 @@ class TestMinitestUnit < MetaMetaMetaTestCase
94
94
  end
95
95
 
96
96
  def test_this_is_non_ascii_failure_message
97
- fail 'ЁЁЁ'.force_encoding('ASCII-8BIT')
97
+ fail 'ЁЁЁ'.dup.force_encoding(Encoding::BINARY)
98
98
  end
99
99
  end
100
100
 
@@ -111,7 +111,7 @@ class TestMinitestUnit < MetaMetaMetaTestCase
111
111
  2) Error:
112
112
  FakeNamedTestXX#test_this_is_non_ascii_failure_message:
113
113
  RuntimeError: ЁЁЁ
114
- FILE:LINE:in `test_this_is_non_ascii_failure_message'
114
+ FILE:LINE:in 'test_this_is_non_ascii_failure_message'
115
115
 
116
116
  2 runs, 1 assertions, 1 failures, 1 errors, 0 skips
117
117
  EOM
@@ -263,7 +263,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
263
263
  1) Error:
264
264
  FakeNamedTestXX#test_error:
265
265
  RuntimeError: unhandled exception
266
- FILE:LINE:in \`test_error\'
266
+ FILE:LINE:in \'test_error\'
267
267
 
268
268
  2 runs, 1 assertions, 0 failures, 1 errors, 0 skips
269
269
  EOM
@@ -291,7 +291,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
291
291
  1) Error:
292
292
  FakeNamedTestXX#test_something:
293
293
  RuntimeError: unhandled exception
294
- FILE:LINE:in \`teardown\'
294
+ FILE:LINE:in \'teardown\'
295
295
 
296
296
  1 runs, 1 assertions, 0 failures, 1 errors, 0 skips
297
297
  EOM
@@ -1089,17 +1089,27 @@ class TestMinitestUnitTestCase < Minitest::Test
1089
1089
 
1090
1090
  def test_autorun_does_not_affect_fork_success_status
1091
1091
  @assertion_count = 0
1092
- skip "windows doesn't have skip" unless Process.respond_to?(:fork)
1092
+ skip "windows doesn't have fork" unless Process.respond_to?(:fork)
1093
1093
  Process.waitpid(fork {})
1094
1094
  assert_equal true, $?.success?
1095
1095
  end
1096
1096
 
1097
1097
  def test_autorun_does_not_affect_fork_exit_status
1098
1098
  @assertion_count = 0
1099
- skip "windows doesn't have skip" unless Process.respond_to?(:fork)
1099
+ skip "windows doesn't have fork" unless Process.respond_to?(:fork)
1100
1100
  Process.waitpid(fork { exit 42 })
1101
1101
  assert_equal 42, $?.exitstatus
1102
1102
  end
1103
+
1104
+ def test_autorun_optionally_can_affect_fork_exit_status
1105
+ @assertion_count = 0
1106
+ skip "windows doesn't have fork" unless Process.respond_to?(:fork)
1107
+ Minitest.allow_fork = true
1108
+ Process.waitpid(fork { exit 42 })
1109
+ refute_equal 42, $?.exitstatus
1110
+ ensure
1111
+ Minitest.allow_fork = false
1112
+ end
1103
1113
  end
1104
1114
 
1105
1115
  class TestMinitestGuard < Minitest::Test
@@ -1116,19 +1126,19 @@ class TestMinitestGuard < Minitest::Test
1116
1126
  end
1117
1127
 
1118
1128
  def test_rubinius_eh
1119
- assert_output "", /DEPRECATED/ do
1129
+ assert_deprecation do
1120
1130
  assert self.class.rubinius? "rbx"
1121
1131
  end
1122
- assert_output "", /DEPRECATED/ do
1132
+ assert_deprecation do
1123
1133
  assert self.rubinius? "rbx"
1124
1134
  end
1125
1135
  end
1126
1136
 
1127
1137
  def test_maglev_eh
1128
- assert_output "", /DEPRECATED/ do
1138
+ assert_deprecation do
1129
1139
  assert self.class.maglev? "maglev"
1130
1140
  end
1131
- assert_output "", /DEPRECATED/ do
1141
+ assert_deprecation do
1132
1142
  assert self.maglev? "maglev"
1133
1143
  end
1134
1144
  end
@@ -1251,12 +1261,12 @@ class TestMinitestUnitRecording < MetaMetaMetaTestCase
1251
1261
  Error:
1252
1262
  FakeNamedTestXX#test_method:
1253
1263
  AnError: AnError
1254
- FILE:LINE:in `test_method'
1264
+ FILE:LINE:in 'test_method'
1255
1265
 
1256
1266
  Error:
1257
1267
  FakeNamedTestXX#test_method:
1258
1268
  RuntimeError: unhandled exception
1259
- FILE:LINE:in `teardown'
1269
+ FILE:LINE:in 'teardown'
1260
1270
  "
1261
1271
 
1262
1272
  assert_equal exp.strip, normalize_output(first_reporter.results.first.to_s).strip
@@ -1270,3 +1280,96 @@ class TestMinitestUnitRecording < MetaMetaMetaTestCase
1270
1280
  end
1271
1281
  end
1272
1282
  end
1283
+
1284
+ class TestUnexpectedError < Minitest::Test
1285
+ def assert_compress exp, input
1286
+ e = Minitest::UnexpectedError.new RuntimeError.new
1287
+
1288
+ exp = exp.lines.map(&:chomp) if String === exp
1289
+ act = e.compress input
1290
+
1291
+ assert_equal exp, act
1292
+ end
1293
+
1294
+ ACT1 = %w[ a b c b c b c b c d ]
1295
+
1296
+ def test_normal
1297
+ assert_compress <<~EXP, %w[ a b c b c b c b c d ]
1298
+ a
1299
+ +->> 4 cycles of 2 lines:
1300
+ | b
1301
+ | c
1302
+ +-<<
1303
+ d
1304
+ EXP
1305
+ end
1306
+
1307
+ def test_normal2
1308
+ assert_compress <<~EXP, %w[ a b c b c b c b c ]
1309
+ a
1310
+ +->> 4 cycles of 2 lines:
1311
+ | b
1312
+ | c
1313
+ +-<<
1314
+ EXP
1315
+ end
1316
+
1317
+ def test_longer_c_than_b
1318
+ # the extra c in the front makes the overall length longer sorting it first
1319
+ assert_compress <<~EXP, %w[ c a b c b c b c b c b d ]
1320
+ c
1321
+ a
1322
+ b
1323
+ +->> 4 cycles of 2 lines:
1324
+ | c
1325
+ | b
1326
+ +-<<
1327
+ d
1328
+ EXP
1329
+ end
1330
+
1331
+ def test_1_line_cycles
1332
+ assert_compress <<~EXP, %w[ c a b c b c b c b c b b b d ]
1333
+ c
1334
+ a
1335
+ +->> 4 cycles of 2 lines:
1336
+ | b
1337
+ | c
1338
+ +-<<
1339
+ +->> 3 cycles of 1 lines:
1340
+ | b
1341
+ +-<<
1342
+ d
1343
+ EXP
1344
+ end
1345
+
1346
+ def test_sanity3
1347
+ pre = ("aa".."am").to_a
1348
+ mid = ("a".."z").to_a * 67
1349
+ post = ("aa".."am").to_a
1350
+ ary = pre + mid + post
1351
+
1352
+ exp = pre +
1353
+ [" +->> 67 cycles of 26 lines:"] +
1354
+ ("a".."z").map { |s| " | #{s}" } +
1355
+ [" +-<<"] +
1356
+ post
1357
+
1358
+ assert_compress exp, ary
1359
+ end
1360
+
1361
+ def test_absurd_patterns
1362
+ assert_compress <<~EXP, %w[ a b c b c a b c b c a b c ]
1363
+ +->> 2 cycles of 5 lines:
1364
+ | a
1365
+ | +->> 2 cycles of 2 lines:
1366
+ | | b
1367
+ | | c
1368
+ | +-<<
1369
+ +-<<
1370
+ a
1371
+ b
1372
+ c
1373
+ EXP
1374
+ end
1375
+ end
@@ -26,6 +26,7 @@ class TestHoeTest < Minitest::Test
26
26
  end
27
27
 
28
28
  assert_equal MT_EXPECTED % [framework].join("; "), @tester.make_test_cmd
29
+ .sub(/ -- .+/, " -- ")
29
30
  end
30
31
 
31
32
  def test_make_test_cmd_for_minitest_prelude
@@ -42,5 +43,6 @@ class TestHoeTest < Minitest::Test
42
43
  end
43
44
 
44
45
  assert_equal MT_EXPECTED % [prelude, framework].join("; "), @tester.make_test_cmd
46
+ .sub(/ -- .+/, " -- ")
45
47
  end
46
48
  end
data.tar.gz.sig CHANGED
Binary file