minitap 0.4.1 → 0.5.0

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