minitest 5.27.0 → 6.0.0.a1

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.
@@ -0,0 +1,104 @@
1
+ $LOAD_PATH.unshift "test", "lib"
2
+
3
+ require "simplecov" if ENV["MT_COV"] || ARGV.delete("--simplecov")
4
+ require_relative "autorun"
5
+ require_relative "path_expander"
6
+
7
+ ##
8
+ # Runs (Get it? It's fast!) your tests and makes it easier to rerun individual
9
+ # failures.
10
+
11
+ module Minitest
12
+ class Sprint
13
+ # extracted version = "1.5.0"
14
+
15
+ ##
16
+ # Process and run minitest cmdline.
17
+
18
+ def self.run args = ARGV
19
+ if ARGV.delete("--bisect") or ARGV.delete("-b") then
20
+ require_relative "bisect"
21
+
22
+ return Minitest::Bisect.run ARGV
23
+ end
24
+
25
+ Minitest::PathExpander.new(args).process { |f|
26
+ require "./#{f}" if File.file? f
27
+ }
28
+ end
29
+
30
+ ##
31
+ # An extra minitest reporter to output how to rerun failures in
32
+ # various styles.
33
+
34
+ class SprintReporter < AbstractReporter
35
+ ##
36
+ # The style to report, either lines or regexp. Defaults to lines.
37
+ attr_accessor :style
38
+ attr_accessor :results # :nodoc:
39
+
40
+ def initialize style = :regexp # :nodoc:
41
+ self.results = []
42
+ self.style = style
43
+ end
44
+
45
+ def record result # :nodoc:
46
+ results << result unless result.passed? or result.skipped?
47
+ end
48
+
49
+ def report # :nodoc:
50
+ return if results.empty?
51
+
52
+ puts
53
+ puts "Happy Happy Sprint List:"
54
+ puts
55
+ print_list
56
+ puts
57
+ end
58
+
59
+ def print_list # :nodoc:
60
+ case style
61
+ when :regexp
62
+ results.each do |result|
63
+ puts " minitest -n #{result.class_name}##{result.name}"
64
+ end
65
+ when :lines
66
+ files = Hash.new { |h,k| h[k] = [] }
67
+ results.each do |result|
68
+ path, line = result.source_location
69
+ path = path.delete_prefix "#{Dir.pwd}/"
70
+ files[path] << line
71
+ end
72
+
73
+ files.sort.each do |path, lines|
74
+ puts " minitest %s:%s" % [path, lines.sort.join(",")]
75
+ end
76
+ else
77
+ raise "unsupported style: %p" % [style]
78
+ end
79
+ end
80
+ end
81
+
82
+ ##
83
+ # An extra minitest reporter to output how to rerun failures using
84
+ # rake.
85
+
86
+ class RakeReporter < SprintReporter
87
+ ##
88
+ # The name of the rake task to rerun. Defaults to nil.
89
+
90
+ attr_accessor :name
91
+
92
+ def initialize name = nil # :nodoc:
93
+ super()
94
+ self.name = name
95
+ end
96
+
97
+ def print_list # :nodoc:
98
+ results.each do |result|
99
+ puts [" rake", name, "N=#{result.class_name}##{result.name}"].compact.join(" ")
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,39 @@
1
+ require_relative "../minitest"
2
+
3
+ # :stopdoc:
4
+ class OptionParser # unofficial embedded gem "makeoptparseworkwell"
5
+ def hidden(...) = define(...).tap { |sw| def sw.summarize(*) = nil }
6
+ def deprecate(from, to) = hidden(from) { abort "#{from} is deprecated. Use #{to}." }
7
+ def topdict(name) = name.length > 1 ? top.long : top.short
8
+ def alias(from, to) = (dict = topdict(from) and dict[to] = dict[from])
9
+ end unless OptionParser.method_defined? :hidden
10
+ # :startdoc:
11
+
12
+ module Minitest # :nodoc:
13
+ def self.plugin_sprint_options opts, options # :nodoc:
14
+ opts.on "--rake [TASK]", "Report how to re-run failures with rake." do |task|
15
+ options[:sprint] = :rake
16
+ options[:rake_task] = task
17
+ end
18
+
19
+ opts.deprecate "--binstub", "--rerun"
20
+
21
+ sprint_styles = %w[rake lines names binstub]
22
+
23
+ opts.on "-r", "--rerun [STYLE]", sprint_styles, "Report how to re-run failures using STYLE (names, lines)." do |style|
24
+ options[:sprint] = (style || :lines).to_sym
25
+ end
26
+ end
27
+
28
+ def self.plugin_sprint_init options
29
+ require_relative "sprint"
30
+ case options[:sprint]
31
+ when :rake then
32
+ self.reporter << Minitest::Sprint::RakeReporter.new(options[:rake_task])
33
+ when :binstub, :names then
34
+ self.reporter << Minitest::Sprint::SprintReporter.new
35
+ when :lines then
36
+ self.reporter << Minitest::Sprint::SprintReporter.new(:lines)
37
+ end
38
+ end
39
+ end
data/lib/minitest/test.rb CHANGED
@@ -1,3 +1,4 @@
1
+ raise "what the fuck?" unless defined? Minitest::Runnable
1
2
  require_relative "../minitest" unless defined? Minitest::Runnable
