tapout 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,8 +4,9 @@ module TapOut
4
4
 
5
5
  module Reporters
6
6
 
7
- # The Breakdown report format give a tally for each test case.
8
- class Breakdown < Abstract
7
+ # The Breakdown report format gives a tally for each test case.
8
+ #
9
+ class BreakdownReporter < Abstract
9
10
 
10
11
  def initialize
11
12
  super
@@ -23,7 +24,7 @@ module TapOut
23
24
  @case_entries = []
24
25
  end
25
26
 
26
- def test(entry)
27
+ def start_test(entry)
27
28
  @case_entries << entry
28
29
  end
29
30
 
@@ -110,7 +111,7 @@ module TapOut
110
111
  end
111
112
  #end
112
113
 
113
- puts tally(entry)
114
+ puts tally_message(entry)
114
115
  end
115
116
 
116
117
  end
@@ -3,7 +3,8 @@ require 'tapout/reporters/abstract'
3
3
  module TapOut::Reporters
4
4
 
5
5
  # Traditional dot progress reporter.
6
- class Dotprogress < Abstract
6
+ #
7
+ class DotReporter < Abstract
7
8
 
8
9
  #
9
10
  def start_suite(entry)
@@ -26,7 +27,7 @@ module TapOut::Reporters
26
27
  end
27
28
 
28
29
  #
29
- def err(entry)
30
+ def error(entry)
30
31
  $stdout.print 'E'.ansi(:yellow)
31
32
  $stdout.flush
32
33
  super(entry)
@@ -61,7 +62,7 @@ module TapOut::Reporters
61
62
  end
62
63
 
63
64
  $stdout.puts "Finished in #{Time.now - @start_time}s"
64
- $stdout.puts tally(entry)
65
+ $stdout.puts tally_message(entry)
65
66
  end
66
67
 
67
68
  end
@@ -81,7 +81,7 @@ module TapOut::Reporters
81
81
  end
82
82
 
83
83
  #
84
- def err(entry)
84
+ def error(entry)
85
85
  e = entry['exception']
86
86
 
87
87
  puts %[<li class="error">]
@@ -117,7 +117,7 @@ module TapOut::Reporters
117
117
  def finish_suite(entry)
118
118
  puts ""
119
119
  puts %[<div class="tally">]
120
- puts tally(entry)
120
+ puts tally_message(entry)
121
121
  puts %[</div>]
122
122
  puts ""
123
123
  puts ""
@@ -34,7 +34,7 @@ module TapOut::Reporters
34
34
  $stdout.puts
35
35
  end
36
36
 
37
- def err(entry)
37
+ def error(entry)
38
38
  super(entry)
39
39
  $stdout.puts "* " + entry['label'].ansi(:yellow) + " #{entry['source']}"
40
40
  $stdout.puts
@@ -48,7 +48,7 @@ module TapOut::Reporters
48
48
  #
49
49
  def finish_suite(entry)
50
50
  #$stderr.puts
51
- $stdout.print tally(entry)
51
+ $stdout.print tally_message(entry)
52
52
  $stdout.puts " [%0.4fs] " % [Time.now - @start_time]
53
53
  end
54
54
 
