mega-sharp-tool 0.0.1
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 +7 -0
- data/mega-sharp-tool.gemspec +12 -0
- data/minitest-6.0.6/History.rdoc +1860 -0
- data/minitest-6.0.6/Manifest.txt +41 -0
- data/minitest-6.0.6/README.rdoc +763 -0
- data/minitest-6.0.6/Rakefile +89 -0
- data/minitest-6.0.6/bin/minitest +5 -0
- data/minitest-6.0.6/design_rationale.rb +54 -0
- data/minitest-6.0.6/lib/hoe/minitest.rb +30 -0
- data/minitest-6.0.6/lib/minitest/assertions.rb +821 -0
- data/minitest-6.0.6/lib/minitest/autorun.rb +5 -0
- data/minitest-6.0.6/lib/minitest/benchmark.rb +452 -0
- data/minitest-6.0.6/lib/minitest/bisect.rb +304 -0
- data/minitest-6.0.6/lib/minitest/complete.rb +56 -0
- data/minitest-6.0.6/lib/minitest/compress.rb +94 -0
- data/minitest-6.0.6/lib/minitest/error_on_warning.rb +11 -0
- data/minitest-6.0.6/lib/minitest/expectations.rb +321 -0
- data/minitest-6.0.6/lib/minitest/find_minimal_combination.rb +127 -0
- data/minitest-6.0.6/lib/minitest/hell.rb +11 -0
- data/minitest-6.0.6/lib/minitest/manual_plugins.rb +4 -0
- data/minitest-6.0.6/lib/minitest/parallel.rb +72 -0
- data/minitest-6.0.6/lib/minitest/path_expander.rb +432 -0
- data/minitest-6.0.6/lib/minitest/pride.rb +4 -0
- data/minitest-6.0.6/lib/minitest/pride_plugin.rb +135 -0
- data/minitest-6.0.6/lib/minitest/server.rb +49 -0
- data/minitest-6.0.6/lib/minitest/server_plugin.rb +88 -0
- data/minitest-6.0.6/lib/minitest/spec.rb +324 -0
- data/minitest-6.0.6/lib/minitest/sprint.rb +105 -0
- data/minitest-6.0.6/lib/minitest/sprint_plugin.rb +39 -0
- data/minitest-6.0.6/lib/minitest/test.rb +232 -0
- data/minitest-6.0.6/lib/minitest/test_task.rb +331 -0
- data/minitest-6.0.6/lib/minitest.rb +1232 -0
- data/minitest-6.0.6/test/minitest/metametameta.rb +150 -0
- data/minitest-6.0.6/test/minitest/test_bisect.rb +249 -0
- data/minitest-6.0.6/test/minitest/test_find_minimal_combination.rb +138 -0
- data/minitest-6.0.6/test/minitest/test_minitest_assertions.rb +1729 -0
- data/minitest-6.0.6/test/minitest/test_minitest_benchmark.rb +151 -0
- data/minitest-6.0.6/test/minitest/test_minitest_reporter.rb +437 -0
- data/minitest-6.0.6/test/minitest/test_minitest_spec.rb +1095 -0
- data/minitest-6.0.6/test/minitest/test_minitest_test.rb +1295 -0
- data/minitest-6.0.6/test/minitest/test_minitest_test_task.rb +57 -0
- data/minitest-6.0.6/test/minitest/test_path_expander.rb +229 -0
- data/minitest-6.0.6/test/minitest/test_server.rb +146 -0
- metadata +83 -0
|
@@ -0,0 +1,821 @@
|
|
|
1
|
+
require "rbconfig"
|
|
2
|
+
require "tempfile"
|
|
3
|
+
require "stringio"
|
|
4
|
+
|
|
5
|
+
module Minitest
|
|
6
|
+
##
|
|
7
|
+
# Minitest Assertions. All assertion methods accept a +msg+ which is
|
|
8
|
+
# printed if the assertion fails.
|
|
9
|
+
#
|
|
10
|
+
# Protocol: Nearly everything here boils up to +assert+, which
|
|
11
|
+
# expects to be able to increment an instance accessor named
|
|
12
|
+
# +assertions+. This is not provided by Assertions and must be
|
|
13
|
+
# provided by the thing including Assertions. See Minitest::Runnable
|
|
14
|
+
# for an example.
|
|
15
|
+
|
|
16
|
+
module Assertions
|
|
17
|
+
UNDEFINED = Object.new # :nodoc:
|
|
18
|
+
|
|
19
|
+
def UNDEFINED.inspect # :nodoc:
|
|
20
|
+
"UNDEFINED" # again with the rdoc bugs... :(
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
##
|
|
24
|
+
# Returns the diff command to use in #diff. Tries to intelligently
|
|
25
|
+
# figure out what diff to use.
|
|
26
|
+
|
|
27
|
+
def self.diff
|
|
28
|
+
return @diff if defined? @diff
|
|
29
|
+
|
|
30
|
+
@diff = if (RbConfig::CONFIG["host_os"] =~ /mswin|mingw/ and
|
|
31
|
+
system "diff.exe", __FILE__, __FILE__) then
|
|
32
|
+
"diff.exe -u"
|
|
33
|
+
elsif system "gdiff", __FILE__, __FILE__ then
|
|
34
|
+
"gdiff -u" # solaris and kin suck
|
|
35
|
+
elsif system "diff", __FILE__, __FILE__ then
|
|
36
|
+
"diff -u"
|
|
37
|
+
else
|
|
38
|
+
nil
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
##
|
|
43
|
+
# Set the diff command to use in #diff.
|
|
44
|
+
|
|
45
|
+
def self.diff= o
|
|
46
|
+
@diff = o
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
##
|
|
50
|
+
# Returns a diff between +exp+ and +act+. If there is no known
|
|
51
|
+
# diff command or if it doesn't make sense to diff the output
|
|
52
|
+
# (single line, short output), then it simply returns a basic
|
|
53
|
+
# comparison between the two.
|
|
54
|
+
#
|
|
55
|
+
# See +things_to_diff+ for more info.
|
|
56
|
+
|
|
57
|
+
def diff exp, act
|
|
58
|
+
result = nil
|
|
59
|
+
|
|
60
|
+
expect, butwas = things_to_diff exp, act
|
|
61
|
+
|
|
62
|
+
return "Expected: #{mu_pp exp}\n Actual: #{mu_pp act}" unless
|
|
63
|
+
expect
|
|
64
|
+
|
|
65
|
+
Tempfile.create "expect" do |a|
|
|
66
|
+
a.puts expect
|
|
67
|
+
a.flush
|
|
68
|
+
|
|
69
|
+
Tempfile.create "butwas" do |b|
|
|
70
|
+
b.puts butwas
|
|
71
|
+
b.flush
|
|
72
|
+
|
|
73
|
+
result = `#{Minitest::Assertions.diff} #{a.path} #{b.path}`
|
|
74
|
+
result.sub!(/^\-\-\- .+/, "--- expected")
|
|
75
|
+
result.sub!(/^\+\+\+ .+/, "+++ actual")
|
|
76
|
+
|
|
77
|
+
if result.empty? then
|
|
78
|
+
klass = exp.class
|
|
79
|
+
result = [
|
|
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,
|
|
84
|
+
].join
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
result
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
##
|
|
93
|
+
# Returns things to diff [expect, butwas], or [nil, nil] if nothing to diff.
|
|
94
|
+
#
|
|
95
|
+
# Criterion:
|
|
96
|
+
#
|
|
97
|
+
# 1. Strings include newlines or escaped newlines, but not both.
|
|
98
|
+
# 2. or: String lengths are > 30 characters.
|
|
99
|
+
# 3. or: Strings are equal to each other (but maybe different encodings?).
|
|
100
|
+
# 4. and: we found a diff executable.
|
|
101
|
+
|
|
102
|
+
def things_to_diff exp, act
|
|
103
|
+
expect = mu_pp_for_diff exp
|
|
104
|
+
butwas = mu_pp_for_diff act
|
|
105
|
+
|
|
106
|
+
e1, e2 = expect.include?("\n"), expect.include?("\\n")
|
|
107
|
+
b1, b2 = butwas.include?("\n"), butwas.include?("\\n")
|
|
108
|
+
|
|
109
|
+
need_to_diff =
|
|
110
|
+
(e1 ^ e2 ||
|
|
111
|
+
b1 ^ b2 ||
|
|
112
|
+
expect.size > 30 ||
|
|
113
|
+
butwas.size > 30 ||
|
|
114
|
+
expect == butwas) &&
|
|
115
|
+
Minitest::Assertions.diff
|
|
116
|
+
|
|
117
|
+
need_to_diff && [expect, butwas]
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
##
|
|
121
|
+
# This returns a human-readable version of +obj+. By default
|
|
122
|
+
# #inspect is called. You can override this to use #pretty_inspect
|
|
123
|
+
# if you want.
|
|
124
|
+
#
|
|
125
|
+
# See Minitest::Test.make_my_diffs_pretty!
|
|
126
|
+
|
|
127
|
+
def mu_pp obj
|
|
128
|
+
s = obj.inspect.encode Encoding.default_external
|
|
129
|
+
|
|
130
|
+
return s unless String === obj &&
|
|
131
|
+
(obj.encoding != Encoding.default_external || !obj.valid_encoding?)
|
|
132
|
+
|
|
133
|
+
enc = "# encoding: #{obj.encoding}"
|
|
134
|
+
val = "# valid: #{obj.valid_encoding?}"
|
|
135
|
+
|
|
136
|
+
[enc, val, s].join "\n"
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
##
|
|
140
|
+
# This returns a diff-able more human-readable version of +obj+.
|
|
141
|
+
# This differs from the regular mu_pp because it expands escaped
|
|
142
|
+
# newlines and makes hex-values (like object_ids) generic. This
|
|
143
|
+
# uses mu_pp to do the first pass and then cleans it up.
|
|
144
|
+
|
|
145
|
+
def mu_pp_for_diff obj
|
|
146
|
+
str = mu_pp obj
|
|
147
|
+
|
|
148
|
+
# both '\n' & '\\n' (_after_ mu_pp (aka inspect))
|
|
149
|
+
single = str.match?(/(?<!\\|^)\\n/)
|
|
150
|
+
double = str.match?(/(?<=\\|^)\\n/)
|
|
151
|
+
|
|
152
|
+
process =
|
|
153
|
+
if single ^ double then
|
|
154
|
+
if single then
|
|
155
|
+
lambda { |s| s == "\\n" ? "\n" : s } # unescape
|
|
156
|
+
else
|
|
157
|
+
lambda { |s| s == "\\\\n" ? "\\n\n" : s } # unescape a bit, add nls
|
|
158
|
+
end
|
|
159
|
+
else
|
|
160
|
+
:itself # leave it alone
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
str
|
|
164
|
+
.gsub(/\\?\\n/, &process)
|
|
165
|
+
.gsub(/:0x[a-fA-F0-9]{4,}/m, ":0xXXXXXX") # anonymize hex values
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
##
|
|
169
|
+
# Fails unless +test+ is truthy.
|
|
170
|
+
|
|
171
|
+
def assert test, msg = nil
|
|
172
|
+
self.assertions += 1
|
|
173
|
+
unless test then
|
|
174
|
+
msg ||= "Expected #{mu_pp test} to be truthy."
|
|
175
|
+
msg = msg.call if Proc === msg
|
|
176
|
+
raise Minitest::Assertion, msg
|
|
177
|
+
end
|
|
178
|
+
true
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
def _synchronize # :nodoc:
|
|
182
|
+
yield
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
##
|
|
186
|
+
# Fails unless +obj+ is empty.
|
|
187
|
+
|
|
188
|
+
def assert_empty obj, msg = nil
|
|
189
|
+
msg = message(msg) { "Expected #{mu_pp(obj)} to be empty" }
|
|
190
|
+
assert_predicate obj, :empty?, msg
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
##
|
|
194
|
+
# Fails unless <tt>exp == act</tt> printing the difference between
|
|
195
|
+
# the two, if possible.
|
|
196
|
+
#
|
|
197
|
+
# If there is no visible difference but the assertion fails, you
|
|
198
|
+
# should suspect that your #== is buggy, or your inspect output is
|
|
199
|
+
# missing crucial details. For nicer structural diffing, set
|
|
200
|
+
# Minitest::Test.make_my_diffs_pretty!
|
|
201
|
+
#
|
|
202
|
+
# For floats use assert_in_delta.
|
|
203
|
+
#
|
|
204
|
+
# See also: Minitest::Assertions.diff
|
|
205
|
+
|
|
206
|
+
def assert_equal exp, act, msg = nil
|
|
207
|
+
msg = message(msg, nil) { diff exp, act }
|
|
208
|
+
|
|
209
|
+
refute_nil exp, message { "Use assert_nil if expecting nil" } if nil == exp # don't count
|
|
210
|
+
|
|
211
|
+
assert exp == act, msg
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
##
|
|
215
|
+
# For comparing Floats. Fails unless +exp+ and +act+ are within +delta+
|
|
216
|
+
# of each other.
|
|
217
|
+
#
|
|
218
|
+
# assert_in_delta Math::PI, (22.0 / 7.0), 0.01
|
|
219
|
+
|
|
220
|
+
def assert_in_delta exp, act, delta = 0.001, msg = nil
|
|
221
|
+
n = (exp - act).abs
|
|
222
|
+
msg = message(msg) {
|
|
223
|
+
"Expected |#{exp} - #{act}| (#{n}) to be <= #{delta}"
|
|
224
|
+
}
|
|
225
|
+
assert delta >= n, msg
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
##
|
|
229
|
+
# For comparing Floats. Fails unless +exp+ and +act+ have a relative
|
|
230
|
+
# error less than +epsilon+.
|
|
231
|
+
|
|
232
|
+
def assert_in_epsilon exp, act, epsilon = 0.001, msg = nil
|
|
233
|
+
assert_in_delta exp, act, [exp.abs, act.abs].min * epsilon, msg
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
##
|
|
237
|
+
# Fails unless +collection+ includes +obj+.
|
|
238
|
+
|
|
239
|
+
def assert_includes collection, obj, msg = nil
|
|
240
|
+
msg = message(msg) {
|
|
241
|
+
"Expected #{mu_pp collection} to include #{mu_pp obj}"
|
|
242
|
+
}
|
|
243
|
+
assert_operator collection, :include?, obj, msg
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
##
|
|
247
|
+
# Fails unless +obj+ is an instance of +cls+.
|
|
248
|
+
|
|
249
|
+
def assert_instance_of cls, obj, msg = nil
|
|
250
|
+
msg = message(msg) {
|
|
251
|
+
"Expected #{mu_pp obj} to be an instance of #{cls}, not #{obj.class}"
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
assert obj.instance_of?(cls), msg
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
##
|
|
258
|
+
# Fails unless +obj+ is a kind of +cls+.
|
|
259
|
+
|
|
260
|
+
def assert_kind_of cls, obj, msg = nil
|
|
261
|
+
msg = message(msg) {
|
|
262
|
+
"Expected #{mu_pp obj} to be a kind of #{cls}, not #{obj.class}"
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
assert obj.kind_of?(cls), msg
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
##
|
|
269
|
+
# Fails unless +matcher+ <tt>=~</tt> +obj+.
|
|
270
|
+
|
|
271
|
+
def assert_match matcher, obj, msg = nil
|
|
272
|
+
msg = message(msg) { "Expected #{mu_pp matcher} to match #{mu_pp obj}" }
|
|
273
|
+
assert_respond_to matcher, :=~
|
|
274
|
+
matcher = Regexp.new Regexp.escape matcher if String === matcher
|
|
275
|
+
assert matcher =~ obj, msg
|
|
276
|
+
|
|
277
|
+
Regexp.last_match
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
##
|
|
281
|
+
# Fails unless +obj+ is nil
|
|
282
|
+
|
|
283
|
+
def assert_nil obj, msg = nil
|
|
284
|
+
msg = message(msg) { "Expected #{mu_pp obj} to be nil" }
|
|
285
|
+
assert nil == obj, msg
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
##
|
|
289
|
+
# For testing with binary operators. Eg:
|
|
290
|
+
#
|
|
291
|
+
# assert_operator 5, :<=, 4
|
|
292
|
+
|
|
293
|
+
def assert_operator o1, op, o2 = UNDEFINED, msg = nil
|
|
294
|
+
return assert_predicate o1, op, msg if UNDEFINED == o2
|
|
295
|
+
assert_respond_to o1, op
|
|
296
|
+
msg = message(msg) { "Expected #{mu_pp o1} to be #{op} #{mu_pp o2}" }
|
|
297
|
+
assert o1.__send__(op, o2), msg
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
##
|
|
301
|
+
# Fails if stdout or stderr do not output the expected results.
|
|
302
|
+
# Pass in nil if you don't care about that streams output. Pass in
|
|
303
|
+
# "" if you require it to be silent. Pass in a regexp if you want
|
|
304
|
+
# to pattern match.
|
|
305
|
+
#
|
|
306
|
+
# assert_output(/hey/) { method_with_output }
|
|
307
|
+
#
|
|
308
|
+
# NOTE: this uses #capture_io, not #capture_subprocess_io.
|
|
309
|
+
#
|
|
310
|
+
# See also: #assert_silent
|
|
311
|
+
|
|
312
|
+
def assert_output stdout = nil, stderr = nil
|
|
313
|
+
flunk "assert_output requires a block to capture output." unless
|
|
314
|
+
block_given?
|
|
315
|
+
|
|
316
|
+
out, err = capture_io do
|
|
317
|
+
yield
|
|
318
|
+
end
|
|
319
|
+
|
|
320
|
+
err_msg = Regexp === stderr ? :assert_match : :assert_equal if stderr
|
|
321
|
+
out_msg = Regexp === stdout ? :assert_match : :assert_equal if stdout
|
|
322
|
+
|
|
323
|
+
y = send err_msg, stderr, err, "In stderr" if err_msg
|
|
324
|
+
x = send out_msg, stdout, out, "In stdout" if out_msg
|
|
325
|
+
|
|
326
|
+
(!stdout || x) && (!stderr || y)
|
|
327
|
+
rescue Assertion
|
|
328
|
+
raise
|
|
329
|
+
rescue => e
|
|
330
|
+
raise UnexpectedError, e
|
|
331
|
+
end
|
|
332
|
+
|
|
333
|
+
##
|
|
334
|
+
# Fails unless +path+ exists.
|
|
335
|
+
|
|
336
|
+
def assert_path_exists path, msg = nil
|
|
337
|
+
msg = message(msg) { "Expected path '#{path}' to exist" }
|
|
338
|
+
assert File.exist?(path), msg
|
|
339
|
+
end
|
|
340
|
+
|
|
341
|
+
##
|
|
342
|
+
# For testing with pattern matching (only supported with Ruby 3.0 and later)
|
|
343
|
+
#
|
|
344
|
+
# # pass
|
|
345
|
+
# assert_pattern { [1,2,3] => [Integer, Integer, Integer] }
|
|
346
|
+
#
|
|
347
|
+
# # fail "length mismatch (given 3, expected 1)"
|
|
348
|
+
# assert_pattern { [1,2,3] => [Integer] }
|
|
349
|
+
#
|
|
350
|
+
# The bare <tt>=></tt> pattern will raise a NoMatchingPatternError on failure, which would
|
|
351
|
+
# normally be counted as a test error. This assertion rescues NoMatchingPatternError and
|
|
352
|
+
# generates a test failure. Any other exception will be raised as normal and generate a test
|
|
353
|
+
# error.
|
|
354
|
+
|
|
355
|
+
def assert_pattern
|
|
356
|
+
flunk "assert_pattern requires a block to capture errors." unless block_given?
|
|
357
|
+
|
|
358
|
+
yield
|
|
359
|
+
pass
|
|
360
|
+
rescue NoMatchingPatternError => e
|
|
361
|
+
flunk e.message
|
|
362
|
+
end
|
|
363
|
+
|
|
364
|
+
##
|
|
365
|
+
# For testing with predicates. Eg:
|
|
366
|
+
#
|
|
367
|
+
# assert_predicate str, :empty?
|
|
368
|
+
#
|
|
369
|
+
# This is really meant for specs and is front-ended by assert_operator:
|
|
370
|
+
#
|
|
371
|
+
# str.must_be :empty?
|
|
372
|
+
|
|
373
|
+
def assert_predicate o1, op, msg = nil
|
|
374
|
+
assert_respond_to o1, op, include_all:true
|
|
375
|
+
msg = message(msg) { "Expected #{mu_pp o1} to be #{op}" }
|
|
376
|
+
assert o1.__send__(op), msg
|
|
377
|
+
end
|
|
378
|
+
|
|
379
|
+
NO_RE_MSG = "class or module required for rescue clause. Got %p"
|
|
380
|
+
|
|
381
|
+
##
|
|
382
|
+
# Fails unless the block raises one of +exp+. Returns the
|
|
383
|
+
# exception matched so you can check the message, attributes, etc.
|
|
384
|
+
#
|
|
385
|
+
# +exp+ takes an optional message on the end to help explain
|
|
386
|
+
# failures and defaults to StandardError if no exception class is
|
|
387
|
+
# passed. Eg:
|
|
388
|
+
#
|
|
389
|
+
# assert_raises(CustomError) { method_with_custom_error }
|
|
390
|
+
#
|
|
391
|
+
# With custom error message:
|
|
392
|
+
#
|
|
393
|
+
# assert_raises(CustomError, 'This should have raised CustomError') { method_with_custom_error }
|
|
394
|
+
#
|
|
395
|
+
# Using the returned object:
|
|
396
|
+
#
|
|
397
|
+
# error = assert_raises(CustomError) do
|
|
398
|
+
# raise CustomError, 'This is really bad'
|
|
399
|
+
# end
|
|
400
|
+
#
|
|
401
|
+
# assert_equal 'This is really bad', error.message
|
|
402
|
+
|
|
403
|
+
def assert_raises *exp
|
|
404
|
+
flunk "assert_raises requires a block to capture errors." unless
|
|
405
|
+
block_given?
|
|
406
|
+
|
|
407
|
+
msg = "#{exp.pop}.\n" if String === exp.last
|
|
408
|
+
exp << StandardError if exp.empty?
|
|
409
|
+
|
|
410
|
+
# TODO: remove this if https://bugs.ruby-lang.org/issues/22007 gets fixed
|
|
411
|
+
raise TypeError, NO_RE_MSG % [exp] unless exp.all? Module
|
|
412
|
+
|
|
413
|
+
begin
|
|
414
|
+
yield
|
|
415
|
+
rescue *exp => e
|
|
416
|
+
pass # count assertion
|
|
417
|
+
return e
|
|
418
|
+
rescue Minitest::Assertion # incl Skip & UnexpectedError
|
|
419
|
+
# don't count assertion
|
|
420
|
+
raise
|
|
421
|
+
rescue SignalException, SystemExit
|
|
422
|
+
raise
|
|
423
|
+
rescue Exception => e
|
|
424
|
+
flunk proc {
|
|
425
|
+
exception_details(e, "#{msg}#{mu_pp exp} exception expected, not")
|
|
426
|
+
}
|
|
427
|
+
end
|
|
428
|
+
|
|
429
|
+
exp = exp.first if exp.size == 1
|
|
430
|
+
|
|
431
|
+
flunk "#{msg}#{mu_pp exp} expected but nothing was raised."
|
|
432
|
+
end
|
|
433
|
+
|
|
434
|
+
##
|
|
435
|
+
# Fails unless +obj+ responds to +meth+.
|
|
436
|
+
# include_all defaults to false to match Object#respond_to?
|
|
437
|
+
|
|
438
|
+
def assert_respond_to obj, meth, msg = nil, include_all: false
|
|
439
|
+
msg = message(msg) { "Expected #{mu_pp obj} (#{obj.class}) to respond to ##{meth}" }
|
|
440
|
+
assert obj.respond_to?(meth, include_all), msg
|
|
441
|
+
end
|
|
442
|
+
|
|
443
|
+
##
|
|
444
|
+
# Fails unless +exp+ and +act+ are #equal?
|
|
445
|
+
|
|
446
|
+
def assert_same exp, act, msg = nil
|
|
447
|
+
msg = message(msg) {
|
|
448
|
+
data = [mu_pp(act), act.object_id, mu_pp(exp), exp.object_id]
|
|
449
|
+
"Expected %s (oid=%d) to be the same as %s (oid=%d)" % data
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
refute_nil exp, message { "Use assert_nil if expecting nil" } if nil == exp # don't count
|
|
453
|
+
|
|
454
|
+
assert exp.equal?(act), msg
|
|
455
|
+
end
|
|
456
|
+
|
|
457
|
+
##
|
|
458
|
+
# Fails if the block outputs anything to stderr or stdout.
|
|
459
|
+
#
|
|
460
|
+
# See also: #assert_output
|
|
461
|
+
|
|
462
|
+
def assert_silent
|
|
463
|
+
assert_output "", "" do
|
|
464
|
+
yield
|
|
465
|
+
end
|
|
466
|
+
end
|
|
467
|
+
|
|
468
|
+
##
|
|
469
|
+
# Fails unless the block throws +sym+
|
|
470
|
+
|
|
471
|
+
def assert_throws sym, msg = nil
|
|
472
|
+
default = "Expected #{mu_pp sym} to have been thrown"
|
|
473
|
+
caught = true
|
|
474
|
+
value = catch sym do
|
|
475
|
+
begin
|
|
476
|
+
yield
|
|
477
|
+
rescue ArgumentError => e # 1.9+ exception
|
|
478
|
+
raise e unless e.message.include? "uncaught throw"
|
|
479
|
+
default += ", not #{e.message.split(/ /).last}"
|
|
480
|
+
end
|
|
481
|
+
caught = false
|
|
482
|
+
end
|
|
483
|
+
|
|
484
|
+
assert caught, message(msg) { default }
|
|
485
|
+
value
|
|
486
|
+
rescue Assertion
|
|
487
|
+
raise
|
|
488
|
+
rescue => e
|
|
489
|
+
raise UnexpectedError, e
|
|
490
|
+
end
|
|
491
|
+
|
|
492
|
+
##
|
|
493
|
+
# Captures $stdout and $stderr into strings:
|
|
494
|
+
#
|
|
495
|
+
# out, err = capture_io do
|
|
496
|
+
# puts "Some info"
|
|
497
|
+
# warn "You did a bad thing"
|
|
498
|
+
# end
|
|
499
|
+
#
|
|
500
|
+
# assert_match %r%info%, out
|
|
501
|
+
# assert_match %r%bad%, err
|
|
502
|
+
#
|
|
503
|
+
# NOTE: For efficiency, this method uses StringIO and does not
|
|
504
|
+
# capture IO for subprocesses. Use #capture_subprocess_io for
|
|
505
|
+
# that.
|
|
506
|
+
|
|
507
|
+
def capture_io
|
|
508
|
+
_synchronize do
|
|
509
|
+
begin
|
|
510
|
+
captured_stdout, captured_stderr = StringIO.new, StringIO.new
|
|
511
|
+
|
|
512
|
+
orig_stdout, orig_stderr = $stdout, $stderr
|
|
513
|
+
$stdout, $stderr = captured_stdout, captured_stderr
|
|
514
|
+
|
|
515
|
+
yield
|
|
516
|
+
|
|
517
|
+
return captured_stdout.string, captured_stderr.string
|
|
518
|
+
ensure
|
|
519
|
+
$stdout = orig_stdout
|
|
520
|
+
$stderr = orig_stderr
|
|
521
|
+
end
|
|
522
|
+
end
|
|
523
|
+
end
|
|
524
|
+
|
|
525
|
+
##
|
|
526
|
+
# Captures $stdout and $stderr into strings, using Tempfile to
|
|
527
|
+
# ensure that subprocess IO is captured as well.
|
|
528
|
+
#
|
|
529
|
+
# out, err = capture_subprocess_io do
|
|
530
|
+
# system "echo Some info"
|
|
531
|
+
# system "echo You did a bad thing 1>&2"
|
|
532
|
+
# end
|
|
533
|
+
#
|
|
534
|
+
# assert_match %r%info%, out
|
|
535
|
+
# assert_match %r%bad%, err
|
|
536
|
+
#
|
|
537
|
+
# NOTE: This method is approximately 10x slower than #capture_io so
|
|
538
|
+
# only use it when you need to test the output of a subprocess.
|
|
539
|
+
|
|
540
|
+
def capture_subprocess_io
|
|
541
|
+
_synchronize do
|
|
542
|
+
begin
|
|
543
|
+
require "tempfile"
|
|
544
|
+
|
|
545
|
+
captured_stdout, captured_stderr = Tempfile.new("out"), Tempfile.new("err")
|
|
546
|
+
|
|
547
|
+
orig_stdout, orig_stderr = $stdout.dup, $stderr.dup
|
|
548
|
+
$stdout.reopen captured_stdout
|
|
549
|
+
$stderr.reopen captured_stderr
|
|
550
|
+
|
|
551
|
+
yield
|
|
552
|
+
|
|
553
|
+
$stdout.rewind
|
|
554
|
+
$stderr.rewind
|
|
555
|
+
|
|
556
|
+
return captured_stdout.read, captured_stderr.read
|
|
557
|
+
ensure
|
|
558
|
+
$stdout.reopen orig_stdout
|
|
559
|
+
$stderr.reopen orig_stderr
|
|
560
|
+
|
|
561
|
+
orig_stdout.close
|
|
562
|
+
orig_stderr.close
|
|
563
|
+
captured_stdout.close!
|
|
564
|
+
captured_stderr.close!
|
|
565
|
+
end
|
|
566
|
+
end
|
|
567
|
+
end
|
|
568
|
+
|
|
569
|
+
##
|
|
570
|
+
# Returns details for exception +e+
|
|
571
|
+
|
|
572
|
+
def exception_details e, msg
|
|
573
|
+
[
|
|
574
|
+
msg,
|
|
575
|
+
"Class: <#{e.class}>",
|
|
576
|
+
"Message: <#{e.message.inspect}>",
|
|
577
|
+
"---Backtrace---",
|
|
578
|
+
Minitest.filter_backtrace(e.backtrace),
|
|
579
|
+
"---------------",
|
|
580
|
+
].join "\n"
|
|
581
|
+
end
|
|
582
|
+
|
|
583
|
+
##
|
|
584
|
+
# Fails after a given date (in the local time zone). This allows
|
|
585
|
+
# you to put time-bombs in your tests if you need to keep
|
|
586
|
+
# something around until a later date lest you forget about it.
|
|
587
|
+
|
|
588
|
+
def fail_after y, m, d, msg
|
|
589
|
+
flunk msg if Time.now > Time.local(y, m, d)
|
|
590
|
+
end
|
|
591
|
+
|
|
592
|
+
##
|
|
593
|
+
# Fails with +msg+.
|
|
594
|
+
|
|
595
|
+
def flunk msg = nil
|
|
596
|
+
msg ||= "Epic Fail!"
|
|
597
|
+
assert false, msg
|
|
598
|
+
end
|
|
599
|
+
|
|
600
|
+
##
|
|
601
|
+
# Returns a proc that delays generation of an output message. If
|
|
602
|
+
# +msg+ is a proc (eg, from another +message+ call) return +msg+
|
|
603
|
+
# as-is. Otherwise, return a proc that will output +msg+ along
|
|
604
|
+
# with the value of the result of the block passed to +message+.
|
|
605
|
+
|
|
606
|
+
def message msg = nil, ending = ".", &default
|
|
607
|
+
return msg if Proc === msg
|
|
608
|
+
proc {
|
|
609
|
+
custom_message = "#{msg}.\n" unless nil == msg or msg.to_s.empty?
|
|
610
|
+
"#{custom_message}#{default.call}#{ending}"
|
|
611
|
+
}
|
|
612
|
+
end
|
|
613
|
+
|
|
614
|
+
##
|
|
615
|
+
# used for counting assertions
|
|
616
|
+
|
|
617
|
+
def pass _msg = nil
|
|
618
|
+
assert true
|
|
619
|
+
end
|
|
620
|
+
|
|
621
|
+
##
|
|
622
|
+
# Fails if +test+ is truthy.
|
|
623
|
+
|
|
624
|
+
def refute test, msg = nil
|
|
625
|
+
msg ||= message { "Expected #{mu_pp test} to not be truthy" }
|
|
626
|
+
assert !test, msg
|
|
627
|
+
end
|
|
628
|
+
|
|
629
|
+
##
|
|
630
|
+
# Fails if +obj+ is empty.
|
|
631
|
+
|
|
632
|
+
def refute_empty obj, msg = nil
|
|
633
|
+
msg = message(msg) { "Expected #{mu_pp obj} to not be empty" }
|
|
634
|
+
refute_predicate obj, :empty?, msg
|
|
635
|
+
end
|
|
636
|
+
|
|
637
|
+
##
|
|
638
|
+
# Fails if <tt>exp == act</tt>.
|
|
639
|
+
#
|
|
640
|
+
# For floats use refute_in_delta.
|
|
641
|
+
|
|
642
|
+
def refute_equal exp, act, msg = nil
|
|
643
|
+
msg = message(msg) {
|
|
644
|
+
"Expected #{mu_pp act} to not be equal to #{mu_pp exp}"
|
|
645
|
+
}
|
|
646
|
+
refute exp == act, msg
|
|
647
|
+
end
|
|
648
|
+
|
|
649
|
+
##
|
|
650
|
+
# For comparing Floats. Fails if +exp+ is within +delta+ of +act+.
|
|
651
|
+
#
|
|
652
|
+
# refute_in_delta Math::PI, (22.0 / 7.0)
|
|
653
|
+
|
|
654
|
+
def refute_in_delta exp, act, delta = 0.001, msg = nil
|
|
655
|
+
n = (exp - act).abs
|
|
656
|
+
msg = message(msg) {
|
|
657
|
+
"Expected |#{exp} - #{act}| (#{n}) to not be <= #{delta}"
|
|
658
|
+
}
|
|
659
|
+
refute delta >= n, msg
|
|
660
|
+
end
|
|
661
|
+
|
|
662
|
+
##
|
|
663
|
+
# For comparing Floats. Fails if +exp+ and +act+ have a relative error
|
|
664
|
+
# less than +epsilon+.
|
|
665
|
+
|
|
666
|
+
def refute_in_epsilon exp, act, epsilon = 0.001, msg = nil
|
|
667
|
+
refute_in_delta exp, act, [exp.abs, act.abs].min * epsilon, msg
|
|
668
|
+
end
|
|
669
|
+
|
|
670
|
+
##
|
|
671
|
+
# Fails if +obj+ includes +sub+.
|
|
672
|
+
|
|
673
|
+
def refute_includes obj, sub, msg = nil
|
|
674
|
+
msg = message(msg) { "Expected #{mu_pp obj} to not include #{mu_pp sub}" }
|
|
675
|
+
refute_operator obj, :include?, sub, msg
|
|
676
|
+
end
|
|
677
|
+
|
|
678
|
+
##
|
|
679
|
+
# Fails if +obj+ is an instance of +cls+.
|
|
680
|
+
|
|
681
|
+
def refute_instance_of cls, obj, msg = nil
|
|
682
|
+
msg = message(msg) {
|
|
683
|
+
"Expected #{mu_pp obj} to not be an instance of #{cls}"
|
|
684
|
+
}
|
|
685
|
+
refute obj.instance_of?(cls), msg
|
|
686
|
+
end
|
|
687
|
+
|
|
688
|
+
##
|
|
689
|
+
# Fails if +obj+ is a kind of +cls+.
|
|
690
|
+
|
|
691
|
+
def refute_kind_of cls, obj, msg = nil
|
|
692
|
+
msg = message(msg) { "Expected #{mu_pp obj} to not be a kind of #{cls}" }
|
|
693
|
+
refute obj.kind_of?(cls), msg
|
|
694
|
+
end
|
|
695
|
+
|
|
696
|
+
##
|
|
697
|
+
# Fails if +matcher+ <tt>=~</tt> +obj+.
|
|
698
|
+
|
|
699
|
+
def refute_match matcher, obj, msg = nil
|
|
700
|
+
msg = message(msg) { "Expected #{mu_pp matcher} to not match #{mu_pp obj}" }
|
|
701
|
+
matcher = Regexp.new Regexp.escape matcher if String === matcher
|
|
702
|
+
refute_operator matcher, :=~, obj, msg
|
|
703
|
+
end
|
|
704
|
+
|
|
705
|
+
##
|
|
706
|
+
# Fails if +obj+ is nil.
|
|
707
|
+
|
|
708
|
+
def refute_nil obj, msg = nil
|
|
709
|
+
msg = message(msg) { "Expected #{mu_pp obj} to not be nil" }
|
|
710
|
+
refute nil == obj, msg
|
|
711
|
+
end
|
|
712
|
+
|
|
713
|
+
##
|
|
714
|
+
# For testing with pattern matching (only supported with Ruby 3.0 and later)
|
|
715
|
+
#
|
|
716
|
+
# # pass
|
|
717
|
+
# refute_pattern { [1,2,3] => [String] }
|
|
718
|
+
#
|
|
719
|
+
# # fail "NoMatchingPatternError expected, but nothing was raised."
|
|
720
|
+
# refute_pattern { [1,2,3] => [Integer, Integer, Integer] }
|
|
721
|
+
#
|
|
722
|
+
# This assertion expects a NoMatchingPatternError exception, and will fail if none is raised. Any
|
|
723
|
+
# other exceptions will be raised as normal and generate a test error.
|
|
724
|
+
|
|
725
|
+
def refute_pattern
|
|
726
|
+
flunk "refute_pattern requires a block to capture errors." unless block_given?
|
|
727
|
+
|
|
728
|
+
yield
|
|
729
|
+
flunk "NoMatchingPatternError expected, but nothing was raised."
|
|
730
|
+
rescue NoMatchingPatternError
|
|
731
|
+
pass
|
|
732
|
+
end
|
|
733
|
+
|
|
734
|
+
##
|
|
735
|
+
# Fails if +o1+ is not +op+ +o2+. Eg:
|
|
736
|
+
#
|
|
737
|
+
# refute_operator 1, :>, 2 #=> pass
|
|
738
|
+
# refute_operator 1, :<, 2 #=> fail
|
|
739
|
+
|
|
740
|
+
def refute_operator o1, op, o2 = UNDEFINED, msg = nil
|
|
741
|
+
return refute_predicate o1, op, msg if UNDEFINED == o2
|
|
742
|
+
assert_respond_to o1, op
|
|
743
|
+
msg = message(msg) { "Expected #{mu_pp o1} to not be #{op} #{mu_pp o2}" }
|
|
744
|
+
refute o1.__send__(op, o2), msg
|
|
745
|
+
end
|
|
746
|
+
|
|
747
|
+
##
|
|
748
|
+
# Fails if +path+ exists.
|
|
749
|
+
|
|
750
|
+
def refute_path_exists path, msg = nil
|
|
751
|
+
msg = message(msg) { "Expected path '#{path}' to not exist" }
|
|
752
|
+
refute File.exist?(path), msg
|
|
753
|
+
end
|
|
754
|
+
|
|
755
|
+
##
|
|
756
|
+
# For testing with predicates.
|
|
757
|
+
#
|
|
758
|
+
# refute_predicate str, :empty?
|
|
759
|
+
#
|
|
760
|
+
# This is really meant for specs and is front-ended by refute_operator:
|
|
761
|
+
#
|
|
762
|
+
# str.wont_be :empty?
|
|
763
|
+
|
|
764
|
+
def refute_predicate o1, op, msg = nil
|
|
765
|
+
assert_respond_to o1, op, include_all:true
|
|
766
|
+
msg = message(msg) { "Expected #{mu_pp o1} to not be #{op}" }
|
|
767
|
+
refute o1.__send__(op), msg
|
|
768
|
+
end
|
|
769
|
+
|
|
770
|
+
##
|
|
771
|
+
# Fails if +obj+ responds to the message +meth+.
|
|
772
|
+
# include_all defaults to false to match Object#respond_to?
|
|
773
|
+
|
|
774
|
+
def refute_respond_to obj, meth, msg = nil, include_all: false
|
|
775
|
+
msg = message(msg) { "Expected #{mu_pp obj} to not respond to #{meth}" }
|
|
776
|
+
|
|
777
|
+
refute obj.respond_to?(meth, include_all), msg
|
|
778
|
+
end
|
|
779
|
+
|
|
780
|
+
##
|
|
781
|
+
# Fails if +exp+ is the same (by object identity) as +act+.
|
|
782
|
+
|
|
783
|
+
def refute_same exp, act, msg = nil
|
|
784
|
+
msg = message(msg) {
|
|
785
|
+
data = [mu_pp(act), act.object_id, mu_pp(exp), exp.object_id]
|
|
786
|
+
"Expected %s (oid=%d) to not be the same as %s (oid=%d)" % data
|
|
787
|
+
}
|
|
788
|
+
refute exp.equal?(act), msg
|
|
789
|
+
end
|
|
790
|
+
|
|
791
|
+
##
|
|
792
|
+
# Skips the current run. If run in verbose-mode, the skipped run
|
|
793
|
+
# gets listed at the end of the run but doesn't cause a failure
|
|
794
|
+
# exit code.
|
|
795
|
+
|
|
796
|
+
def skip msg = nil, _ignored = nil
|
|
797
|
+
msg ||= "Skipped, no message given"
|
|
798
|
+
@skip = true
|
|
799
|
+
raise Minitest::Skip, msg
|
|
800
|
+
end
|
|
801
|
+
|
|
802
|
+
##
|
|
803
|
+
# Skips the current run until a given date (in the local time
|
|
804
|
+
# zone). This allows you to put some fixes on hold until a later
|
|
805
|
+
# date, but still holds you accountable and prevents you from
|
|
806
|
+
# forgetting it.
|
|
807
|
+
|
|
808
|
+
def skip_until y, m, d, msg
|
|
809
|
+
skip msg if Time.now < Time.local(y, m, d)
|
|
810
|
+
where = caller(1..1).first.rpartition(":in").reject(&:empty?).first
|
|
811
|
+
warn "Stale skip_until %p at %s" % [msg, where]
|
|
812
|
+
end
|
|
813
|
+
|
|
814
|
+
##
|
|
815
|
+
# Was this testcase skipped? Meant for #teardown.
|
|
816
|
+
|
|
817
|
+
def skipped?
|
|
818
|
+
defined?(@skip) and @skip
|
|
819
|
+
end
|
|
820
|
+
end
|
|
821
|
+
end
|