2
3
 
3
4
  module Minitest
@@ -12,10 +13,6 @@ module Minitest
12
13
  include Minitest::Reportable
13
14
  include Minitest::Assertions
14
15
 
15
- def class_name # :nodoc:
16
- self.class.name # for Minitest::Reportable
17
- end
18
-
19
16
  PASSTHROUGH_EXCEPTIONS = [NoMemoryError, SignalException, SystemExit] # :nodoc:
20
17
 
21
18
  SETUP_METHODS = %w[ before_setup setup after_setup ] # :nodoc:
@@ -34,8 +31,8 @@ module Minitest
34
31
 
35
32
  def self.i_suck_and_my_tests_are_order_dependent!
36
33
  class << self
37
- undef_method :test_order if method_defined? :test_order
38
- define_method :test_order do :alpha end
34
+ undef_method :run_order if method_defined? :run_order
35
+ define_method :run_order do :alpha end
39
36
  end
40
37
  end
41
38
 
@@ -65,20 +62,20 @@ module Minitest
65
62
 
66
63
  ##
67
64
  # Returns all instance methods starting with "test_". Based on
68
- # #test_order, the methods are either sorted, randomized
65
+ # #run_order, the methods are either sorted, randomized
69
66
  # (default), or run in parallel.
70
67
 
71
68
  def self.runnable_methods
72
69
  methods = methods_matching(/^test_/)
73
70
 
74
- case self.test_order
71
+ case self.run_order
75
72
  when :random, :parallel then
76
73
  srand Minitest.seed
77
74
  methods.sort.shuffle
78
75
  when :alpha, :sorted then
79
76
  methods.sort
80
77
  else
81
- raise "Unknown test_order: #{self.test_order.inspect}"
78
+ raise "Unknown_order: %p" % [self.run_order]
82
79
  end
83
80
  end
84
81
 
@@ -234,5 +231,3 @@ module Minitest
234
231
  extend Guard
235
232
  end # Test
236
233
  end
237
-
238
- require_relative "unit" if ENV["MT_COMPAT"] # compatibility layer only
@@ -168,20 +168,18 @@ module Minitest # :nodoc:
168
168
  ENV["TESTOPTS"]
169
169
  warn "FILTER is deprecated in Minitest::TestTask. Use A instead" if
170
170
  ENV["FILTER"]
171
- warn "N is deprecated in Minitest::TestTask. Use MT_CPU instead" if
172
- ENV["N"] && ENV["N"].to_i > 0
173
171
 
174
172
  lib_extras = (ENV["MT_LIB_EXTRAS"] || "").split File::PATH_SEPARATOR
175
173
  self.libs[0, 0] = lib_extras
176
174
 
177
- extra_args << "-n" << ENV["N"] if ENV["N"]
178
- extra_args << "-e" << ENV["X"] if ENV["X"]
175
+ extra_args << "-i" << ENV["N"] if ENV["N"]
176
+ extra_args << "-i" << ENV["I"] if ENV["I"]
177
+ extra_args << "-x" << ENV["X"] if ENV["X"]
178
+ extra_args << "-x" << ENV["E"] if ENV["E"]
179
179
  extra_args.concat Shellwords.split(ENV["TESTOPTS"]) if ENV["TESTOPTS"]
180
180
  extra_args.concat Shellwords.split(ENV["FILTER"]) if ENV["FILTER"]
181
181
  extra_args.concat Shellwords.split(ENV["A"]) if ENV["A"]
182
182
 
183
- ENV.delete "N" if ENV["N"]
184
-
185
183
  # TODO? RUBY_DEBUG = ENV["RUBY_DEBUG"]
186
184
  # TODO? ENV["RUBY_FLAGS"]
187
185
 
data/lib/minitest.rb CHANGED
@@ -10,7 +10,7 @@ require_relative "minitest/compress"
10
10
  # runtime. See +Minitest.run+ for more information.
11
11
 
