minitest 5.25.4 → 5.27.0
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +4 -2
- data/History.rdoc +51 -0
- data/README.rdoc +25 -15
- data/Rakefile +18 -2
- data/design_rationale.rb +21 -19
- data/lib/hoe/minitest.rb +2 -1
- data/lib/minitest/assertions.rb +21 -26
- data/lib/minitest/autorun.rb +4 -4
- data/lib/minitest/benchmark.rb +2 -2
- data/lib/minitest/expectations.rb +2 -2
- data/lib/minitest/hell.rb +1 -1
- data/lib/minitest/manual_plugins.rb +1 -1
- data/lib/minitest/mock.rb +5 -25
- data/lib/minitest/parallel.rb +2 -0
- data/lib/minitest/pride.rb +1 -1
- data/lib/minitest/pride_plugin.rb +1 -1
- data/lib/minitest/spec.rb +9 -6
- data/lib/minitest/test.rb +5 -4
- data/lib/minitest/test_task.rb +28 -11
- data/lib/minitest/unit.rb +1 -1
- data/lib/minitest.rb +48 -33
- data/test/minitest/test_minitest_assertions.rb +19 -62
- data/test/minitest/test_minitest_mock.rb +5 -10
- data/test/minitest/test_minitest_reporter.rb +6 -5
- data/test/minitest/test_minitest_spec.rb +23 -27
- data/test/minitest/test_minitest_test.rb +20 -2
- data.tar.gz.sig +0 -0
- metadata +32 -22
- metadata.gz.sig +0 -0
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.
|
|
13
|
+
VERSION = "5.26.2" # :nodoc:
|
|
14
14
|
|
|
15
15
|
@@installed_at_exit ||= false
|
|
16
16
|
@@after_run = []
|
|
@@ -36,7 +36,7 @@ module Minitest
|
|
|
36
36
|
warn "DEPRECATED: use MT_CPU instead of N for parallel test runs" if ENV["N"] && ENV["N"].to_i > 0
|
|
37
37
|
n_threads = (ENV["MT_CPU"] || ENV["N"] || Etc.nprocessors).to_i
|
|
38
38
|
|
|
39
|
-
self.parallel_executor = Parallel::Executor.new n_threads
|
|
39
|
+
self.parallel_executor = Parallel::Executor.new n_threads if n_threads > 1
|
|
40
40
|
|
|
41
41
|
##
|
|
42
42
|
# Filter object for backtraces.
|
|
@@ -68,8 +68,7 @@ module Minitest
|
|
|
68
68
|
# Registers Minitest to run at process exit
|
|
69
69
|
|
|
70
70
|
def self.autorun
|
|
71
|
-
Warning[:deprecated] = true
|
|
72
|
-
Object.const_defined?(:Warning) && Warning.respond_to?(:[]=)
|
|
71
|
+
Warning[:deprecated] = true
|
|
73
72
|
|
|
74
73
|
at_exit {
|
|
75
74
|
next if $! and not ($!.kind_of? SystemExit and $!.success?)
|
|
@@ -147,26 +146,32 @@ module Minitest
|
|
|
147
146
|
orig_args = args.dup
|
|
148
147
|
|
|
149
148
|
OptionParser.new do |opts|
|
|
150
|
-
opts.
|
|
149
|
+
opts.program_name = "minitest"
|
|
151
150
|
opts.version = Minitest::VERSION
|
|
152
151
|
|
|
152
|
+
opts.banner = [
|
|
153
|
+
"Usage: rake test [A=options] (see Minitest::TestTask for more options)",
|
|
154
|
+
"minitest [paths] [options] (with minitest-sprint gem)",
|
|
155
|
+
"ruby path/to/test.rb [options]\n\n",
|
|
156
|
+
].join "\n or: "
|
|
157
|
+
|
|
153
158
|
opts.on "-h", "--help", "Display this help." do
|
|
154
159
|
puts opts
|
|
155
160
|
exit
|
|
156
161
|
end
|
|
157
162
|
|
|
158
|
-
opts.on "--no-plugins", "Bypass minitest plugin auto-loading (or
|
|
163
|
+
opts.on "--no-plugins", "Bypass minitest plugin auto-loading (or env: MT_NO_PLUGINS=1)."
|
|
159
164
|
|
|
160
|
-
desc = "Sets random seed. Also via env
|
|
165
|
+
desc = "Sets random seed. Also via env, eg: SEED=42"
|
|
161
166
|
opts.on "-s", "--seed SEED", Integer, desc do |m|
|
|
162
|
-
options[:seed] = m
|
|
167
|
+
options[:seed] = m
|
|
163
168
|
end
|
|
164
169
|
|
|
165
|
-
opts.on "-v", "--verbose", "Verbose.
|
|
170
|
+
opts.on "-v", "--verbose", "Verbose. Print each name as they run." do
|
|
166
171
|
options[:verbose] = true
|
|
167
172
|
end
|
|
168
173
|
|
|
169
|
-
opts.on "-q", "--quiet", "Quiet. Show no
|
|
174
|
+
opts.on "-q", "--quiet", "Quiet. Show no dots while processing files." do
|
|
170
175
|
options[:quiet] = true
|
|
171
176
|
end
|
|
172
177
|
|
|
@@ -174,7 +179,7 @@ module Minitest
|
|
|
174
179
|
options[:show_skips] = true
|
|
175
180
|
end
|
|
176
181
|
|
|
177
|
-
opts.on "-n", "--name PATTERN", "
|
|
182
|
+
opts.on "-n", "--name PATTERN", "Include /regexp/ or string for run." do |a|
|
|
178
183
|
options[:filter] = a
|
|
179
184
|
end
|
|
180
185
|
|
|
@@ -182,21 +187,28 @@ module Minitest
|
|
|
182
187
|
options[:exclude] = a
|
|
183
188
|
end
|
|
184
189
|
|
|
190
|
+
# part of my unofficial embedded gem "makeoptparseworkwell"
|
|
191
|
+
def opts.topdict(name) = (name.length > 1 ? top.long : top.short)
|
|
192
|
+
def opts.alias(from, to) = (dict = topdict(from) ; dict[to] = dict[from])
|
|
193
|
+
|
|
194
|
+
# 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"
|
|
198
|
+
|
|
185
199
|
opts.on "-S", "--skip CODES", String, "Skip reporting of certain types of results (eg E)." do |s|
|
|
186
200
|
options[:skip] = s.chars.to_a
|
|
187
201
|
end
|
|
188
202
|
|
|
189
|
-
ruby27plus = ::Warning.respond_to? :[]=
|
|
190
|
-
|
|
191
203
|
opts.on "-W[error]", String, "Turn Ruby warnings into errors" do |s|
|
|
192
204
|
options[:Werror] = true
|
|
193
205
|
case s
|
|
194
206
|
when "error", "all", nil then
|
|
195
|
-
|
|
207
|
+
require_relative "minitest/error_on_warning"
|
|
196
208
|
$VERBOSE = true
|
|
197
|
-
::Warning[:deprecated] = true
|
|
209
|
+
::Warning[:deprecated] = true
|
|
198
210
|
else
|
|
199
|
-
::Warning[s.to_sym] = true
|
|
211
|
+
::Warning[s.to_sym] = true # check validity of category
|
|
200
212
|
end
|
|
201
213
|
end
|
|
202
214
|
|
|
@@ -259,12 +271,13 @@ module Minitest
|
|
|
259
271
|
# Minitest.process_args
|
|
260
272
|
# Minitest.init_plugins
|
|
261
273
|
# Minitest.__run(reporter, options)
|
|
262
|
-
# Runnable.runnables.each
|
|
274
|
+
# Runnable.runnables.each |runnable_klass|
|
|
263
275
|
# runnable_klass.run(reporter, options)
|
|
264
|
-
#
|
|
265
|
-
#
|
|
266
|
-
#
|
|
267
|
-
#
|
|
276
|
+
# filtered_methods = runnable_methods.select {...}.reject {...}
|
|
277
|
+
# 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
|
|
268
281
|
|
|
269
282
|
def self.run args = []
|
|
270
283
|
self.load_plugins unless args.delete("--no-plugins") || ENV["MT_NO_PLUGINS"]
|
|
@@ -286,18 +299,19 @@ module Minitest
|
|
|
286
299
|
reporter.start
|
|
287
300
|
begin
|
|
288
301
|
__run reporter, options
|
|
302
|
+
finished = true
|
|
289
303
|
rescue Interrupt
|
|
290
304
|
warn "Interrupted. Exiting..."
|
|
291
305
|
end
|
|
292
|
-
self.parallel_executor.shutdown
|
|
306
|
+
self.parallel_executor.shutdown if parallel_executor.respond_to? :shutdown
|
|
293
307
|
|
|
294
308
|
# might have been removed/replaced during init_plugins:
|
|
295
309
|
summary = reporter.reporters.grep(SummaryReporter).first
|
|
296
310
|
|
|
297
311
|
reporter.report
|
|
298
312
|
|
|
299
|
-
return empty_run! options if summary && summary.count == 0
|
|
300
|
-
reporter.passed?
|
|
313
|
+
return empty_run! options if finished && summary && summary.count == 0
|
|
314
|
+
finished and reporter.passed?
|
|
301
315
|
end
|
|
302
316
|
|
|
303
317
|
def self.empty_run! options # :nodoc:
|
|
@@ -409,6 +423,7 @@ module Minitest
|
|
|
409
423
|
pos = Regexp.new $1 if pos.kind_of?(String) && pos =~ %r%/(.*)/%
|
|
410
424
|
neg = Regexp.new $1 if neg.kind_of?(String) && neg =~ %r%/(.*)/%
|
|
411
425
|
|
|
426
|
+
# at most 1-2% slower than a 1-pass version, stop optimizing this
|
|
412
427
|
filtered_methods = self.runnable_methods
|
|
413
428
|
.select { |m| !pos || pos === m || pos === "#{self}##{m}" }
|
|
414
429
|
.reject { |m| neg && (neg === m || neg === "#{self}##{m}") }
|
|
@@ -572,7 +587,7 @@ module Minitest
|
|
|
572
587
|
def skipped?
|
|
573
588
|
raise NotImplementedError, "subclass responsibility"
|
|
574
589
|
end
|
|
575
|
-
end
|
|
590
|
+
end # Runnable
|
|
576
591
|
|
|
577
592
|
##
|
|
578
593
|
# Shared code for anything that can get passed to a Reporter. See
|
|
@@ -624,7 +639,7 @@ module Minitest
|
|
|
624
639
|
def error?
|
|
625
640
|
self.failures.any? UnexpectedError
|
|
626
641
|
end
|
|
627
|
-
end
|
|
642
|
+
end # Reportable
|
|
628
643
|
|
|
629
644
|
##
|
|
630
645
|
# This represents a test result in a clean way that can be
|
|
@@ -678,7 +693,7 @@ module Minitest
|
|
|
678
693
|
"#{failure.result_label}:\n#{self.location}:\n#{failure.message}\n"
|
|
679
694
|
}.join "\n"
|
|
680
695
|
end
|
|
681
|
-
end
|
|
696
|
+
end # Result
|
|
682
697
|
|
|
683
698
|
##
|
|
684
699
|
# Defines the API for Reporters. Subclass this and override whatever
|
|
@@ -728,7 +743,7 @@ module Minitest
|
|
|
728
743
|
def synchronize &block # :nodoc:
|
|
729
744
|
@mutex.synchronize(&block)
|
|
730
745
|
end
|
|
731
|
-
end
|
|
746
|
+
end # AbstractReportera
|
|
732
747
|
|
|
733
748
|
class Reporter < AbstractReporter # :nodoc:
|
|
734
749
|
##
|
|
@@ -883,7 +898,7 @@ module Minitest
|
|
|
883
898
|
self.warnings = aggregate[UnexpectedWarning].size
|
|
884
899
|
self.skips = aggregate[Skip].size
|
|
885
900
|
end
|
|
886
|
-
end
|
|
901
|
+
end # StatisticsReporter
|
|
887
902
|
|
|
888
903
|
##
|
|
889
904
|
# A reporter that prints the header, summary, and failure details at
|
|
@@ -961,7 +976,7 @@ module Minitest
|
|
|
961
976
|
"%d runs, %d assertions, %d failures, %d errors, %d skips%s" %
|
|
962
977
|
[count, assertions, failures, errors, skips, extra.join]
|
|
963
978
|
end
|
|
964
|
-
end
|
|
979
|
+
end # SummaryReporter
|
|
965
980
|
|
|
966
981
|
##
|
|
967
982
|
# Dispatch to multiple reporters as one.
|
|
@@ -1012,7 +1027,7 @@ module Minitest
|
|
|
1012
1027
|
def report # :nodoc:
|
|
1013
1028
|
self.reporters.each(&:report)
|
|
1014
1029
|
end
|
|
1015
|
-
end
|
|
1030
|
+
end # CompositeReporter
|
|
1016
1031
|
|
|
1017
1032
|
##
|
|
1018
1033
|
# Represents run failures.
|
|
@@ -1079,7 +1094,7 @@ module Minitest
|
|
|
1079
1094
|
self.error.backtrace
|
|
1080
1095
|
end
|
|
1081
1096
|
|
|
1082
|
-
BASE_RE = %r%#{Dir.pwd}/% # :nodoc:
|
|
1097
|
+
BASE_RE = %r%#{Regexp.escape Dir.pwd}/% # :nodoc:
|
|
1083
1098
|
|
|
1084
1099
|
def message # :nodoc:
|
|
1085
1100
|
bt = Minitest.filter_backtrace(self.backtrace).join("\n ")
|
|
@@ -1232,4 +1247,4 @@ module Minitest
|
|
|
1232
1247
|
# :startdoc:
|
|
1233
1248
|
end
|
|
1234
1249
|
|
|
1235
|
-
|
|
1250
|
+
require_relative "minitest/test"
|
|
@@ -142,8 +142,7 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
142
142
|
exp[1] = Object.new
|
|
143
143
|
act[1] = Object.new
|
|
144
144
|
act_obj = act[1]
|
|
145
|
-
|
|
146
|
-
act_obj.define_singleton_method(:inspect) { "#<Object:0xXXXXXX>" }
|
|
145
|
+
def act_obj.inspect = "#<Object:0xXXXXXX>"
|
|
147
146
|
msg = <<~EOM.chomp % [act]
|
|
148
147
|
No visible difference in the Hash#inspect output.
|
|
149
148
|
You should look at the implementation of #== on Hash or its members.
|
|
@@ -292,7 +291,7 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
292
291
|
@tc.assert_equal nil, nil
|
|
293
292
|
end
|
|
294
293
|
else
|
|
295
|
-
err_re =
|
|
294
|
+
err_re = /.*?test_minitest_\w+.rb:\d+: warning: DEPRECATED: Use assert_nil if expecting nil. This will fail in Minitest 6./
|
|
296
295
|
err_re = "" if $-w.nil?
|
|
297
296
|
|
|
298
297
|
assert_deprecation err_re do
|
|
@@ -318,13 +317,13 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
318
317
|
end
|
|
319
318
|
|
|
320
319
|
def test_assert_equal_string_both_escaped_unescaped_newlines
|
|
321
|
-
msg = <<~EOM
|
|
320
|
+
msg = <<~'EOM' # NOTE: single quotes on heredoc
|
|
322
321
|
--- expected
|
|
323
322
|
+++ actual
|
|
324
323
|
@@ -1,2 +1 @@
|
|
325
|
-
-"A
|
|
324
|
+
-"A\n
|
|
326
325
|
-B"
|
|
327
|
-
+"A\\
|
|
326
|
+
+"A\n\\nB"
|
|
328
327
|
EOM
|
|
329
328
|
|
|
330
329
|
assert_triggered msg do
|
|
@@ -1074,48 +1073,24 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
1074
1073
|
end
|
|
1075
1074
|
|
|
1076
1075
|
def test_assert_pattern
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
"(eval):1: warning: One-line pattern matching is experimental, and the behavior may change in future versions of Ruby!\n"
|
|
1081
|
-
else
|
|
1082
|
-
""
|
|
1083
|
-
end
|
|
1084
|
-
assert_output nil, exp do
|
|
1085
|
-
eval "[1,2,3] => [Integer, Integer, Integer]" # eval to escape parser for ruby<3
|
|
1086
|
-
end
|
|
1087
|
-
end
|
|
1088
|
-
else
|
|
1089
|
-
@assertion_count = 0
|
|
1090
|
-
|
|
1091
|
-
assert_raises NotImplementedError do
|
|
1092
|
-
@tc.assert_pattern do
|
|
1093
|
-
# do nothing
|
|
1094
|
-
end
|
|
1076
|
+
@tc.assert_pattern do
|
|
1077
|
+
assert_output nil, "" do
|
|
1078
|
+
[1,2,3] => [Integer, Integer, Integer]
|
|
1095
1079
|
end
|
|
1096
1080
|
end
|
|
1097
1081
|
end
|
|
1098
1082
|
|
|
1099
1083
|
def test_assert_pattern_traps_nomatchingpatternerror
|
|
1100
|
-
|
|
1101
|
-
exp = if RUBY_VERSION.start_with? "3.0" then
|
|
1102
|
-
"[1, 2, 3]" # terrible error message!
|
|
1103
|
-
else
|
|
1104
|
-
/length mismatch/
|
|
1105
|
-
end
|
|
1084
|
+
exp = /length mismatch/
|
|
1106
1085
|
|
|
1107
1086
|
assert_triggered exp do
|
|
1108
1087
|
@tc.assert_pattern do
|
|
1109
|
-
|
|
1110
|
-
eval "[1,2,3] => [Integer, Integer]" # eval to escape parser for ruby<3
|
|
1111
|
-
end
|
|
1088
|
+
[1,2,3] => [Integer, Integer]
|
|
1112
1089
|
end
|
|
1113
1090
|
end
|
|
1114
1091
|
end
|
|
1115
1092
|
|
|
1116
1093
|
def test_assert_pattern_raises_other_exceptions
|
|
1117
|
-
skip unless RUBY_VERSION >= "3.0"
|
|
1118
|
-
|
|
1119
1094
|
@assertion_count = 0
|
|
1120
1095
|
|
|
1121
1096
|
assert_raises RuntimeError do
|
|
@@ -1126,8 +1101,6 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
1126
1101
|
end
|
|
1127
1102
|
|
|
1128
1103
|
def test_assert_pattern_with_no_block
|
|
1129
|
-
skip unless RUBY_VERSION >= "3.0"
|
|
1130
|
-
|
|
1131
1104
|
assert_triggered "assert_pattern requires a block to capture errors." do
|
|
1132
1105
|
@tc.assert_pattern
|
|
1133
1106
|
end
|
|
@@ -1280,12 +1253,16 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
1280
1253
|
end
|
|
1281
1254
|
|
|
1282
1255
|
def test_refute_in_epsilon_triggered
|
|
1283
|
-
assert_triggered "Expected |10000 -
|
|
1284
|
-
@tc.refute_in_epsilon 10_000,
|
|
1256
|
+
assert_triggered "Expected |10000 - 9991| (9) to not be <= 9.991." do
|
|
1257
|
+
@tc.refute_in_epsilon 10_000, 9991
|
|
1285
1258
|
flunk
|
|
1286
1259
|
end
|
|
1287
1260
|
end
|
|
1288
1261
|
|
|
1262
|
+
def test_refute_in_epsilon_minimum
|
|
1263
|
+
@tc.refute_in_epsilon 10_000, 9990
|
|
1264
|
+
end
|
|
1265
|
+
|
|
1289
1266
|
def test_refute_includes
|
|
1290
1267
|
@assertion_count = 2
|
|
1291
1268
|
|
|
@@ -1382,38 +1359,20 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
1382
1359
|
end
|
|
1383
1360
|
|
|
1384
1361
|
def test_refute_pattern
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
capture_io do # 3.0 is noisy
|
|
1388
|
-
eval "[1,2,3] => [Integer, Integer, String]"
|
|
1389
|
-
end
|
|
1390
|
-
end
|
|
1391
|
-
else
|
|
1392
|
-
@assertion_count = 0
|
|
1393
|
-
|
|
1394
|
-
assert_raises NotImplementedError do
|
|
1395
|
-
@tc.refute_pattern do
|
|
1396
|
-
eval "[1,2,3] => [Integer, Integer, String]"
|
|
1397
|
-
end
|
|
1398
|
-
end
|
|
1362
|
+
@tc.refute_pattern do
|
|
1363
|
+
[1,2,3] => [Integer, Integer, String]
|
|
1399
1364
|
end
|
|
1400
1365
|
end
|
|
1401
1366
|
|
|
1402
1367
|
def test_refute_pattern_expects_nomatchingpatternerror
|
|
1403
|
-
skip unless RUBY_VERSION > "3"
|
|
1404
|
-
|
|
1405
1368
|
assert_triggered(/NoMatchingPatternError expected, but nothing was raised./) do
|
|
1406
1369
|
@tc.refute_pattern do
|
|
1407
|
-
|
|
1408
|
-
eval "[1,2,3] => [Integer, Integer, Integer]"
|
|
1409
|
-
end
|
|
1370
|
+
[1,2,3] => [Integer, Integer, Integer]
|
|
1410
1371
|
end
|
|
1411
1372
|
end
|
|
1412
1373
|
end
|
|
1413
1374
|
|
|
1414
1375
|
def test_refute_pattern_raises_other_exceptions
|
|
1415
|
-
skip unless RUBY_VERSION >= "3.0"
|
|
1416
|
-
|
|
1417
1376
|
@assertion_count = 0
|
|
1418
1377
|
|
|
1419
1378
|
assert_raises RuntimeError do
|
|
@@ -1424,8 +1383,6 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
1424
1383
|
end
|
|
1425
1384
|
|
|
1426
1385
|
def test_refute_pattern_with_no_block
|
|
1427
|
-
skip unless RUBY_VERSION >= "3.0"
|
|
1428
|
-
|
|
1429
1386
|
assert_triggered "refute_pattern requires a block to capture errors." do
|
|
1430
1387
|
@tc.refute_pattern
|
|
1431
1388
|
end
|
|
@@ -368,11 +368,7 @@ class TestMinitestMock < Minitest::Test
|
|
|
368
368
|
end
|
|
369
369
|
|
|
370
370
|
assert_silent do
|
|
371
|
-
|
|
372
|
-
mock.foo arg1, arg2, arg3
|
|
373
|
-
else
|
|
374
|
-
mock.foo arg1, arg2, **arg3 # oddity just for ruby 2.7
|
|
375
|
-
end
|
|
371
|
+
mock.foo arg1, arg2, arg3
|
|
376
372
|
end
|
|
377
373
|
|
|
378
374
|
assert_mock mock
|
|
@@ -401,8 +397,8 @@ class TestMinitestMock < Minitest::Test
|
|
|
401
397
|
mock.foo k1: arg1, k2: arg2
|
|
402
398
|
end
|
|
403
399
|
|
|
404
|
-
# basically testing ruby
|
|
405
|
-
assert_match(/missing keyword:
|
|
400
|
+
# basically testing ruby
|
|
401
|
+
assert_match(/missing keyword: :k3/, e.message)
|
|
406
402
|
end
|
|
407
403
|
|
|
408
404
|
def test_mock_block_is_passed_keyword_args__block_bad_extra
|
|
@@ -416,8 +412,7 @@ class TestMinitestMock < Minitest::Test
|
|
|
416
412
|
mock.foo k1: arg1, k2: arg2, k3: arg3
|
|
417
413
|
end
|
|
418
414
|
|
|
419
|
-
|
|
420
|
-
assert_match(/unknown keyword: :?k3/, e.message)
|
|
415
|
+
assert_match(/unknown keyword: :k3/, e.message)
|
|
421
416
|
end
|
|
422
417
|
|
|
423
418
|
def test_mock_block_is_passed_keyword_args__block_bad_value
|
|
@@ -656,7 +651,7 @@ class TestMinitestMock < Minitest::Test
|
|
|
656
651
|
|
|
657
652
|
end
|
|
658
653
|
|
|
659
|
-
|
|
654
|
+
require_relative "metametameta"
|
|
660
655
|
|
|
661
656
|
class TestMinitestStub < Minitest::Test
|
|
662
657
|
# Do not parallelize since we're calling stub on class methods
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
require "minitest/autorun"
|
|
2
|
-
|
|
2
|
+
require_relative "metametameta"
|
|
3
3
|
require "forwardable"
|
|
4
4
|
|
|
5
5
|
class FakeTest < Minitest::Test
|
|
@@ -29,10 +29,11 @@ class TestMinitestReporter < MetaMetaMetaTestCase
|
|
|
29
29
|
super
|
|
30
30
|
self.io = StringIO.new(+"")
|
|
31
31
|
self.r = new_composite_reporter
|
|
32
|
+
@et = @ft = @pt = @st = @sse = nil
|
|
32
33
|
end
|
|
33
34
|
|
|
34
35
|
def error_test
|
|
35
|
-
unless
|
|
36
|
+
unless @et then
|
|
36
37
|
@et = FakeTest.new :woot
|
|
37
38
|
@et.failures << Minitest::UnexpectedError.new(begin
|
|
38
39
|
raise "no"
|
|
@@ -45,7 +46,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
|
|
|
45
46
|
end
|
|
46
47
|
|
|
47
48
|
def system_stack_error_test
|
|
48
|
-
unless
|
|
49
|
+
unless @sse then
|
|
49
50
|
|
|
50
51
|
ex = SystemStackError.new
|
|
51
52
|
|
|
@@ -64,7 +65,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
|
|
|
64
65
|
end
|
|
65
66
|
|
|
66
67
|
def fail_test
|
|
67
|
-
unless
|
|
68
|
+
unless @ft then
|
|
68
69
|
@ft = FakeTest.new :woot
|
|
69
70
|
@ft.failures << begin
|
|
70
71
|
raise Minitest::Assertion, "boo"
|
|
@@ -87,7 +88,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
|
|
|
87
88
|
end
|
|
88
89
|
|
|
89
90
|
def skip_test
|
|
90
|
-
unless
|
|
91
|
+
unless @st then
|
|
91
92
|
@st = FakeTest.new :woot
|
|
92
93
|
@st.failures << begin
|
|
93
94
|
raise Minitest::Skip
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
require_relative "metametameta"
|
|
2
2
|
require "stringio"
|
|
3
3
|
|
|
4
4
|
class MiniSpecA < Minitest::Spec; end
|
|
@@ -108,7 +108,7 @@ describe Minitest::Spec do
|
|
|
108
108
|
end
|
|
109
109
|
|
|
110
110
|
it "needs to catch an expected exception" do
|
|
111
|
-
@assertion_count
|
|
111
|
+
@assertion_count -= 2
|
|
112
112
|
|
|
113
113
|
expect { raise "blah" }.must_raise RuntimeError
|
|
114
114
|
expect { raise Minitest::Assertion }.must_raise Minitest::Assertion
|
|
@@ -148,25 +148,13 @@ describe Minitest::Spec do
|
|
|
148
148
|
it "needs to pattern match" do
|
|
149
149
|
@assertion_count = 1
|
|
150
150
|
|
|
151
|
-
|
|
152
|
-
expect { good_pattern }.must_pattern_match
|
|
153
|
-
else
|
|
154
|
-
assert_raises NotImplementedError do
|
|
155
|
-
expect {}.must_pattern_match
|
|
156
|
-
end
|
|
157
|
-
end
|
|
151
|
+
expect { good_pattern }.must_pattern_match
|
|
158
152
|
end
|
|
159
153
|
|
|
160
154
|
it "needs to error on bad pattern match" do
|
|
161
|
-
skip unless RUBY_VERSION > "3"
|
|
162
|
-
|
|
163
155
|
@assertion_count = 1
|
|
164
156
|
|
|
165
|
-
exp =
|
|
166
|
-
"[1, 2, 3]" # terrible error message!
|
|
167
|
-
else
|
|
168
|
-
/length mismatch/
|
|
169
|
-
end
|
|
157
|
+
exp = /length mismatch/
|
|
170
158
|
|
|
171
159
|
assert_triggered exp do
|
|
172
160
|
expect { bad_pattern }.must_pattern_match
|
|
@@ -284,7 +272,7 @@ describe Minitest::Spec do
|
|
|
284
272
|
@assertion_count = 3
|
|
285
273
|
@assertion_count += 2 unless error_on_warn? # 2 extra assertions
|
|
286
274
|
|
|
287
|
-
exp =
|
|
275
|
+
exp = /.*?test_minitest_\w+.rb:\d+: warning: DEPRECATED: Use assert_nil if expecting nil. This will fail in Minitest 6./
|
|
288
276
|
|
|
289
277
|
assert_deprecation exp do
|
|
290
278
|
assert_success _(nil).must_equal(nil)
|
|
@@ -710,8 +698,6 @@ describe Minitest::Spec do
|
|
|
710
698
|
end
|
|
711
699
|
|
|
712
700
|
describe Minitest::Spec, :let do
|
|
713
|
-
i_suck_and_my_tests_are_order_dependent!
|
|
714
|
-
|
|
715
701
|
def _count
|
|
716
702
|
$let_count ||= 0
|
|
717
703
|
end
|
|
@@ -722,21 +708,21 @@ describe Minitest::Spec, :let do
|
|
|
722
708
|
end
|
|
723
709
|
|
|
724
710
|
it "is evaluated once per example" do
|
|
725
|
-
|
|
711
|
+
exp = _count + 1
|
|
726
712
|
|
|
727
|
-
_(count).must_equal
|
|
728
|
-
_(count).must_equal
|
|
713
|
+
_(count).must_equal exp
|
|
714
|
+
_(count).must_equal exp
|
|
729
715
|
|
|
730
|
-
_(_count).must_equal
|
|
716
|
+
_(_count).must_equal exp
|
|
731
717
|
end
|
|
732
718
|
|
|
733
719
|
it "is REALLY evaluated once per example" do
|
|
734
|
-
|
|
720
|
+
exp = _count + 1
|
|
735
721
|
|
|
736
|
-
_(count).must_equal
|
|
737
|
-
_(count).must_equal
|
|
722
|
+
_(count).must_equal exp
|
|
723
|
+
_(count).must_equal exp
|
|
738
724
|
|
|
739
|
-
_(_count).must_equal
|
|
725
|
+
_(_count).must_equal exp
|
|
740
726
|
end
|
|
741
727
|
|
|
742
728
|
it 'raises an error if the name begins with "test"' do
|
|
@@ -941,6 +927,16 @@ class TestMeta < MetaMetaMetaTestCase
|
|
|
941
927
|
assert_equal "ExampleB::random_method::addl_context", spec_c.name
|
|
942
928
|
end
|
|
943
929
|
|
|
930
|
+
def test_inspect
|
|
931
|
+
spec_a = describe ExampleA do; end
|
|
932
|
+
spec_b = describe ExampleB, :random_method do; end
|
|
933
|
+
spec_c = describe ExampleB, :random_method, :addl_context do; end
|
|
934
|
+
|
|
935
|
+
assert_equal "ExampleA", spec_a.inspect
|
|
936
|
+
assert_equal "ExampleB::random_method", spec_b.inspect
|
|
937
|
+
assert_equal "ExampleB::random_method::addl_context", spec_c.inspect
|
|
938
|
+
end
|
|
939
|
+
|
|
944
940
|
def test_name2
|
|
945
941
|
assert_equal "NamedExampleA", NamedExampleA.name
|
|
946
942
|
assert_equal "NamedExampleB", NamedExampleB.name
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
require_relative "metametameta"
|
|
2
2
|
|
|
3
3
|
e = Encoding.default_external
|
|
4
4
|
if e != Encoding::UTF_8 then
|
|
@@ -157,6 +157,24 @@ class TestMinitestUnit < MetaMetaMetaTestCase
|
|
|
157
157
|
refute_predicate test, :skipped?
|
|
158
158
|
end
|
|
159
159
|
|
|
160
|
+
def test_skipped_is_reachable
|
|
161
|
+
test_class = Class.new FakeNamedTest do
|
|
162
|
+
def test_omg
|
|
163
|
+
skip
|
|
164
|
+
ensure
|
|
165
|
+
flunk unless skipped?
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
test = test_class.new :test_omg
|
|
170
|
+
test.run
|
|
171
|
+
|
|
172
|
+
refute_predicate test, :error?
|
|
173
|
+
refute_predicate test, :passed?
|
|
174
|
+
|
|
175
|
+
assert_predicate test, :skipped?
|
|
176
|
+
end
|
|
177
|
+
|
|
160
178
|
def util_expand_bt bt
|
|
161
179
|
bt.map { |f| f.start_with?(".") ? File.expand_path(f) : f }
|
|
162
180
|
end
|
|
@@ -644,7 +662,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
|
644
662
|
2 runs, 2 assertions, 0 failures, 0 errors, 0 skips
|
|
645
663
|
EOM
|
|
646
664
|
|
|
647
|
-
skip
|
|
665
|
+
skip unless Minitest.parallel_executor # locks up test runner if 1 CPU
|
|
648
666
|
|
|
649
667
|
assert_report expected do |reporter|
|
|
650
668
|
reporter.extend Module.new {
|
data.tar.gz.sig
CHANGED
|
Binary file
|