minitest 5.16.2 → 6.0.5
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 +0 -0
- data/History.rdoc +373 -1
- data/Manifest.txt +16 -4
- data/README.rdoc +48 -118
- data/Rakefile +17 -2
- data/bin/minitest +5 -0
- data/design_rationale.rb +21 -19
- data/lib/hoe/minitest.rb +4 -2
- data/lib/minitest/assertions.rb +142 -124
- data/lib/minitest/autorun.rb +3 -11
- data/lib/minitest/benchmark.rb +9 -12
- data/lib/minitest/bisect.rb +304 -0
- data/lib/minitest/complete.rb +56 -0
- data/lib/minitest/compress.rb +94 -0
- data/lib/minitest/error_on_warning.rb +11 -0
- data/lib/minitest/expectations.rb +18 -0
- data/lib/minitest/find_minimal_combination.rb +127 -0
- data/lib/minitest/hell.rb +1 -1
- data/lib/minitest/manual_plugins.rb +4 -0
- data/lib/minitest/parallel.rb +10 -8
- data/lib/minitest/path_expander.rb +432 -0
- data/lib/minitest/pride.rb +2 -2
- data/lib/minitest/pride_plugin.rb +17 -24
- data/lib/minitest/server.rb +49 -0
- data/lib/minitest/server_plugin.rb +88 -0
- data/lib/minitest/spec.rb +27 -46
- data/lib/minitest/sprint.rb +105 -0
- data/lib/minitest/sprint_plugin.rb +39 -0
- data/lib/minitest/test.rb +32 -52
- data/lib/minitest/test_task.rb +68 -42
- data/lib/minitest.rb +361 -215
- data/test/minitest/metametameta.rb +33 -19
- data/test/minitest/test_bisect.rb +249 -0
- data/test/minitest/test_find_minimal_combination.rb +138 -0
- data/test/minitest/test_minitest_assertions.rb +311 -173
- data/test/minitest/test_minitest_benchmark.rb +15 -1
- data/test/minitest/test_minitest_reporter.rb +148 -23
- data/test/minitest/test_minitest_spec.rb +157 -132
- data/test/minitest/test_minitest_test.rb +270 -204
- data/test/minitest/test_minitest_test_task.rb +18 -7
- data/test/minitest/test_path_expander.rb +229 -0
- data/test/minitest/test_server.rb +146 -0
- data.tar.gz.sig +2 -2
- metadata +97 -37
- metadata.gz.sig +0 -0
- data/.autotest +0 -34
- data/lib/minitest/mock.rb +0 -323
- data/lib/minitest/unit.rb +0 -42
- data/test/minitest/test_minitest_mock.rb +0 -1139
data/lib/minitest/assertions.rb
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
|
-
|
|
3
1
|
require "rbconfig"
|
|
4
2
|
require "tempfile"
|
|
5
3
|
require "stringio"
|
|
@@ -29,12 +27,12 @@ module Minitest
|
|
|
29
27
|
def self.diff
|
|
30
28
|
return @diff if defined? @diff
|
|
31
29
|
|
|
32
|
-
@diff = if (RbConfig::CONFIG["host_os"] =~ /mswin|mingw/
|
|
33
|
-
system
|
|
30
|
+
@diff = if (RbConfig::CONFIG["host_os"] =~ /mswin|mingw/ and
|
|
31
|
+
system "diff.exe", __FILE__, __FILE__) then
|
|
34
32
|
"diff.exe -u"
|
|
35
|
-
elsif system
|
|
33
|
+
elsif system "gdiff", __FILE__, __FILE__ then
|
|
36
34
|
"gdiff -u" # solaris and kin suck
|
|
37
|
-
elsif system
|
|
35
|
+
elsif system "diff", __FILE__, __FILE__ then
|
|
38
36
|
"diff -u"
|
|
39
37
|
else
|
|
40
38
|
nil
|
|
@@ -59,16 +57,16 @@ module Minitest
|
|
|
59
57
|
def diff exp, act
|
|
60
58
|
result = nil
|
|
61
59
|
|
|
62
|
-
expect, butwas = things_to_diff
|
|
60
|
+
expect, butwas = things_to_diff exp, act
|
|
63
61
|
|
|
64
62
|
return "Expected: #{mu_pp exp}\n Actual: #{mu_pp act}" unless
|
|
65
63
|
expect
|
|
66
64
|
|
|
67
|
-
Tempfile.
|
|
65
|
+
Tempfile.create "expect" do |a|
|
|
68
66
|
a.puts expect
|
|
69
67
|
a.flush
|
|
70
68
|
|
|
71
|
-
Tempfile.
|
|
69
|
+
Tempfile.create "butwas" do |b|
|
|
72
70
|
b.puts butwas
|
|
73
71
|
b.flush
|
|
74
72
|
|
|
@@ -79,10 +77,10 @@ module Minitest
|
|
|
79
77
|
if result.empty? then
|
|
80
78
|
klass = exp.class
|
|
81
79
|
result = [
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
80
|
+
"No visible difference in the #{klass}#inspect output.\n",
|
|
81
|
+
"You should look at the implementation of #== on ",
|
|
82
|
+
"#{klass} or its members.\n",
|
|
83
|
+
expect,
|
|
86
84
|
].join
|
|
87
85
|
end
|
|
88
86
|
end
|
|
@@ -127,20 +125,15 @@ module Minitest
|
|
|
127
125
|
# See Minitest::Test.make_my_diffs_pretty!
|
|
128
126
|
|
|
129
127
|
def mu_pp obj
|
|
130
|
-
s = obj.inspect
|
|
128
|
+
s = obj.inspect.encode Encoding.default_external
|
|
131
129
|
|
|
132
|
-
|
|
133
|
-
|
|
130
|
+
return s unless String === obj &&
|
|
131
|
+
(obj.encoding != Encoding.default_external || !obj.valid_encoding?)
|
|
134
132
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
enc = "# encoding: #{obj.encoding}"
|
|
138
|
-
val = "# valid: #{obj.valid_encoding?}"
|
|
139
|
-
s = "#{enc}\n#{val}\n#{s}"
|
|
140
|
-
end
|
|
141
|
-
end
|
|
133
|
+
enc = "# encoding: #{obj.encoding}"
|
|
134
|
+
val = "# valid: #{obj.valid_encoding?}"
|
|
142
135
|
|
|
143
|
-
s
|
|
136
|
+
[enc, val, s].join "\n"
|
|
144
137
|
end
|
|
145
138
|
|
|
146
139
|
##
|
|
@@ -153,8 +146,8 @@ module Minitest
|
|
|
153
146
|
str = mu_pp obj
|
|
154
147
|
|
|
155
148
|
# both '\n' & '\\n' (_after_ mu_pp (aka inspect))
|
|
156
|
-
single =
|
|
157
|
-
double =
|
|
149
|
+
single = str.match?(/(?<!\\|^)\\n/)
|
|
150
|
+
double = str.match?(/(?<=\\|^)\\n/)
|
|
158
151
|
|
|
159
152
|
process =
|
|
160
153
|
if single ^ double then
|
|
@@ -167,9 +160,9 @@ module Minitest
|
|
|
167
160
|
:itself # leave it alone
|
|
168
161
|
end
|
|
169
162
|
|
|
170
|
-
str
|
|
171
|
-
gsub(/\\?\\n/, &process)
|
|
172
|
-
gsub(/:0x[a-fA-F0-9]{4,}/m, ":0xXXXXXX") # anonymize hex values
|
|
163
|
+
str
|
|
164
|
+
.gsub(/\\?\\n/, &process)
|
|
165
|
+
.gsub(/:0x[a-fA-F0-9]{4,}/m, ":0xXXXXXX") # anonymize hex values
|
|
173
166
|
end
|
|
174
167
|
|
|
175
168
|
##
|
|
@@ -194,11 +187,13 @@ module Minitest
|
|
|
194
187
|
|
|
195
188
|
def assert_empty obj, msg = nil
|
|
196
189
|
msg = message(msg) { "Expected #{mu_pp(obj)} to be empty" }
|
|
197
|
-
|
|
198
|
-
assert obj.empty?, msg
|
|
190
|
+
assert_predicate obj, :empty?, msg
|
|
199
191
|
end
|
|
200
192
|
|
|
201
|
-
|
|
193
|
+
def _where # :nodoc:
|
|
194
|
+
Minitest.filter_backtrace(caller).first
|
|
195
|
+
.split(":in ", 2).first # clean up noise
|
|
196
|
+
end
|
|
202
197
|
|
|
203
198
|
##
|
|
204
199
|
# Fails unless <tt>exp == act</tt> printing the difference between
|
|
@@ -214,21 +209,11 @@ module Minitest
|
|
|
214
209
|
# See also: Minitest::Assertions.diff
|
|
215
210
|
|
|
216
211
|
def assert_equal exp, act, msg = nil
|
|
217
|
-
msg = message(msg,
|
|
218
|
-
result = assert exp == act, msg
|
|
219
|
-
|
|
220
|
-
if nil == exp then
|
|
221
|
-
if Minitest::VERSION =~ /^6/ then
|
|
222
|
-
refute_nil exp, "Use assert_nil if expecting nil."
|
|
223
|
-
else
|
|
224
|
-
where = Minitest.filter_backtrace(caller).first
|
|
225
|
-
where = where.split(/:in /, 2).first # clean up noise
|
|
212
|
+
msg = message(msg, nil) { diff exp, act }
|
|
226
213
|
|
|
227
|
-
|
|
228
|
-
end
|
|
229
|
-
end
|
|
214
|
+
refute_nil exp, message { "Use assert_nil if expecting nil" } if exp.nil? # don't count
|
|
230
215
|
|
|
231
|
-
|
|
216
|
+
assert exp == act, msg
|
|
232
217
|
end
|
|
233
218
|
|
|
234
219
|
##
|
|
@@ -258,10 +243,9 @@ module Minitest
|
|
|
258
243
|
|
|
259
244
|
def assert_includes collection, obj, msg = nil
|
|
260
245
|
msg = message(msg) {
|
|
261
|
-
"Expected #{mu_pp
|
|
246
|
+
"Expected #{mu_pp collection} to include #{mu_pp obj}"
|
|
262
247
|
}
|
|
263
|
-
|
|
264
|
-
assert collection.include?(obj), msg
|
|
248
|
+
assert_operator collection, :include?, obj, msg
|
|
265
249
|
end
|
|
266
250
|
|
|
267
251
|
##
|
|
@@ -269,7 +253,7 @@ module Minitest
|
|
|
269
253
|
|
|
270
254
|
def assert_instance_of cls, obj, msg = nil
|
|
271
255
|
msg = message(msg) {
|
|
272
|
-
"Expected #{mu_pp
|
|
256
|
+
"Expected #{mu_pp obj} to be an instance of #{cls}, not #{obj.class}"
|
|
273
257
|
}
|
|
274
258
|
|
|
275
259
|
assert obj.instance_of?(cls), msg
|
|
@@ -280,7 +264,8 @@ module Minitest
|
|
|
280
264
|
|
|
281
265
|
def assert_kind_of cls, obj, msg = nil
|
|
282
266
|
msg = message(msg) {
|
|
283
|
-
"Expected #{mu_pp
|
|
267
|
+
"Expected #{mu_pp obj} to be a kind of #{cls}, not #{obj.class}"
|
|
268
|
+
}
|
|
284
269
|
|
|
285
270
|
assert obj.kind_of?(cls), msg
|
|
286
271
|
end
|
|
@@ -290,7 +275,7 @@ module Minitest
|
|
|
290
275
|
|
|
291
276
|
def assert_match matcher, obj, msg = nil
|
|
292
277
|
msg = message(msg) { "Expected #{mu_pp matcher} to match #{mu_pp obj}" }
|
|
293
|
-
assert_respond_to matcher,
|
|
278
|
+
assert_respond_to matcher, :=~
|
|
294
279
|
matcher = Regexp.new Regexp.escape matcher if String === matcher
|
|
295
280
|
assert matcher =~ obj, msg
|
|
296
281
|
|
|
@@ -301,7 +286,7 @@ module Minitest
|
|
|
301
286
|
# Fails unless +obj+ is nil
|
|
302
287
|
|
|
303
288
|
def assert_nil obj, msg = nil
|
|
304
|
-
msg = message(msg) { "Expected #{mu_pp
|
|
289
|
+
msg = message(msg) { "Expected #{mu_pp obj} to be nil" }
|
|
305
290
|
assert obj.nil?, msg
|
|
306
291
|
end
|
|
307
292
|
|
|
@@ -312,7 +297,8 @@ module Minitest
|
|
|
312
297
|
|
|
313
298
|
def assert_operator o1, op, o2 = UNDEFINED, msg = nil
|
|
314
299
|
return assert_predicate o1, op, msg if UNDEFINED == o2
|
|
315
|
-
|
|
300
|
+
assert_respond_to o1, op
|
|
301
|
+
msg = message(msg) { "Expected #{mu_pp o1} to be #{op} #{mu_pp o2}" }
|
|
316
302
|
assert o1.__send__(op, o2), msg
|
|
317
303
|
end
|
|
318
304
|
|
|
@@ -357,6 +343,29 @@ module Minitest
|
|
|
357
343
|
assert File.exist?(path), msg
|
|
358
344
|
end
|
|
359
345
|
|
|
346
|
+
##
|
|
347
|
+
# For testing with pattern matching (only supported with Ruby 3.0 and later)
|
|
348
|
+
#
|
|
349
|
+
# # pass
|
|
350
|
+
# assert_pattern { [1,2,3] => [Integer, Integer, Integer] }
|
|
351
|
+
#
|
|
352
|
+
# # fail "length mismatch (given 3, expected 1)"
|
|
353
|
+
# assert_pattern { [1,2,3] => [Integer] }
|
|
354
|
+
#
|
|
355
|
+
# The bare <tt>=></tt> pattern will raise a NoMatchingPatternError on failure, which would
|
|
356
|
+
# normally be counted as a test error. This assertion rescues NoMatchingPatternError and
|
|
357
|
+
# generates a test failure. Any other exception will be raised as normal and generate a test
|
|
358
|
+
# error.
|
|
359
|
+
|
|
360
|
+
def assert_pattern
|
|
361
|
+
flunk "assert_pattern requires a block to capture errors." unless block_given?
|
|
362
|
+
|
|
363
|
+
yield
|
|
364
|
+
pass
|
|
365
|
+
rescue NoMatchingPatternError => e
|
|
366
|
+
flunk e.message
|
|
367
|
+
end
|
|
368
|
+
|
|
360
369
|
##
|
|
361
370
|
# For testing with predicates. Eg:
|
|
362
371
|
#
|
|
@@ -367,10 +376,13 @@ module Minitest
|
|
|
367
376
|
# str.must_be :empty?
|
|
368
377
|
|
|
369
378
|
def assert_predicate o1, op, msg = nil
|
|
370
|
-
|
|
379
|
+
assert_respond_to o1, op, include_all:true
|
|
380
|
+
msg = message(msg) { "Expected #{mu_pp o1} to be #{op}" }
|
|
371
381
|
assert o1.__send__(op), msg
|
|
372
382
|
end
|
|
373
383
|
|
|
384
|
+
NO_RE_MSG = "class or module required for rescue clause. Got %p"
|
|
385
|
+
|
|
374
386
|
##
|
|
375
387
|
# Fails unless the block raises one of +exp+. Returns the
|
|
376
388
|
# exception matched so you can check the message, attributes, etc.
|
|
@@ -400,6 +412,9 @@ module Minitest
|
|
|
400
412
|
msg = "#{exp.pop}.\n" if String === exp.last
|
|
401
413
|
exp << StandardError if exp.empty?
|
|
402
414
|
|
|
415
|
+
# TODO: remove this if https://bugs.ruby-lang.org/issues/22007 gets fixed
|
|
416
|
+
raise TypeError, NO_RE_MSG % [exp] unless exp.all? Module
|
|
417
|
+
|
|
403
418
|
begin
|
|
404
419
|
yield
|
|
405
420
|
rescue *exp => e
|
|
@@ -412,23 +427,22 @@ module Minitest
|
|
|
412
427
|
raise
|
|
413
428
|
rescue Exception => e
|
|
414
429
|
flunk proc {
|
|
415
|
-
exception_details(e, "#{msg}#{mu_pp
|
|
430
|
+
exception_details(e, "#{msg}#{mu_pp exp} exception expected, not")
|
|
416
431
|
}
|
|
417
432
|
end
|
|
418
433
|
|
|
419
434
|
exp = exp.first if exp.size == 1
|
|
420
435
|
|
|
421
|
-
flunk "#{msg}#{mu_pp
|
|
436
|
+
flunk "#{msg}#{mu_pp exp} expected but nothing was raised."
|
|
422
437
|
end
|
|
423
438
|
|
|
424
439
|
##
|
|
425
440
|
# Fails unless +obj+ responds to +meth+.
|
|
441
|
+
# include_all defaults to false to match Object#respond_to?
|
|
426
442
|
|
|
427
|
-
def assert_respond_to obj, meth, msg = nil
|
|
428
|
-
msg = message(msg) {
|
|
429
|
-
|
|
430
|
-
}
|
|
431
|
-
assert obj.respond_to?(meth), msg
|
|
443
|
+
def assert_respond_to obj, meth, msg = nil, include_all: false
|
|
444
|
+
msg = message(msg) { "Expected #{mu_pp obj} (#{obj.class}) to respond to ##{meth}" }
|
|
445
|
+
assert obj.respond_to?(meth, include_all), msg
|
|
432
446
|
end
|
|
433
447
|
|
|
434
448
|
##
|
|
@@ -439,23 +453,10 @@ module Minitest
|
|
|
439
453
|
data = [mu_pp(act), act.object_id, mu_pp(exp), exp.object_id]
|
|
440
454
|
"Expected %s (oid=%d) to be the same as %s (oid=%d)" % data
|
|
441
455
|
}
|
|
442
|
-
assert exp.equal?(act), msg
|
|
443
|
-
end
|
|
444
456
|
|
|
445
|
-
|
|
446
|
-
# +send_ary+ is a receiver, message and arguments.
|
|
447
|
-
#
|
|
448
|
-
# Fails unless the call returns a true value
|
|
449
|
-
|
|
450
|
-
def assert_send send_ary, m = nil
|
|
451
|
-
where = Minitest.filter_backtrace(caller).first
|
|
452
|
-
where = where.split(/:in /, 2).first # clean up noise
|
|
453
|
-
warn "DEPRECATED: assert_send. From #{where}"
|
|
457
|
+
refute_nil exp, message { "Use assert_nil if expecting nil" } if exp.nil? # don't count
|
|
454
458
|
|
|
455
|
-
|
|
456
|
-
m = message(m) {
|
|
457
|
-
"Expected #{mu_pp(recv)}.#{msg}(*#{mu_pp(args)}) to return true" }
|
|
458
|
-
assert recv.__send__(msg, *args), m
|
|
459
|
+
assert exp.equal?(act), msg
|
|
459
460
|
end
|
|
460
461
|
|
|
461
462
|
##
|
|
@@ -473,19 +474,14 @@ module Minitest
|
|
|
473
474
|
# Fails unless the block throws +sym+
|
|
474
475
|
|
|
475
476
|
def assert_throws sym, msg = nil
|
|
476
|
-
default = "Expected #{mu_pp
|
|
477
|
+
default = "Expected #{mu_pp sym} to have been thrown"
|
|
477
478
|
caught = true
|
|
478
|
-
value = catch
|
|
479
|
+
value = catch sym do
|
|
479
480
|
begin
|
|
480
481
|
yield
|
|
481
|
-
rescue
|
|
482
|
-
|
|
483
|
-
rescue ArgumentError => e # 1.9 exception
|
|
484
|
-
raise e unless e.message.include?("uncaught throw")
|
|
482
|
+
rescue ArgumentError => e # 1.9+ exception
|
|
483
|
+
raise e unless e.message.include? "uncaught throw"
|
|
485
484
|
default += ", not #{e.message.split(/ /).last}"
|
|
486
|
-
rescue NameError => e # 1.8 exception
|
|
487
|
-
raise e unless e.name == sym
|
|
488
|
-
default += ", not #{e.name.inspect}"
|
|
489
485
|
end
|
|
490
486
|
caught = false
|
|
491
487
|
end
|
|
@@ -580,12 +576,12 @@ module Minitest
|
|
|
580
576
|
|
|
581
577
|
def exception_details e, msg
|
|
582
578
|
[
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
579
|
+
msg,
|
|
580
|
+
"Class: <#{e.class}>",
|
|
581
|
+
"Message: <#{e.message.inspect}>",
|
|
582
|
+
"---Backtrace---",
|
|
583
|
+
Minitest.filter_backtrace(e.backtrace),
|
|
584
|
+
"---------------",
|
|
589
585
|
].join "\n"
|
|
590
586
|
end
|
|
591
587
|
|
|
@@ -594,7 +590,7 @@ module Minitest
|
|
|
594
590
|
# you to put time-bombs in your tests if you need to keep
|
|
595
591
|
# something around until a later date lest you forget about it.
|
|
596
592
|
|
|
597
|
-
def fail_after y,m,d,msg
|
|
593
|
+
def fail_after y, m, d, msg
|
|
598
594
|
flunk msg if Time.now > Time.local(y, m, d)
|
|
599
595
|
end
|
|
600
596
|
|
|
@@ -607,13 +603,16 @@ module Minitest
|
|
|
607
603
|
end
|
|
608
604
|
|
|
609
605
|
##
|
|
610
|
-
# Returns a proc that
|
|
606
|
+
# Returns a proc that delays generation of an output message. If
|
|
607
|
+
# +msg+ is a proc (eg, from another +message+ call) return +msg+
|
|
608
|
+
# as-is. Otherwise, return a proc that will output +msg+ along
|
|
609
|
+
# with the value of the result of the block passed to +message+.
|
|
611
610
|
|
|
612
|
-
def message msg = nil, ending =
|
|
611
|
+
def message msg = nil, ending = ".", &default
|
|
612
|
+
return msg if Proc === msg
|
|
613
613
|
proc {
|
|
614
|
-
msg = msg.call.chomp(".") if Proc === msg
|
|
615
614
|
custom_message = "#{msg}.\n" unless msg.nil? or msg.to_s.empty?
|
|
616
|
-
"#{custom_message}#{default.call}#{ending
|
|
615
|
+
"#{custom_message}#{default.call}#{ending}"
|
|
617
616
|
}
|
|
618
617
|
end
|
|
619
618
|
|
|
@@ -628,7 +627,7 @@ module Minitest
|
|
|
628
627
|
# Fails if +test+ is truthy.
|
|
629
628
|
|
|
630
629
|
def refute test, msg = nil
|
|
631
|
-
msg ||= message { "Expected #{mu_pp
|
|
630
|
+
msg ||= message { "Expected #{mu_pp test} to not be truthy" }
|
|
632
631
|
assert !test, msg
|
|
633
632
|
end
|
|
634
633
|
|
|
@@ -636,9 +635,8 @@ module Minitest
|
|
|
636
635
|
# Fails if +obj+ is empty.
|
|
637
636
|
|
|
638
637
|
def refute_empty obj, msg = nil
|
|
639
|
-
msg = message(msg) { "Expected #{mu_pp
|
|
640
|
-
|
|
641
|
-
refute obj.empty?, msg
|
|
638
|
+
msg = message(msg) { "Expected #{mu_pp obj} to not be empty" }
|
|
639
|
+
refute_predicate obj, :empty?, msg
|
|
642
640
|
end
|
|
643
641
|
|
|
644
642
|
##
|
|
@@ -648,7 +646,7 @@ module Minitest
|
|
|
648
646
|
|
|
649
647
|
def refute_equal exp, act, msg = nil
|
|
650
648
|
msg = message(msg) {
|
|
651
|
-
"Expected #{mu_pp
|
|
649
|
+
"Expected #{mu_pp act} to not be equal to #{mu_pp exp}"
|
|
652
650
|
}
|
|
653
651
|
refute exp == act, msg
|
|
654
652
|
end
|
|
@@ -670,19 +668,16 @@ module Minitest
|
|
|
670
668
|
# For comparing Floats. Fails if +exp+ and +act+ have a relative error
|
|
671
669
|
# less than +epsilon+.
|
|
672
670
|
|
|
673
|
-
def refute_in_epsilon
|
|
674
|
-
refute_in_delta
|
|
671
|
+
def refute_in_epsilon exp, act, epsilon = 0.001, msg = nil
|
|
672
|
+
refute_in_delta exp, act, [exp.abs, act.abs].min * epsilon, msg
|
|
675
673
|
end
|
|
676
674
|
|
|
677
675
|
##
|
|
678
|
-
# Fails if +
|
|
676
|
+
# Fails if +obj+ includes +sub+.
|
|
679
677
|
|
|
680
|
-
def refute_includes
|
|
681
|
-
msg = message(msg) {
|
|
682
|
-
|
|
683
|
-
}
|
|
684
|
-
assert_respond_to collection, :include?
|
|
685
|
-
refute collection.include?(obj), msg
|
|
678
|
+
def refute_includes obj, sub, msg = nil
|
|
679
|
+
msg = message(msg) { "Expected #{mu_pp obj} to not include #{mu_pp sub}" }
|
|
680
|
+
refute_operator obj, :include?, sub, msg
|
|
686
681
|
end
|
|
687
682
|
|
|
688
683
|
##
|
|
@@ -690,7 +685,7 @@ module Minitest
|
|
|
690
685
|
|
|
691
686
|
def refute_instance_of cls, obj, msg = nil
|
|
692
687
|
msg = message(msg) {
|
|
693
|
-
"Expected #{mu_pp
|
|
688
|
+
"Expected #{mu_pp obj} to not be an instance of #{cls}"
|
|
694
689
|
}
|
|
695
690
|
refute obj.instance_of?(cls), msg
|
|
696
691
|
end
|
|
@@ -699,7 +694,7 @@ module Minitest
|
|
|
699
694
|
# Fails if +obj+ is a kind of +cls+.
|
|
700
695
|
|
|
701
696
|
def refute_kind_of cls, obj, msg = nil
|
|
702
|
-
msg = message(msg) { "Expected #{mu_pp
|
|
697
|
+
msg = message(msg) { "Expected #{mu_pp obj} to not be a kind of #{cls}" }
|
|
703
698
|
refute obj.kind_of?(cls), msg
|
|
704
699
|
end
|
|
705
700
|
|
|
@@ -708,19 +703,39 @@ module Minitest
|
|
|
708
703
|
|
|
709
704
|
def refute_match matcher, obj, msg = nil
|
|
710
705
|
msg = message(msg) { "Expected #{mu_pp matcher} to not match #{mu_pp obj}" }
|
|
711
|
-
assert_respond_to matcher, :"=~"
|
|
712
706
|
matcher = Regexp.new Regexp.escape matcher if String === matcher
|
|
713
|
-
|
|
707
|
+
refute_operator matcher, :=~, obj, msg
|
|
714
708
|
end
|
|
715
709
|
|
|
716
710
|
##
|
|
717
711
|
# Fails if +obj+ is nil.
|
|
718
712
|
|
|
719
713
|
def refute_nil obj, msg = nil
|
|
720
|
-
msg = message(msg) { "Expected #{mu_pp
|
|
714
|
+
msg = message(msg) { "Expected #{mu_pp obj} to not be nil" }
|
|
721
715
|
refute obj.nil?, msg
|
|
722
716
|
end
|
|
723
717
|
|
|
718
|
+
##
|
|
719
|
+
# For testing with pattern matching (only supported with Ruby 3.0 and later)
|
|
720
|
+
#
|
|
721
|
+
# # pass
|
|
722
|
+
# refute_pattern { [1,2,3] => [String] }
|
|
723
|
+
#
|
|
724
|
+
# # fail "NoMatchingPatternError expected, but nothing was raised."
|
|
725
|
+
# refute_pattern { [1,2,3] => [Integer, Integer, Integer] }
|
|
726
|
+
#
|
|
727
|
+
# This assertion expects a NoMatchingPatternError exception, and will fail if none is raised. Any
|
|
728
|
+
# other exceptions will be raised as normal and generate a test error.
|
|
729
|
+
|
|
730
|
+
def refute_pattern
|
|
731
|
+
flunk "refute_pattern requires a block to capture errors." unless block_given?
|
|
732
|
+
|
|
733
|
+
yield
|
|
734
|
+
flunk "NoMatchingPatternError expected, but nothing was raised."
|
|
735
|
+
rescue NoMatchingPatternError
|
|
736
|
+
pass
|
|
737
|
+
end
|
|
738
|
+
|
|
724
739
|
##
|
|
725
740
|
# Fails if +o1+ is not +op+ +o2+. Eg:
|
|
726
741
|
#
|
|
@@ -729,7 +744,8 @@ module Minitest
|
|
|
729
744
|
|
|
730
745
|
def refute_operator o1, op, o2 = UNDEFINED, msg = nil
|
|
731
746
|
return refute_predicate o1, op, msg if UNDEFINED == o2
|
|
732
|
-
|
|
747
|
+
assert_respond_to o1, op
|
|
748
|
+
msg = message(msg) { "Expected #{mu_pp o1} to not be #{op} #{mu_pp o2}" }
|
|
733
749
|
refute o1.__send__(op, o2), msg
|
|
734
750
|
end
|
|
735
751
|
|
|
@@ -751,17 +767,19 @@ module Minitest
|
|
|
751
767
|
# str.wont_be :empty?
|
|
752
768
|
|
|
753
769
|
def refute_predicate o1, op, msg = nil
|
|
754
|
-
|
|
770
|
+
assert_respond_to o1, op, include_all:true
|
|
771
|
+
msg = message(msg) { "Expected #{mu_pp o1} to not be #{op}" }
|
|
755
772
|
refute o1.__send__(op), msg
|
|
756
773
|
end
|
|
757
774
|
|
|
758
775
|
##
|
|
759
776
|
# Fails if +obj+ responds to the message +meth+.
|
|
777
|
+
# include_all defaults to false to match Object#respond_to?
|
|
760
778
|
|
|
761
|
-
def refute_respond_to obj, meth, msg = nil
|
|
762
|
-
msg = message(msg) { "Expected #{mu_pp
|
|
779
|
+
def refute_respond_to obj, meth, msg = nil, include_all: false
|
|
780
|
+
msg = message(msg) { "Expected #{mu_pp obj} to not respond to #{meth}" }
|
|
763
781
|
|
|
764
|
-
refute obj.respond_to?(meth), msg
|
|
782
|
+
refute obj.respond_to?(meth, include_all), msg
|
|
765
783
|
end
|
|
766
784
|
|
|
767
785
|
##
|
|
@@ -780,10 +798,10 @@ module Minitest
|
|
|
780
798
|
# gets listed at the end of the run but doesn't cause a failure
|
|
781
799
|
# exit code.
|
|
782
800
|
|
|
783
|
-
def skip msg = nil,
|
|
801
|
+
def skip msg = nil, _ignored = nil
|
|
784
802
|
msg ||= "Skipped, no message given"
|
|
785
803
|
@skip = true
|
|
786
|
-
raise Minitest::Skip, msg
|
|
804
|
+
raise Minitest::Skip, msg
|
|
787
805
|
end
|
|
788
806
|
|
|
789
807
|
##
|
|
@@ -792,9 +810,9 @@ module Minitest
|
|
|
792
810
|
# date, but still holds you accountable and prevents you from
|
|
793
811
|
# forgetting it.
|
|
794
812
|
|
|
795
|
-
def skip_until y,m,d,msg
|
|
813
|
+
def skip_until y, m, d, msg
|
|
796
814
|
skip msg if Time.now < Time.local(y, m, d)
|
|
797
|
-
where = caller.first.rpartition(
|
|
815
|
+
where = caller(1..1).first.rpartition(":in").reject(&:empty?).first
|
|
798
816
|
warn "Stale skip_until %p at %s" % [msg, where]
|
|
799
817
|
end
|
|
800
818
|
|
data/lib/minitest/autorun.rb
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
rescue Gem::LoadError
|
|
5
|
-
# do nothing
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
require "minitest"
|
|
9
|
-
require "minitest/spec"
|
|
10
|
-
require "minitest/mock"
|
|
11
|
-
require "minitest/hell" if ENV["MT_HELL"]
|
|
1
|
+
require_relative "../minitest"
|
|
2
|
+
require_relative "spec"
|
|
3
|
+
require_relative "hell" if ENV["MT_HELL"]
|
|
12
4
|
|
|
13
5
|
Minitest.autorun
|
data/lib/minitest/benchmark.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
require_relative "test"
|
|
2
|
+
require_relative "spec"
|
|
3
3
|
|
|
4
4
|
module Minitest
|
|
5
5
|
##
|
|
@@ -17,7 +17,7 @@ module Minitest
|
|
|
17
17
|
self.class.io
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
def self.run
|
|
20
|
+
def self.run klass, method_name, reporter # :nodoc:
|
|
21
21
|
@io = reporter.io
|
|
22
22
|
super
|
|
23
23
|
end
|
|
@@ -47,8 +47,6 @@ module Minitest
|
|
|
47
47
|
|
|
48
48
|
def self.bench_linear min, max, step = 10
|
|
49
49
|
(min..max).step(step).to_a
|
|
50
|
-
rescue LocalJumpError # 1.8.6
|
|
51
|
-
r = []; (min..max).step(step) { |n| r << n }; r
|
|
52
50
|
end
|
|
53
51
|
|
|
54
52
|
##
|
|
@@ -83,7 +81,7 @@ module Minitest
|
|
|
83
81
|
def assert_performance validation, &work
|
|
84
82
|
range = self.class.bench_range
|
|
85
83
|
|
|
86
|
-
io.print
|
|
84
|
+
io.print self.name
|
|
87
85
|
|
|
88
86
|
times = []
|
|
89
87
|
|
|
@@ -236,7 +234,7 @@ module Minitest
|
|
|
236
234
|
|
|
237
235
|
def fit_exponential xs, ys
|
|
238
236
|
n = xs.size
|
|
239
|
-
xys = xs.zip
|
|
237
|
+
xys = xs.zip ys
|
|
240
238
|
sxlny = sigma(xys) { |x, y| x * Math.log(y) }
|
|
241
239
|
slny = sigma(xys) { |_, y| Math.log(y) }
|
|
242
240
|
sx2 = sigma(xys) { |x, _| x * x }
|
|
@@ -258,7 +256,7 @@ module Minitest
|
|
|
258
256
|
|
|
259
257
|
def fit_logarithmic xs, ys
|
|
260
258
|
n = xs.size
|
|
261
|
-
xys = xs.zip
|
|
259
|
+
xys = xs.zip ys
|
|
262
260
|
slnx2 = sigma(xys) { |x, _| Math.log(x) ** 2 }
|
|
263
261
|
slnx = sigma(xys) { |x, _| Math.log(x) }
|
|
264
262
|
sylnx = sigma(xys) { |x, y| y * Math.log(x) }
|
|
@@ -280,7 +278,7 @@ module Minitest
|
|
|
280
278
|
|
|
281
279
|
def fit_linear xs, ys
|
|
282
280
|
n = xs.size
|
|
283
|
-
xys = xs.zip
|
|
281
|
+
xys = xs.zip ys
|
|
284
282
|
sx = sigma xs
|
|
285
283
|
sy = sigma ys
|
|
286
284
|
sx2 = sigma(xs) { |x| x ** 2 }
|
|
@@ -302,7 +300,7 @@ module Minitest
|
|
|
302
300
|
|
|
303
301
|
def fit_power xs, ys
|
|
304
302
|
n = xs.size
|
|
305
|
-
xys = xs.zip
|
|
303
|
+
xys = xs.zip ys
|
|
306
304
|
slnxlny = sigma(xys) { |x, y| Math.log(x) * Math.log(y) }
|
|
307
305
|
slnx = sigma(xs) { |x | Math.log(x) }
|
|
308
306
|
slny = sigma(ys) { | y| Math.log(y) }
|
|
@@ -323,7 +321,7 @@ module Minitest
|
|
|
323
321
|
|
|
324
322
|
def sigma enum, &block
|
|
325
323
|
enum = enum.map(&block) if block
|
|
326
|
-
enum.
|
|
324
|
+
enum.sum
|
|
327
325
|
end
|
|
328
326
|
|
|
329
327
|
##
|
|
@@ -419,7 +417,6 @@ module Minitest
|
|
|
419
417
|
end
|
|
420
418
|
end
|
|
421
419
|
|
|
422
|
-
|
|
423
420
|
##
|
|
424
421
|
# Create a benchmark that verifies that the performance is logarithmic.
|
|
425
422
|
#
|