12
12
  module Minitest
13
- VERSION = "5.26.2" # :nodoc:
13
+ VERSION = "6.0.0.a1" # :nodoc:
14
14
 
15
15
  @@installed_at_exit ||= false
16
16
  @@after_run = []
@@ -33,8 +33,7 @@ module Minitest
33
33
 
34
34
  cattr_accessor :parallel_executor
35
35
 
36
- warn "DEPRECATED: use MT_CPU instead of N for parallel test runs" if ENV["N"] && ENV["N"].to_i > 0
37
- n_threads = (ENV["MT_CPU"] || ENV["N"] || Etc.nprocessors).to_i
36
+ n_threads = (ENV["MT_CPU"] || Etc.nprocessors).to_i
38
37
 
39
38
  self.parallel_executor = Parallel::Executor.new n_threads if n_threads > 1
40
39
 
@@ -97,6 +96,17 @@ module Minitest
97
96
  @@after_run << block
98
97
  end
99
98
 
99
+ ##
100
+ # Manually load plugins by name.
101
+
102
+ def self.load *names
103
+ names.each do |name|
104
+ require "minitest/#{name}_plugin"
105
+
106
+ self.extensions << name.to_s
107
+ end
108
+ end
109
+
100
110
  ##
101
111
  # Register a plugin to be used. Does NOT require / load it.
102
112
 
@@ -145,6 +155,8 @@ module Minitest
145
155
  }
146
156
  orig_args = args.dup
147
157
 
158
+ warn "--no-plugins is a no-op" if args.delete "--no-plugins" # TODO: remove me! when?
159
+
148
160
  OptionParser.new do |opts|
149
161
  opts.program_name = "minitest"
150
162
  opts.version = Minitest::VERSION
@@ -160,8 +172,6 @@ module Minitest
160
172
  exit
161
173
  end
162
174
 
163
- opts.on "--no-plugins", "Bypass minitest plugin auto-loading (or env: MT_NO_PLUGINS=1)."
164
-
165
175
  desc = "Sets random seed. Also via env, eg: SEED=42"
166
176
  opts.on "-s", "--seed SEED", Integer, desc do |m|
167
177
  options[:seed] = m
@@ -179,8 +189,10 @@ module Minitest
179
189
  options[:show_skips] = true
180
190
  end
181
191
 
182
- opts.on "-n", "--name PATTERN", "Include /regexp/ or string for run." do |a|
183
- options[:filter] = a
192
+ opts.on "-b", "--bisect", "Run minitest in bisect-mode to isolate flaky tests."
193
+
194
+ opts.on "-i", "--include PATTERN", "Include /regexp/ or string for run." do |a|
195
+ options[:include] = a
184
196
  end
185
197
 
186
198
  opts.on "-e", "--exclude PATTERN", "Exclude /regexp/ or string from run." do |a|
@@ -192,9 +204,9 @@ module Minitest
192
204
  def opts.alias(from, to) = (dict = topdict(from) ; dict[to] = dict[from])
193
205
 
194
206
  # these will work but won't show up in --help output:
195
- opts.alias "name", "include"
196
- opts.alias "n", "i"
197
- opts.alias "e", "x"
207
+ opts.alias "include", "name"
208
+ opts.alias "i", "n"
209
+ opts.alias "e", "x"
198
210
 
199
211
  opts.on "-S", "--skip CODES", String, "Skip reporting of certain types of results (eg E)." do |s|
200
212
  options[:skip] = s.chars.to_a
@@ -265,23 +277,20 @@ module Minitest
265
277
  #
266
278
  # The overall structure of a run looks like this:
267
279
  #
280
+ # [Minitest.load_plugins] optional, called by user, or require what you want
268
281
  # Minitest.autorun
269
282
  # Minitest.run(args)
270
- # Minitest.load_plugins
271
283
  # Minitest.process_args
272
284
  # Minitest.init_plugins
273
- # Minitest.__run(reporter, options)
285
+ # Minitest.run_all_suites(reporter, options)
274
286
  # Runnable.runnables.each |runnable_klass|
275
- # runnable_klass.run(reporter, options)
276
- # filtered_methods = runnable_methods.select {...}.reject {...}
287
+ # runnable_klass.run_suite(reporter, options)
288
+ # filtered_methods = runnable_klass.filter_runnable_methods options
277
289
  # filtered_methods.each |runnable_method|
278
- # runnable_klass.run_one_method(self, runnable_method, reporter)
279
- # Minitest.run_one_method(runnable_klass, runnable_method)
280
- # runnable_klass.new(runnable_method).run
290
+ # runnable_klass.run(self, runnable_method, reporter)
291
+ # runnable_klass.new(runnable_method).run
281
292
 
