minitest 5.23.1 → 5.25.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,18 +1,14 @@
1
- # encoding: UTF-8
2
-
3
1
  require "minitest/autorun"
4
2
  require_relative "metametameta"
5
3
 
6
- if defined? Encoding then
7
- e = Encoding.default_external
8
- if e != Encoding::UTF_8 then
9
- warn ""
10
- warn ""
11
- warn "NOTE: External encoding #{e} is not UTF-8. Tests WILL fail."
12
- warn " Run tests with `RUBYOPT=-Eutf-8 rake` to avoid errors."
13
- warn ""
14
- warn ""
15
- end
4
+ e = Encoding.default_external
5
+ if e != Encoding::UTF_8 then
6
+ warn ""
7
+ warn ""
8
+ warn "NOTE: External encoding #{e} is not UTF-8. Tests WILL fail."
9
+ warn " Run tests with `RUBYOPT=-Eutf-8 rake` to avoid errors."
10
+ warn ""
11
+ warn ""
16
12
  end
17
13
 
18
14
  SomeError = Class.new Exception
@@ -27,8 +23,6 @@ class TestMinitestAssertions < Minitest::Test
27
23
  # which is not threadsafe. Nearly every method in here is an
28
24
  # assertion test so it isn't worth splitting it out further.
29
25
 
30
- RUBY18 = !defined? Encoding
31
-
32
26
  # not included in JRuby
33
27
  RE_LEVELS = /\(\d+ levels\) /
34
28
 
@@ -79,10 +73,6 @@ class TestMinitestAssertions < Minitest::Test
79
73
  end
80
74
  end
81
75
 
82
- def clean s
83
- s.gsub(/^ {6,10}/, "")
84
- end
85
-
86
76
  def non_verbose
87
77
  orig_verbose = $VERBOSE
88
78
  $VERBOSE = false
@@ -135,36 +125,43 @@ class TestMinitestAssertions < Minitest::Test
135
125
  end
136
126
 
137
127
  def test_assert_equal_different_collection_array_hex_invisible
138
- object1 = Object.new
139
- object2 = Object.new
140
- msg = "No visible difference in the Array#inspect output.
128
+ exp = Object.new
129
+ act = Object.new
130
+ msg = <<~EOM.chomp
131
+ No visible difference in the Array#inspect output.
141
132
  You should look at the implementation of #== on Array or its members.
