test 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,197 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'test/reporters/abstract'
4
+
5
+ module Test::Reporters
6
+
7
+ # Progess reporter gives test counter, precentage and times.
8
+ #
9
+ class Progress < Abstract
10
+
11
+ #
12
+ def begin_suite(suite)
13
+ @tab = 0
14
+ @total_count = total_count(suite)
15
+ @start_time = Time.now
16
+ @test_cache = {}
17
+ @count = 0
18
+
19
+ max = @total_count.to_s.size
20
+
21
+ @layout_head = " %3u%% %#{max}s %#{max}s %8s %11s %1s %s"
22
+ @layout = " %3u%% %#{max}u/%#{max}u %8s %11s %1s %s"
23
+
24
+ timer_reset
25
+ end
26
+
27
+ #
28
+ def begin_case(tc)
29
+ #tabs tc.to_s.ansi(:bold)
30
+ show_header(' ', tc.to_s)
31
+ @tab += 2
32
+ end
33
+
34
+ #
35
+ def begin_test(test)
36
+ if test.respond_to?(:topic) && test.topic
37
+ topic = test.topic.to_s.rstrip
38
+ @test_cache[topic] ||= (
39
+ show_header(' ', topic) unless topic.empty?
40
+ true
41
+ )
42
+ end
43
+ timer_reset
44
+ end
45
+
46
+ #
47
+ def pass(test)
48
+ show_line(".", test, :green)
49
+ end
50
+
51
+ #
52
+ def fail(test, exception)
53
+ show_line("F", test, :red)
54
+ end
55
+
56
+ #
57
+ def error(test, exception)
58
+ show_line("E", test, :red)
59
+ end
60
+
61
+ #
62
+ def todo(test, exception)
63
+ show_line("P", test, :yellow)
64
+ end
65
+
66
+ #
67
+ def omit(test, exception)
68
+ show_line("O", test, :cyan)
69
+ end
70
+
71
+ #
72
+ def end_case(tcase)
73
+ @tab -= 2
74
+ end
75
+
76
+ #
77
+ def end_suite(suite)
78
+ puts
79
+
80
+ if runner.verbose?
81
+ unless record[:omit].empty?
82
+ puts "OMISSIONS:\n\n"
83
+ record[:omit].reverse_each do |test, exception|
84
+ s = []
85
+ s << "#{test}".ansi(:bold)
86
+ s << "#{file_and_line(exception)}"
87
+ puts s.join("\n").tabto(4)
88
+ puts code(exception).to_s.tabto(7)
89
+ puts
90
+ end
91
+ end
92
+ end
93
+
94
+ unless record[:todo].empty?
95
+ puts "PENDING:\n\n"
96
+ record[:todo].reverse_each do |test, exception|
97
+ s = []
98
+ s << "#{test}".ansi(:bold)
99
+ s << "#{file_and_line(exception)}"
100
+ puts s.join("\n").tabto(4)
101
+ puts code(exception).to_s.tabto(7)
102
+ puts
103
+ end
104
+ end
105
+
106
+ unless record[:fail].empty?
107
+ puts "FAILURES:\n\n"
108
+ record[:fail].reverse_each do |test, exception|
109
+ s = []
110
+ s << "#{test}".ansi(:bold)
111
+ s << "#{exception}".ansi(:red)
112
+ s << "#{file_and_line(exception)}"
113
+ puts s.join("\n").tabto(4)
114
+ puts code(exception).to_s.tabto(7)
115
+ #puts " #{exception.backtrace[0]}"
116
+ puts
117
+ end
118
+ end
119
+
120
+ unless record[:error].empty?
121
+ puts "ERRORS:\n\n"
122
+ record[:error].reverse_each do |test, exception|
123
+ trace = clean_backtrace(exception)[1..-1].map{ |bt| bt.sub(Dir.pwd+'/', '') }
124
+ s = []
125
+ s << "#{test}".ansi(:bold)
126
+ s << "#{exception.class}".ansi(:red)
127
+ s << "#{exception}".ansi(:red)
128
+ s << "#{file_and_line(exception)}"
129
+ puts s.join("\n").tabto(4)
130
+ puts code(exception).to_s.tabto(7)
131
+ puts trace.join("\n").tabto(4) unless trace.empty?
132
+ puts
133
+ end
134
+ end
135
+
136
+ puts
137
+ puts timestamp
138
+ puts
139
+ puts tally
140
+ end
141
+
142
+ private
143
+
144
+ #
145
+ def show_header(status, text)
146
+ text = text[0..text.index("\n")||-1]
147
+ data = [prcnt, ' ', ' ', clock, timer, status, (' ' * @tab) + text.to_s]
148
+ #puts (" " * @tab) + (@layout_head % data)
149
+ puts (@layout_head % data).ansi(:bold)
150
+ end
151
+
152
+ #
153
+ def show_line(status, test, color)
154
+ @count += 1
155
+ data = [prcnt, @count, @total_count, clock, timer, status, (' ' * @tab) + test.to_s]
156
+ #puts (" " * @tab) + (@layout % data)
157
+ puts (@layout % data).ansi(color)
158
+ end
159
+
160
+ #
161
+ def prcnt
162
+ ((@count.to_f / @total_count) * 100).round.to_s
163
+ end
164
+
165
+ #
166
+ def clock
167
+ secs = Time.now - @start_time
168
+ m, s = secs.divmod(60)
169
+ #s, ms = s.divmod(1)
170
+ #ms = ms * 1000
171
+ return "%u:%02u" % [m, s]
172
+ end
173
+
174
+ #
175
+ def timer
176
+ secs = Time.now - @time
177
+ @time = Time.now
178
+ return "%0.5fs" % secs
179
+ end
180
+
181
+ #
182
+ def timer_reset
183
+ @time = Time.now
184
+ end
185
+
186
+ #
187
+ def tabs(str=nil)
188
+ if str
189
+ puts(str.tabto(@tab))
190
+ else
191
+ puts
192
+ end
193
+ end
194
+
195
+ end
196
+
197
+ end
@@ -0,0 +1,145 @@
1
+ require 'test/reporters/abstract'
2
+
3
+ module Test::Reporters
4
+
5
+ # Summary Reporter
6
+ class Summary < Abstract
7
+
8
+ #
9
+ SEP = ' '
10
+
11
+ #
12
+ def begin_suite(suite)
13
+ timer_reset
14
+ @tc = []
15
+ end
16
+
17
+ #
18
+ def begin_case(tc)
19
+ @tc << tc.to_s.split("\n").first
20
+ end
21
+
22
+ #
23
+ #def report_instance(instance)
24
+ # puts
25
+ # puts instance #"== #{concern.description}\n\n" unless concern.description.empty?
26
+ # #timer_reset
27
+ #end
28
+
29
+ #
30
+ #def begin_test(test)
31
+ # context = test.context
32
+ # if @instance != context
33
+ # @context = context
34
+ # puts
35
+ # puts " #{context}"
36
+ # puts
37
+ # end
38
+ #end
39
+
40
+ #
41
+ def pass(test)
42
+ print "PASS ".ansi(:green, :bold)
43
+ e = @tc + [test.to_s]
44
+ puts e.join(SEP).ansi(:green)
45
+ end
46
+
47
+ #
48
+ def fail(test, exception)
49
+ print "FAIL ".ansi(:red, :bold)
50
+ e = @tc + [test.to_s]
51
+ puts e.join(SEP).ansi(:red)
52
+ end
53
+
54
+ #
55
+ def error(test, exception)
56
+ print "ERROR ".ansi(:red, :bold)
57
+ e = @tc + [test.to_s]
58
+ puts e.join(SEP).ansi(:red)
59
+ end
60
+
61
+ #
62
+ def todo(test, exception)
63
+ print "TODO ".ansi(:yellow, :bold)
64
+ e = @tc + [test.to_s]
65
+ puts e.join(SEP).ansi(:yellow)
66
+ end
67
+
68
+ #
69
+ def omit(test)
70
+ print "OMIT ".ansi(:cyan, :bold)
71
+ e = @tc + [test.to_s]
72
+ puts e.join(SEP).ansi(:cyan)
73
+ end
74
+
75
+ #
76
+ def skip_test(test)
77
+ print "SKIP ".ansi(:blue, :bold)
78
+ e = @tc + [test.to_s]
79
+ puts e.join(SEP).ansi(:blue)
80
+ end
81
+
82
+ #
83
+ def end_case(test_case)
84
+ @tc.pop
85
+ end
86
+
87
+ #
88
+ def end_suite(suite)
89
+ puts
90
+
91
+ unless record[:pending].empty?
92
+ puts "PENDING:\n\n"
93
+ record[:pending].each do |test, exception|
94
+ puts " #{test}"
95
+ puts " #{file_and_line(exception)}"
96
+ puts
97
+ end
98
+ end
99
+
100
+ unless record[:fail].empty?
101
+ puts "FAILURES:\n\n"
102
+ record[:fail].each do |test, exception|
103
+ puts " #{test}"
104
+ puts " #{file_and_line(exception)}"
105
+ puts " #{exception}"
106
+ puts code(exception).to_s
107
+ #puts " #{exception.backtrace[0]}"
108
+ puts
109
+ end
110
+ end
111
+
112
+ unless record[:error].empty?
113
+ puts "ERRORS:\n\n"
114
+ record[:error].each do |test, exception|
115
+ puts " #{test}"
116
+ puts " #{file_and_line(exception)}"
117
+ puts " #{exception}"
118
+ puts code(exception).to_s
119
+ #puts " #{exception.backtrace[0]}"
120
+ puts
121
+ end
122
+ end
123
+
124
+ puts timestamp
125
+ puts
126
+ puts tally
127
+ end
128
+
129
+ private
130
+
131
+ #
132
+ def timer
133
+ secs = Time.now - @time
134
+ @time = Time.now
135
+ return "%0.5fs" % [secs.to_s]
136
+ end
137
+
138
+ #
139
+ def timer_reset
140
+ @time = Time.now
141
+ end
142
+
143
+ end
144
+
145
+ end
@@ -0,0 +1,61 @@
1
+ require 'test/reporters/abstract'
2
+
3
+ module Test::Reporters
4
+
5
+ # Classic TAP Reporter
6
+ #
7
+ # This reporter conforms to v12 of TAP. It could do with some
8
+ # imporvements yet, and eventually upgraded to v13 of standard.
9
+ class Tap < Abstract
10
+
11
+ #
12
+ def begin_suite(suite)
13
+ @start_time = Time.now
14
+ @i = 0
15
+ @n = total_count(suite)
16
+ puts "1..#{@n}"
17
+ end
18
+
19
+ def begin_test(test)
20
+ @i += 1
21
+ end
22
+
23
+ #
24
+ def pass(test)
25
+ puts "ok #{@i} - #{test}"
26
+ end
27
+
28
+ #
29
+ def fail(test, exception)
30
+ puts "not ok #{@i} - #{test}"
31
+ puts " FAIL #{exception.class}"
32
+ puts " #{exception}"
33
+ puts " #{clean_backtrace(exception)[0]}"
34
+ end
35
+
36
+ #
37
+ def error(test, exception)
38
+ puts "not ok #{@i} - #{test}"
39
+ puts " ERROR #{exception.class}"
40
+ puts " #{exception}"
41
+ puts " " + clean_backtrace(exception).join("\n ")
42
+ end
43
+
44
+ #
45
+ def todo(test, exception)
46
+ puts "not ok #{@i} - #{test}"
47
+ puts " PENDING"
48
+ puts " #{clean_backtrace(exception)[1]}"
49
+ end
50
+
51
+ #
52
+ def omit(test, exception)
53
+ puts "ok #{@i} - #{test}"
54
+ puts " OMIT"
55
+ puts " #{clean_backtrace(exception)[1]}"
56
+ end
57
+
58
+ end
59
+
60
+ end
61
+
@@ -0,0 +1,53 @@
1
+ require 'test/reporters/hash'
2
+
3
+ module Test::Reporters
4
+
5
+ # TAP-J Reporter
6
+ #
7
+ class Tapj < AbstractHash
8
+
9
+ #
10
+ def initialize(runner)
11
+ require 'json'
12
+ super(runner)
13
+ end
14
+
15
+ #
16
+ def begin_suite(suite)
17
+ puts super(suite).to_json
18
+ end
19
+
20
+ #
21
+ def begin_case(test_case)
22
+ puts super(test_case).to_json
23
+ end
24
+
25
+ #
26
+ def pass(test) #, backtrace=nil)
27
+ puts super(test).to_json
28
+ end
29
+
30
+ #
31
+ def fail(test, exception)
32
+ puts super(test, exception).to_json
33
+ end
34
+
35
+ #
36
+ def error(test, exception)
37
+ puts super(test, exception).to_json
38
+ end
39
+
40
+ #
41
+ def todo(test, exception)
42
+ puts super(test, exception).to_json
43
+ end
44
+
45
+ #
46
+ def end_suite(suite)
47
+ puts super(suite).to_json
48
+ puts "..."
49
+ end
50
+
51
+ end
52
+
53
+ end