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,1295 @@
|
|
|
1
|
+
require_relative "metametameta"
|
|
2
|
+
|
|
3
|
+
e = Encoding.default_external
|
|
4
|
+
if e != Encoding::UTF_8 then
|
|
5
|
+
warn ""
|
|
6
|
+
warn ""
|
|
7
|
+
warn "NOTE: External encoding #{e} is not UTF-8. Tests WILL fail."
|
|
8
|
+
warn " Run tests with `RUBYOPT=-Eutf-8 rake` to avoid errors."
|
|
9
|
+
warn ""
|
|
10
|
+
warn ""
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class Minitest::Runnable
|
|
14
|
+
attr_reader :gc_stats # only needed if running w/ minitest-gcstats
|
|
15
|
+
|
|
16
|
+
def whatever # faked for testing
|
|
17
|
+
assert true
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
class TestMinitestUnit < MetaMetaMetaTestCase
|
|
22
|
+
parallelize_me!
|
|
23
|
+
|
|
24
|
+
MINITEST_BASE_DIR = "./lib/minitest/mini"
|
|
25
|
+
BT_MIDDLE = ["#{MINITEST_BASE_DIR}/test.rb:161:in 'each'",
|
|
26
|
+
"#{MINITEST_BASE_DIR}/test.rb:158:in 'each'",
|
|
27
|
+
"#{MINITEST_BASE_DIR}/test.rb:139:in 'run'",
|
|
28
|
+
"#{MINITEST_BASE_DIR}/test.rb:106:in 'run'"]
|
|
29
|
+
|
|
30
|
+
def test_filter_backtrace
|
|
31
|
+
# this is a semi-lame mix of relative paths.
|
|
32
|
+
# I cheated by making the autotest parts not have ./
|
|
33
|
+
bt = (["lib/autotest.rb:571:in 'add_exception'",
|
|
34
|
+
"test/test_autotest.rb:62:in 'test_add_exception'",
|
|
35
|
+
"#{MINITEST_BASE_DIR}/test.rb:165:in '__send__'"] +
|
|
36
|
+
BT_MIDDLE +
|
|
37
|
+
["#{MINITEST_BASE_DIR}/test.rb:29",
|
|
38
|
+
"test/test_autotest.rb:422"])
|
|
39
|
+
bt = util_expand_bt bt
|
|
40
|
+
|
|
41
|
+
ex = ["lib/autotest.rb:571:in 'add_exception'",
|
|
42
|
+
"test/test_autotest.rb:62:in 'test_add_exception'"]
|
|
43
|
+
ex = util_expand_bt ex
|
|
44
|
+
|
|
45
|
+
Minitest::Test.io_lock.synchronize do # try not to trounce in parallel
|
|
46
|
+
fu = Minitest.filter_backtrace bt
|
|
47
|
+
|
|
48
|
+
assert_equal ex, fu
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def test_filter_backtrace_all_unit
|
|
53
|
+
bt = (["#{MINITEST_BASE_DIR}/test.rb:165:in '__send__'"] +
|
|
54
|
+
BT_MIDDLE +
|
|
55
|
+
["#{MINITEST_BASE_DIR}/test.rb:29"])
|
|
56
|
+
ex = bt.clone
|
|
57
|
+
fu = Minitest.filter_backtrace bt
|
|
58
|
+
assert_equal ex, fu
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def test_filter_backtrace_unit_starts
|
|
62
|
+
bt = (["#{MINITEST_BASE_DIR}/test.rb:165:in '__send__'"] +
|
|
63
|
+
BT_MIDDLE +
|
|
64
|
+
["#{MINITEST_BASE_DIR}/mini/test.rb:29",
|
|
65
|
+
"-e:1"])
|
|
66
|
+
|
|
67
|
+
bt = util_expand_bt bt
|
|
68
|
+
|
|
69
|
+
ex = ["-e:1"]
|
|
70
|
+
Minitest::Test.io_lock.synchronize do # try not to trounce in parallel
|
|
71
|
+
fu = Minitest.filter_backtrace bt
|
|
72
|
+
assert_equal ex, fu
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def test_filter_backtrace__empty
|
|
77
|
+
with_empty_backtrace_filter do
|
|
78
|
+
bt = %w[first second third]
|
|
79
|
+
fu = Minitest.filter_backtrace bt.dup
|
|
80
|
+
assert_equal bt, fu
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def test_infectious_binary_encoding
|
|
85
|
+
@tu = Class.new FakeNamedTest do
|
|
86
|
+
def test_this_is_not_ascii_assertion
|
|
87
|
+
assert_equal "ЁЁЁ", "ёёё"
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def test_this_is_non_ascii_failure_message
|
|
91
|
+
raise "ЁЁЁ".dup.force_encoding(Encoding::BINARY)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
expected = <<~EOM
|
|
96
|
+
FE
|
|
97
|
+
|
|
98
|
+
Finished in 0.00
|
|
99
|
+
|
|
100
|
+
1) Failure:
|
|
101
|
+
FakeNamedTestXX#test_this_is_not_ascii_assertion [FILE:LINE]:
|
|
102
|
+
Expected: "ЁЁЁ"
|
|
103
|
+
Actual: "ёёё"
|
|
104
|
+
|
|
105
|
+
2) Error:
|
|
106
|
+
FakeNamedTestXX#test_this_is_non_ascii_failure_message:
|
|
107
|
+
RuntimeError: ЁЁЁ
|
|
108
|
+
FILE:LINE:in 'test_this_is_non_ascii_failure_message'
|
|
109
|
+
|
|
110
|
+
2 runs, 1 assertions, 1 failures, 1 errors, 0 skips
|
|
111
|
+
EOM
|
|
112
|
+
|
|
113
|
+
Minitest::Test.io_lock.synchronize do # try not to trounce in parallel
|
|
114
|
+
assert_report expected
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def test_passed_eh_teardown_good
|
|
119
|
+
test_class = Class.new FakeNamedTest do
|
|
120
|
+
def teardown; assert true; end
|
|
121
|
+
def test_omg; assert true; end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
test = test_class.new :test_omg
|
|
125
|
+
test.run
|
|
126
|
+
|
|
127
|
+
refute_predicate test, :error?
|
|
128
|
+
assert_predicate test, :passed?
|
|
129
|
+
refute_predicate test, :skipped?
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def test_passed_eh_teardown_skipped
|
|
133
|
+
test_class = Class.new FakeNamedTest do
|
|
134
|
+
def teardown; assert true; end
|
|
135
|
+
def test_omg; skip "bork"; end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
test = test_class.new :test_omg
|
|
139
|
+
test.run
|
|
140
|
+
|
|
141
|
+
refute_predicate test, :error?
|
|
142
|
+
refute_predicate test, :passed?
|
|
143
|
+
assert_predicate test, :skipped?
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def test_passed_eh_teardown_flunked
|
|
147
|
+
test_class = Class.new FakeNamedTest do
|
|
148
|
+
def teardown; flunk; end
|
|
149
|
+
def test_omg; assert true; end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
test = test_class.new :test_omg
|
|
153
|
+
test.run
|
|
154
|
+
|
|
155
|
+
refute_predicate test, :error?
|
|
156
|
+
refute_predicate test, :passed?
|
|
157
|
+
refute_predicate test, :skipped?
|
|
158
|
+
end
|
|
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
|
+
|
|
178
|
+
def util_expand_bt bt
|
|
179
|
+
bt.map { |f| f.start_with?(".") ? File.expand_path(f) : f }
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
class TestMinitestUnitInherited < MetaMetaMetaTestCase
|
|
184
|
+
def with_overridden_include
|
|
185
|
+
Class.class_eval do
|
|
186
|
+
def inherited_with_hacks _klass
|
|
187
|
+
throw :inherited_hook
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
alias inherited_without_hacks inherited
|
|
191
|
+
alias inherited inherited_with_hacks
|
|
192
|
+
alias IGNORE_ME! inherited # 1.8 bug. god I love venture bros
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
yield
|
|
196
|
+
ensure
|
|
197
|
+
Class.class_eval do
|
|
198
|
+
alias inherited inherited_without_hacks
|
|
199
|
+
|
|
200
|
+
undef_method :inherited_with_hacks
|
|
201
|
+
undef_method :inherited_without_hacks
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
refute_respond_to Class, :inherited_with_hacks
|
|
205
|
+
refute_respond_to Class, :inherited_without_hacks
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
def test_inherited_hook_plays_nice_with_others
|
|
209
|
+
with_overridden_include do
|
|
210
|
+
assert_throws :inherited_hook do
|
|
211
|
+
Class.new FakeNamedTest
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
class TestMinitestRunner < MetaMetaMetaTestCase
|
|
218
|
+
# do not parallelize this suite... it just can't handle it.
|
|
219
|
+
|
|
220
|
+
def test_class_runnables
|
|
221
|
+
@assertion_count = 0
|
|
222
|
+
|
|
223
|
+
tc = Class.new Minitest::Test
|
|
224
|
+
|
|
225
|
+
assert_equal 1, Minitest::Test.runnables.size
|
|
226
|
+
assert_equal [tc], Minitest::Test.runnables
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
def test_run_test
|
|
230
|
+
@tu = Class.new FakeNamedTest do
|
|
231
|
+
attr_reader :foo
|
|
232
|
+
|
|
233
|
+
def run
|
|
234
|
+
@foo = "hi mom!"
|
|
235
|
+
r = super
|
|
236
|
+
@foo = "okay"
|
|
237
|
+
|
|
238
|
+
r
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
def test_something
|
|
242
|
+
assert_equal "hi mom!", foo
|
|
243
|
+
end
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
expected = <<~EOM
|
|
247
|
+
.
|
|
248
|
+
|
|
249
|
+
Finished in 0.00
|
|
250
|
+
|
|
251
|
+
1 runs, 1 assertions, 0 failures, 0 errors, 0 skips
|
|
252
|
+
EOM
|
|
253
|
+
|
|
254
|
+
assert_report expected
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
def test_run_error
|
|
258
|
+
@tu = Class.new FakeNamedTest do
|
|
259
|
+
def test_something
|
|
260
|
+
assert true
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
def test_error
|
|
264
|
+
raise "unhandled exception"
|
|
265
|
+
end
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
expected = <<~EOM
|
|
269
|
+
.E
|
|
270
|
+
|
|
271
|
+
Finished in 0.00
|
|
272
|
+
|
|
273
|
+
1) Error:
|
|
274
|
+
FakeNamedTestXX#test_error:
|
|
275
|
+
RuntimeError: unhandled exception
|
|
276
|
+
FILE:LINE:in 'test_error'
|
|
277
|
+
|
|
278
|
+
2 runs, 1 assertions, 0 failures, 1 errors, 0 skips
|
|
279
|
+
EOM
|
|
280
|
+
|
|
281
|
+
assert_report expected
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
def test_run_error_teardown
|
|
285
|
+
@tu = Class.new FakeNamedTest do
|
|
286
|
+
def test_something
|
|
287
|
+
assert true
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
def teardown
|
|
291
|
+
raise "unhandled exception"
|
|
292
|
+
end
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
expected = <<~EOM
|
|
296
|
+
E
|
|
297
|
+
|
|
298
|
+
Finished in 0.00
|
|
299
|
+
|
|
300
|
+
1) Error:
|
|
301
|
+
FakeNamedTestXX#test_something:
|
|
302
|
+
RuntimeError: unhandled exception
|
|
303
|
+
FILE:LINE:in 'teardown'
|
|
304
|
+
|
|
305
|
+
1 runs, 1 assertions, 0 failures, 1 errors, 0 skips
|
|
306
|
+
EOM
|
|
307
|
+
|
|
308
|
+
assert_report expected
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
def test_run_failing
|
|
312
|
+
setup_basic_tu
|
|
313
|
+
|
|
314
|
+
expected = <<~EOM
|
|
315
|
+
.F
|
|
316
|
+
|
|
317
|
+
Finished in 0.00
|
|
318
|
+
|
|
319
|
+
1) Failure:
|
|
320
|
+
FakeNamedTestXX#test_failure [FILE:LINE]:
|
|
321
|
+
Expected false to be truthy.
|
|
322
|
+
|
|
323
|
+
2 runs, 2 assertions, 1 failures, 0 errors, 0 skips
|
|
324
|
+
EOM
|
|
325
|
+
|
|
326
|
+
assert_report expected
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
def setup_basic_tu
|
|
330
|
+
@tu = Class.new FakeNamedTest do
|
|
331
|
+
def test_something
|
|
332
|
+
assert true
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
def test_failure
|
|
336
|
+
assert false
|
|
337
|
+
end
|
|
338
|
+
end
|
|
339
|
+
end
|
|
340
|
+
|
|
341
|
+
def test_seed # this is set for THIS run, so I'm not testing it's actual value
|
|
342
|
+
assert_instance_of Integer, Minitest.seed
|
|
343
|
+
end
|
|
344
|
+
|
|
345
|
+
def test_filter_runnable_methods
|
|
346
|
+
cls = Class.new Minitest::Runnable
|
|
347
|
+
def cls.runnable_methods
|
|
348
|
+
%w[ x y z ]
|
|
349
|
+
end
|
|
350
|
+
|
|
351
|
+
assert_equal %w[x y z], cls.filter_runnable_methods
|
|
352
|
+
assert_equal %w[x y], cls.filter_runnable_methods(exclude: "z")
|
|
353
|
+
assert_equal %w[x], cls.filter_runnable_methods(include: "x")
|
|
354
|
+
|
|
355
|
+
assert_empty cls.filter_runnable_methods(exclude: "/./")
|
|
356
|
+
assert_empty cls.filter_runnable_methods(include: "x", exclude: "x")
|
|
357
|
+
end
|
|
358
|
+
|
|
359
|
+
def test_run_failing_filtered
|
|
360
|
+
setup_basic_tu
|
|
361
|
+
|
|
362
|
+
expected = <<~EOM
|
|
363
|
+
.
|
|
364
|
+
|
|
365
|
+
Finished in 0.00
|
|
366
|
+
|
|
367
|
+
1 runs, 1 assertions, 0 failures, 0 errors, 0 skips
|
|
368
|
+
EOM
|
|
369
|
+
|
|
370
|
+
assert_report expected, %w[--name /some|thing/ --seed 42]
|
|
371
|
+
end
|
|
372
|
+
|
|
373
|
+
def assert_filtering filter, name, expected, a = false
|
|
374
|
+
args = %W[--#{filter} #{name} --seed 42]
|
|
375
|
+
|
|
376
|
+
alpha = Class.new FakeNamedTest do
|
|
377
|
+
define_method :test_something do
|
|
378
|
+
assert a
|
|
379
|
+
end
|
|
380
|
+
end
|
|
381
|
+
Object.const_set :Alpha, alpha
|
|
382
|
+
|
|
383
|
+
beta = Class.new FakeNamedTest do
|
|
384
|
+
define_method :test_something do
|
|
385
|
+
assert true
|
|
386
|
+
end
|
|
387
|
+
end
|
|
388
|
+
Object.const_set :Beta, beta
|
|
389
|
+
|
|
390
|
+
@tus = [alpha, beta]
|
|
391
|
+
|
|
392
|
+
assert_report expected, args
|
|
393
|
+
ensure
|
|
394
|
+
Object.send :remove_const, :Alpha
|
|
395
|
+
Object.send :remove_const, :Beta
|
|
396
|
+
end
|
|
397
|
+
|
|
398
|
+
def test_run_filtered_including_suite_name
|
|
399
|
+
expected = <<~EOM
|
|
400
|
+
.
|
|
401
|
+
|
|
402
|
+
Finished in 0.00
|
|
403
|
+
|
|
404
|
+
1 runs, 1 assertions, 0 failures, 0 errors, 0 skips
|
|
405
|
+
EOM
|
|
406
|
+
|
|
407
|
+
assert_filtering "name", "/Beta#test_something/", expected
|
|
408
|
+
end
|
|
409
|
+
|
|
410
|
+
def test_run_filtered_including_suite_name_string
|
|
411
|
+
expected = <<~EOM
|
|
412
|
+
.
|
|
413
|
+
|
|
414
|
+
Finished in 0.00
|
|
415
|
+
|
|
416
|
+
1 runs, 1 assertions, 0 failures, 0 errors, 0 skips
|
|
417
|
+
EOM
|
|
418
|
+
|
|
419
|
+
assert_filtering "name", "Beta#test_something", expected
|
|
420
|
+
end
|
|
421
|
+
|
|
422
|
+
def test_run_filtered_string_method_only
|
|
423
|
+
expected = <<~EOM
|
|
424
|
+
..
|
|
425
|
+
|
|
426
|
+
Finished in 0.00
|
|
427
|
+
|
|
428
|
+
2 runs, 2 assertions, 0 failures, 0 errors, 0 skips
|
|
429
|
+
EOM
|
|
430
|
+
|
|
431
|
+
assert_filtering "name", "test_something", expected, :pass
|
|
432
|
+
end
|
|
433
|
+
|
|
434
|
+
def test_run_failing_excluded
|
|
435
|
+
setup_basic_tu
|
|
436
|
+
|
|
437
|
+
expected = <<~EOM
|
|
438
|
+
.
|
|
439
|
+
|
|
440
|
+
Finished in 0.00
|
|
441
|
+
|
|
442
|
+
1 runs, 1 assertions, 0 failures, 0 errors, 0 skips
|
|
443
|
+
EOM
|
|
444
|
+
|
|
445
|
+
assert_report expected, %w[--exclude /failure/ --seed 42]
|
|
446
|
+
end
|
|
447
|
+
|
|
448
|
+
def test_run_filtered_excluding_suite_name
|
|
449
|
+
expected = <<~EOM
|
|
450
|
+
.
|
|
451
|
+
|
|
452
|
+
Finished in 0.00
|
|
453
|
+
|
|
454
|
+
1 runs, 1 assertions, 0 failures, 0 errors, 0 skips
|
|
455
|
+
EOM
|
|
456
|
+
|
|
457
|
+
assert_filtering "exclude", "/Alpha#test_something/", expected
|
|
458
|
+
end
|
|
459
|
+
|
|
460
|
+
def test_run_filtered_excluding_suite_name_string
|
|
461
|
+
expected = <<~EOM
|
|
462
|
+
.
|
|
463
|
+
|
|
464
|
+
Finished in 0.00
|
|
465
|
+
|
|
466
|
+
1 runs, 1 assertions, 0 failures, 0 errors, 0 skips
|
|
467
|
+
EOM
|
|
468
|
+
|
|
469
|
+
assert_filtering "exclude", "Alpha#test_something", expected
|
|
470
|
+
end
|
|
471
|
+
|
|
472
|
+
def test_run_filtered_excluding_string_method_only
|
|
473
|
+
expected = <<~EOM
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
Finished in 0.00
|
|
477
|
+
|
|
478
|
+
0 runs, 0 assertions, 0 failures, 0 errors, 0 skips
|
|
479
|
+
EOM
|
|
480
|
+
|
|
481
|
+
assert_filtering "exclude", "test_something", expected, :pass
|
|
482
|
+
end
|
|
483
|
+
|
|
484
|
+
def test_run_passing
|
|
485
|
+
@tu = Class.new FakeNamedTest do
|
|
486
|
+
def test_something
|
|
487
|
+
assert true
|
|
488
|
+
end
|
|
489
|
+
end
|
|
490
|
+
|
|
491
|
+
expected = <<~EOM
|
|
492
|
+
.
|
|
493
|
+
|
|
494
|
+
Finished in 0.00
|
|
495
|
+
|
|
496
|
+
1 runs, 1 assertions, 0 failures, 0 errors, 0 skips
|
|
497
|
+
EOM
|
|
498
|
+
|
|
499
|
+
assert_report expected
|
|
500
|
+
end
|
|
501
|
+
|
|
502
|
+
def test_run_skip
|
|
503
|
+
@tu = Class.new FakeNamedTest do
|
|
504
|
+
def test_something
|
|
505
|
+
assert true
|
|
506
|
+
end
|
|
507
|
+
|
|
508
|
+
def test_skip
|
|
509
|
+
skip "not yet"
|
|
510
|
+
end
|
|
511
|
+
end
|
|
512
|
+
|
|
513
|
+
expected = <<~EOM
|
|
514
|
+
.S
|
|
515
|
+
|
|
516
|
+
Finished in 0.00
|
|
517
|
+
|
|
518
|
+
2 runs, 1 assertions, 0 failures, 0 errors, 1 skips
|
|
519
|
+
|
|
520
|
+
You have skipped tests. Run with --verbose for details.
|
|
521
|
+
EOM
|
|
522
|
+
|
|
523
|
+
restore_env do
|
|
524
|
+
assert_report expected
|
|
525
|
+
end
|
|
526
|
+
end
|
|
527
|
+
|
|
528
|
+
def test_run_skip_verbose
|
|
529
|
+
@tu = Class.new FakeNamedTest do
|
|
530
|
+
def test_something
|
|
531
|
+
assert true
|
|
532
|
+
end
|
|
533
|
+
|
|
534
|
+
def test_skip
|
|
535
|
+
skip "not yet"
|
|
536
|
+
end
|
|
537
|
+
end
|
|
538
|
+
|
|
539
|
+
expected = <<~EOM
|
|
540
|
+
FakeNamedTestXX#test_something = 0.00 s = .
|
|
541
|
+
FakeNamedTestXX#test_skip = 0.00 s = S
|
|
542
|
+
|
|
543
|
+
Finished in 0.00
|
|
544
|
+
|
|
545
|
+
1) Skipped:
|
|
546
|
+
FakeNamedTestXX#test_skip [FILE:LINE]:
|
|
547
|
+
not yet
|
|
548
|
+
|
|
549
|
+
2 runs, 1 assertions, 0 failures, 0 errors, 1 skips
|
|
550
|
+
EOM
|
|
551
|
+
|
|
552
|
+
assert_report expected, %w[--seed 42 --verbose]
|
|
553
|
+
end
|
|
554
|
+
|
|
555
|
+
def test_run_skip_show_skips
|
|
556
|
+
@tu = Class.new FakeNamedTest do
|
|
557
|
+
def test_something
|
|
558
|
+
assert true
|
|
559
|
+
end
|
|
560
|
+
|
|
561
|
+
def test_skip
|
|
562
|
+
skip "not yet"
|
|
563
|
+
end
|
|
564
|
+
end
|
|
565
|
+
|
|
566
|
+
expected = <<~EOM
|
|
567
|
+
.S
|
|
568
|
+
|
|
569
|
+
Finished in 0.00
|
|
570
|
+
|
|
571
|
+
1) Skipped:
|
|
572
|
+
FakeNamedTestXX#test_skip [FILE:LINE]:
|
|
573
|
+
not yet
|
|
574
|
+
|
|
575
|
+
2 runs, 1 assertions, 0 failures, 0 errors, 1 skips
|
|
576
|
+
EOM
|
|
577
|
+
|
|
578
|
+
assert_report expected, %w[--seed 42 --show-skips]
|
|
579
|
+
end
|
|
580
|
+
|
|
581
|
+
def test_run_with_other_runner
|
|
582
|
+
@tu = Class.new FakeNamedTest do
|
|
583
|
+
def self.run_suite reporter, options = {}
|
|
584
|
+
@reporter = reporter
|
|
585
|
+
before_my_suite
|
|
586
|
+
super
|
|
587
|
+
end
|
|
588
|
+
|
|
589
|
+
def self.name; "wacky!" end
|
|
590
|
+
|
|
591
|
+
def self.before_my_suite
|
|
592
|
+
@reporter.io.puts "Running #{self.name} tests"
|
|
593
|
+
@@foo = 1
|
|
594
|
+
end
|
|
595
|
+
|
|
596
|
+
def test_something
|
|
597
|
+
assert_equal 1, @@foo
|
|
598
|
+
end
|
|
599
|
+
|
|
600
|
+
def test_something_else
|
|
601
|
+
assert_equal 1, @@foo
|
|
602
|
+
end
|
|
603
|
+
end
|
|
604
|
+
|
|
605
|
+
expected = <<~EOM
|
|
606
|
+
Running wacky! tests
|
|
607
|
+
..
|
|
608
|
+
|
|
609
|
+
Finished in 0.00
|
|
610
|
+
|
|
611
|
+
2 runs, 2 assertions, 0 failures, 0 errors, 0 skips
|
|
612
|
+
EOM
|
|
613
|
+
|
|
614
|
+
assert_report expected
|
|
615
|
+
end
|
|
616
|
+
|
|
617
|
+
require "monitor"
|
|
618
|
+
|
|
619
|
+
class Latch
|
|
620
|
+
def initialize count = 1
|
|
621
|
+
@count = count
|
|
622
|
+
@lock = Monitor.new
|
|
623
|
+
@cv = @lock.new_cond
|
|
624
|
+
end
|
|
625
|
+
|
|
626
|
+
def release
|
|
627
|
+
@lock.synchronize do
|
|
628
|
+
@count -= 1 if @count > 0
|
|
629
|
+
@cv.broadcast if @count == 0
|
|
630
|
+
end
|
|
631
|
+
end
|
|
632
|
+
|
|
633
|
+
def await
|
|
634
|
+
@lock.synchronize { @cv.wait_while { @count > 0 } }
|
|
635
|
+
end
|
|
636
|
+
end
|
|
637
|
+
|
|
638
|
+
def test_run_parallel
|
|
639
|
+
test_count = 2
|
|
640
|
+
test_latch = Latch.new test_count
|
|
641
|
+
wait_latch = Latch.new test_count
|
|
642
|
+
main_latch = Latch.new
|
|
643
|
+
|
|
644
|
+
thread = Thread.new {
|
|
645
|
+
Thread.current.abort_on_exception = true
|
|
646
|
+
|
|
647
|
+
# This latch waits until both test latches have been released. Both
|
|
648
|
+
# latches can't be released unless done in separate threads because
|
|
649
|
+
# `main_latch` keeps the test method from finishing.
|
|
650
|
+
test_latch.await
|
|
651
|
+
main_latch.release
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
@tu = Class.new FakeNamedTest do
|
|
655
|
+
parallelize_me!
|
|
656
|
+
|
|
657
|
+
test_count.times do |i|
|
|
658
|
+
define_method :"test_wait_on_main_thread_#{i}" do
|
|
659
|
+
test_latch.release
|
|
660
|
+
|
|
661
|
+
# This latch blocks until the "main thread" releases it. The main
|
|
662
|
+
# thread can't release this latch until both test latches have
|
|
663
|
+
# been released. This forces the latches to be released in separate
|
|
664
|
+
# threads.
|
|
665
|
+
main_latch.await
|
|
666
|
+
assert true
|
|
667
|
+
end
|
|
668
|
+
end
|
|
669
|
+
end
|
|
670
|
+
|
|
671
|
+
expected = <<~EOM
|
|
672
|
+
..
|
|
673
|
+
|
|
674
|
+
Finished in 0.00
|
|
675
|
+
|
|
676
|
+
2 runs, 2 assertions, 0 failures, 0 errors, 0 skips
|
|
677
|
+
EOM
|
|
678
|
+
|
|
679
|
+
skip unless Minitest.parallel_executor # locks up test runner if 1 CPU
|
|
680
|
+
|
|
681
|
+
assert_report expected do |reporter|
|
|
682
|
+
reporter.extend Module.new {
|
|
683
|
+
define_method :record do |result|
|
|
684
|
+
super(result)
|
|
685
|
+
wait_latch.release
|
|
686
|
+
end
|
|
687
|
+
|
|
688
|
+
define_method :report do
|
|
689
|
+
wait_latch.await
|
|
690
|
+
super()
|
|
691
|
+
end
|
|
692
|
+
}
|
|
693
|
+
end
|
|
694
|
+
assert thread.join
|
|
695
|
+
end
|
|
696
|
+
end
|
|
697
|
+
|
|
698
|
+
class TestMinitestUnitOrder < MetaMetaMetaTestCase
|
|
699
|
+
# do not parallelize this suite... it just can't handle it.
|
|
700
|
+
|
|
701
|
+
def test_before_setup
|
|
702
|
+
call_order = []
|
|
703
|
+
|
|
704
|
+
@tu = Class.new FakeNamedTest do
|
|
705
|
+
define_method :setup do
|
|
706
|
+
super()
|
|
707
|
+
call_order << :setup
|
|
708
|
+
end
|
|
709
|
+
|
|
710
|
+
define_method :before_setup do
|
|
711
|
+
call_order << :before_setup
|
|
712
|
+
end
|
|
713
|
+
|
|
714
|
+
def test_omg; assert true; end
|
|
715
|
+
end
|
|
716
|
+
|
|
717
|
+
run_tu_with_fresh_reporter
|
|
718
|
+
|
|
719
|
+
expected = %i[before_setup setup]
|
|
720
|
+
assert_equal expected, call_order
|
|
721
|
+
end
|
|
722
|
+
|
|
723
|
+
def test_after_teardown
|
|
724
|
+
call_order = []
|
|
725
|
+
@tu = Class.new FakeNamedTest do
|
|
726
|
+
define_method :teardown do
|
|
727
|
+
super()
|
|
728
|
+
call_order << :teardown
|
|
729
|
+
end
|
|
730
|
+
|
|
731
|
+
define_method :after_teardown do
|
|
732
|
+
call_order << :after_teardown
|
|
733
|
+
end
|
|
734
|
+
|
|
735
|
+
def test_omg; assert true; end
|
|
736
|
+
end
|
|
737
|
+
|
|
738
|
+
run_tu_with_fresh_reporter
|
|
739
|
+
|
|
740
|
+
expected = %i[teardown after_teardown]
|
|
741
|
+
assert_equal expected, call_order
|
|
742
|
+
end
|
|
743
|
+
|
|
744
|
+
def test_all_teardowns_are_guaranteed_to_run
|
|
745
|
+
call_order = []
|
|
746
|
+
|
|
747
|
+
@tu = Class.new FakeNamedTest do
|
|
748
|
+
define_method :after_teardown do
|
|
749
|
+
super()
|
|
750
|
+
call_order << :after_teardown
|
|
751
|
+
raise
|
|
752
|
+
end
|
|
753
|
+
|
|
754
|
+
define_method :teardown do
|
|
755
|
+
super()
|
|
756
|
+
call_order << :teardown
|
|
757
|
+
raise
|
|
758
|
+
end
|
|
759
|
+
|
|
760
|
+
define_method :before_teardown do
|
|
761
|
+
super()
|
|
762
|
+
call_order << :before_teardown
|
|
763
|
+
raise
|
|
764
|
+
end
|
|
765
|
+
|
|
766
|
+
def test_omg; assert true; end
|
|
767
|
+
end
|
|
768
|
+
|
|
769
|
+
run_tu_with_fresh_reporter
|
|
770
|
+
|
|
771
|
+
expected = %i[before_teardown teardown after_teardown]
|
|
772
|
+
assert_equal expected, call_order
|
|
773
|
+
end
|
|
774
|
+
|
|
775
|
+
def test_setup_and_teardown_survive_inheritance
|
|
776
|
+
call_order = []
|
|
777
|
+
|
|
778
|
+
@tu = Class.new FakeNamedTest do
|
|
779
|
+
define_method :setup do
|
|
780
|
+
call_order << :setup_method
|
|
781
|
+
end
|
|
782
|
+
|
|
783
|
+
define_method :teardown do
|
|
784
|
+
call_order << :teardown_method
|
|
785
|
+
end
|
|
786
|
+
|
|
787
|
+
define_method :test_something do
|
|
788
|
+
call_order << :test
|
|
789
|
+
end
|
|
790
|
+
end
|
|
791
|
+
|
|
792
|
+
run_tu_with_fresh_reporter
|
|
793
|
+
|
|
794
|
+
@tu = Class.new @tu
|
|
795
|
+
run_tu_with_fresh_reporter
|
|
796
|
+
|
|
797
|
+
# Once for the parent class, once for the child
|
|
798
|
+
expected = %i[setup_method test teardown_method] * 2
|
|
799
|
+
|
|
800
|
+
assert_equal expected, call_order
|
|
801
|
+
end
|
|
802
|
+
end
|
|
803
|
+
|
|
804
|
+
class BetterError < RuntimeError # like better_error w/o infecting RuntimeError
|
|
805
|
+
def set_backtrace bt
|
|
806
|
+
super
|
|
807
|
+
@bad_ivar = binding
|
|
808
|
+
end
|
|
809
|
+
end
|
|
810
|
+
|
|
811
|
+
class TestMinitestRunnable < Minitest::Test
|
|
812
|
+
def test_spec_marshal
|
|
813
|
+
klass = describe("whatever") { it("passes") { assert true } }
|
|
814
|
+
rm = klass.runnable_methods.first
|
|
815
|
+
|
|
816
|
+
# Run the test
|
|
817
|
+
@tc = klass.new(rm).run
|
|
818
|
+
|
|
819
|
+
assert_kind_of Minitest::Result, @tc
|
|
820
|
+
|
|
821
|
+
# Pass it over the wire
|
|
822
|
+
over_the_wire = Marshal.load Marshal.dump @tc
|
|
823
|
+
|
|
824
|
+
assert_equal @tc.time, over_the_wire.time
|
|
825
|
+
assert_equal @tc.name, over_the_wire.name
|
|
826
|
+
assert_equal @tc.assertions, over_the_wire.assertions
|
|
827
|
+
assert_equal @tc.failures, over_the_wire.failures
|
|
828
|
+
assert_equal @tc.klass, over_the_wire.klass
|
|
829
|
+
end
|
|
830
|
+
|
|
831
|
+
def test_spec_marshal_with_exception
|
|
832
|
+
klass = describe("whatever") {
|
|
833
|
+
it("raises, badly") {
|
|
834
|
+
raise Class.new(StandardError), "this is bad!"
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
rm = klass.runnable_methods.first
|
|
839
|
+
|
|
840
|
+
# Run the test
|
|
841
|
+
@tc = klass.new(rm).run
|
|
842
|
+
|
|
843
|
+
assert_kind_of Minitest::Result, @tc
|
|
844
|
+
assert_instance_of Minitest::UnexpectedError, @tc.failure
|
|
845
|
+
|
|
846
|
+
msg = @tc.failure.error.message
|
|
847
|
+
assert_includes msg, "Neutered Exception #<Class:"
|
|
848
|
+
assert_includes msg, "this is bad!"
|
|
849
|
+
|
|
850
|
+
# Pass it over the wire
|
|
851
|
+
over_the_wire = Marshal.load Marshal.dump @tc
|
|
852
|
+
|
|
853
|
+
assert_equal @tc.time, over_the_wire.time
|
|
854
|
+
assert_equal @tc.name, over_the_wire.name
|
|
855
|
+
assert_equal @tc.assertions, over_the_wire.assertions
|
|
856
|
+
assert_equal @tc.failures, over_the_wire.failures
|
|
857
|
+
assert_equal @tc.klass, over_the_wire.klass
|
|
858
|
+
end
|
|
859
|
+
|
|
860
|
+
def test_spec_marshal_with_exception_nameerror
|
|
861
|
+
klass = describe "whatever" do
|
|
862
|
+
it "raises NameError" do
|
|
863
|
+
NOPE::does_not_exist
|
|
864
|
+
end
|
|
865
|
+
end
|
|
866
|
+
|
|
867
|
+
rm = klass.runnable_methods.first
|
|
868
|
+
|
|
869
|
+
# Run the test
|
|
870
|
+
@tc = klass.new(rm).run
|
|
871
|
+
|
|
872
|
+
assert_kind_of Minitest::Result, @tc
|
|
873
|
+
assert_instance_of Minitest::UnexpectedError, @tc.failure
|
|
874
|
+
|
|
875
|
+
msg = @tc.failure.error.message
|
|
876
|
+
assert_includes msg, "uninitialized constant TestMinitestRunnable::NOPE"
|
|
877
|
+
|
|
878
|
+
# Pass it over the wire
|
|
879
|
+
over_the_wire = Marshal.load Marshal.dump @tc
|
|
880
|
+
|
|
881
|
+
assert_equal @tc.time, over_the_wire.time
|
|
882
|
+
assert_equal @tc.name, over_the_wire.name
|
|
883
|
+
assert_equal @tc.assertions, over_the_wire.assertions
|
|
884
|
+
assert_equal @tc.failures, over_the_wire.failures
|
|
885
|
+
assert_equal @tc.klass, over_the_wire.klass
|
|
886
|
+
end
|
|
887
|
+
|
|
888
|
+
def with_runtime_error klass
|
|
889
|
+
old_runtime = RuntimeError
|
|
890
|
+
Object.send :remove_const, :RuntimeError
|
|
891
|
+
Object.const_set :RuntimeError, klass
|
|
892
|
+
yield
|
|
893
|
+
ensure
|
|
894
|
+
Object.send :remove_const, :RuntimeError
|
|
895
|
+
Object.const_set :RuntimeError, old_runtime
|
|
896
|
+
end
|
|
897
|
+
|
|
898
|
+
def test_spec_marshal_with_exception__better_error_typeerror
|
|
899
|
+
klass = describe("whatever") {
|
|
900
|
+
it("raises with binding") {
|
|
901
|
+
raise BetterError, "boom"
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
rm = klass.runnable_methods.first
|
|
906
|
+
|
|
907
|
+
# Run the test
|
|
908
|
+
@tc = with_runtime_error BetterError do
|
|
909
|
+
klass.new(rm).run
|
|
910
|
+
end
|
|
911
|
+
|
|
912
|
+
assert_kind_of Minitest::Result, @tc
|
|
913
|
+
assert_instance_of Minitest::UnexpectedError, @tc.failure
|
|
914
|
+
|
|
915
|
+
msg = @tc.failure.error.message
|
|
916
|
+
assert_equal "Neutered Exception BetterError: boom", msg
|
|
917
|
+
|
|
918
|
+
# Pass it over the wire
|
|
919
|
+
over_the_wire = Marshal.load Marshal.dump @tc
|
|
920
|
+
|
|
921
|
+
assert_equal @tc.time, over_the_wire.time
|
|
922
|
+
assert_equal @tc.name, over_the_wire.name
|
|
923
|
+
assert_equal @tc.assertions, over_the_wire.assertions
|
|
924
|
+
assert_equal @tc.failures, over_the_wire.failures
|
|
925
|
+
assert_equal @tc.klass, over_the_wire.klass
|
|
926
|
+
end
|
|
927
|
+
|
|
928
|
+
def test_spec_marshal_with_exception__worse_error_typeerror
|
|
929
|
+
worse_error_klass = Class.new StandardError do
|
|
930
|
+
# problem #1: anonymous subclass can't marshal, fails sanitize_exception
|
|
931
|
+
def initialize record = nil
|
|
932
|
+
super(record.first)
|
|
933
|
+
end
|
|
934
|
+
end
|
|
935
|
+
|
|
936
|
+
klass = describe("whatever") {
|
|
937
|
+
it("raises with NoMethodError") {
|
|
938
|
+
# problem #2: instantiated with a NON-string argument
|
|
939
|
+
#
|
|
940
|
+
# problem #3: arg responds to #first, but it becomes message
|
|
941
|
+
# which gets passed back in via new_exception
|
|
942
|
+
# that passes a string to worse_error_klass#initialize
|
|
943
|
+
# which calls first on it, which raises NoMethodError
|
|
944
|
+
raise worse_error_klass.new(["boom"])
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
rm = klass.runnable_methods.first
|
|
949
|
+
|
|
950
|
+
# Run the test
|
|
951
|
+
@tc = klass.new(rm).run
|
|
952
|
+
|
|
953
|
+
assert_kind_of Minitest::Result, @tc
|
|
954
|
+
assert_instance_of Minitest::UnexpectedError, @tc.failure
|
|
955
|
+
|
|
956
|
+
msg = @tc.failure.error.message.gsub(/0x[A-Fa-f0-9]+/, "0xXXX")
|
|
957
|
+
|
|
958
|
+
assert_equal "Neutered Exception #<Class:0xXXX>: boom", msg
|
|
959
|
+
|
|
960
|
+
# Pass it over the wire
|
|
961
|
+
over_the_wire = Marshal.load Marshal.dump @tc
|
|
962
|
+
|
|
963
|
+
assert_equal @tc.time, over_the_wire.time
|
|
964
|
+
assert_equal @tc.name, over_the_wire.name
|
|
965
|
+
assert_equal @tc.assertions, over_the_wire.assertions
|
|
966
|
+
assert_equal @tc.failures, over_the_wire.failures
|
|
967
|
+
assert_equal @tc.klass, over_the_wire.klass
|
|
968
|
+
end
|
|
969
|
+
end
|
|
970
|
+
|
|
971
|
+
class TestMinitestUnitTestCase < Minitest::Test
|
|
972
|
+
# do not call parallelize_me! - teardown accesses @tc._assertions
|
|
973
|
+
# which is not threadsafe. Nearly every method in here is an
|
|
974
|
+
# assertion test so it isn't worth splitting it out further.
|
|
975
|
+
|
|
976
|
+
def setup
|
|
977
|
+
super
|
|
978
|
+
|
|
979
|
+
Minitest::Test.reset
|
|
980
|
+
|
|
981
|
+
@tc = Minitest::Test.new "fake tc"
|
|
982
|
+
@zomg = "zomg ponies!"
|
|
983
|
+
@assertion_count = 1
|
|
984
|
+
end
|
|
985
|
+
|
|
986
|
+
def teardown
|
|
987
|
+
assert_equal(@assertion_count, @tc.assertions,
|
|
988
|
+
message { "expected #{@assertion_count} assertions to be fired during the test, not #{@tc.assertions}" }) if @tc.passed?
|
|
989
|
+
end
|
|
990
|
+
|
|
991
|
+
def non_verbose
|
|
992
|
+
orig_verbose = $VERBOSE
|
|
993
|
+
$VERBOSE = false
|
|
994
|
+
|
|
995
|
+
yield
|
|
996
|
+
ensure
|
|
997
|
+
$VERBOSE = orig_verbose
|
|
998
|
+
end
|
|
999
|
+
|
|
1000
|
+
def sample_test_case rand
|
|
1001
|
+
srand rand
|
|
1002
|
+
Class.new FakeNamedTest do
|
|
1003
|
+
100.times do |i|
|
|
1004
|
+
define_method("test_#{i}") { assert true }
|
|
1005
|
+
end
|
|
1006
|
+
end.runnable_methods
|
|
1007
|
+
end
|
|
1008
|
+
|
|
1009
|
+
# srand varies with OS
|
|
1010
|
+
def test_runnable_methods_random
|
|
1011
|
+
@assertion_count = 0
|
|
1012
|
+
|
|
1013
|
+
random_tests_1 = sample_test_case 42
|
|
1014
|
+
random_tests_2 = sample_test_case 42
|
|
1015
|
+
random_tests_3 = sample_test_case 1_000
|
|
1016
|
+
|
|
1017
|
+
assert_equal random_tests_1, random_tests_2
|
|
1018
|
+
assert_equal random_tests_1, random_tests_3
|
|
1019
|
+
end
|
|
1020
|
+
|
|
1021
|
+
def test_runnable_methods_sorted
|
|
1022
|
+
@assertion_count = 0
|
|
1023
|
+
|
|
1024
|
+
sample_test_case = Class.new FakeNamedTest do
|
|
1025
|
+
def self.run_order; :sorted end
|
|
1026
|
+
def test_test3; assert "does not matter" end
|
|
1027
|
+
def test_test2; assert "does not matter" end
|
|
1028
|
+
def test_test1; assert "does not matter" end
|
|
1029
|
+
end
|
|
1030
|
+
|
|
1031
|
+
expected = %w[test_test1 test_test2 test_test3]
|
|
1032
|
+
assert_equal expected, sample_test_case.runnable_methods
|
|
1033
|
+
end
|
|
1034
|
+
|
|
1035
|
+
def test_i_suck_and_my_tests_are_order_dependent_bang_sets_run_order_alpha
|
|
1036
|
+
@assertion_count = 0
|
|
1037
|
+
|
|
1038
|
+
shitty_test_case = Class.new FakeNamedTest
|
|
1039
|
+
|
|
1040
|
+
shitty_test_case.i_suck_and_my_tests_are_order_dependent!
|
|
1041
|
+
|
|
1042
|
+
assert_equal :alpha, shitty_test_case.run_order
|
|
1043
|
+
end
|
|
1044
|
+
|
|
1045
|
+
def test_i_suck_and_my_tests_are_order_dependent_bang_does_not_warn
|
|
1046
|
+
@assertion_count = 0
|
|
1047
|
+
|
|
1048
|
+
shitty_test_case = Class.new FakeNamedTest
|
|
1049
|
+
|
|
1050
|
+
def shitty_test_case.run_order; :lol end
|
|
1051
|
+
|
|
1052
|
+
assert_silent do
|
|
1053
|
+
shitty_test_case.i_suck_and_my_tests_are_order_dependent!
|
|
1054
|
+
end
|
|
1055
|
+
end
|
|
1056
|
+
|
|
1057
|
+
def test_autorun_does_not_affect_fork_success_status
|
|
1058
|
+
@assertion_count = 0
|
|
1059
|
+
skip "windows doesn't have fork" unless Process.respond_to? :fork
|
|
1060
|
+
Process.waitpid(fork {})
|
|
1061
|
+
assert_equal true, $?.success?
|
|
1062
|
+
end
|
|
1063
|
+
|
|
1064
|
+
def test_autorun_does_not_affect_fork_exit_status
|
|
1065
|
+
@assertion_count = 0
|
|
1066
|
+
skip "windows doesn't have fork" unless Process.respond_to? :fork
|
|
1067
|
+
Process.waitpid(fork { exit 42 })
|
|
1068
|
+
assert_equal 42, $?.exitstatus
|
|
1069
|
+
end
|
|
1070
|
+
|
|
1071
|
+
def test_autorun_optionally_can_affect_fork_exit_status
|
|
1072
|
+
@assertion_count = 0
|
|
1073
|
+
skip "windows doesn't have fork" unless Process.respond_to? :fork
|
|
1074
|
+
Minitest.allow_fork = true
|
|
1075
|
+
Process.waitpid(fork { exit 42 })
|
|
1076
|
+
refute_equal 42, $?.exitstatus
|
|
1077
|
+
ensure
|
|
1078
|
+
Minitest.allow_fork = false
|
|
1079
|
+
end
|
|
1080
|
+
end
|
|
1081
|
+
|
|
1082
|
+
class TestMinitestGuard < Minitest::Test
|
|
1083
|
+
parallelize_me!
|
|
1084
|
+
|
|
1085
|
+
def test_mri_eh
|
|
1086
|
+
assert self.class.mri? "ruby blah"
|
|
1087
|
+
assert self.mri? "ruby blah"
|
|
1088
|
+
end
|
|
1089
|
+
|
|
1090
|
+
def test_jruby_eh
|
|
1091
|
+
assert self.class.jruby? "java"
|
|
1092
|
+
assert self.jruby? "java"
|
|
1093
|
+
end
|
|
1094
|
+
|
|
1095
|
+
def test_osx_eh
|
|
1096
|
+
assert self.class.osx? "darwin"
|
|
1097
|
+
assert self.osx? "darwin"
|
|
1098
|
+
end
|
|
1099
|
+
|
|
1100
|
+
def test_windows_eh
|
|
1101
|
+
assert self.class.windows? "mswin"
|
|
1102
|
+
assert self.windows? "mswin"
|
|
1103
|
+
end
|
|
1104
|
+
end
|
|
1105
|
+
|
|
1106
|
+
class TestMinitestUnitRecording < MetaMetaMetaTestCase
|
|
1107
|
+
# do not parallelize this suite... it just can't handle it.
|
|
1108
|
+
|
|
1109
|
+
def assert_run_record *expected, &block
|
|
1110
|
+
@tu = Class.new FakeNamedTest, &block
|
|
1111
|
+
|
|
1112
|
+
run_tu_with_fresh_reporter
|
|
1113
|
+
|
|
1114
|
+
recorded = first_reporter.results.map(&:failures).flatten.map { |f| f.error.class }
|
|
1115
|
+
|
|
1116
|
+
assert_equal expected, recorded
|
|
1117
|
+
end
|
|
1118
|
+
|
|
1119
|
+
def test_record_passing
|
|
1120
|
+
assert_run_record do
|
|
1121
|
+
def test_method
|
|
1122
|
+
assert true
|
|
1123
|
+
end
|
|
1124
|
+
end
|
|
1125
|
+
end
|
|
1126
|
+
|
|
1127
|
+
def test_record_failing
|
|
1128
|
+
assert_run_record Minitest::Assertion do
|
|
1129
|
+
def test_method
|
|
1130
|
+
assert false
|
|
1131
|
+
end
|
|
1132
|
+
end
|
|
1133
|
+
end
|
|
1134
|
+
|
|
1135
|
+
def test_record_error
|
|
1136
|
+
assert_run_record RuntimeError do
|
|
1137
|
+
def test_method
|
|
1138
|
+
raise "unhandled exception"
|
|
1139
|
+
end
|
|
1140
|
+
end
|
|
1141
|
+
end
|
|
1142
|
+
|
|
1143
|
+
def test_record_error_teardown
|
|
1144
|
+
assert_run_record RuntimeError do
|
|
1145
|
+
def test_method
|
|
1146
|
+
assert true
|
|
1147
|
+
end
|
|
1148
|
+
|
|
1149
|
+
def teardown
|
|
1150
|
+
raise "unhandled exception"
|
|
1151
|
+
end
|
|
1152
|
+
end
|
|
1153
|
+
end
|
|
1154
|
+
|
|
1155
|
+
def test_record_error_in_test_and_teardown
|
|
1156
|
+
assert_run_record AnError, RuntimeError do
|
|
1157
|
+
def test_method
|
|
1158
|
+
raise AnError
|
|
1159
|
+
end
|
|
1160
|
+
|
|
1161
|
+
def teardown
|
|
1162
|
+
raise "unhandled exception"
|
|
1163
|
+
end
|
|
1164
|
+
end
|
|
1165
|
+
end
|
|
1166
|
+
|
|
1167
|
+
def test_to_s_error_in_test_and_teardown
|
|
1168
|
+
@tu = Class.new FakeNamedTest do
|
|
1169
|
+
def test_method
|
|
1170
|
+
raise AnError
|
|
1171
|
+
end
|
|
1172
|
+
|
|
1173
|
+
def teardown
|
|
1174
|
+
raise "unhandled exception"
|
|
1175
|
+
end
|
|
1176
|
+
end
|
|
1177
|
+
|
|
1178
|
+
run_tu_with_fresh_reporter
|
|
1179
|
+
|
|
1180
|
+
exp = <<~EOM
|
|
1181
|
+
Error:
|
|
1182
|
+
FakeNamedTestXX#test_method:
|
|
1183
|
+
AnError: AnError
|
|
1184
|
+
FILE:LINE:in 'test_method'
|
|
1185
|
+
|
|
1186
|
+
Error:
|
|
1187
|
+
FakeNamedTestXX#test_method:
|
|
1188
|
+
RuntimeError: unhandled exception
|
|
1189
|
+
FILE:LINE:in 'teardown'
|
|
1190
|
+
EOM
|
|
1191
|
+
|
|
1192
|
+
assert_equal exp.strip, normalize_output(first_reporter.results.first.to_s).strip
|
|
1193
|
+
end
|
|
1194
|
+
|
|
1195
|
+
def test_record_skip
|
|
1196
|
+
assert_run_record Minitest::Skip do
|
|
1197
|
+
def test_method
|
|
1198
|
+
skip "not yet"
|
|
1199
|
+
end
|
|
1200
|
+
end
|
|
1201
|
+
end
|
|
1202
|
+
end
|
|
1203
|
+
|
|
1204
|
+
class TestUnexpectedError < Minitest::Test
|
|
1205
|
+
def assert_compress exp, input
|
|
1206
|
+
e = Minitest::UnexpectedError.new RuntimeError.new
|
|
1207
|
+
|
|
1208
|
+
exp = exp.lines.map(&:chomp) if String === exp
|
|
1209
|
+
act = e.compress input
|
|
1210
|
+
|
|
1211
|
+
assert_equal exp, act
|
|
1212
|
+
end
|
|
1213
|
+
|
|
1214
|
+
ACT1 = %w[ a b c b c b c b c d ]
|
|
1215
|
+
|
|
1216
|
+
def test_normal
|
|
1217
|
+
assert_compress <<~EXP, %w[ a b c b c b c b c d ]
|
|
1218
|
+
a
|
|
1219
|
+
+->> 4 cycles of 2 lines:
|
|
1220
|
+
| b
|
|
1221
|
+
| c
|
|
1222
|
+
+-<<
|
|
1223
|
+
d
|
|
1224
|
+
EXP
|
|
1225
|
+
end
|
|
1226
|
+
|
|
1227
|
+
def test_normal2
|
|
1228
|
+
assert_compress <<~EXP, %w[ a b c b c b c b c ]
|
|
1229
|
+
a
|
|
1230
|
+
+->> 4 cycles of 2 lines:
|
|
1231
|
+
| b
|
|
1232
|
+
| c
|
|
1233
|
+
+-<<
|
|
1234
|
+
EXP
|
|
1235
|
+
end
|
|
1236
|
+
|
|
1237
|
+
def test_longer_c_than_b
|
|
1238
|
+
# the extra c in the front makes the overall length longer sorting it first
|
|
1239
|
+
assert_compress <<~EXP, %w[ c a b c b c b c b c b d ]
|
|
1240
|
+
c
|
|
1241
|
+
a
|
|
1242
|
+
b
|
|
1243
|
+
+->> 4 cycles of 2 lines:
|
|
1244
|
+
| c
|
|
1245
|
+
| b
|
|
1246
|
+
+-<<
|
|
1247
|
+
d
|
|
1248
|
+
EXP
|
|
1249
|
+
end
|
|
1250
|
+
|
|
1251
|
+
def test_1_line_cycles
|
|
1252
|
+
assert_compress <<~EXP, %w[ c a b c b c b c b c b b b d ]
|
|
1253
|
+
c
|
|
1254
|
+
a
|
|
1255
|
+
+->> 4 cycles of 2 lines:
|
|
1256
|
+
| b
|
|
1257
|
+
| c
|
|
1258
|
+
+-<<
|
|
1259
|
+
+->> 3 cycles of 1 lines:
|
|
1260
|
+
| b
|
|
1261
|
+
+-<<
|
|
1262
|
+
d
|
|
1263
|
+
EXP
|
|
1264
|
+
end
|
|
1265
|
+
|
|
1266
|
+
def test_sanity3
|
|
1267
|
+
pre = ("aa".."am").to_a
|
|
1268
|
+
mid = ("a".."z").to_a * 67
|
|
1269
|
+
post = ("aa".."am").to_a
|
|
1270
|
+
ary = pre + mid + post
|
|
1271
|
+
|
|
1272
|
+
exp = pre +
|
|
1273
|
+
[" +->> 67 cycles of 26 lines:"] +
|
|
1274
|
+
("a".."z").map { |s| " | #{s}" } +
|
|
1275
|
+
[" +-<<"] +
|
|
1276
|
+
post
|
|
1277
|
+
|
|
1278
|
+
assert_compress exp, ary
|
|
1279
|
+
end
|
|
1280
|
+
|
|
1281
|
+
def test_absurd_patterns
|
|
1282
|
+
assert_compress <<~EXP, %w[ a b c b c a b c b c a b c ]
|
|
1283
|
+
+->> 2 cycles of 5 lines:
|
|
1284
|
+
| a
|
|
1285
|
+
| +->> 2 cycles of 2 lines:
|
|
1286
|
+
| | b
|
|
1287
|
+
| | c
|
|
1288
|
+
| +-<<
|
|
1289
|
+
+-<<
|
|
1290
|
+
a
|
|
1291
|
+
b
|
|
1292
|
+
c
|
|
1293
|
+
EXP
|
|
1294
|
+
end
|
|
1295
|
+
end
|