minitap 0.5.3 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/HISTORY.md +41 -0
- data/README.md +82 -80
- data/demo/01_tapy.md +100 -0
- data/demo/02_tapj.md +32 -0
- data/demo/03_spec.md +45 -0
- data/demo/04_helper.md +109 -0
- data/demo/05_details.md +127 -0
- data/demo/06_tapout.md +44 -0
- data/demo/applique/ae.rb +1 -0
- data/demo/applique/run.rb +48 -0
- data/lib/minitap/autorun.rb +4 -5
- data/lib/minitap/reporter.rb +294 -0
- data/lib/minitap/version.rb +3 -0
- data/lib/minitap.rb +87 -7
- data/lib/minitest/minitap_plugin.rb +11 -31
- metadata +70 -58
- data/.index +0 -66
- data/DEMO.md +0 -95
- data/lib/minitap/ignore_callers.rb +0 -5
- data/lib/minitap/minitest5.rb +0 -885
data/lib/minitap/minitest5.rb
DELETED
|
@@ -1,885 +0,0 @@
|
|
|
1
|
-
# MiniTest adaptor for tapout.
|
|
2
|
-
|
|
3
|
-
# Have to make sure the latest version of minitest is used.
|
|
4
|
-
begin; gem 'minitest'; rescue; end
|
|
5
|
-
|
|
6
|
-
#require 'minitest/unit'
|
|
7
|
-
require 'minitap/ignore_callers'
|
|
8
|
-
require 'stringio'
|
|
9
|
-
|
|
10
|
-
# Becuase of some wierdness in MiniTest
|
|
11
|
-
#debug, $DEBUG = $DEBUG, false
|
|
12
|
-
#require 'minitest/unit'
|
|
13
|
-
#$DEBUG = debug
|
|
14
|
-
|
|
15
|
-
module Minitest
|
|
16
|
-
|
|
17
|
-
##
|
|
18
|
-
# Base class for TapY and TapJ runners.
|
|
19
|
-
#
|
|
20
|
-
class Minitap < StatisticsReporter #Reporter
|
|
21
|
-
|
|
22
|
-
# TAP-Y/J Revision
|
|
23
|
-
REVISION = 4
|
|
24
|
-
|
|
25
|
-
# Backtrace patterns to be omitted.
|
|
26
|
-
IGNORE_CALLERS = $RUBY_IGNORE_CALLERS
|
|
27
|
-
|
|
28
|
-
# Test results.
|
|
29
|
-
#attr_reader :test_results
|
|
30
|
-
|
|
31
|
-
attr_reader :test_cases
|
|
32
|
-
attr_reader :test_count
|
|
33
|
-
|
|
34
|
-
attr_accessor :suite_start_time
|
|
35
|
-
attr_accessor :case_start_time
|
|
36
|
-
attr_accessor :test_start_time
|
|
37
|
-
|
|
38
|
-
# Initialize new Minitap Minitest reporter.
|
|
39
|
-
def initialize(options = {})
|
|
40
|
-
io = options.delete(:io) || $stdout
|
|
41
|
-
|
|
42
|
-
super(io, options)
|
|
43
|
-
|
|
44
|
-
# since tapout uses a unix pipe, we don't want any buffering
|
|
45
|
-
io.sync = true
|
|
46
|
-
|
|
47
|
-
#@_stdout = StringIO.new
|
|
48
|
-
#@_stderr = StringIO.new
|
|
49
|
-
|
|
50
|
-
#@test_results = {}
|
|
51
|
-
#self.assertion_count = 0
|
|
52
|
-
|
|
53
|
-
@_source_cache = {}
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
#
|
|
57
|
-
# Minitest's initial hook ran just before testing begins.
|
|
58
|
-
#
|
|
59
|
-
def start
|
|
60
|
-
super
|
|
61
|
-
|
|
62
|
-
@test_cases = Runnable.runnables
|
|
63
|
-
|
|
64
|
-
capture_io
|
|
65
|
-
|
|
66
|
-
#@_stdout, @_stderr = capture_io do
|
|
67
|
-
# super_result = super(suite, type)
|
|
68
|
-
#end
|
|
69
|
-
|
|
70
|
-
before_suite(@test_cases)
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
#
|
|
74
|
-
# Process a test result.
|
|
75
|
-
#
|
|
76
|
-
def record(minitest_result)
|
|
77
|
-
super(minitest_result)
|
|
78
|
-
|
|
79
|
-
result = TestResult.new(minitest_result)
|
|
80
|
-
|
|
81
|
-
#if exception #&& ENV['minitap_debug']
|
|
82
|
-
# STDERR.puts exception
|
|
83
|
-
# STDERR.puts exception.backtrace.join("\n")
|
|
84
|
-
#end
|
|
85
|
-
|
|
86
|
-
#@test_results[suite] ||= {}
|
|
87
|
-
#@test_results[suite][test.to_sym] = record
|
|
88
|
-
|
|
89
|
-
case_change = false
|
|
90
|
-
|
|
91
|
-
if @previous_case != result.test_case
|
|
92
|
-
case_change = true
|
|
93
|
-
before_case(result.test_case)
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
#before_test(result)
|
|
97
|
-
case result.type
|
|
98
|
-
when :skip
|
|
99
|
-
test_skip(result)
|
|
100
|
-
when :pass
|
|
101
|
-
test_pass(result)
|
|
102
|
-
when :fail
|
|
103
|
-
test_fail(result)
|
|
104
|
-
when :err
|
|
105
|
-
test_err(result)
|
|
106
|
-
end
|
|
107
|
-
after_test(result)
|
|
108
|
-
|
|
109
|
-
if case_change
|
|
110
|
-
after_case(result.test_case)
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
@previous_case = result.test_case
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
#
|
|
117
|
-
# Minitest's finalization hook.
|
|
118
|
-
#
|
|
119
|
-
def report
|
|
120
|
-
super
|
|
121
|
-
|
|
122
|
-
uncapture_io
|
|
123
|
-
|
|
124
|
-
after_suite()
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
#
|
|
128
|
-
# Intermediary Callbacks
|
|
129
|
-
#
|
|
130
|
-
|
|
131
|
-
#
|
|
132
|
-
def before_suite(test_cases)
|
|
133
|
-
@suite_start_time = Time.now
|
|
134
|
-
count_tests!(test_cases)
|
|
135
|
-
tapout_before_suite()
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
def after_suite() #(test_cases)
|
|
139
|
-
tapout_after_suite()
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
def before_case(test_case)
|
|
143
|
-
@case_start_time = Time.now
|
|
144
|
-
tapout_before_case(test_case)
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
def after_case(test_case)
|
|
148
|
-
tapout_after_case(test_case)
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
def before_test(result)
|
|
152
|
-
@test_start_time = Time.now
|
|
153
|
-
tapout_before_test(result)
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
def after_test(result)
|
|
157
|
-
tapout_after_test(result)
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
def test_skip(result)
|
|
161
|
-
tapout_test_skip(result)
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
def test_pass(result)
|
|
165
|
-
tapout_test_pass(result)
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
def test_fail(result)
|
|
169
|
-
tapout_test_failure(result)
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
def test_err(result)
|
|
173
|
-
tapout_test_error(result)
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
=begin
|
|
177
|
-
def _run_suites(suites, type)
|
|
178
|
-
#output.puts "# Run options: #{@help}"
|
|
179
|
-
|
|
180
|
-
@suites_start_time = Time.now
|
|
181
|
-
count_tests!(suites, type)
|
|
182
|
-
trigger_callback(:before_suites, suites, type)
|
|
183
|
-
super(suites, type)
|
|
184
|
-
ensure
|
|
185
|
-
trigger_callback(:after_suites, suites, type)
|
|
186
|
-
end
|
|
187
|
-
|
|
188
|
-
def _run_suite(suite, type)
|
|
189
|
-
# The only reason this is here is b/c MiniTest wil try to run
|
|
190
|
-
# base classes like `MiniTest::Spec`. So to prevent that,
|
|
191
|
-
# if there are no tests to run, we don't bother to process
|
|
192
|
-
# the "suite" at all.
|
|
193
|
-
@_suite_tests = suite.send("#{type}_methods")
|
|
194
|
-
return [0,0] if @_suite_tests.empty?
|
|
195
|
-
|
|
196
|
-
begin
|
|
197
|
-
@suite_start_time = Time.now
|
|
198
|
-
trigger_callback(:before_suite, suite)
|
|
199
|
-
|
|
200
|
-
super_result = nil
|
|
201
|
-
@_stdout, @_stderr = capture_io do
|
|
202
|
-
super_result = super(suite, type)
|
|
203
|
-
end
|
|
204
|
-
super_result
|
|
205
|
-
ensure
|
|
206
|
-
trigger_callback(:after_suite, suite)
|
|
207
|
-
end
|
|
208
|
-
end
|
|
209
|
-
|
|
210
|
-
def before_test(suite, test)
|
|
211
|
-
@test_start_time = Time.now
|
|
212
|
-
trigger_callback(:before_test, suite, test)
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
def after_test(suite, test)
|
|
216
|
-
#runners = @test_recorder[suite, test.to_sym]
|
|
217
|
-
#records = @test_results[suite][test.to_sym]
|
|
218
|
-
record = @test_results[suite][test.to_sym]
|
|
219
|
-
|
|
220
|
-
#records.each do |record|
|
|
221
|
-
# trigger_callback(record.result, suite, test.to_sym, record)
|
|
222
|
-
#end
|
|
223
|
-
|
|
224
|
-
trigger_callback(record.result, suite, test.to_sym, record)
|
|
225
|
-
|
|
226
|
-
#trigger_callback(:after_test, suite, test.to_sym)
|
|
227
|
-
end
|
|
228
|
-
=end
|
|
229
|
-
|
|
230
|
-
# Stub out the three IO methods used by the built-in reporter.
|
|
231
|
-
def p(*args)
|
|
232
|
-
args.each{ |a| io.print(a.inspect); puts }
|
|
233
|
-
end
|
|
234
|
-
|
|
235
|
-
def puts(*args)
|
|
236
|
-
io.puts(*args)
|
|
237
|
-
end
|
|
238
|
-
|
|
239
|
-
def print(*args)
|
|
240
|
-
io.print(*args)
|
|
241
|
-
end
|
|
242
|
-
|
|
243
|
-
#def status(io = output); end
|
|
244
|
-
|
|
245
|
-
private
|
|
246
|
-
|
|
247
|
-
#
|
|
248
|
-
def filtered_tests(test_case) #suite, type
|
|
249
|
-
filter = options[:filter] || '/./'
|
|
250
|
-
filter = Regexp.new($1) if filter =~ /\/(.*)\//
|
|
251
|
-
test_case.runnable_methods.grep(filter)
|
|
252
|
-
end
|
|
253
|
-
|
|
254
|
-
=begin
|
|
255
|
-
#
|
|
256
|
-
def add_test_result(suite, test, test_runner)
|
|
257
|
-
self.report[suite] ||= {}
|
|
258
|
-
self.report[suite][test.to_sym] = test_runner
|
|
259
|
-
|
|
260
|
-
self.assertion_count += test_runner.assertions
|
|
261
|
-
|
|
262
|
-
case test_runner.result
|
|
263
|
-
when :skip then self.skips += 1
|
|
264
|
-
when :failure then self.failures += 1
|
|
265
|
-
when :error then self.errors += 1
|
|
266
|
-
end
|
|
267
|
-
end
|
|
268
|
-
=end
|
|
269
|
-
|
|
270
|
-
def count_tests!(test_cases)
|
|
271
|
-
filter = options[:filter] || '/./'
|
|
272
|
-
filter = Regexp.new $1 if filter =~ /\/(.*)\//
|
|
273
|
-
|
|
274
|
-
@test_count = test_cases.inject(0) do |acc, test_case|
|
|
275
|
-
acc + test_case.runnable_methods.grep(filter).length
|
|
276
|
-
end
|
|
277
|
-
end
|
|
278
|
-
|
|
279
|
-
#
|
|
280
|
-
# Tapout Records
|
|
281
|
-
#
|
|
282
|
-
|
|
283
|
-
#
|
|
284
|
-
def tapout_before_suite()
|
|
285
|
-
doc = {
|
|
286
|
-
'type' => 'suite',
|
|
287
|
-
'start' => self.suite_start_time.strftime('%Y-%m-%d %H:%M:%S'),
|
|
288
|
-
'count' => self.test_count,
|
|
289
|
-
'seed' => self.options[:seed],
|
|
290
|
-
'rev' => REVISION
|
|
291
|
-
}
|
|
292
|
-
return doc
|
|
293
|
-
end
|
|
294
|
-
|
|
295
|
-
#
|
|
296
|
-
def tapout_after_suite()
|
|
297
|
-
doc = {
|
|
298
|
-
'type' => 'final',
|
|
299
|
-
'time' => Time.now - self.suite_start_time,
|
|
300
|
-
'counts' => {
|
|
301
|
-
'total' => self.test_count,
|
|
302
|
-
'pass' => self.test_count - self.failures - self.errors - self.skips,
|
|
303
|
-
'fail' => self.failures,
|
|
304
|
-
'error' => self.errors,
|
|
305
|
-
'omit' => self.skips,
|
|
306
|
-
'todo' => 0 # TODO: does minitest support pending tests?
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
return doc
|
|
310
|
-
end
|
|
311
|
-
|
|
312
|
-
#
|
|
313
|
-
def tapout_before_case(test_case)
|
|
314
|
-
doc = {
|
|
315
|
-
'type' => 'case',
|
|
316
|
-
'subtype' => '',
|
|
317
|
-
'label' => "#{test_case}",
|
|
318
|
-
'level' => 0
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
record_stdcom(doc)
|
|
322
|
-
|
|
323
|
-
return doc
|
|
324
|
-
end
|
|
325
|
-
|
|
326
|
-
#
|
|
327
|
-
def tapout_after_case(test_case)
|
|
328
|
-
end
|
|
329
|
-
|
|
330
|
-
#
|
|
331
|
-
def tapout_before_test(result)
|
|
332
|
-
end
|
|
333
|
-
|
|
334
|
-
#
|
|
335
|
-
def tapout_after_test(result)
|
|
336
|
-
end
|
|
337
|
-
|
|
338
|
-
# TAP record for pass.
|
|
339
|
-
#
|
|
340
|
-
# Returns [Hash].
|
|
341
|
-
def tapout_test_pass(result) #suite, test, test_runner
|
|
342
|
-
doc = {
|
|
343
|
-
'type' => 'test',
|
|
344
|
-
'subtype' => '',
|
|
345
|
-
'status' => 'pass',
|
|
346
|
-
#'setup': foo instance
|
|
347
|
-
'label' => "#{result.label}",
|
|
348
|
-
#'expected' => 2
|
|
349
|
-
#'returned' => 2
|
|
350
|
-
#'file' => 'test/test_foo.rb'
|
|
351
|
-
#'line': 45
|
|
352
|
-
#'source': ok 1, 2
|
|
353
|
-
#'snippet':
|
|
354
|
-
# - 44: ok 0,0
|
|
355
|
-
# - 45: ok 1,2
|
|
356
|
-
# - 46: ok 2,4
|
|
357
|
-
#'coverage':
|
|
358
|
-
# file: lib/foo.rb
|
|
359
|
-
# line: 11..13
|
|
360
|
-
# code: Foo#*
|
|
361
|
-
'time' => Time.now - self.suite_start_time
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
record_stdcom(doc)
|
|
365
|
-
|
|
366
|
-
#stdout, stderr = @_stdout, @_stderr
|
|
367
|
-
#doc['stdout'] = stdout unless stdout.empty?
|
|
368
|
-
#doc['stderr'] = stderr unless stderr.empty?
|
|
369
|
-
|
|
370
|
-
return doc
|
|
371
|
-
end
|
|
372
|
-
|
|
373
|
-
# TAP record for skip.
|
|
374
|
-
#
|
|
375
|
-
# Returns [Hash].
|
|
376
|
-
def tapout_test_skip(result) #suite, test, test_runner
|
|
377
|
-
e = result.exception
|
|
378
|
-
e_file, e_line = location(result.exception)
|
|
379
|
-
r_file = e_file.sub(Dir.pwd+'/', '')
|
|
380
|
-
|
|
381
|
-
doc = {
|
|
382
|
-
'type' => 'test',
|
|
383
|
-
'subtype' => '',
|
|
384
|
-
'status' => 'skip',
|
|
385
|
-
'label' => "#{result.label}",
|
|
386
|
-
#'setup' => "foo instance",
|
|
387
|
-
#'expected' => 2,
|
|
388
|
-
#'returned' => 1,
|
|
389
|
-
#'file' => test/test_foo.rb
|
|
390
|
-
#'line' => 45
|
|
391
|
-
#'source' => ok 1, 2
|
|
392
|
-
#'snippet' =>
|
|
393
|
-
# - 44: ok 0,0
|
|
394
|
-
# - 45: ok 1,2
|
|
395
|
-
# - 46: ok 2,4
|
|
396
|
-
#'coverage' =>
|
|
397
|
-
# 'file' => lib/foo.rb
|
|
398
|
-
# 'line' => 11..13
|
|
399
|
-
# 'code' => Foo#*
|
|
400
|
-
'exception' => {
|
|
401
|
-
'message' => clean_message(e.message),
|
|
402
|
-
'class' => e.class.name,
|
|
403
|
-
'file' => r_file,
|
|
404
|
-
'line' => e_line,
|
|
405
|
-
'source' => source(e_file)[e_line-1].strip,
|
|
406
|
-
'snippet' => code_snippet(e_file, e_line),
|
|
407
|
-
'backtrace' => filter_backtrace(e.backtrace)
|
|
408
|
-
},
|
|
409
|
-
'time' => Time.now - self.suite_start_time
|
|
410
|
-
}
|
|
411
|
-
return doc
|
|
412
|
-
end
|
|
413
|
-
|
|
414
|
-
# TAP record for failure.
|
|
415
|
-
#
|
|
416
|
-
# Returns [Hash].
|
|
417
|
-
def tapout_test_failure(result)
|
|
418
|
-
e = result.exception
|
|
419
|
-
e_file, e_line = location(result.exception)
|
|
420
|
-
r_file = e_file.sub(Dir.pwd+'/', '')
|
|
421
|
-
|
|
422
|
-
doc = {
|
|
423
|
-
'type' => 'test',
|
|
424
|
-
'subtype' => '',
|
|
425
|
-
'status' => 'fail',
|
|
426
|
-
'label' => "#{result.label}",
|
|
427
|
-
#'setup' => "foo instance",
|
|
428
|
-
#'expected' => 2,
|
|
429
|
-
#'returned' => 1,
|
|
430
|
-
#'file' => test/test_foo.rb
|
|
431
|
-
#'line' => 45
|
|
432
|
-
#'source' => ok 1, 2
|
|
433
|
-
#'snippet' =>
|
|
434
|
-
# - 44: ok 0,0
|
|
435
|
-
# - 45: ok 1,2
|
|
436
|
-
# - 46: ok 2,4
|
|
437
|
-
#'coverage' =>
|
|
438
|
-
# 'file' => lib/foo.rb
|
|
439
|
-
# 'line' => 11..13
|
|
440
|
-
# 'code' => Foo#*
|
|
441
|
-
'exception' => {
|
|
442
|
-
'message' => clean_message(e.message),
|
|
443
|
-
'class' => e.class.name,
|
|
444
|
-
'file' => r_file,
|
|
445
|
-
'line' => e_line,
|
|
446
|
-
'source' => source(e_file)[e_line-1].strip,
|
|
447
|
-
'snippet' => code_snippet(e_file, e_line),
|
|
448
|
-
'backtrace' => filter_backtrace(e.backtrace)
|
|
449
|
-
},
|
|
450
|
-
'time' => Time.now - self.suite_start_time # result.time
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
record_stdcom(doc)
|
|
454
|
-
|
|
455
|
-
#stdout, stderr = @_stdout, @_stderr
|
|
456
|
-
#doc['stdout'] = stdout unless stdout.empty?
|
|
457
|
-
#doc['stderr'] = stderr unless stderr.empty?
|
|
458
|
-
|
|
459
|
-
return doc
|
|
460
|
-
end
|
|
461
|
-
|
|
462
|
-
# TAP record for error.
|
|
463
|
-
#
|
|
464
|
-
# Returns [Hash].
|
|
465
|
-
def tapout_test_error(result)
|
|
466
|
-
e = result.exception
|
|
467
|
-
e_file, e_line = location(e)
|
|
468
|
-
r_file = e_file.sub(Dir.pwd+'/', '')
|
|
469
|
-
|
|
470
|
-
doc = {
|
|
471
|
-
'type' => 'test',
|
|
472
|
-
'subtype' => '',
|
|
473
|
-
'status' => 'error',
|
|
474
|
-
'label' => "#{result.label}",
|
|
475
|
-
#'setup' => "foo instance",
|
|
476
|
-
#'expected' => 2,
|
|
477
|
-
#'returned' => 1,
|
|
478
|
-
#'file' => test/test_foo.rb
|
|
479
|
-
#'line' => 45
|
|
480
|
-
#'source' => ok 1, 2
|
|
481
|
-
#'snippet' =>
|
|
482
|
-
# - 44: ok 0,0
|
|
483
|
-
# - 45: ok 1,2
|
|
484
|
-
# - 46: ok 2,4
|
|
485
|
-
#'coverage' =>
|
|
486
|
-
# 'file' => lib/foo.rb
|
|
487
|
-
# 'line' => 11..13
|
|
488
|
-
# 'code' => Foo#*
|
|
489
|
-
'exception' => {
|
|
490
|
-
'message' => clean_message(e.error.message),
|
|
491
|
-
'class' => e.error.class.name,
|
|
492
|
-
'file' => r_file,
|
|
493
|
-
'line' => e_line,
|
|
494
|
-
'source' => source(e_file)[e_line-1].strip,
|
|
495
|
-
'snippet' => code_snippet(e_file, e_line),
|
|
496
|
-
'backtrace' => filter_backtrace(e.backtrace)
|
|
497
|
-
},
|
|
498
|
-
'time' => Time.now - self.suite_start_time # result.time
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
record_stdcom(doc)
|
|
502
|
-
|
|
503
|
-
#stdout, stderr = @_stdout, @_stderr
|
|
504
|
-
#doc['stdout'] = stdout unless stdout.empty?
|
|
505
|
-
#doc['stderr'] = stderr unless stderr.empty?
|
|
506
|
-
|
|
507
|
-
return doc
|
|
508
|
-
end
|
|
509
|
-
|
|
510
|
-
# ---------------------------------------------------------------------
|
|
511
|
-
|
|
512
|
-
#
|
|
513
|
-
#
|
|
514
|
-
#
|
|
515
|
-
def record_stdcom(doc)
|
|
516
|
-
begin
|
|
517
|
-
doc['stdout'] = $stdout.string unless $stdout.length == 0 #empty?
|
|
518
|
-
doc['stderr'] = $stderr.string unless $stderr.length == 0 #empty?
|
|
519
|
-
$stdout.close; $stderr.close
|
|
520
|
-
$stdout, $stderr = StringIO.new, StringIO.new
|
|
521
|
-
#end
|
|
522
|
-
rescue => err
|
|
523
|
-
uncapture_io
|
|
524
|
-
raise err
|
|
525
|
-
end
|
|
526
|
-
end
|
|
527
|
-
|
|
528
|
-
#
|
|
529
|
-
#def filter_backtrace(backtrace)
|
|
530
|
-
# trace = backtrace
|
|
531
|
-
# trace = clean_backtrace(trace)
|
|
532
|
-
# trace = MiniTest::filter_backtrace(trace)
|
|
533
|
-
# trace
|
|
534
|
-
#end
|
|
535
|
-
|
|
536
|
-
# Clean the backtrace of any reference to test framework itself.
|
|
537
|
-
def filter_backtrace(backtrace)
|
|
538
|
-
## remove backtraces that match any pattern in IGNORE_CALLERS
|
|
539
|
-
trace = backtrace.reject{|b| IGNORE_CALLERS.any?{|i| i=~b}}
|
|
540
|
-
## remove `:in ...` portion of backtraces
|
|
541
|
-
trace = trace.map do |bt|
|
|
542
|
-
i = bt.index(':in')
|
|
543
|
-
i ? bt[0...i] : bt
|
|
544
|
-
end
|
|
545
|
-
## now apply MiniTest's own filter (note: doesn't work if done first, why?)
|
|
546
|
-
trace = Minitest::filter_backtrace(trace)
|
|
547
|
-
## if the backtrace is empty now then revert to the original
|
|
548
|
-
trace = backtrace if trace.empty?
|
|
549
|
-
## simplify paths to be relative to current workding diectory
|
|
550
|
-
trace = trace.map{ |bt| bt.sub(Dir.pwd+File::SEPARATOR,'') }
|
|
551
|
-
return trace
|
|
552
|
-
end
|
|
553
|
-
|
|
554
|
-
# Returns a String of source code.
|
|
555
|
-
def code_snippet(file, line)
|
|
556
|
-
s = []
|
|
557
|
-
if File.file?(file)
|
|
558
|
-
source = source(file)
|
|
559
|
-
radius = 2 # TODO: make customizable (number of surrounding lines to show)
|
|
560
|
-
region = [line - radius, 1].max ..
|
|
561
|
-
[line + radius, source.length].min
|
|
562
|
-
|
|
563
|
-
s = region.map do |n|
|
|
564
|
-
{n => source[n-1].chomp}
|
|
565
|
-
end
|
|
566
|
-
end
|
|
567
|
-
return s
|
|
568
|
-
end
|
|
569
|
-
|
|
570
|
-
# Cache source file text. This is only used if the TAP-Y stream
|
|
571
|
-
# doesn not provide a snippet and the test file is locatable.
|
|
572
|
-
def source(file)
|
|
573
|
-
@_source_cache[file] ||= (
|
|
574
|
-
File.readlines(file)
|
|
575
|
-
)
|
|
576
|
-
end
|
|
577
|
-
|
|
578
|
-
# Parse source location from caller, caller[0] or an Exception object.
|
|
579
|
-
def parse_source_location(caller)
|
|
580
|
-
case caller
|
|
581
|
-
when Exception
|
|
582
|
-
trace = caller.backtrace.reject{ |bt| bt =~ INTERNALS }
|
|
583
|
-
caller = trace.first
|
|
584
|
-
when Array
|
|
585
|
-
caller = caller.first
|
|
586
|
-
end
|
|
587
|
-
caller =~ /(.+?):(\d+(?=:|\z))/ or return ""
|
|
588
|
-
source_file, source_line = $1, $2.to_i
|
|
589
|
-
return source_file, source_line
|
|
590
|
-
end
|
|
591
|
-
|
|
592
|
-
# Get location of exception.
|
|
593
|
-
def location e # :nodoc:
|
|
594
|
-
last_before_assertion = ""
|
|
595
|
-
e.backtrace.reverse_each do |s|
|
|
596
|
-
break if s =~ /in .(assert|refute|flunk|pass|fail|raise|must|wont)/
|
|
597
|
-
last_before_assertion = s
|
|
598
|
-
end
|
|
599
|
-
file, line = last_before_assertion.sub(/:in .*$/, '').split(':')
|
|
600
|
-
line = line.to_i if line
|
|
601
|
-
return file, line
|
|
602
|
-
end
|
|
603
|
-
|
|
604
|
-
#
|
|
605
|
-
def clean_message(message)
|
|
606
|
-
message.strip #.gsub(/\s*\n\s*/, "\n")
|
|
607
|
-
end
|
|
608
|
-
|
|
609
|
-
#
|
|
610
|
-
#def capture_io
|
|
611
|
-
# ostdout, ostderr = $stdout, $stderr
|
|
612
|
-
# cstdout, cstderr = StringIO.new, StringIO.new
|
|
613
|
-
# $stdout, $stderr = cstdout, cstderr
|
|
614
|
-
#
|
|
615
|
-
# yield
|
|
616
|
-
#
|
|
617
|
-
# return cstdout.string.chomp("\n"), cstderr.string.chomp("\n")
|
|
618
|
-
#ensure
|
|
619
|
-
# $stdout = ostdout
|
|
620
|
-
# $stderr = ostderr
|
|
621
|
-
#end
|
|
622
|
-
|
|
623
|
-
#
|
|
624
|
-
def capture_io
|
|
625
|
-
@_stdout, @_stderr = $stdout, $stderr
|
|
626
|
-
$stdout, $stderr = StringIO.new, StringIO.new
|
|
627
|
-
end
|
|
628
|
-
|
|
629
|
-
#
|
|
630
|
-
def uncapture_io
|
|
631
|
-
$stdout, $stderr = @_stdout, @_stderr
|
|
632
|
-
end
|
|
633
|
-
|
|
634
|
-
end
|
|
635
|
-
|
|
636
|
-
#
|
|
637
|
-
# TestResult delegtes to Minitest's own test result object.
|
|
638
|
-
#
|
|
639
|
-
class TestResult
|
|
640
|
-
# Create new TestResult instance.
|
|
641
|
-
#
|
|
642
|
-
# result - MiniTest's test result object.
|
|
643
|
-
#
|
|
644
|
-
def initialize(result)
|
|
645
|
-
@result = result
|
|
646
|
-
end
|
|
647
|
-
|
|
648
|
-
def test_case
|
|
649
|
-
@result.class
|
|
650
|
-
end
|
|
651
|
-
alias :testcase :test_case
|
|
652
|
-
|
|
653
|
-
# Name of the test.
|
|
654
|
-
def name
|
|
655
|
-
@result.name
|
|
656
|
-
end
|
|
657
|
-
alias :test :name
|
|
658
|
-
|
|
659
|
-
#
|
|
660
|
-
def label
|
|
661
|
-
if spec?
|
|
662
|
-
name.sub(/^test_\d+_/, '').gsub('_', ' ')
|
|
663
|
-
else
|
|
664
|
-
name
|
|
665
|
-
end
|
|
666
|
-
end
|
|
667
|
-
|
|
668
|
-
# Is this a Minitest::Spec?
|
|
669
|
-
#
|
|
670
|
-
# Returns [Boolean].
|
|
671
|
-
def spec?
|
|
672
|
-
@is_spec ||= (
|
|
673
|
-
Minitest.const_defined?(:Spec) && @result.class < Minitest::Spec
|
|
674
|
-
#@result.class.methods.include?(:it) || @result.class.methods.include?('it')
|
|
675
|
-
)
|
|
676
|
-
end
|
|
677
|
-
|
|
678
|
-
# Number of assertions made by test.
|
|
679
|
-
#
|
|
680
|
-
# Returns [Integer].
|
|
681
|
-
def assertions
|
|
682
|
-
@result.assertions
|
|
683
|
-
end
|
|
684
|
-
|
|
685
|
-
#
|
|
686
|
-
def time
|
|
687
|
-
@result.time
|
|
688
|
-
end
|
|
689
|
-
|
|
690
|
-
#
|
|
691
|
-
def exception
|
|
692
|
-
@result.failure
|
|
693
|
-
end
|
|
694
|
-
|
|
695
|
-
# Result type.
|
|
696
|
-
def type
|
|
697
|
-
case exception
|
|
698
|
-
when UnexpectedError
|
|
699
|
-
:err
|
|
700
|
-
when Skip
|
|
701
|
-
:skip
|
|
702
|
-
when Assertion
|
|
703
|
-
:fail
|
|
704
|
-
when nil
|
|
705
|
-
:pass
|
|
706
|
-
else
|
|
707
|
-
:err
|
|
708
|
-
end
|
|
709
|
-
end
|
|
710
|
-
end
|
|
711
|
-
|
|
712
|
-
=begin
|
|
713
|
-
# Runner for individual MiniTest tests.
|
|
714
|
-
#
|
|
715
|
-
# You *should not* create instances of this class directly. Instances of
|
|
716
|
-
# {SuiteRunner} will create these and send them to the reporters.
|
|
717
|
-
#
|
|
718
|
-
# Based upon Ryan Davis of Seattle.rb's MiniTest (MIT License).
|
|
719
|
-
#
|
|
720
|
-
# @see https://github.com/seattlerb/minitest MiniTest
|
|
721
|
-
class TestRunner
|
|
722
|
-
attr_reader :suite, :test, :assertions, :result, :exception
|
|
723
|
-
attr_reader :stdout, :stderr
|
|
724
|
-
|
|
725
|
-
def initialize(suite, test)
|
|
726
|
-
@suite = suite
|
|
727
|
-
@test = test
|
|
728
|
-
@assertions = 0
|
|
729
|
-
end
|
|
730
|
-
|
|
731
|
-
def run
|
|
732
|
-
suite_instance = suite.new(test)
|
|
733
|
-
test_result = nil
|
|
734
|
-
@stdout, @stderr = capture_io do
|
|
735
|
-
test_result = suite_instance.run(self)
|
|
736
|
-
end
|
|
737
|
-
@result, @exception = fix_result(test_result)
|
|
738
|
-
@assertions = suite_instance._assertions
|
|
739
|
-
end
|
|
740
|
-
|
|
741
|
-
def puke(suite, test, exception)
|
|
742
|
-
case exception
|
|
743
|
-
when MiniTest::Skip then [:skip, exception]
|
|
744
|
-
when MiniTest::Assertion then [:failure, exception]
|
|
745
|
-
else [:error, exception]
|
|
746
|
-
end
|
|
747
|
-
end
|
|
748
|
-
|
|
749
|
-
def record(suite, method, assertions, time, error)
|
|
750
|
-
end
|
|
751
|
-
|
|
752
|
-
private
|
|
753
|
-
|
|
754
|
-
#
|
|
755
|
-
def fix_result(result)
|
|
756
|
-
result == '.' ? [:pass, nil] : result
|
|
757
|
-
end
|
|
758
|
-
|
|
759
|
-
#
|
|
760
|
-
def capture_io
|
|
761
|
-
ostdout, ostderr = $stdout, $stderr
|
|
762
|
-
cstdout, cstderr = StringIO.new, StringIO.new
|
|
763
|
-
$stdout, $stderr = cstdout, cstderr
|
|
764
|
-
|
|
765
|
-
yield
|
|
766
|
-
|
|
767
|
-
return cstdout.string.chomp("\n"), cstderr.string.chomp("\n")
|
|
768
|
-
ensure
|
|
769
|
-
$stdout = ostdout
|
|
770
|
-
$stderr = ostderr
|
|
771
|
-
end
|
|
772
|
-
end
|
|
773
|
-
=end
|
|
774
|
-
|
|
775
|
-
=begin
|
|
776
|
-
##
|
|
777
|
-
# Around advice.
|
|
778
|
-
#
|
|
779
|
-
module AroundTestHooks
|
|
780
|
-
def self.before_test(instance)
|
|
781
|
-
if before_test = (MiniTest::Unit.runner.method(:before_test) rescue nil)
|
|
782
|
-
before_test.call(instance.class, instance.__name__)
|
|
783
|
-
end
|
|
784
|
-
end
|
|
785
|
-
|
|
786
|
-
def self.after_test(instance)
|
|
787
|
-
# MiniTest < 4.1.0 sends #record after all teardown hooks, so don't call
|
|
788
|
-
# #after_test here.
|
|
789
|
-
if MiniTest::Unit::VERSION > "4.1.0"
|
|
790
|
-
if after_test = (MiniTest::Unit.runner.method(:after_test) rescue nil)
|
|
791
|
-
after_test.call(instance.class, instance.__name__)
|
|
792
|
-
end
|
|
793
|
-
end
|
|
794
|
-
end
|
|
795
|
-
|
|
796
|
-
def before_setup
|
|
797
|
-
AroundTestHooks.before_test(self)
|
|
798
|
-
super
|
|
799
|
-
end
|
|
800
|
-
|
|
801
|
-
def after_teardown
|
|
802
|
-
super
|
|
803
|
-
AroundTestHooks.after_test(self)
|
|
804
|
-
end
|
|
805
|
-
end
|
|
806
|
-
|
|
807
|
-
class Unit::TestCase
|
|
808
|
-
include AroundTestHooks
|
|
809
|
-
end
|
|
810
|
-
=end
|
|
811
|
-
|
|
812
|
-
##
|
|
813
|
-
# TAP-Y adapater.
|
|
814
|
-
#
|
|
815
|
-
class TapY < Minitap
|
|
816
|
-
def initialize(options={})
|
|
817
|
-
require 'yaml' unless respond_to?(:to_yaml)
|
|
818
|
-
super(options)
|
|
819
|
-
end
|
|
820
|
-
|
|
821
|
-
def tapout_before_suite()
|
|
822
|
-
wp super().to_yaml
|
|
823
|
-
end
|
|
824
|
-
def tapout_before_case(test_case)
|
|
825
|
-
wp super(test_case).to_yaml
|
|
826
|
-
end
|
|
827
|
-
def tapout_test_pass(result)
|
|
828
|
-
wp super(result).to_yaml
|
|
829
|
-
end
|
|
830
|
-
def tapout_test_skip(result)
|
|
831
|
-
wp super(result).to_yaml
|
|
832
|
-
end
|
|
833
|
-
def tapout_test_failure(result)
|
|
834
|
-
wp super(result).to_yaml
|
|
835
|
-
end
|
|
836
|
-
def tapout_test_error(result)
|
|
837
|
-
wp super(result).to_yaml
|
|
838
|
-
end
|
|
839
|
-
def tapout_after_suite()
|
|
840
|
-
wp super().to_yaml
|
|
841
|
-
wp "..."
|
|
842
|
-
end
|
|
843
|
-
|
|
844
|
-
def wp(str)
|
|
845
|
-
io.puts(str)
|
|
846
|
-
end
|
|
847
|
-
end
|
|
848
|
-
|
|
849
|
-
##
|
|
850
|
-
# TAP-J adapater.
|
|
851
|
-
#
|
|
852
|
-
class TapJ < Minitap
|
|
853
|
-
def initialize(options={})
|
|
854
|
-
require 'json' unless respond_to?(:to_json)
|
|
855
|
-
super(options)
|
|
856
|
-
end
|
|
857
|
-
|
|
858
|
-
def tapout_before_suite()
|
|
859
|
-
wp super().to_json
|
|
860
|
-
end
|
|
861
|
-
def tapout_before_case(test_case)
|
|
862
|
-
wp super(test_case).to_json
|
|
863
|
-
end
|
|
864
|
-
def tapout_test_pass(result)
|
|
865
|
-
wp super(result).to_json
|
|
866
|
-
end
|
|
867
|
-
def tapout_test_skip(result)
|
|
868
|
-
wp super(result).to_json
|
|
869
|
-
end
|
|
870
|
-
def tapout_test_failure(result)
|
|
871
|
-
wp super(result).to_json
|
|
872
|
-
end
|
|
873
|
-
def tapout_test_error(result)
|
|
874
|
-
wp super(result).to_json
|
|
875
|
-
end
|
|
876
|
-
def tapout_after_suite()
|
|
877
|
-
wp super().to_json
|
|
878
|
-
end
|
|
879
|
-
|
|
880
|
-
def wp(str)
|
|
881
|
-
io.puts(str)
|
|
882
|
-
end
|
|
883
|
-
end
|
|
884
|
-
|
|
885
|
-
end
|