openlogic-turn 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,93 @@
1
+ require 'turn/reporter'
2
+
3
+ module Turn
4
+
5
+ # = Traditional Dot Reporter
6
+ #
7
+ class DotReporter < Reporter
8
+
9
+ def start_suite(suite)
10
+ @time = Time.now
11
+ io.puts "Loaded suite #{suite.name}"
12
+ io.puts "Started"
13
+ end
14
+
15
+ def start_case(kase)
16
+ end
17
+
18
+ def start_test(test)
19
+ end
20
+
21
+ def pass(message=nil)
22
+ io.print Colorize.pass('.'); io.flush
23
+ end
24
+
25
+ def fail(message=nil)
26
+ io.print Colorize.fail('F'); io.flush
27
+ end
28
+
29
+ def error(message=nil)
30
+ io.print Colorize.error('E'); io.flush
31
+ end
32
+
33
+ def finish_test(test)
34
+ end
35
+
36
+ def finish_case(kase)
37
+ end
38
+
39
+ def finish_suite(suite)
40
+ io.puts("\nFinished in %.5f seconds." % [Time.now - @time])
41
+
42
+ report = ''
43
+
44
+ list = []
45
+ suite.each do |testcase|
46
+ testcase.each do |testunit|
47
+ if testunit.fail? || testunit.error?
48
+ list << testunit
49
+ end
50
+ end
51
+ end
52
+
53
+ unless list.empty? # or verbose?
54
+ #report << "\n\n-- Failures and Errors --\n\n"
55
+ list.uniq.each do |testunit|
56
+ message = testunit.fail? ? ' ' + FAIL : ERROR
57
+ message = message + ' ' + testunit.message.tabto(0)
58
+ message << "\n" + (filter_backtrace(testunit.backtrace).first || '')
59
+ report << "\n" << message << "\n"
60
+ end
61
+ report << "\n"
62
+ end
63
+
64
+ io.puts report
65
+
66
+ count = test_tally(suite)
67
+
68
+ tally = "%s tests, %s assertions, %s failures, %s errors" % count
69
+
70
+ if count[-1] > 0 or count[-2] > 0
71
+ tally = Colorize.red(tally)
72
+ else
73
+ tally = Colorize.green(tally)
74
+ end
75
+
76
+ io.puts tally
77
+ end
78
+
79
+ private
80
+
81
+ def test_tally(suite)
82
+ counts = suite.collect{ |tr| tr.counts }
83
+ tally = [0,0,0,0]
84
+ counts.each do |count|
85
+ 4.times{ |i| tally[i] += count[i] }
86
+ end
87
+ return tally
88
+ end
89
+
90
+ end
91
+
92
+ end
93
+
@@ -0,0 +1,17 @@
1
+ require 'turn/reporter'
2
+ require 'yaml'
3
+
4
+ module Turn
5
+
6
+ # = Marshal Reporter
7
+ #
8
+ class MarshalReporter < Reporter
9
+
10
+ def finish_suite(suite)
11
+ $stdout << suite.to_yaml
12
+ end
13
+
14
+ end
15
+
16
+ end
17
+
@@ -0,0 +1,144 @@
1
+ require 'turn/reporter'
2
+ require 'stringio'
3
+
4
+ module Turn
5
+
6
+ # = Outline Reporter (Turn's Original)
7
+ #
8
+ #--
9
+ # TODO: Should we fit reporter output to width of console?
10
+ # TODO: Running percentages?
11
+ #++
12
+ class OutlineReporter < Reporter
13
+
14
+ #
15
+ def start_suite(suite)
16
+ @suite = suite
17
+ @time = Time.now
18
+ @stdout = StringIO.new
19
+ @stderr = StringIO.new
20
+ #files = suite.collect{ |s| s.file }.join(' ')
21
+ io.puts "LOADED SUITE #{suite.name}"
22
+ #io.puts "Started"
23
+ end
24
+
25
+ #
26
+ def start_case(kase)
27
+ io.puts(Colorize.bold("#{kase.name}"))
28
+ end
29
+
30
+ #
31
+ def start_test(test)
32
+ #if @file != test.file
33
+ # @file = test.file
34
+ # io.puts(test.file)
35
+ #end
36
+ io.print " %-69s" % test.name
37
+
38
+ @stdout.rewind
39
+ @stderr.rewind
40
+
41
+ $stdout = @stdout
42
+ $stderr = @stderr unless $DEBUG
43
+ end
44
+
45
+ #
46
+ def pass(message=nil)
47
+ io.puts " #{PASS}"
48
+ if message
49
+ message = Colorize.magenta(message)
50
+ message = message.to_s.tabto(8)
51
+ io.puts(message)
52
+ end
53
+ end
54
+
55
+ #
56
+ def fail(assertion)
57
+ message = assertion.message.to_s
58
+ backtrace = filter_backtrace(assertion.backtrace)
59
+
60
+ io.puts(" #{FAIL}")
61
+ io.puts Colorize.bold(message).tabto(8)
62
+ unless backtrace.empty?
63
+ backtrace = "Assertion at " + filter_backtrace(assertion.backtrace).first
64
+ io.puts "STDERR:".tabto(8)
65
+ io.puts(backtrace.tabto(8))
66
+ end
67
+ show_captured_output
68
+ end
69
+
70
+ #
71
+ def error(exception)
72
+ message = exception.message
73
+ backtrace = "Exception `#{exception.class}' at " + filter_backtrace(exception.backtrace).join("\n")
74
+ message = Colorize.bold(message)
75
+ io.puts("#{ERROR}")
76
+ io.puts(message.tabto(8))
77
+ io.puts "STDERR:".tabto(8)
78
+ io.puts(backtrace.tabto(8))
79
+ show_captured_output
80
+ end
81
+
82
+ #
83
+ def finish_test(test)
84
+ $stdout = STDOUT
85
+ $stderr = STDERR
86
+ end
87
+
88
+ #
89
+ def show_captured_output
90
+ show_captured_stdout
91
+ #show_captured_stderr
92
+ end
93
+
94
+ #
95
+ def show_captured_stdout
96
+ @stdout.rewind
97
+ return if @stdout.eof?
98
+ STDOUT.puts(<<-output.tabto(8))
99
+ \nSTDOUT:
100
+ #{@stdout.read}
101
+ output
102
+ end
103
+
104
+ # No longer used b/c of error messages are fairly extraneous.
105
+ =begin
106
+ def show_captured_stderr
107
+ @stderr.rewind
108
+ return if @stderr.eof?
109
+ STDOUT.puts(<<-output.tabto(8))
110
+ \nSTDERR:
111
+ #{@stderr.read}
112
+ output
113
+ end
114
+ =end
115
+
116
+ #
117
+ #def finish_case(kase)
118
+ #end
119
+
120
+ #
121
+ def finish_suite(suite)
122
+ total = suite.count_tests
123
+ failure = suite.count_failures
124
+ error = suite.count_errors
125
+ pass = total - failure - error
126
+
127
+ bar = '=' * 78
128
+ if COLORIZE
129
+ bar = if pass == total then Colorize.green(bar)
130
+ else Colorize.red(bar) end
131
+ end
132
+
133
+ tally = [total, suite.count_assertions]
134
+
135
+ io.puts bar
136
+ io.puts " pass: %d, fail: %d, error: %d" % [pass, failure, error]
137
+ io.puts " total: %d tests with %d assertions in #{Time.new - @time} seconds" % tally
138
+ io.puts bar
139
+ end
140
+
141
+ end
142
+
143
+ end
144
+
@@ -0,0 +1,184 @@
1
+ require 'turn/reporter'
2
+
3
+ module Turn
4
+
5
+ # = Pretty Reporter (by Paydro)
6
+ #
7
+ class PrettyReporter < Reporter
8
+ #
9
+ PADDING_SIZE = 4
10
+
11
+ #
12
+ def start_suite(suite)
13
+ #old_sync, @@out.sync = @@out.sync, true if io.respond_to? :sync=
14
+ @suite = suite
15
+ @time = Time.now
16
+ #@stdout = StringIO.new
17
+ #@stderr = StringIO.new
18
+ #files = suite.collect{ |s| s.file }.join(' ')
19
+ io.puts "Loaded suite #{suite.name}"
20
+ #io.puts "Loaded suite #{$0.sub(/\.rb$/, '')}\nStarted"
21
+ io.puts "Started"
22
+ end
23
+
24
+ #
25
+ def start_case(kase)
26
+ #if kase.size > 0 # TODO: Don't have size yet?
27
+ io.print "\n#{kase.name}:\n"
28
+ #end
29
+ end
30
+
31
+ #
32
+ def start_test(test)
33
+ @test_time = Time.now
34
+ @test = test
35
+ #if @file != test.file
36
+ # @file = test.file
37
+ # io.puts(test.file)
38
+ #end
39
+ #io.print " %-69s" % test.name
40
+ #$stdout = @stdout
41
+ #$stderr = @stderr
42
+ #$stdout.rewind
43
+ #$stderr.rewind
44
+ end
45
+
46
+ #
47
+ def pass(message=nil)
48
+ io.print pad_with_size("#{PASS}")
49
+ io.print " #{@test}"
50
+ io.print " (%.2fs) " % (Time.now - @test_time)
51
+ if message
52
+ message = Colorize.magenta(message)
53
+ message = message.to_s.tabto(10)
54
+ io.puts(message)
55
+ end
56
+ end
57
+
58
+ #
59
+ def fail(assertion)
60
+ io.print pad_with_size("#{FAIL}")
61
+ io.print " #{@test}"
62
+ io.print " (%.2fs) " % (Time.now - @test_time)
63
+
64
+ #message = assertion.location[0] + "\n" + assertion.message #.gsub("\n","\n")
65
+ #trace = MiniTest::filter_backtrace(report[:exception].backtrace).first
66
+
67
+ message = assertion.message
68
+
69
+ if assertion.respond_to?(:backtrace)
70
+ trace = filter_backtrace(assertion.backtrace).first
71
+ else
72
+ trace = filter_backtrace(assertion.location).first
73
+ end
74
+
75
+ io.puts
76
+ #io.puts pad(message, 10)
77
+ io.puts message.tabto(10)
78
+ io.puts trace.tabto(10)
79
+ #show_captured_output
80
+ end
81
+
82
+ #
83
+ def error(exception)
84
+ io.print pad_with_size("#{ERROR}")
85
+ io.print " #{@test}"
86
+ io.print " (%.2fs) " % (Time.now - @test_time)
87
+
88
+ #message = exception.to_s.split("\n")[2..-1].join("\n")
89
+
90
+ message = exception.message
91
+
92
+ if exception.respond_to?(:backtrace)
93
+ trace = filter_backtrace(exception.backtrace).first
94
+ else
95
+ trace = filter_backtrace(exception.location).first
96
+ end
97
+
98
+ io.puts
99
+ io.puts message.tabto(10)
100
+ io.puts trace.tabto(10)
101
+ end
102
+
103
+ # TODO: skip support
104
+ #def skip
105
+ # io.puts(pad_with_size("#{SKIP}"))
106
+ #end
107
+
108
+ #
109
+ def finish_test(test)
110
+ io.puts
111
+ #@test_count += 1
112
+ #@assertion_count += inst._assertions
113
+ #$stdout = STDOUT
114
+ #$stderr = STDERR
115
+ end
116
+
117
+ =begin
118
+ def show_captured_output
119
+ show_captured_stdout
120
+ show_captured_stderr
121
+ end
122
+
123
+ def show_captured_stdout
124
+ @stdout.rewind
125
+ return if @stdout.eof?
126
+ STDOUT.puts(<<-output.tabto(8))
127
+ \nSTDOUT:
128
+ #{@stdout.read}
129
+ output
130
+ end
131
+
132
+ def show_captured_stderr
133
+ @stderr.rewind
134
+ return if @stderr.eof?
135
+ STDOUT.puts(<<-output.tabto(8))
136
+ \nSTDERR:
137
+ #{@stderr.read}
138
+ output
139
+ end
140
+ =end
141
+
142
+ def finish_case(kase)
143
+ if kase.size == 0
144
+ io.puts pad("(No Tests)")
145
+ end
146
+ end
147
+
148
+ #
149
+ def finish_suite(suite)
150
+ #@@out.sync = old_sync if @@out.respond_to? :sync=
151
+
152
+ total = suite.count_tests
153
+ failure = suite.count_failures
154
+ error = suite.count_errors
155
+ #pass = total - failure - error
156
+
157
+ io.puts
158
+ io.puts "Finished in #{'%.6f' % (Time.now - @time)} seconds."
159
+ io.puts
160
+
161
+ io.print "%d tests, " % total
162
+ io.print "%d assertions, " % suite.count_assertions
163
+ io.print Colorize.fail( "%d failures" % failure) + ', '
164
+ io.print Colorize.error("%d errors" % error) #+ ', '
165
+ #io.puts Colorize.cyan( "%d skips" % skips ) #TODO
166
+ io.puts
167
+ end
168
+
169
+ private
170
+
171
+ #
172
+ def pad(str, size=PADDING_SIZE)
173
+ " " * size + str
174
+ end
175
+
176
+ #
177
+ def pad_with_size(str)
178
+ " " * (18 - str.size) + str
179
+ end
180
+
181
+ end
182
+
183
+ end
184
+
@@ -0,0 +1,116 @@
1
+ require 'turn/reporter'
2
+ require 'ansi/progressbar'
3
+
4
+ module Turn
5
+
6
+ #
7
+ class ProgressReporter < Reporter
8
+
9
+ def start_suite(suite)
10
+ @pbar = ::ANSI::Progressbar.new('Testing', suite.size)
11
+ @pbar.inc
12
+ end
13
+
14
+ #def start_case(kase)
15
+ #end
16
+
17
+ #def start_test(test)
18
+ #end
19
+
20
+ #def pass(message=nil)
21
+ # #@pbar.inc
22
+ #end
23
+
24
+ #def fail(message=nil)
25
+ # #@pbar.inc
26
+ #end
27
+
28
+ #def error(message=nil)
29
+ # #@pbar.inc
30
+ #end
31
+
32
+ def finish_case(kase)
33
+ @pbar.inc
34
+ end
35
+
36
+ def finish_suite(suite)
37
+ @pbar.finish
38
+ post_report(suite)
39
+ end
40
+
41
+ #
42
+ def post_report(suite)
43
+ tally = test_tally(suite)
44
+
45
+ width = suite.collect{ |tr| tr.name.size }.max
46
+
47
+ headers = [ 'TESTCASE ', ' TESTS ', 'ASSERTIONS', ' FAILURES ', ' ERRORS ' ]
48
+ io.puts "\n%-#{width}s %10s %10s %10s %10s\n" % headers
49
+
50
+ files = nil
51
+
52
+ suite.each do |testrun|
53
+ if testrun.files != [testrun.name] && testrun.files != files
54
+ label = testrun.files.join(' ')
55
+ label = Colorize.magenta(label)
56
+ io.puts(label + "\n")
57
+ files = testrun.files
58
+ end
59
+ io.puts paint_line(testrun, width)
60
+ end
61
+
62
+ #puts("\n%i tests, %i assertions, %i failures, %i errors\n\n" % tally)
63
+
64
+ tally_line = "-----\n"
65
+ tally_line << "%-#{width}s " % "TOTAL"
66
+ tally_line << "%10s %10s %10s %10s" % tally
67
+
68
+ io.puts(tally_line + "\n")
69
+
70
+ fails = suite.select do |testrun|
71
+ testrun.fail? || testrun.error?
72
+ end
73
+
74
+ #if tally[2] != 0 or tally[3] != 0
75
+ unless fails.empty? # or verbose?
76
+ io.puts "\n\n-- Failures and Errors --\n\n"
77
+ fails.uniq.each do |testrun|
78
+ message = testrun.message.tabto(0).strip
79
+ message = Colorize.red(message)
80
+ io.puts(message+"\n\n")
81
+ end
82
+ io.puts
83
+ end
84
+ #end
85
+ end
86
+
87
+ private
88
+
89
+ def paint_line(testrun, width)
90
+ line = ''
91
+ line << "%-#{width}s " % [testrun.name]
92
+ line << "%10s %10s %10s %10s" % testrun.counts
93
+ line << " " * 8
94
+ if testrun.fail?
95
+ line << "[#{FAIL}]"
96
+ elsif testrun.error?
97
+ line << "[#{FAIL}]"
98
+ else
99
+ line << "[#{PASS}]"
100
+ end
101
+ line
102
+ end
103
+
104
+ def test_tally(suite)
105
+ counts = suite.collect{ |tr| tr.counts }
106
+ tally = [0,0,0,0]
107
+ counts.each do |count|
108
+ 4.times{ |i| tally[i] += count[i] }
109
+ end
110
+ return tally
111
+ end
112
+
113
+ end
114
+
115
+ end
116
+