minitest 5.24.0 → 5.25.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  module Minitest
2
- module Parallel #:nodoc:
2
+ module Parallel # :nodoc:
3
3
 
4
4
  ##
5
5
  # The engine used to run multiple tests in parallel.
@@ -24,10 +24,10 @@ module Minitest
24
24
  # Start the executor
25
25
 
26
26
  def start
27
- @pool = size.times.map {
28
- Thread.new(@queue) do |queue|
27
+ @pool = Array.new(size) {
28
+ Thread.new @queue do |queue|
29
29
  Thread.current.abort_on_exception = true
30
- while (job = queue.pop)
30
+ while job = queue.pop do
31
31
  klass, method, reporter = job
32
32
  reporter.synchronize { reporter.prerecord klass, method }
33
33
  result = Minitest.run_one_method klass, method
@@ -8,13 +8,13 @@ module Minitest
8
8
  end
9
9
 
10
10
  def self.plugin_pride_init options # :nodoc:
11
- if PrideIO.pride? then
12
- klass = ENV["TERM"] =~ /^xterm|-256color$/ ? PrideLOL : PrideIO
13
- io = klass.new options[:io]
11
+ return unless PrideIO.pride?
14
12
 
15
- self.reporter.reporters.grep(Minitest::Reporter).each do |rep|
16
- rep.io = io if rep.io.tty?
17
- end
13
+ klass = ENV["TERM"].match?(/^xterm|-256color$/) ? PrideLOL : PrideIO
14
+ io = klass.new options[:io]
15
+
16
+ self.reporter.reporters.grep(Minitest::Reporter).each do |rep|
17
+ rep.io = io if rep.io.tty?
18
18
  end
19
19
  end
20
20
 
@@ -59,12 +59,10 @@ module Minitest
59
59
 
60
60
  def print o
61
61
  case o
62
- when "." then
62
+ when ".", "S" then
63
63
  io.print pride o
64
64
  when "E", "F" then
65
65
  io.print "#{ESC}41m#{ESC}37m#{o}#{NND}"
66
- when "S" then
67
- io.print pride o
68
66
  else
69
67
  io.print o
70
68
  end
@@ -72,11 +70,9 @@ module Minitest
72
70
 
73
71
  def puts *o # :nodoc:
74
72
  o.map! { |s|
75
- s.to_s.sub(/Finished/) {
73
+ s.to_s.sub("Finished") {
76
74
  @index = 0
77
- "Fabulous run".split(//).map { |c|
78
- pride(c)
79
- }.join
75
+ "Fabulous run".chars.map { |c| pride(c) }.join
80
76
  }
81
77
  }
82
78
 
@@ -113,7 +109,7 @@ module Minitest
113
109
  #
114
110
  # plot (3*sin(x)+3), (3*sin(x+2*pi/3)+3), (3*sin(x+4*pi/3)+3)
115
111
 
116
- @colors = (6 * 7).times.map { |n|
112
+ @colors = Array.new(6 * 7) { |n|
117
113
  n *= 1.0 / 3
118
114
  r = (3 * Math.sin(n ) + 3).to_i
119
115
  g = (3 * Math.sin(n + 4 * PI_3) + 3).to_i
data/lib/minitest/spec.rb CHANGED
@@ -4,11 +4,11 @@ class Module # :nodoc:
4
4
  def infect_an_assertion meth, new_name, dont_flip = false # :nodoc:
5
5
  block = dont_flip == :block
6
6
  dont_flip = false if block
7
- target_obj = block ? '_{obj.method}' : '_(obj)'
7
+ target_obj = block ? "_{obj.method}" : "_(obj)"
8
8
 
9
9
  # https://eregon.me/blog/2021/02/13/correct-delegation-in-ruby-2-27-3.html
10
10
  # Drop this when we can drop ruby 2.6 (aka after rails 6.1 EOL, ~2024-06)
11
- kw_extra = "ruby2_keywords %p" % [new_name] if respond_to?(:ruby2_keywords, true)
11
+ kw_extra = "ruby2_keywords %p" % [new_name] if respond_to? :ruby2_keywords, true
12
12
 
13
13
  # warn "%-22p -> %p %p" % [meth, new_name, dont_flip]
14
14
  self.class_eval <<-EOM, __FILE__, __LINE__ + 1
@@ -249,7 +249,7 @@ class Minitest::Spec < Minitest::Test
249
249
  pre, post = "let '#{name}' cannot ", ". Please use another name."
250
250
  methods = Minitest::Spec.instance_methods.map(&:to_s) - %w[subject]
251
251
  raise ArgumentError, "#{pre}begin with 'test'#{post}" if
252
- name =~ /\Atest/
252
+ name.start_with? "test"
253
253
  raise ArgumentError, "#{pre}override a method in Minitest::Spec#{post}" if
254
254
  methods.include? name
255
255
 
@@ -268,7 +268,7 @@ class Minitest::Spec < Minitest::Test
268
268
  end
269
269
 
270
270
  def create name, desc # :nodoc:
271
- cls = Class.new(self) do
271
+ cls = Class.new self do
272
272
  @name = name
273
273
  @desc = desc
274
274
 
@@ -289,7 +289,7 @@ class Minitest::Spec < Minitest::Test
289
289
  end
290
290
 
291
291
  attr_reader :desc # :nodoc:
292
- alias :specify :it
292
+ alias specify it
293
293
 
294
294
  ##
295
295
  # Rdoc... why are you so dumb?
data/lib/minitest/test.rb CHANGED
@@ -85,20 +85,18 @@ module Minitest
85
85
  # Runs a single test with setup/teardown hooks.
86
86
 
87
87
  def run
88
- with_info_handler do
89
- time_it do
90
- capture_exceptions do
91
- SETUP_METHODS.each do |hook|
92
- self.send hook
93
- end
94
-
95
- self.send self.name
88
+ time_it do
89
+ capture_exceptions do
90
+ SETUP_METHODS.each do |hook|
91
+ self.send hook
96
92
  end
97
93
 
98
- TEARDOWN_METHODS.each do |hook|
99
- capture_exceptions do
100
- self.send hook
101
- end
94
+ self.send self.name
95
+ end
96
+
97
+ TEARDOWN_METHODS.each do |hook|
98
+ capture_exceptions do
99
+ self.send hook
102
100
  end
103
101
  end
104
102
  end
@@ -230,16 +228,6 @@ module Minitest
230
228
  ne
231
229
  end
232
230
 
233
- def with_info_handler &block # :nodoc:
234
- t0 = Minitest.clock_time
235
-
236
- handler = lambda do
237
- warn "\nCurrent: %s#%s %.2fs" % [self.class, self.name, Minitest.clock_time - t0]
238
- end
239
-
240
- self.class.on_signal ::Minitest.info_signal, handler, &block
241
- end
242
-
243
231
  include LifecycleHooks
244
232
  include Guard
245
233
  extend Guard
@@ -150,7 +150,7 @@ module Minitest # :nodoc:
150
150
  ENV["N"] && ENV["N"].to_i > 0
151
151
 
152
152
  lib_extras = (ENV["MT_LIB_EXTRAS"] || "").split File::PATH_SEPARATOR
153
- self.libs[0,0] = lib_extras
153
+ self.libs[0, 0] = lib_extras
154
154
 
155
155
  extra_args << "-n" << ENV["N"] if ENV["N"]
156
156
  extra_args << "-e" << ENV["X"] if ENV["X"]
@@ -169,7 +169,7 @@ module Minitest # :nodoc:
169
169
  def define # :nodoc:
170
170
  desc "Run the test suite. Use N, X, A, and TESTOPTS to add flags/args."
171
171
  task name do
172
- ruby make_test_cmd, verbose:verbose
172
+ ruby make_test_cmd, verbose: verbose
173
173
  end
174
174
 
175
175
  desc "Print out the test command. Good for profiling and other tools."
@@ -183,7 +183,7 @@ module Minitest # :nodoc:
183
183
 
184
184
  # 3 seems to be the magic number... (tho not by that much)
185
185
  bad, good, n = {}, [], (ENV.delete("K") || 3).to_i
186
- file = ENV.delete("F")
186
+ file = ENV.delete "F"
187
187
  times = {}
188
188
 
189
189
  tt0 = Time.now
@@ -244,7 +244,7 @@ module Minitest # :nodoc:
244
244
 
245
245
  task "#{name}:deps" => "#{name}:isolated" # now just an alias
246
246
 
247
- desc "Show bottom 25 tests wrt time."
247
+ desc "Run the test suite and report the slowest 25 tests."
248
248
  task "#{name}:slow" do
249
249
  sh ["rake #{name} A=-v",
250
250
  "egrep '#test_.* s = .'",
@@ -268,11 +268,11 @@ module Minitest # :nodoc:
268
268
  runner = runner.join "; "
269
269
 
270
270
  args = []
271
- args << "-I#{libs.join(File::PATH_SEPARATOR)}" unless libs.empty?
271
+ args << "-I#{libs.join File::PATH_SEPARATOR}" unless libs.empty?
272
272
  args << "-w" if warning
273
- args << '-e'
273
+ args << "-e"
274
274
  args << "'#{runner}'"
275
- args << '--'
275
+ args << "--"
276
276
  args << extra_args.map(&:shellescape)
277
277
 
278
278
  args.join " "
@@ -293,10 +293,10 @@ class Work < Queue # :nodoc:
293
293
  end
294
294
 
295
295
  class Integer # :nodoc:
296
- def threads_do(jobs) # :nodoc:
296
+ def threads_do jobs # :nodoc:
297
297
  q = Work.new jobs
298
298
 
299
- self.times.map {
299
+ Array.new(self) {
300
300
  Thread.new do
301
301
  while job = q.pop # go until quit value
302
302
  yield job
data/lib/minitest.rb CHANGED
@@ -9,7 +9,7 @@ require_relative "minitest/compress"
9
9
  # :include: README.rdoc
10
10
 
11
11
  module Minitest
12
- VERSION = "5.24.0" # :nodoc:
12
+ VERSION = "5.25.0" # :nodoc:
13
13
 
14
14
  @@installed_at_exit ||= false
15
15
  @@after_run = []
@@ -67,9 +67,8 @@ module Minitest
67
67
  # Registers Minitest to run at process exit
68
68
 
69
69
  def self.autorun
70
- if Object.const_defined?(:Warning) && Warning.respond_to?(:[]=)
71
- Warning[:deprecated] = true
72
- end
70
+ Warning[:deprecated] = true if
71
+ Object.const_defined?(:Warning) && Warning.respond_to?(:[]=)
73
72
 
74
73
  at_exit {
75
74
  next if $! and not ($!.kind_of? SystemExit and $!.success?)
@@ -135,14 +134,14 @@ module Minitest
135
134
  next unless recv.respond_to? :minitest_plugin_init
136
135
  recv.minitest_plugin_init options
137
136
  else
138
- raise ArgumentError, "blahblah %p" % [mod_or_meth]
137
+ raise ArgumentError, "plugin is %p, but it must be a symbol, string or module" % [mod_or_meth]
139
138
  end
140
139
  end
141
140
  end
142
141
 
143
142
  def self.process_args args = [] # :nodoc:
144
143
  options = {
145
- :io => $stdout,
144
+ :io => $stdout,
146
145
  }
147
146
  orig_args = args.dup
148
147
 
@@ -186,7 +185,7 @@ module Minitest
186
185
  options[:skip] = s.chars.to_a
187
186
  end
188
187
 
189
- ruby27plus = ::Warning.respond_to?(:[]=)
188
+ ruby27plus = ::Warning.respond_to? :[]=
190
189
 
191
190
  opts.on "-W[error]", String, "Turn Ruby warnings into errors" do |s|
192
191
  options[:Werror] = true
@@ -202,20 +201,20 @@ module Minitest
202
201
 
203
202
  unless extensions.empty?
204
203
  opts.separator ""
205
- opts.separator "Known extensions: #{extensions.join(", ")}"
204
+ opts.separator "Known extensions: #{extensions.join ", "}"
206
205
 
207
206
  extensions.each do |mod_or_meth|
208
207
  case mod_or_meth
209
208
  when Symbol, String then
210
209
  meth = mod_or_meth
211
210
  msg = "plugin_#{meth}_options"
212
- send msg, opts, options if respond_to?(msg)
211
+ send msg, opts, options if respond_to? msg
213
212
  when Module
214
213
  recv = mod_or_meth
215
214
  next unless recv.respond_to? :minitest_plugin_options
216
215
  recv.minitest_plugin_options opts, options
217
216
  else
218
- raise ArgumentError, "blahblah %p" % [mod_or_meth]
217
+ raise ArgumentError, "plugin is %p, but it must be a symbol, string or module" % [mod_or_meth]
219
218
  end
220
219
  end
221
220
  end
@@ -240,7 +239,7 @@ module Minitest
240
239
  end
241
240
 
242
241
  options[:args] = orig_args.map { |s|
243
- s =~ /[\s|&<>$()]/ ? s.inspect : s
242
+ s.match?(/[\s|&<>$()]/) ? s.inspect : s
244
243
  }.join " "
245
244
 
246
245
  options
@@ -282,7 +281,7 @@ module Minitest
282
281
  self.init_plugins options
283
282
  self.reporter = nil # runnables shouldn't depend on the reporter, ever
284
283
 
285
- self.parallel_executor.start if parallel_executor.respond_to?(:start)
284
+ self.parallel_executor.start if parallel_executor.respond_to? :start
286
285
  reporter.start
287
286
  begin
288
287
  __run reporter, options
@@ -406,8 +405,8 @@ module Minitest
406
405
  pos = options[:filter]
407
406
  neg = options[:exclude]
408
407
 
409
- pos = Regexp.new $1 if pos.is_a?(String) && pos =~ %r%/(.*)/%
410
- neg = Regexp.new $1 if neg.is_a?(String) && neg =~ %r%/(.*)/%
408
+ pos = Regexp.new $1 if pos.kind_of?(String) && pos =~ %r%/(.*)/%
409
+ neg = Regexp.new $1 if neg.kind_of?(String) && neg =~ %r%/(.*)/%
411
410
 
412
411
  filtered_methods = self.runnable_methods
413
412
  .select { |m| !pos || pos === m || pos === "#{self}##{m}" }
@@ -415,8 +414,22 @@ module Minitest
415
414
 
416
415
  return if filtered_methods.empty?
417
416
 
418
- with_info_handler reporter do
417
+ t0 = name = nil
418
+
419
+ handler = lambda do
420
+ unless reporter.passed? then
421
+ warn "Current results:"
422
+ warn reporter.reporters.grep(SummaryReporter).first
423
+ end
424
+
425
+ warn "Current: %s#%s %.2fs" % [self, name, Minitest.clock_time - t0]
426
+ end
427
+
428
+ with_info_handler reporter, handler do
419
429
  filtered_methods.each do |method_name|
430
+ name = method_name
431
+ t0 = Minitest.clock_time
432
+
420
433
  run_one_method self, method_name, reporter
421
434
  end
422
435
  end
@@ -441,16 +454,7 @@ module Minitest
441
454
  :random
442
455
  end
443
456
 
444
- def self.with_info_handler reporter, &block # :nodoc:
445
- handler = lambda do
446
- unless reporter.passed? then
447
- warn "Current results:"
448
- warn ""
449
- warn reporter.reporters.first
450
- warn ""
451
- end
452
- end
453
-
457
+ def self.with_info_handler reporter, handler, &block # :nodoc:
454
458
  on_signal ::Minitest.info_signal, handler, &block
455
459
  end
456
460
 
@@ -489,7 +493,7 @@ module Minitest
489
493
  def marshal_dump # :nodoc:
490
494
  unless @@marshal_dump_warned then
491
495
  warn ["Minitest::Runnable#marshal_dump is deprecated.",
492
- "You might be violating internals. From", caller.first].join " "
496
+ "You might be violating internals. From", caller(1..1).first].join " "
493
497
  @@marshal_dump_warned = true
494
498
  end
495
499
 
@@ -617,7 +621,7 @@ module Minitest
617
621
  # Did this run error?
618
622
 
619
623
  def error?
620
- self.failures.any? { |f| UnexpectedError === f }
624
+ self.failures.any? UnexpectedError
621
625
  end
622
626
  end
623
627
 
@@ -720,7 +724,7 @@ module Minitest
720
724
  true
721
725
  end
722
726
 
723
- def synchronize(&block) # :nodoc:
727
+ def synchronize &block # :nodoc:
724
728
  @mutex.synchronize(&block)
725
729
  end
726
730
  end
@@ -752,11 +756,11 @@ module Minitest
752
756
  # own.
753
757
 
754
758
  class ProgressReporter < Reporter
755
- def prerecord klass, name #:nodoc:
756
- if options[:verbose] then
757
- io.print "%s#%s = " % [klass.name, name]
758
- io.flush
759
- end
759
+ def prerecord klass, name # :nodoc:
760
+ return unless options[:verbose]
761
+
762
+ io.print "%s#%s = " % [klass.name, name]
763
+ io.flush
760
764
  end
761
765
 
762
766
  def record result # :nodoc:
@@ -890,10 +894,8 @@ module Minitest
890
894
  # own.
891
895
 
892
896
  class SummaryReporter < StatisticsReporter
893
- # :stopdoc:
894
- attr_accessor :sync
895
- attr_accessor :old_sync
896
- # :startdoc:
897
+ attr_accessor :sync # :nodoc:
898
+ attr_accessor :old_sync # :nodoc:
897
899
 
898
900
  def start # :nodoc:
899
901
  super
@@ -941,20 +943,22 @@ module Minitest
941
943
  end
942
944
 
943
945
  def to_s # :nodoc:
944
- aggregated_results(StringIO.new(''.b)).string
946
+ aggregated_results(StringIO.new("".b)).string
945
947
  end
946
948
 
947
949
  def summary # :nodoc:
948
- extra = ""
950
+ extra = []
949
951
 
950
- extra = "\n\nYou have skipped tests. Run with --verbose for details." if
951
- results.any?(&:skipped?) unless
952
- options[:verbose] or options[:show_skips] or ENV["MT_NO_SKIP_MSG"]
952
+ extra << ", %d warnings" % [warnings] if options[:Werror]
953
953
 
954
- extra.prepend ", %d warnings" % [warnings] if options[:Werror]
954
+ extra << "\n\nYou have skipped tests. Run with --verbose for details." if
955
+ results.any?(&:skipped?) unless
956
+ options[:verbose] or
957
+ options[:show_skips] or
958
+ ENV["MT_NO_SKIP_MSG"]
955
959
 
956
960
  "%d runs, %d assertions, %d failures, %d errors, %d skips%s" %
957
- [count, assertions, failures, errors, skips, extra]
961
+ [count, assertions, failures, errors, skips, extra.join]
958
962
  end
959
963
  end
960
964
 
@@ -1125,7 +1129,7 @@ module Minitest
1125
1129
 
1126
1130
  def maglev? platform = defined?(RUBY_ENGINE) && RUBY_ENGINE
1127
1131
  where = Minitest.filter_backtrace(caller).first
1128
- where = where.split(/:in /, 2).first # clean up noise
1132
+ where = where.split(":in ", 2).first # clean up noise
1129
1133
  warn "DEPRECATED: `maglev?` called from #{where}. This will fail in Minitest 6."
1130
1134
  "maglev" == platform
1131
1135
  end
@@ -1134,14 +1138,14 @@ module Minitest
1134
1138
  # Is this running on mri?
1135
1139
 
1136
1140
  def mri? platform = RUBY_DESCRIPTION
1137
- /^ruby/ =~ platform
1141
+ platform.start_with? "ruby"
1138
1142
  end
1139
1143
 
1140
1144
  ##
1141
1145
  # Is this running on macOS?
1142
1146
 
1143
1147
  def osx? platform = RUBY_PLATFORM
1144
- /darwin/ =~ platform
1148
+ platform.include? "darwin"
1145
1149
  end
1146
1150
 
1147
1151
  ##
@@ -1149,7 +1153,7 @@ module Minitest
1149
1153
 
1150
1154
  def rubinius? platform = defined?(RUBY_ENGINE) && RUBY_ENGINE
1151
1155
  where = Minitest.filter_backtrace(caller).first
1152
- where = where.split(/:in /, 2).first # clean up noise
1156
+ where = where.split(":in ", 2).first # clean up noise
1153
1157
  warn "DEPRECATED: `rubinius?` called from #{where}. This will fail in Minitest 6."
1154
1158
  "rbx" == platform
1155
1159
  end
@@ -1158,7 +1162,7 @@ module Minitest
1158
1162
  # Is this running on windows?
1159
1163
 
1160
1164
  def windows? platform = RUBY_PLATFORM
1161
- /mswin|mingw/ =~ platform
1165
+ /mswin|mingw/.match? platform
1162
1166
  end
1163
1167
  end
1164
1168
 
@@ -1169,11 +1173,14 @@ module Minitest
1169
1173
 
1170
1174
  class BacktraceFilter
1171
1175
 
1172
- MT_RE = %r%lib/minitest|internal:warning% #:nodoc:
1176
+ MT_RE = %r%lib/minitest|internal:warning% # :nodoc:
1177
+
1178
+ ##
1179
+ # The regular expression to use to filter backtraces. Defaults to +MT_RE+.
1173
1180
 
1174
1181
  attr_accessor :regexp
1175
1182
 
1176
- def initialize regexp = MT_RE
1183
+ def initialize regexp = MT_RE # :nodoc:
1177
1184
  self.regexp = regexp
1178
1185
  end
1179
1186
 
@@ -1186,9 +1193,9 @@ module Minitest
1186
1193
 
1187
1194
  return bt.dup if $DEBUG || ENV["MT_DEBUG"]
1188
1195
 
1189
- new_bt = bt.take_while { |line| line.to_s !~ regexp }
1190
- new_bt = bt.select { |line| line.to_s !~ regexp } if new_bt.empty?
1191
- new_bt = bt.dup if new_bt.empty?
1196
+ new_bt = bt.take_while { |line| !regexp.match? line.to_s }
1197
+ new_bt = bt.select { |line| !regexp.match? line.to_s } if new_bt.empty?
1198
+ new_bt = bt.dup if new_bt.empty?
1192
1199
 
1193
1200
  new_bt
1194
1201
  end
@@ -3,10 +3,6 @@ require "stringio"
3
3
  require "minitest/autorun"
4
4
 
5
5
  class Minitest::Test
6
- def clean s
7
- s.gsub(/^ {6}/, "")
8
- end
9
-
10
6
  def with_empty_backtrace_filter
11
7
  with_backtrace_filter Minitest::BacktraceFilter.new %r%.% do
12
8
  yield
@@ -31,6 +27,7 @@ class Minitest::Test
31
27
  end
32
28
 
33
29
  def assert_deprecation re = /DEPRECATED/
30
+ re = // if $-w.nil? # "skip" if running `rake testW0`
34
31
  assert_output "", re do
35
32
  yield
36
33
  end
@@ -67,7 +64,7 @@ class MetaMetaMetaTestCase < Minitest::Test
67
64
  def run_tu_with_fresh_reporter flags = %w[--seed 42]
68
65
  options = Minitest.process_args flags
69
66
 
70
- @output = StringIO.new("".encode(Encoding::UTF_8))
67
+ @output = StringIO.new(+"")
71
68
 
72
69
  self.reporter = Minitest::CompositeReporter.new
73
70
  reporter << Minitest::SummaryReporter.new(@output, options)
@@ -76,7 +73,7 @@ class MetaMetaMetaTestCase < Minitest::Test
76
73
  with_stderr @output do
77
74
  reporter.start
78
75
 
79
- yield(reporter) if block_given?
76
+ yield reporter if block_given?
80
77
 
81
78
  @tus ||= [@tu]
82
79
  @tus.each do |tu|
@@ -94,8 +91,8 @@ class MetaMetaMetaTestCase < Minitest::Test
94
91
  end
95
92
 
96
93
  def assert_report expected, flags = %w[--seed 42], &block
97
- header = clean <<-EOM
98
- 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 " "}
99
96
 
100
97
  # Running:
101
98
 
@@ -130,7 +127,7 @@ class MetaMetaMetaTestCase < Minitest::Test
130
127
  output.gsub!(/in [`']block in (?:([^']+)[#.])?/, "in 'block in")
131
128
  output.gsub!(/in [`'](?:([^']+)[#.])?/, "in '")
132
129
 
133
- output.gsub!(/( at )[^:]+:\d+/) { "#{$1}[#{file[$2]}:LINE]" } # eval?
130
+ output.gsub!(/( at )([^:]+):\d+/) { "#{$1}[#{file[$2]}:LINE]" } # eval?
134
131
 
135
132
  output
136
133
  end