minitest 5.11.3 → 5.25.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,8 @@
1
1
  require "minitest/autorun"
2
2
  require "minitest/metametameta"
3
+ require "forwardable"
3
4
 
4
- class Runnable
5
+ class FakeTest < Minitest::Test
5
6
  def woot
6
7
  assert true
7
8
  end
@@ -16,33 +17,23 @@ class TestMinitestReporter < MetaMetaMetaTestCase
16
17
  reporter << Minitest::SummaryReporter.new(self.io)
17
18
  reporter << Minitest::ProgressReporter.new(self.io)
18
19
 
19
- def reporter.first
20
- reporters.first
21
- end
22
-
23
- def reporter.results
24
- first.results
25
- end
26
-
27
- def reporter.count
28
- first.count
29
- end
30
-
31
- def reporter.assertions
32
- first.assertions
33
- end
20
+ # eg reporter.results -> reporters.first.results
21
+ reporter.extend Forwardable
22
+ reporter.delegate :first => :reporters
23
+ reporter.delegate %i[results count assertions options to_s] => :first
34
24
 
35
25
  reporter
36
26
  end
37
27
 
38
28
  def setup
39
- self.io = StringIO.new("")
29
+ super
30
+ self.io = StringIO.new(+"")
40
31
  self.r = new_composite_reporter
41
32
  end
42
33
 
43
34
  def error_test
44
35
  unless defined? @et then
45
- @et = Minitest::Test.new(:woot)
36
+ @et = FakeTest.new :woot
46
37
  @et.failures << Minitest::UnexpectedError.new(begin
47
38
  raise "no"
48
39
  rescue => e
@@ -53,9 +44,28 @@ class TestMinitestReporter < MetaMetaMetaTestCase
53
44
  @et
54
45
  end
55
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 = FakeTest.new :woot
60
+ @sse.failures << Minitest::UnexpectedError.new(ex)
61
+ @sse = Minitest::Result.from @sse
62
+ end
63
+ @sse
64
+ end
65
+
56
66
  def fail_test
57
67
  unless defined? @ft then
58
- @ft = Minitest::Test.new(:woot)
68
+ @ft = FakeTest.new :woot
59
69
  @ft.failures << begin
60
70
  raise Minitest::Assertion, "boo"
61
71
  rescue Minitest::Assertion => e
@@ -67,12 +77,18 @@ class TestMinitestReporter < MetaMetaMetaTestCase
67
77
  end
68
78
 
69
79
  def passing_test
70
- @pt ||= Minitest::Result.from Minitest::Test.new(:woot)
80
+ @pt ||= Minitest::Result.from FakeTest.new(:woot)
81
+ end
82
+
83
+ def passing_test_with_metadata
84
+ test = FakeTest.new :woot
85
+ test.metadata[:meta] = :data
86
+ @pt ||= Minitest::Result.from test
71
87
  end
72
88
 
73
89
  def skip_test
74
90
  unless defined? @st then
75
- @st = Minitest::Test.new(:woot)
91
+ @st = FakeTest.new :woot
76
92
  @st.failures << begin
77
93
  raise Minitest::Skip
78
94
  rescue Minitest::Assertion => e
@@ -86,7 +102,25 @@ class TestMinitestReporter < MetaMetaMetaTestCase
86
102
  def test_to_s
87
103
  r.record passing_test
88
104
  r.record fail_test
89
- assert_match "woot", r.first.to_s
105
+ assert_match "woot", r.to_s
106
+ end
107
+
108
+ def test_options_skip_F
109
+ r.options[:skip] = "F"
110
+
111
+ r.record passing_test
112
+ r.record fail_test
113
+
114
+ refute_match "woot", r.to_s
115
+ end
116
+
117
+ def test_options_skip_E
118
+ r.options[:skip] = "E"
119
+
120
+ r.record passing_test
121
+ r.record error_test
122
+
123
+ refute_match "RuntimeError: no", r.to_s
90
124
  end
91
125
 
92
126
  def test_passed_eh_empty
@@ -126,7 +160,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
126
160
  end
127
161
 
128
162
  def test_passed_eh_skipped_verbose
129
- r.first.options[:verbose] = true
163
+ r.options[:verbose] = true
130
164
 
131
165
  r.start
132
166
  r.results << skip_test
@@ -153,6 +187,29 @@ class TestMinitestReporter < MetaMetaMetaTestCase
153
187
  assert_equal 0, r.assertions
154
188
  end
155
189
 
190
+ def test_record_pass_with_metadata
191
+ reporter = self.r
192
+
193
+ def reporter.metadata
194
+ @metadata
195
+ end
196
+
197
+ def reporter.record result
198
+ super
199
+ @metadata = result.metadata if result.metadata?
200
+ end
201
+
202
+ r.record passing_test_with_metadata
203
+
204
+ exp = { :meta => :data }
205
+ assert_equal exp, reporter.metadata
206
+
207
+ assert_equal ".", io.string
208
+ assert_empty r.results
209
+ assert_equal 1, r.count
210
+ assert_equal 0, r.assertions
211
+ end
212
+
156
213
  def test_record_fail
157
214
  fail_test = self.fail_test
158
215
  r.record fail_test
@@ -187,7 +244,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
187
244
  r.start
188
245
  r.report
189
246
 
190
- exp = clean <<-EOM
247
+ exp = <<~EOM
191
248
  Run options:
192
249
 
193
250
  # Running:
@@ -207,7 +264,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
207
264
  r.record passing_test
208
265
  r.report
209
266
 
210
- exp = clean <<-EOM
267
+ exp = <<~EOM
211
268
  Run options:
212
269
 
213
270
  # Running:
@@ -227,7 +284,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
227
284
  r.record fail_test
228
285
  r.report
229
286
 
230
- exp = clean <<-EOM
287
+ exp = <<~EOM
231
288
  Run options:
232
289
 
233
290
  # Running:
@@ -237,7 +294,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
237
294
  Finished in 0.00
238
295
 
239
296
  1) Failure:
240
- Minitest::Test#woot [FILE:LINE]:
297
+ FakeTest#woot [FILE:LINE]:
241
298
  boo
242
299
 
243
300
  1 runs, 0 assertions, 1 failures, 0 errors, 0 skips
@@ -251,7 +308,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
251
308
  r.record error_test
252
309
  r.report
253
310
 
254
- exp = clean <<-EOM
311
+ exp = <<~EOM
255
312
  Run options:
256
313
 
257
314
  # Running:
@@ -261,10 +318,46 @@ class TestMinitestReporter < MetaMetaMetaTestCase
261
318
  Finished in 0.00
262
319
 
263
320
  1) Error:
264
- Minitest::Test#woot:
321
+ FakeTest#woot:
265
322
  RuntimeError: no
266
- FILE:LINE:in `error_test'
267
- 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
+ FakeTest#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
268
361
 
269
362
  1 runs, 0 assertions, 0 failures, 1 errors, 0 skips
270
363
  EOM
@@ -280,7 +373,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
280
373
  r.report
281
374
  end
282
375
 
283
- exp = clean <<-EOM
376
+ exp = <<~EOM
284
377
  Run options:
285
378
 
286
379
  # Running:
@@ -296,4 +389,48 @@ class TestMinitestReporter < MetaMetaMetaTestCase
296
389
 
297
390
  assert_equal exp, normalize_output(io.string)
298
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 = "FakeTest#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
299
436
  end