282
293
  def self.run args = []
283
- self.load_plugins unless args.delete("--no-plugins") || ENV["MT_NO_PLUGINS"]
284
-
285
294
  options = process_args args
286
295
 
287
296
  Minitest.seed = options[:seed]
@@ -298,7 +307,7 @@ module Minitest
298
307
  self.parallel_executor.start if parallel_executor.respond_to? :start
299
308
  reporter.start
300
309
  begin
301
- __run reporter, options
310
+ run_all_suites reporter, options
302
311
  finished = true
303
312
  rescue Interrupt
304
313
  warn "Interrupted. Exiting..."
@@ -315,7 +324,7 @@ module Minitest
315
324
  end
316
325
 
317
326
  def self.empty_run! options # :nodoc:
318
- filter = options[:filter]
327
+ filter = options[:include]
319
328
  return true unless filter # no filter, but nothing ran == success
320
329
 
321
330
  warn "Nothing ran for filter: %s" % [filter]
@@ -334,17 +343,17 @@ module Minitest
334
343
  # Internal run method. Responsible for telling all Runnable
335
344
  # sub-classes to run.
336
345
 
337
- def self.__run reporter, options
346
+ def self.run_all_suites reporter, options
338
347
  suites = Runnable.runnables.shuffle
339
- parallel, serial = suites.partition { |s| s.test_order == :parallel }
348
+ parallel, serial = suites.partition { |s| s.run_order == :parallel }
340
349
 
341
350
  # If we run the parallel tests before the serial tests, the parallel tests
342
351
  # could run in parallel with the serial tests. This would be bad because
343
352
  # the serial tests won't lock around Reporter#record. Run the serial tests
344
353
  # first, so that after they complete, the parallel tests will lock when
345
354
  # recording results.
346
- serial.map { |suite| suite.run reporter, options } +
347
- parallel.map { |suite| suite.run reporter, options }
355
+ serial.map { |suite| suite.run_suite reporter, options } +
356
+ parallel.map { |suite| suite.run_suite reporter, options }
348
357
  end
349
358
 
350
359
  def self.filter_backtrace bt # :nodoc:
@@ -412,21 +421,30 @@ module Minitest
412
421
  reset
413
422
 
414
423
  ##
415
- # Responsible for running all runnable methods in a given class,
416
- # each in its own instance. Each instance is passed to the
417
- # reporter to record.
424
+ # Returns an array of filtered +runnable_methods+. Uses
425
+ # options[:include] (--include arguments) and options[:exclude]
426
+ # (--exclude arguments) values to filter.
418
427
 
419
- def self.run reporter, options = {}
420
- pos = options[:filter]
428
+ def self.filter_runnable_methods options={}
429
+ pos = options[:include]
421
430
  neg = options[:exclude]
422
431
 
423
432
  pos = Regexp.new $1 if pos.kind_of?(String) && pos =~ %r%/(.*)/%
424
433
  neg = Regexp.new $1 if neg.kind_of?(String) && neg =~ %r%/(.*)/%
425
434
 
426
435
  # at most 1-2% slower than a 1-pass version, stop optimizing this
427
- filtered_methods = self.runnable_methods
436
+ self.runnable_methods
428
437
  .select { |m| !pos || pos === m || pos === "#{self}##{m}" }
429
438
  .reject { |m| neg && (neg === m || neg === "#{self}##{m}") }
439
+ end
440
+
441
+ ##
442
+ # Responsible for running all runnable methods in a given class,
443
+ # each in its own instance. Each instance is passed to the
444
+ # reporter to record.
445
+
446
+ def Runnable.run_suite reporter, options = {}
447
+ filtered_methods = filter_runnable_methods options
430
448
 
431
449
  return if filtered_methods.empty?
432
450
 
@@ -441,12 +459,12 @@ module Minitest
441
459
  warn "Current: %s#%s %.2fs" % [self, name, Minitest.clock_time - t0]
442
460
  end
443
461
 
444
- with_info_handler reporter do
462
+ with_info_handler do
445
463
  filtered_methods.each do |method_name|
446
464
  name = method_name
447
465
  t0 = Minitest.clock_time
448
466
 
449
- run_one_method self, method_name, reporter
467
+ run self, method_name, reporter
450
468
  end
451
469
  end
452
470
  end
@@ -457,20 +475,20 @@ module Minitest
457
475
  # that subclasses can specialize the running of an individual
458
476
  # test. See Minitest::ParallelTest::ClassMethods for an example.
459
477
 