142
- [#<Object:0xXXXXXX>]".gsub(/^ +/, "")
133
+ [#<Object:0xXXXXXX>]
134
+ EOM
143
135
  assert_triggered msg do
144
- @tc.assert_equal [object1], [object2]
136
+ @tc.assert_equal [exp], [act]
145
137
  end
146
138
  end
147
139
 
148
140
  def test_assert_equal_different_collection_hash_hex_invisible
149
- h1, h2 = {}, {}
150
- h1[1] = Object.new
151
- h2[1] = Object.new
152
- msg = "No visible difference in the Hash#inspect output.
141
+ exp, act = {}, {}
142
+ exp[1] = Object.new
143
+ act[1] = Object.new
144
+ act_obj = act[1]
145
+ # TODO: switch to endless when 2.7 is dropped
146
+ act_obj.define_singleton_method(:inspect) { "#<Object:0xXXXXXX>" }
147
+ msg = <<~EOM.chomp % [act]
148
+ No visible difference in the Hash#inspect output.
153
149
  You should look at the implementation of #== on Hash or its members.
154
- {1=>#<Object:0xXXXXXX>}".gsub(/^ +/, "")
150
+ %p
151
+ EOM
155
152
 
156
153
  assert_triggered msg do
157
- @tc.assert_equal h1, h2
154
+ @tc.assert_equal exp, act
158
155
  end
159
156
  end
160
157
 
161
158
  def test_assert_equal_different_diff_deactivated
162
159
  without_diff do
163
160
  assert_triggered util_msg("haha" * 10, "blah" * 10) do
164
- o1 = "haha" * 10
165
- o2 = "blah" * 10
161
+ exp = "haha" * 10
162
+ act = "blah" * 10
166
163
 
167
- @tc.assert_equal o1, o2
164
+ @tc.assert_equal exp, act
168
165
  end
169
166
  end
170
167
  end
@@ -186,78 +183,84 @@ class TestMinitestAssertions < Minitest::Test
186
183
  def initialize s; @name = s; end
187
184
  end
188
185
 
189
- o1 = c.new "a"
190
- o2 = c.new "b"
191
- msg = clean <<-EOS
186
+ exp = c.new "a"
187
+ act = c.new "b"
188
+ msg = <<~EOS
192
189
  --- expected
193
190
  +++ actual
194
191
  @@ -1 +1 @@
195
- -#<#<Class:0xXXXXXX>:0xXXXXXX @name=\"a\">
196
- +#<#<Class:0xXXXXXX>:0xXXXXXX @name=\"b\">
192
+ -#<#<Class:0xXXXXXX>:0xXXXXXX @name="a">
193
+ +#<#<Class:0xXXXXXX>:0xXXXXXX @name="b">
197
194
  EOS
198
195
 
199
196
  assert_triggered msg do
200
- @tc.assert_equal o1, o2
197
+ @tc.assert_equal exp, act
201
198
  end
202
199
  end
203
200
 
204
201
  def test_assert_equal_different_hex_invisible
205
- o1 = Object.new
206
- o2 = Object.new
202
+ exp = Object.new
203
+ act = Object.new
207
204
 
208
- msg = "No visible difference in the Object#inspect output.
205
+ msg = <<~EOM.chomp
206
+ No visible difference in the Object#inspect output.
209
207
  You should look at the implementation of #== on Object or its members.
210
- #<Object:0xXXXXXX>".gsub(/^ +/, "")
208
+ #<Object:0xXXXXXX>
209
+ EOM
211
210
 
212
211
  assert_triggered msg do
213
- @tc.assert_equal o1, o2
212
+ @tc.assert_equal exp, act
214
213
  end
215
214
  end
216
215
 
217
216
  def test_assert_equal_different_long
218
- msg = "--- expected
217
+ msg = <<~EOM
218
+ --- expected
219
219
  +++ actual
220
220
  @@ -1 +1 @@
221
- -\"hahahahahahahahahahahahahahahahahahahaha\"
222
- +\"blahblahblahblahblahblahblahblahblahblah\"
223
- ".gsub(/^ +/, "")
221
+ -"hahahahahahahahahahahahahahahahahahahaha"
222
+ +"blahblahblahblahblahblahblahblahblahblah"
223
+ EOM
224
224
 
225
225
  assert_triggered msg do
226
- o1 = "haha" * 10
227
- o2 = "blah" * 10
226
+ exp = "haha" * 10
227
+ act = "blah" * 10
228
228
 
229
- @tc.assert_equal o1, o2
229
+ @tc.assert_equal exp, act
230
230
  end
231
231
  end
232
232
 
233
233
  def test_assert_equal_different_long_invisible
234
- msg = "No visible difference in the String#inspect output.
234
+ msg = <<~EOM.chomp
235
+ No visible difference in the String#inspect output.
235
236
  You should look at the implementation of #== on String or its members.
236
- \"blahblahblahblahblahblahblahblahblahblah\"".gsub(/^ +/, "")
237
+ "blahblahblahblahblahblahblahblahblahblah"
238
+ EOM
237
239
 
238
240
  assert_triggered msg do
239
- o1 = "blah" * 10
240
- o2 = "blah" * 10
241
- def o1.== _
241
+ exp = "blah" * 10
242
+ act = "blah" * 10
243
+ def exp.== _
242
244
  false
243
245
  end
244
- @tc.assert_equal o1, o2
246
+ @tc.assert_equal exp, act
245
247
  end
246
248
  end
247
249
 
248
250
  def test_assert_equal_different_long_msg
249
- msg = "message.
251
+ msg = <<~EOM
252
+ message.
250
253
  --- expected
251
254
  +++ actual
252
255
  @@ -1 +1 @@
253
- -\"hahahahahahahahahahahahahahahahahahahaha\"
254
- +\"blahblahblahblahblahblahblahblahblahblah\"
255
- ".gsub(/^ +/, "")
256
+ -"hahahahahahahahahahahahahahahahahahahaha"
257
+ +"blahblahblahblahblahblahblahblahblahblah"
258
+ EOM
256
259
 
257
260
  assert_triggered msg do
258
- o1 = "haha" * 10
259
- o2 = "blah" * 10
260
- @tc.assert_equal o1, o2, "message"
261
+ exp = "haha" * 10
262
+ act = "blah" * 10
263
+ @tc.assert_equal exp, act, "message"
261
264
  end
262
265
  end
263
266
 
@@ -281,7 +284,7 @@ class TestMinitestAssertions < Minitest::Test
281
284
  end
282
285
 
283
286
  def test_assert_equal_does_not_allow_lhs_nil
284
- if Minitest::VERSION =~ /^6/ then
287
+ if Minitest::VERSION >= "6" then
285
288
  warn "Time to strip the MT5 test"
286
289
 
287
290
  @assertion_count += 1
@@ -305,29 +308,23 @@ class TestMinitestAssertions < Minitest::Test
305
308
  end
306
309
 
307
310
  def test_assert_equal_string_bug791
308
- exp = <<-'EOF'.gsub(/^ {10}/, "") # note single quotes
309
- --- expected
310
- +++ actual
311
- @@ -1,2 +1 @@
312
- -"\\n
313
- -"
314
- +"\\\"
315
- EOF
316
-
317
- exp = "Expected: \"\\\\n\"\n Actual: \"\\\\\""
311
+ exp = <<~EOM.chomp
312
+ Expected: "\\\\n"
313
+ Actual: "\\\\"
314
+ EOM
318
315
  assert_triggered exp do
319
316
  @tc.assert_equal "\\n", "\\"
320
317
  end
321
318
  end
322
319
 
323
320
  def test_assert_equal_string_both_escaped_unescaped_newlines
324
- msg = <<-EOM.gsub(/^ {10}/, "")
321
+ msg = <<~EOM
325
322
  --- expected
326
323
  +++ actual
327
324
  @@ -1,2 +1 @@
328
- -\"A\\n
329
- -B\"
330
- +\"A\\n\\\\nB\"
325
+ -"A\\n
326
+ -B"
327
+ +"A\\n\\\\nB"
331
328
  EOM
332
329
 
333
330
  assert_triggered msg do
@@ -339,7 +336,7 @@ class TestMinitestAssertions < Minitest::Test
339
336
  end
340
337
 
341
338
  def test_assert_equal_string_encodings
342
- msg = <<-EOM.gsub(/^ {10}/, "")
339
+ msg = <<~EOM
343
340
  --- expected
344
341
  +++ actual
345
342
  @@ -1,3 +1,3 @@
@@ -351,14 +348,14 @@ class TestMinitestAssertions < Minitest::Test
351
348
  EOM
352
349
 
353
350
  assert_triggered msg do
354
- x = "bad-utf8-\xF1.txt"
355
- y = x.dup.force_encoding "binary" # TODO: switch to .b when 1.9 dropped
356
- @tc.assert_equal x, y
351
+ exp = "bad-utf8-\xF1.txt"
352
+ act = exp.dup.b
353
+ @tc.assert_equal exp, act
357
354
  end
358
- end unless RUBY18
355
+ end
359
356
 
360
357
  def test_assert_equal_string_encodings_both_different
361
- msg = <<-EOM.gsub(/^ {10}/, "")
358
+ msg = <<~EOM
362
359
  --- expected
363
360
  +++ actual
364
361
  @@ -1,3 +1,3 @@
@@ -370,14 +367,14 @@ class TestMinitestAssertions < Minitest::Test
370
367
  EOM
371
368
 
372
369
  assert_triggered msg do
373
- x = "bad-utf8-\xF1.txt".dup.force_encoding Encoding::ASCII
374
- y = x.dup.force_encoding "binary" # TODO: switch to .b when 1.9 dropped
375
- @tc.assert_equal x, y
370
+ exp = "bad-utf8-\xF1.txt".dup.force_encoding Encoding::ASCII
371
+ act = exp.dup.b
372
+ @tc.assert_equal exp, act
376
373
  end
377
- end unless RUBY18
374
+ end
378
375
 
379
376
  def test_assert_equal_unescape_newlines
380
- msg = <<-'EOM'.gsub(/^ {10}/, "") # NOTE single quotes on heredoc
377
+ msg = <<~'EOM' # NOTE single quotes on heredoc
381
378
  --- expected
382
379
  +++ actual
383
380
  @@ -1,2 +1,2 @@
@@ -429,7 +426,7 @@ class TestMinitestAssertions < Minitest::Test
429
426
  end
430
427
 
431
428
  def test_assert_in_epsilon_triggered_negative_case
432
- x = (RUBY18 and not maglev?) ? "0.1" : "0.100000xxx"
429
+ x = "0.100000xxx"
433
430
  y = "0.1"
434
431
  assert_triggered "Expected |-1.1 - -1| (#{x}) to be <= #{y}." do
435
432
  @tc.assert_in_epsilon(-1.1, -1, 0.1)
@@ -719,6 +716,7 @@ class TestMinitestAssertions < Minitest::Test
719
716
  end
720
717
  end
721
718
  end
719
+
722
720
  def test_assert_predicate
723
721
  @tc.assert_predicate "", :empty?
724
722
  end
@@ -748,17 +746,17 @@ class TestMinitestAssertions < Minitest::Test
748
746
  end
749
747
  end
750
748
 
751
- expected = clean <<-EOM.chomp
749
+ expected = <<~EOM.chomp
752
750
  [StandardError] exception expected, not
753
751
  Class: <SomeError>
754
- Message: <\"blah\">
752
+ Message: <"blah">
755
753
  ---Backtrace---
756
- FILE:LINE:in \'block in test_assert_raises_default_triggered\'
754
+ FILE:LINE:in 'block in test_assert_raises_default_triggered'
757
755
  ---------------
758
756
  EOM
759
757
 
760
758
  actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
761
- actual.gsub!(RE_LEVELS, "") unless jruby?
759
+ actual.gsub! RE_LEVELS, "" unless jruby?
762
760
  actual.gsub!(/[`']block in (?:TestMinitestAssertions#)?/, "'block in ")
763
761
 
764
762
  assert_equal expected, actual
@@ -828,17 +826,17 @@ class TestMinitestAssertions < Minitest::Test
828
826
  end
829
827
  end
830
828
 
831
- expected = clean <<-EOM
829
+ expected = <<~EOM
832
830
  [SomeError] exception expected, not
833
831
  Class: <AnError>
834
- Message: <\"some message\">
832
+ Message: <"some message">
835
833
  ---Backtrace---
836
- FILE:LINE:in \'block in test_assert_raises_subclass_triggered\'
834
+ FILE:LINE:in 'block in test_assert_raises_subclass_triggered'
837
835
  ---------------
838
836
  EOM
839
837
 
840
838
  actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
841
- actual.gsub!(RE_LEVELS, "") unless jruby?
839
+ actual.gsub! RE_LEVELS, "" unless jruby?
842
840
  actual.gsub!(/[`']block in (?:TestMinitestAssertions#)?/, "'block in ")
843
841
 
844
842
  assert_equal expected.chomp, actual
@@ -851,17 +849,17 @@ class TestMinitestAssertions < Minitest::Test
851
849
  end
852
850
  end
853
851
 
854
- expected = clean <<-EOM.chomp
852
+ expected = <<~EOM.chomp
855
853
  [RuntimeError] exception expected, not
856
854
  Class: <SyntaxError>
857
- Message: <\"icky\">
855
+ Message: <"icky">
858
856
  ---Backtrace---
859
- FILE:LINE:in \'block in test_assert_raises_triggered_different\'
857
+ FILE:LINE:in 'block in test_assert_raises_triggered_different'
860
858
  ---------------
861
859
  EOM
862
860
 
863
861
  actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
864
- actual.gsub!(RE_LEVELS, "") unless jruby?
862
+ actual.gsub! RE_LEVELS, "" unless jruby?
865
863
  actual.gsub!(/[`']block in (?:TestMinitestAssertions#)?/, "'block in ")
866
864
 
867
865
  assert_equal expected, actual
@@ -874,18 +872,18 @@ class TestMinitestAssertions < Minitest::Test
874
872
  end
875
873
  end
876
874
 
877
- expected = clean <<-EOM
875
+ expected = <<~EOM
878
876
  XXX.
879
877
  [RuntimeError] exception expected, not
880
878
  Class: <SyntaxError>
881
- Message: <\"icky\">
879
+ Message: <"icky">
882
880
  ---Backtrace---
883
- FILE:LINE:in \'block in test_assert_raises_triggered_different_msg\'
881
+ FILE:LINE:in 'block in test_assert_raises_triggered_different_msg'
884
882
  ---------------
885
883
  EOM
886
884
 
887
885
  actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
888
- actual.gsub!(RE_LEVELS, "") unless jruby?
886
+ actual.gsub! RE_LEVELS, "" unless jruby?
889
887
  actual.gsub!(/[`']block in (?:TestMinitestAssertions#)?/, "'block in ")
890
888
 
891
889
  assert_equal expected.chomp, actual
@@ -957,8 +955,8 @@ class TestMinitestAssertions < Minitest::Test
957
955
  @tc.assert_same 1, 2
958
956
  end
959
957
 
960
- s1 = "blah"
961
- s2 = "blah"
958
+ s1 = +"blah"
959
+ s2 = +"blah"
962
960
 
963
961
  assert_triggered 'Expected "blah" (oid=N) to be the same as "blah" (oid=N).' do
964
962
  @tc.assert_same s1, s2
@@ -1154,8 +1152,8 @@ class TestMinitestAssertions < Minitest::Test
1154
1152
 
1155
1153
  non_verbose do
1156
1154
  out, err = capture_subprocess_io do
1157
- system("echo hi")
1158
- system("echo bye! 1>&2")
1155
+ system "echo hi"
1156
+ system "echo bye! 1>&2"
1159
1157
  end
1160
1158
 
1161
1159
  assert_equal "hi\n", out
@@ -1548,9 +1546,11 @@ class TestMinitestAssertionHelpers < Minitest::Test
1548
1546
  end
1549
1547
 
1550
1548
  def test_diff_equal
1551
- msg = "No visible difference in the String#inspect output.
1549
+ msg = <<~EOM.chomp
1550
+ No visible difference in the String#inspect output.
1552
1551
  You should look at the implementation of #== on String or its members.
1553
- \"blahblahblahblahblahblahblahblahblahblah\"".gsub(/^ +/, "")
1552
+ "blahblahblahblahblahblahblahblahblahblah"
1553
+ EOM
1554
1554
 
1555
1555
  o1 = "blah" * 10
1556
1556
  o2 = "blah" * 10
@@ -1562,7 +1562,7 @@ class TestMinitestAssertionHelpers < Minitest::Test
1562
1562
  end
1563
1563
 
1564
1564
  def test_diff_str_mixed
1565
- msg = <<-'EOM'.gsub(/^ {10}/, "") # NOTE single quotes on heredoc
1565
+ msg = <<~'EOM' # NOTE single quotes on heredoc
1566
1566
  --- expected
1567
1567
  +++ actual
1568
1568
  @@ -1 +1 @@
@@ -1577,7 +1577,7 @@ class TestMinitestAssertionHelpers < Minitest::Test
1577
1577
  end
1578
1578
 
1579
1579
  def test_diff_str_multiline
1580
- msg = <<-'EOM'.gsub(/^ {10}/, "") # NOTE single quotes on heredoc
1580
+ msg = <<~EOM
1581
1581
  --- expected
1582
1582
  +++ actual
1583
1583
  @@ -1,2 +1,2 @@
@@ -1593,7 +1593,7 @@ class TestMinitestAssertionHelpers < Minitest::Test
1593
1593
  end
1594
1594
 
1595
1595
  def test_diff_str_simple
1596
- msg = <<-'EOM'.gsub(/^ {10}/, "").chomp # NOTE single quotes on heredoc
1596
+ msg = <<~EOM.chomp
1597
1597
  Expected: "A"
1598
1598
  Actual: "B"
1599
1599
  EOM
@@ -17,7 +17,7 @@ class TestMinitestBenchmark < Minitest::Test
17
17
  def test_cls_runnable_methods
18
18
  assert_equal [], Minitest::Benchmark.runnable_methods
19
19
 
20
- c = Class.new(Minitest::Benchmark) do
20
+ c = Class.new Minitest::Benchmark do
21
21
  def bench_blah
22
22
  end
23
23
  end