test 0.2.1 → 0.3.1

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.
@@ -1,224 +0,0 @@
1
- require 'test/reporters/abstract'
2
-
3
- module Test::Reporters
4
-
5
- # Hash Abstract is a base class for the TAP-Y
6
- # and TAP-J reporters.
7
- #
8
- class AbstractHash < Abstract
9
-
10
- #
11
- def begin_suite(suite)
12
- require 'yaml'
13
-
14
- @start_time = Time.now
15
- @case_level = 0
16
- @test_index = 0
17
-
18
- now = Time.now.strftime('%Y-%m-%d %H:%M:%S')
19
-
20
- h = {
21
- 'type' => 'suite',
22
- 'start' => now,
23
- 'count' => total_count(suite)
24
- }
25
-
26
- return h
27
- end
28
-
29
- #
30
- def begin_case(test_case)
31
- h = {}
32
- h['type' ] = 'case'
33
- h['level'] = @case_level
34
-
35
- merge_subtype h, test_case
36
- merge_setup h, test_case
37
- merge_description h, test_case
38
-
39
- @case_level += 1
40
-
41
- return h
42
- end
43
-
44
- #
45
- def begin_test(test)
46
- @test_index += 1
47
- end
48
-
49
- #
50
- def pass(test) #, backtrace=nil)
51
- h = {}
52
- h['type' ] = 'test'
53
- h['status'] = 'pass'
54
-
55
- merge_subtype h, test
56
- merge_setup h, test
57
- merge_description h, test
58
- #merge_comparison h, test, exception
59
- #merge_coverage h, test
60
- merge_source h, test
61
- merge_time h
62
-
63
- return h
64
- end
65
-
66
- #
67
- def fail(test, exception)
68
- h = {}
69
- h['type' ] = 'test'
70
- h['status'] = 'fail'
71
-
72
- merge_subtype h, test
73
- merge_setup h, test
74
- merge_description h, test
75
- #merge_comparison h, test, exception
76
- #merge_coverage h, test
77
- merge_source h, test
78
- merge_exception h, test, exception
79
- merge_time h
80
-
81
- return h
82
- end
83
-
84
- #
85
- def error(test, exception)
86
- h = {}
87
- h['type' ] = 'test'
88
- h['status'] = 'error'
89
-
90
- merge_subtype h, test
91
- merge_setup h, test
92
- merge_description h, test
93
- #merge_comparison h, test, exception
94
- #merge_coverage h, test
95
- merge_source h, test
96
- merge_exception h, test, exception, true
97
- merge_time h
98
-
99
- return h
100
- end
101
-
102
- #
103
- def todo(test, exception)
104
- h = {}
105
- h['type' ] = 'test'
106
- h['status'] = 'todo'
107
-
108
- merge_subtype h, test
109
- merge_setup h, test
110
- merge_description h, test
111
- #merge_comparison h, test, exception
112
- #merge_coverage h, test
113
- merge_source h, test
114
- merge_exception h, test, exception
115
- merge_time h
116
-
117
- return h
118
- end
119
-
120
- #
121
- def omit(test, exception)
122
- h = {}
123
- h['type' ] = 'test'
124
- h['status'] = 'omit'
125
-
126
- merge_subtype h, test
127
- merge_setup h, test
128
- merge_description h, test
129
- #merge_comparison h, test, exception
130
- #merge_coverage h, test
131
- merge_source h, test
132
- merge_exception h, test, exception
133
- merge_time h
134
-
135
- return h
136
- end
137
-
138
- #
139
- def end_case(test_case)
140
- @case_level -= 1
141
- end
142
-
143
- #
144
- def end_suite(suite)
145
- h = {
146
- 'type' => 'tally',
147
- 'time' => Time.now - @start_time,
148
- 'counts' => {
149
- 'total' => total,
150
- 'pass' => record[:pass].size,
151
- 'fail' => record[:fail].size,
152
- 'error' => record[:error].size,
153
- 'omit' => record[:omit].size,
154
- 'todo' => record[:todo].size
155
- }
156
- }
157
- return h
158
- end
159
-
160
- private
161
-
162
- #
163
- def merge_subtype(hash, test)
164
- hash['subtype'] = test.type.to_s if test.respond_to?(:type)
165
- end
166
-
167
- # TODO: topic or setup ?
168
- def merge_setup(hash, test)
169
- #hash['setup'] = test.setup.to_s if test.respond_to?(:setup)
170
- hash['setup'] = test.topic.to_s if test.respond_to?(:topic)
171
- end
172
-
173
- # Add test description to hash.
174
- def merge_description(hash, test)
175
- hash['description'] = test.to_s.strip
176
- end
177
-
178
- # NOTE: Not presently used.
179
- def merge_comparison(hash, test, exception)
180
- hash['returned'] = exception.returned
181
- hash['expected'] = exception.expected
182
- end
183
-
184
- # Add source location information to hash.
185
- def merge_source(hash, test)
186
- if test.respond_to?('source_location')
187
- file, line = source_location
188
- hash['file' ] = file
189
- hash['line' ] = line
190
- hash['source' ] = code(file, line).to_str
191
- hash['snippet'] = code(file, line).to_omap
192
- end
193
- end
194
-
195
- # Add exception subsection of hash.
196
- def merge_exception(hash, test, exception, bt=false)
197
- hash['exception'] = {}
198
- hash['exception']['file' ] = code(exception).file
199
- hash['exception']['line' ] = code(exception).line
200
- hash['exception']['source' ] = code(exception).to_str
201
- hash['exception']['snippet' ] = code(exception).to_omap
202
- hash['exception']['message' ] = exception.message
203
- hash['exception']['backtrace'] = clean_backtrace(exception) if bt
204
- end
205
-
206
- # TODO: Really?
207
- def merge_coverage(hash, test)
208
- if test.respond_to?(:file_coverage) or test.respond_to?(:code_coverage)
209
- fc = test.file_coverage
210
- cc = test.code_coverage
211
- hash['coverage'] = {}
212
- hash['coverage']['file'] = fc if fc
213
- hash['coverage']['code'] = cc if cc
214
- end
215
- end
216
-
217
- #
218
- def merge_time(hash)
219
- hash['time'] = Time.now - @start_time
220
- end
221
-
222
- end
223
-
224
- end
@@ -1,89 +0,0 @@
1
- require 'test/reporters/abstract'
2
-
3
- module Test::Reporters
4
-
5
- # Simple Dot-Progress Reporter
6
- class Dotprogress < Abstract
7
-
8
- def pass(unit)
9
- print "."
10
- $stdout.flush
11
- end
12
-
13
- def fail(unit, exception)
14
- print "F".ansi(:red)
15
- $stdout.flush
16
- end
17
-
18
- def error(unit, exception)
19
- print "E".ansi(:red, :bold)
20
- $stdout.flush
21
- end
22
-
23
- def todo(unit, exception)
24
- print "P".ansi(:yellow)
25
- $stdout.flush
26
- end
27
-
28
- def omit(unit, exception)
29
- print "O".ansi(:cyan)
30
- $stdout.flush
31
- end
32
-
33
- def end_suite(suite)
34
- puts; puts
35
- puts timestamp
36
- puts
37
-
38
- if runner.verbose?
39
- unless record[:omit].empty?
40
- puts "OMISSIONS\n\n"
41
- record[:omit].each do |test, exception|
42
- puts " #{test}".ansi(:bold)
43
- puts " #{exception}"
44
- puts " #{file_and_line(exception)}"
45
- #puts code(exception)
46
- puts
47
- end
48
- end
49
- end
50
-
51
- unless record[:todo].empty?
52
- puts "PENDING\n\n"
53
- record[:todo].each do |test, exception|
54
- puts " #{test}".ansi(:bold) unless test.to_s.empty?
55
- puts " #{exception}"
56
- puts " #{file_and_line(exception)}"
57
- puts code(exception)
58
- puts
59
- end
60
- end
61
-
62
- unless record[:fail].empty?
63
- puts "FAILURES\n\n"
64
- record[:fail].each do |test_unit, exception|
65
- puts " #{test_unit}".ansi(:bold)
66
- puts " #{exception}"
67
- puts " #{file_and_line(exception)}"
68
- puts code(exception)
69
- puts
70
- end
71
- end
72
-
73
- unless record[:error].empty?
74
- puts "ERRORS\n\n"
75
- record[:error].each do |test_unit, exception|
76
- puts " #{test_unit}".ansi(:bold)
77
- puts " #{exception}"
78
- puts " #{file_and_line(exception)}"
79
- puts code(exception)
80
- puts
81
- end
82
- end
83
-
84
- puts tally
85
- end
86
-
87
- end
88
-
89
- end
@@ -1,155 +0,0 @@
1
- require 'test/reporters/abstract'
2
-
3
- module Test::Reporters
4
-
5
- # HTML Test Reporter
6
- #
7
- # This reporter is rather simplistic and rough at this point --in need
8
- # of some TLC. Also, it may move to the TAPOUT project rather than be
9
- # a built-in Ruby-Test reporter.
10
- #--
11
- # TODO: Make this more like a microformat and add timer info.
12
- #++
13
- class Html < Abstract
14
-
15
- #
16
- def begin_suite(suite)
17
- timer_reset
18
-
19
- @html = []
20
- @html << %[<html>]
21
- @html << %[<head>]
22
- @html << %[<title>Test Report</title>]
23
- @html << %[ <style>]
24
- @html << %[ html{ background: #fff; margin: 0; padding: 0; font-family: helvetica; }]
25
- @html << %[ body{ margin: 0; padding: 0;}]
26
- @html << %[ h3{color:#555;}]
27
- @html << %[ #main{ margin: 0 auto; color: #110; width: 600px; ]
28
- @html << %[ border-right: 1px solid #ddd; border-left: 1px solid #ddd; ]
29
- @html << %[ padding: 10px 30px; width: 500px; } ]
30
- @html << %[ .lemon{ color: gold; font-size: 22px; font-weight: bold; ]
31
- @html << %[ font-family: courier; margin-bottom: -15px;}]
32
- @html << %[ .tally{ font-weight: bold; margin-bottom: 10px; }]
33
- @html << %[ .omit{ color: cyan; }]
34
- @html << %[ .pass{ color: green; }]
35
- @html << %[ .fail{ color: red; }]
36
- @html << %[ .footer{ font-size: 0.7em; color: #666; margin: 20px 0; }]
37
- @html << %[ </style>]
38
- @html << %[</head>]
39
- @html << %[<body>]
40
- @html << %[<div id="main">]
41
- @html << %[<div class="lemon">R U B Y - T E S T</div>]
42
- @html << %[<h1>Test Report</h1>]
43
- @body = []
44
- end
45
-
46
- #
47
- def begin_case(tc)
48
- lines = tc.to_s.split("\n")
49
- title = lines.shift
50
- @body << "<h2>"
51
- @body << title
52
- @body << "</h2>"
53
- @body << "<div>"
54
- @body << lines.join("<br/>")
55
- @body << "</div>"
56
- end
57
-
58
- #
59
- def begin_test(test)
60
- if test.respond_to?(:topic)
61
- topic = test.topic
62
- if @topic != topic
63
- @topic = topic
64
- @body << "<h3>"
65
- @body << "#{topic}"
66
- @body << "</h3>"
67
- end
68
- end
69
- end
70
-
71
- #
72
- def pass(test)
73
- @body << %[<li class="pass">]
74
- @body << "%s %s" % ["PASS", test.to_s]
75
- @body << %[</li>]
76
- end
77
-
78
- #
79
- def fail(test, exception)
80
- @body << %[<li class="fail">]
81
- @body << "%s %s" % ["FAIL", test.to_s]
82
- @body << "<pre>"
83
- @body << " FAIL #{clean_backtrace(exception)[0]}"
84
- @body << " #{exception}"
85
- @body << "</pre>"
86
- @body << %[</li>]
87
- end
88
-
89
- #
90
- def error(test, exception)
91
- @body << %[<li class="error">]
92
- @body << "%s %s" % ["ERROR", test.to_s]
93
- @body << "<pre>"
94
- @body << " ERROR #{exception.class}"
95
- @body << " #{exception}"
96
- @body << " " + clean_backtrace(exception).join("\n ")
97
- @body << "</pre>"
98
- @body << %[</li>]
99
- end
100
-
101
- #
102
- def todo(test, exception)
103
- @body << %[<li class="pending">]
104
- @body << "%s %s" % ["PENDING", test.to_s]
105
- @body << %[</li>]
106
- end
107
-
108
- #
109
- def omit(test, exception)
110
- @body << %[<li class="omit">]
111
- @body << "%s %s" % ["OMIT", test.to_s]
112
- @body << %[</li>]
113
- end
114
-
115
- #
116
- def end_suite(suite)
117
- @html << ""
118
- @html << %[<div class="tally">]
119
- @html << tally
120
- @html << %[</div>]
121
- @html << ""
122
-
123
- @body << ""
124
- @body << %[<div class="footer">]
125
- @body << %[Generated by <a href="http://rubyworks.github.com/test">Lemon</a>]
126
- @body << %[on #{Time.now}.]
127
- @body << %[</div>]
128
- @body << ""
129
- @body << %[</div>]
130
- @body << %[</div>]
131
- @body << ""
132
- @body << %[</body>]
133
- @body << %[</html>]
134
-
135
- puts @html.join("\n")
136
- puts @body.join("\n")
137
- end
138
-
139
- private
140
-
141
- #
142
- def timer
143
- secs = Time.now - @time
144
- @time = Time.now
145
- return "%0.5fs" % [secs.to_s]
146
- end
147
-
148
- #
149
- def timer_reset
150
- @time = Time.now
151
- end
152
-
153
- end
154
-
155
- end