460
- def self.run_one_method klass, method_name, reporter
478
+ def Runnable.run klass, method_name, reporter
461
479
  reporter.prerecord klass, method_name
462
- reporter.record Minitest.run_one_method(klass, method_name)
480
+ reporter.record klass.new(method_name).run
463
481
  end
464
482
 
465
483
  ##
466
484
  # Defines the order to run tests (:random by default). Override
467
485
  # this or use a convenience method to change it for your tests.
468
486
 
469
- def self.test_order
487
+ def self.run_order
470
488
  :random
471
489
  end
472
490
 
473
- def self.with_info_handler reporter, &block # :nodoc:
491
+ def self.with_info_handler _reporter=nil, &block # :nodoc:
474
492
  on_signal ::Minitest.info_signal, @_info_handler, &block
475
493
  end
476
494
 
@@ -504,22 +522,6 @@ module Minitest
504
522
  @@runnables
505
523
  end
506
524
 
507
- @@marshal_dump_warned = false
508
-
509
- def marshal_dump # :nodoc:
510
- unless @@marshal_dump_warned then
511
- warn ["Minitest::Runnable#marshal_dump is deprecated.",
512
- "You might be violating internals. From", caller(1..1).first].join " "
513
- @@marshal_dump_warned = true
514
- end
515
-
516
- [self.name, self.failures, self.assertions, self.time]
517
- end
518
-
519
- def marshal_load ary # :nodoc:
520
- self.name, self.failures, self.assertions, self.time = ary
521
- end
522
-
523
525
  def failure # :nodoc:
524
526
  self.failures.first
525
527
  end
@@ -651,9 +653,6 @@ module Minitest
651
653
  class Result < Runnable
652
654
  include Minitest::Reportable
653
655
 
654
- undef_method :marshal_dump
655
- undef_method :marshal_load
656
-
657
656
  ##
658
657
  # The class name of the test result.
659
658
 
@@ -1013,8 +1012,7 @@ module Minitest
1013
1012
 
1014
1013
  def prerecord klass, name # :nodoc:
1015
1014
  self.reporters.each do |reporter|
1016
- # TODO: remove conditional for minitest 6
1017
- reporter.prerecord klass, name if reporter.respond_to? :prerecord
1015
+ reporter.prerecord klass, name
1018
1016
  end
1019
1017
  end
1020
1018
 
@@ -1140,16 +1138,6 @@ module Minitest
1140
1138
  "java" == platform
1141
1139
  end
1142
1140
 
1143
- ##
1144
- # Is this running on maglev?
1145
-
1146
- def maglev? platform = defined?(RUBY_ENGINE) && RUBY_ENGINE
1147
- where = Minitest.filter_backtrace(caller).first
1148
- where = where.split(":in ", 2).first # clean up noise
1149
- warn "DEPRECATED: `maglev?` called from #{where}. This will fail in Minitest 6."
1150
- "maglev" == platform
1151
- end
1152
-
1153
1141
  ##
1154
1142
  # Is this running on mri?
1155
1143
 
@@ -1164,16 +1152,6 @@ module Minitest
1164
1152
  platform.include? "darwin"
1165
1153
  end
1166
1154
 
1167
- ##
1168
- # Is this running on rubinius?
1169
-
1170
- def rubinius? platform = defined?(RUBY_ENGINE) && RUBY_ENGINE
1171
- where = Minitest.filter_backtrace(caller).first
1172
- where = where.split(":in ", 2).first # clean up noise
1173
- warn "DEPRECATED: `rubinius?` called from #{where}. This will fail in Minitest 6."
1174
- "rbx" == platform
1175
- end
1176
-
1177
1155
  ##
1178
1156
  # Is this running on windows?
1179
1157
 
@@ -1219,12 +1197,6 @@ module Minitest
1219
1197
 
1220
1198
  self.backtrace_filter = BacktraceFilter.new
1221
1199
 
1222
- def self.run_one_method klass, method_name # :nodoc:
1223
- result = klass.new(method_name).run
1224
- raise "#{klass}#run _must_ return a Result" unless Result === result
1225
- result
1226
- end
1227
-
1228
1200
  # :stopdoc:
1229
1201
 
1230
1202
  if defined? Process::CLOCK_MONOTONIC # :nodoc:
@@ -79,7 +79,7 @@ class MetaMetaMetaTestCase < Minitest::Test
79
79
  @tus.each do |tu|
80
80
  Minitest::Runnable.runnables.delete tu
81
81
 
82
- tu.run reporter, options
82
+ tu.run_suite reporter, options
83
83
  end
84
84
 
85
85
  reporter.report