@@ -0,0 +1,205 @@
1
+ require 'tapout/core_ext'
2
+ require 'tapout/reporters/abstract'
3
+
4
+ module TapOut
5
+
6
+ module Reporters
7
+
8
+ # = Pretty Reporter (by Paydro)
9
+ #
10
+ class PrettyReporter < Abstract
11
+
12
+ #
13
+ PADDING_SIZE = 4
14
+
15
+ PASS = "PASS".ansi(:green)
16
+ FAIL = "FAIL".ansi(:red)
17
+ ERROR = "ERROR".ansi(:yellow)
18
+
19
+ #
20
+ def start_suite(suite)
21
+ #old_sync, @@out.sync = @@out.sync, true if io.respond_to? :sync=
22
+ @suite = suite
23
+ @time = Time.now
24
+ #@stdout = StringIO.new
25
+ #@stderr = StringIO.new
26
+ #files = suite.collect{ |s| s.file }.join(' ')
27
+ #puts "Loaded suite #{suite.name}"
28
+ puts "Suite seed: #{suite['seed']}" if suite['seed']
29
+ puts "Started"
30
+ end
31
+
32
+ #
33
+ def start_case(kase)
34
+ #if kase.size > 0 # TODO: Don't have size yet?
35
+ print "\n#{kase['label']}:\n"
36
+ #end
37
+ end
38
+
39
+ #
40
+ def start_test(test)
41
+ @test_time = Time.now
42
+ @test = test
43
+ #if @file != test.file
44
+ # @file = test.file
45
+ # puts(test.file)
46
+ #end
47
+ #print " %-69s" % test.name
48
+ #$stdout = @stdout
49
+ #$stderr = @stderr
50
+ #$stdout.rewind
51
+ #$stderr.rewind
52
+ end
53
+
54
+ #
55
+ def pass(test)
56
+ print pad_with_size("#{PASS}")
57
+ print " #{test['label']}"
58
+ print " (%.2fs) " % (Time.now - @test_time)
59
+ #if message
60
+ # message = test['source'].ansi(:magenta)
61
+ # message = message.to_s.tabto(10)
62
+ # puts(message)
63
+ #end
64
+ end
65
+
66
+ #
67
+ def fail(test)
68
+ print pad_with_size("#{FAIL}")
69
+ print " #{test['label']}"
70
+ print " (%.2fs) " % (Time.now - @test_time)
71
+
72
+ #message = assertion.location[0] + "\n" + assertion.message #.gsub("\n","\n")
73
+ #trace = MiniTest::filter_backtrace(report[:exception].backtrace).first
74
+
75
+ message = test['exception']['message']
76
+
77
+ if bt = test['exception']['backtrace']
78
+ _trace = clean_backtrace(bt)
79
+ else
80
+ _trace = clean_backtrace(bt)
81
+ end
82
+
83
+ puts
84
+ tabsize = 10
85
+ #puts pad(message, tabsize)
86
+ puts message.tabto(tabsize)
87
+ puts _trace.shift.tabto(tabsize)
88
+ if depth = TapOut.trace
89
+ puts _trace[0,depth].map{|l| l.tabto(tabsize) }.join("\n")
90
+ end
91
+ #show_captured_output
92
+ end
93
+
94
+ #
95
+ def error(test)
96
+ print pad_with_size("#{ERROR}")
97
+ print " #{test['label']}"
98
+ print " (%.2fs) " % (Time.now - @test_time)
99
+
100
+ #message = exception.to_s.split("\n")[2..-1].join("\n")
101
+
102
+ message = test['exception']['message']
103
+
104
+ if bt = test['exception']['backtrace']
105
+ _trace = clean_backtrace(bt)
106
+ else
107
+ _trace = filter_backtrace(bt)
108
+ end
109
+
110
+ trace = _trace.shift
111
+ puts
112
+ tabsize = 10
113
+ puts message.tabto(tabsize)
114
+ puts trace.tabto(tabsize)
115
+ if depth = TapOut.trace
116
+ puts _trace[0,depth].map{|l| l.tabto(tabsize) }.join("\n")
117
+ end
118
+ end
119
+
120
+ # TODO: skip support
121
+ #def skip
122
+ # puts(pad_with_size("#{SKIP}"))
123
+ #end
124
+
125
+ #
126
+ def finish_test(test)
127
+ puts
128
+ #@test_count += 1
129
+ #@assertion_count += inst._assertions
130
+ #$stdout = STDOUT
131
+ #$stderr = STDERR
132
+ end
133
+
134
+ =begin
135
+ def show_captured_output
136
+ show_captured_stdout
137
+ show_captured_stderr
138
+ end
139
+
140
+ def show_captured_stdout
141
+ @stdout.rewind
142
+ return if @stdout.eof?
143
+ STDOUT.puts(<<-output.tabto(8))
144
+ \nSTDOUT:
145
+ #{@stdout.read}
146
+ output
147
+ end
148
+
149
+ def show_captured_stderr
150
+ @stderr.rewind
151
+ return if @stderr.eof?
152
+ STDOUT.puts(<<-output.tabto(8))
153
+ \nSTDERR:
154
+ #{@stderr.read}
155
+ output
156
+ end
157
+ =end
158
+
159
+ def finish_case(kase)
160
+ #if kase.size == 0
161
+ # puts pad("(No Tests)")
162
+ #end
163
+ end
164
+
165
+ #
166
+ def finish_suite(final)
167
+ #@@out.sync = old_sync if @@out.respond_to? :sync=
168
+
169
+ total = final['counts']['total'] || 0
170
+ failure = final['counts']['fail'] || 0
171
+ error = final['counts']['error'] || 0
172
+ skip = final['counts']['skip'] || 0
173
+ omit = final['counts']['omit'] || 0
174
+ #pass = total - failure - error
175
+
176
+ puts
177
+ puts "Finished in #{'%.6f' % (Time.now - @time)} seconds."
178
+ puts
179
+
180
+ print "%d tests, " % total
181
+ #print "%d assertions, " % suite.count_assertions
182
+ print ("%d failures" % failure).ansi(:red) + ', '
183
+ print ("%d errors" % error).ansi(:yellow) + ', '
184
+ print ("%d pending" % skip).ansi(:cyan)
185
+ puts
186
+ end
187
+
188
+ private
189
+
190
+ #
191
+ def pad(str, size=PADDING_SIZE)
192
+ " " * size + str
193
+ end
194
+
195
+ #
196
+ def pad_with_size(str)
197
+ " " * (18 - str.size) + str
198
+ end
199
+
200
+ end
201
+
202
+ end
203
+
204
+ end
205
+
@@ -0,0 +1,205 @@
1
+ require 'tapout/reporters/abstract'
2
+ require 'ansi/progressbar'
3
+
4
+ module TapOut
5
+
6
+ module Reporters
7
+
8
+ # The progress report format utilises a progress bar to indicate
9
+ # elapsed progress.
10
+ #
11
+ class ProgressReporter < Abstract
12
+
13
+ def start_suite(entry)
14
+ @pbar = ::ANSI::Progressbar.new('Testing', entry['count'].to_i + 1)
15
+ @pbar.style(:bar=>:green)
16
+ @pbar.inc
17
+ end
18
+
19
+ def start_case(entry)
20
+ end
21
+
22
+ #def test(entry)
23
+ # #@pbar.inc
24
+ #end
25
+
26
+ def pass(entry)
27
+ @pbar.inc
28
+ end
29
+
30
+ #
31
+ def fail(entry)
32
+ @pbar.clear
33
+
34
+ e = entry['exception']
35
+
36
+ puts
37
+ message = e['message'].strip
38
+ message = message.ansi(:red)
39
+ puts(message)
40
+ puts "#{e['file']}:#{e['line']}"
41
+ puts
42
+ puts code_snippet(e)
43
+ puts
44
+
45
+ @pbar.style(:bar=>:red)
46
+ @pbar.inc
47
+ end
48
+
49
+ #
50
+ def error(entry) #message=nil)
51
+ @pbar.clear
52
+
53
+ e = entry['exception']
54
+
55
+ puts
56
+ message = e['message'].strip
57
+ message = message.ansi(:red)
58
+ puts(message)
59
+ puts "#{e['file']}:#{e['line']}"
60
+ puts
61
+ puts code_snippet(e)
62
+ puts
63
+
64
+ @pbar.style(:bar=>:yellow)
65
+ @pbar.inc
66
+ end
67
+
68
+ #
69
+ def omit(entry)
70
+ @pbar.inc
71
+ end
72
+
73
+ #
74
+ def skip(entry)
75
+ @pbar.inc
76
+ end
77
+
78
+ #def finish_case(kase)
79
+ #end
80
+
81
+ def finish_suite(entry)
82
+ @pbar.finish
83
+ #post_report(entry)
84
+ puts
85
+ puts tally_message(entry)
86
+ end
87
+
88
+ end
89
+
90
+ end
91
+
92
+ end
93
+
94
+
95
+
96
+
97
+ =begin
98
+ def start_suite(suite)
99
+ @pbar = ::ANSI::Progressbar.new('Testing', suite.size)
100
+ @pbar.inc
101
+ end
102
+
103
+ #def start_case(kase)
104
+ #end
105
+
106
+ #def start_test(test)
107
+ #end
108
+
109
+ #def pass(message=nil)
110
+ # #@pbar.inc
111
+ #end
112
+
113
+ #def fail(message=nil)
114
+ # #@pbar.inc
115
+ #end
116
+
117
+ #def error(message=nil)
118
+ # #@pbar.inc
119
+ #end
120
+
121
+ def finish_case(kase)
122
+ @pbar.inc
123
+ end
124
+
125
+ def finish_suite(suite)
126
+ @pbar.finish
127
+ post_report(suite)
128
+ end
129
+
130
+ #
131
+ def post_report(suite)
132
+ tally = test_tally(suite)
133
+
134
+ width = suite.collect{ |tr| tr.name.size }.max
135
+
136
+ headers = [ 'TESTCASE ', ' TESTS ', 'ASSERTIONS', ' FAILURES ', ' ERRORS ' ]
137
+ io.puts "\n%-#{width}s %10s %10s %10s %10s\n" % headers
138
+
139
+ files = nil
140
+
141
+ suite.each do |testrun|
142
+ if testrun.files != [testrun.name] && testrun.files != files
143
+ label = testrun.files.join(' ')
144
+ label = Colorize.magenta(label)
145
+ io.puts(label + "\n")
146
+ files = testrun.files
147
+ end
148
+ io.puts paint_line(testrun, width)
149
+ end
150
+
151
+ #puts("\n%i tests, %i assertions, %i failures, %i errors\n\n" % tally)
152
+
153
+ tally_line = "-----\n"
154
+ tally_line << "%-#{width}s " % "TOTAL"
155
+ tally_line << "%10s %10s %10s %10s" % tally
156
+
157
+ io.puts(tally_line + "\n")
158
+
159
+ fails = suite.select do |testrun|
160
+ testrun.fail? || testrun.error?
161
+ end
162
+
163
+ #if tally[2] != 0 or tally[3] != 0
164
+ unless fails.empty? # or verbose?
165
+ io.puts "\n\n-- Failures and Errors --\n\n"
166
+ fails.uniq.each do |testrun|
167
+ message = testrun.message.tabto(0).strip
168
+ message = Colorize.red(message)
169
+ io.puts(message+"\n\n")
170
+ end
171
+ io.puts
172
+ end
173
+ #end
174
+ end
175
+
176
+ private
177
+
178
+ def paint_line(testrun, width)
179
+ line = ''
180
+ line << "%-#{width}s " % [testrun.name]
181
+ line << "%10s %10s %10s %10s" % testrun.counts
182
+ line << " " * 8
183
+ if testrun.fail?
184
+ line << "[#{FAIL}]"
185
+ elsif testrun.error?
186
+ line << "[#{FAIL}]"
187
+ else
188
+ line << "[#{PASS}]"
189
+ end
190
+ line
191
+ end
192
+
193
+ def test_tally(suite)
194
+ counts = suite.collect{ |tr| tr.counts }
195
+ tally = [0,0,0,0]
196
+ counts.each do |count|
197
+ 4.times{ |i| tally[i] += count[i] }
198
+ end
199
+ return tally
200
+ end
201
+
202
+ end
203
+
204
+ =end
205
+