minitest 5.11.3 → 5.25.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,8 +3,36 @@ require "stringio"
3
3
  require "minitest/autorun"
4
4
 
5
5
  class Minitest::Test
6
- def clean s
7
- s.gsub(/^ {6}/, "")
6
+ def with_empty_backtrace_filter
7
+ with_backtrace_filter Minitest::BacktraceFilter.new %r%.% do
8
+ yield
9
+ end
10
+ end
11
+
12
+ def with_backtrace_filter filter
13
+ original = Minitest.backtrace_filter
14
+
15
+ Minitest::Test.io_lock.synchronize do # try not to trounce in parallel
16
+ begin
17
+ Minitest.backtrace_filter = filter
18
+ yield
19
+ ensure
20
+ Minitest.backtrace_filter = original
21
+ end
22
+ end
23
+ end
24
+
25
+ def error_on_warn?
26
+ defined?(Minitest::ErrorOnWarning)
27
+ end
28
+
29
+ def assert_deprecation re = /DEPRECATED/
30
+ re = // if $-w.nil? # "skip" if running `rake testW0`
31
+ assert_output "", re do
32
+ yield
33
+ end
34
+ rescue Minitest::UnexpectedWarning => e # raised if -Werror was used
35
+ assert_match re, e.message
8
36
  end
9
37
  end
10
38
 
@@ -19,30 +47,43 @@ class FakeNamedTest < Minitest::Test
19
47
  end
20
48
  end
21
49
 
50
+ module MyModule; end
51
+ class AnError < StandardError; include MyModule; end
52
+
22
53
  class MetaMetaMetaTestCase < Minitest::Test
23
54
  attr_accessor :reporter, :output, :tu
24
55
 
56
+ def with_stderr err
57
+ old = $stderr
58
+ $stderr = err
59
+ yield
60
+ ensure
61
+ $stderr = old
62
+ end
63
+
25
64
  def run_tu_with_fresh_reporter flags = %w[--seed 42]
26
65
  options = Minitest.process_args flags
27
66
 
28
- @output = StringIO.new("".encode('UTF-8'))
67
+ @output = StringIO.new(+"")
29
68
 
30
69
  self.reporter = Minitest::CompositeReporter.new
31
70
  reporter << Minitest::SummaryReporter.new(@output, options)
32
71
  reporter << Minitest::ProgressReporter.new(@output, options)
33
72
 
34
- reporter.start
73
+ with_stderr @output do
74
+ reporter.start
35
75
 
36
- yield(reporter) if block_given?
76
+ yield reporter if block_given?
37
77
 
38
- @tus ||= [@tu]
39
- @tus.each do |tu|
40
- Minitest::Runnable.runnables.delete tu
78
+ @tus ||= [@tu]
79
+ @tus.each do |tu|
80
+ Minitest::Runnable.runnables.delete tu
41
81
 
42
- tu.run reporter, options
43
- end
82
+ tu.run reporter, options
83
+ end
44
84
 
45
- reporter.report
85
+ reporter.report
86
+ end
46
87
  end
47
88
 
48
89
  def first_reporter
@@ -50,8 +91,8 @@ class MetaMetaMetaTestCase < Minitest::Test
50
91
  end
51
92
 
52
93
  def assert_report expected, flags = %w[--seed 42], &block
53
- header = clean <<-EOM
54
- Run options: #{flags.map { |s| s =~ /\|/ ? s.inspect : s }.join " "}
94
+ header = <<~EOM
95
+ Run options: #{flags.map { |s| s.include?("|") ? s.inspect : s }.join " "}
55
96
 
56
97
  # Running:
57
98
 
@@ -73,14 +114,21 @@ class MetaMetaMetaTestCase < Minitest::Test
73
114
  output.gsub!(/0x[A-Fa-f0-9]+/, "0xXXX")
74
115
  output.gsub!(/ +$/, "")
75
116
 
117
+ file = ->(s) { s.start_with?("/") ? "FULLFILE" : "FILE" }
118
+
76
119
  if windows? then
77
120
  output.gsub!(/\[(?:[A-Za-z]:)?[^\]:]+:\d+\]/, "[FILE:LINE]")
78
- output.gsub!(/^(\s+)(?:[A-Za-z]:)?[^:]+:\d+:in/, '\1FILE:LINE:in')
121
+ output.gsub!(/^(\s+)(?:[A-Za-z]:)?[^:]+:\d+:in [`']/, '\1FILE:LINE:in \'')
79
122
  else
80
- output.gsub!(/\[[^\]:]+:\d+\]/, "[FILE:LINE]")
81
- output.gsub!(/^(\s+)[^:]+:\d+:in/, '\1FILE:LINE:in')
123
+ output.gsub!(/\[([^\]:]+):\d+\]/) { "[#{file[$1]}:LINE]" }
124
+ output.gsub!(/^(\s+)([^:]+):\d+:in [`']/) { "#{$1}#{file[$2]}:LINE:in '" }
82
125
  end
83
126
 
127
+ output.gsub!(/in [`']block in (?:([^']+)[#.])?/, "in 'block in")
128
+ output.gsub!(/in [`'](?:([^']+)[#.])?/, "in '")
129
+
130
+ output.gsub!(/( at )([^:]+):\d+/) { "#{$1}[#{file[$2]}:LINE]" } # eval?
131
+
84
132
  output
85
133
  end
86
134
 
@@ -95,7 +143,7 @@ class MetaMetaMetaTestCase < Minitest::Test
95
143
 
96
144
  def setup
97
145
  super
98
- srand 42
146
+ Minitest.seed = 42
99
147
  Minitest::Test.reset
100
148
  @tu = nil
101
149
  end