author | Claus Gittinger <cg@exept.de> |
Sat, 30 Jul 2011 10:32:26 +0200 | |
changeset 268 | 02c41854a7b8 |
parent 267 | 7d2e67524850 |
child 272 | 492c13b42f3b |
permissions | -rw-r--r-- |
222 | 1 |
"{ Package: 'stx:goodies/sunit' }" |
2 |
||
3 |
Object subclass:#TestResultReporter |
|
4 |
instanceVariableNames:'result stream' |
|
5 |
classVariableNames:'' |
|
6 |
poolDictionaries:'' |
|
7 |
category:'SUnit-Report' |
|
8 |
! |
|
9 |
||
267 | 10 |
!TestResultReporter class methodsFor:'documentation'! |
11 |
||
12 |
documentation |
|
13 |
" |
|
268
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
14 |
Currently supported formats are: |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
15 |
#xml - a junit-like format |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
16 |
#tap - perl TAP unit test format; very naive and simple, |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
17 |
but there are tools for it... |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
18 |
|
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
19 |
public API entry: |
267 | 20 |
|aTestResult| |
21 |
||
22 |
aTestResult := aUnitTest suite run. |
|
23 |
TestResultReporter report:aTestResult format:#xml on: aStream |
|
268
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
24 |
|
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
25 |
[author:] |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
26 |
Jan Vranji |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
27 |
documentation & tap format added by Claus Gittinger |
267 | 28 |
" |
29 |
! |
|
30 |
||
31 |
examples |
|
32 |
" |
|
33 |
|testResult| |
|
34 |
||
35 |
testResult := RegressionTests::IntegerTest suite run. |
|
268
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
36 |
TestResultReporter report:testResult format:#xml on:Transcript. |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
37 |
TestResultReporter report:testResult format:#tap on:Transcript. |
267 | 38 |
" |
39 |
! ! |
|
40 |
||
268
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
41 |
!TestResultReporter class methodsFor:'queries'! |
267 | 42 |
|
268
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
43 |
supportedFormats |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
44 |
^ #( |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
45 |
(#'xml' 'a junit-like format') |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
46 |
(#'tap' 'perl TAP unit test format') |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
47 |
) |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
48 |
|
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
49 |
"Created: / 30-07-2011 / 10:18:18 / cg" |
267 | 50 |
! ! |
222 | 51 |
|
52 |
!TestResultReporter class methodsFor:'reporting'! |
|
53 |
||
54 |
report: aTestResult format: format as: stringOrFilename |
|
55 |
||
56 |
self new report: aTestResult format: format as: stringOrFilename |
|
57 |
! |
|
58 |
||
59 |
report: aTestResult format: format on: stream |
|
60 |
||
61 |
self new report: aTestResult format: format on: stream |
|
267 | 62 |
|
63 |
" |
|
64 |
self report:(RegressionTests::IntegerTest runTests) format:#xml on:Transcript |
|
65 |
" |
|
66 |
||
67 |
"Modified (comment): / 30-07-2011 / 09:37:53 / cg" |
|
222 | 68 |
! ! |
69 |
||
70 |
!TestResultReporter methodsFor:'reporting'! |
|
71 |
||
267 | 72 |
report:formatSymbol |
73 |
"currently supported formatSymbols: |
|
74 |
xml" |
|
75 |
||
222 | 76 |
|reportFormatSelector| |
77 |
||
267 | 78 |
reportFormatSelector := self reportFormatSelector:formatSymbol. |
222 | 79 |
(self respondsTo: reportFormatSelector) |
267 | 80 |
ifTrue:[self perform: reportFormatSelector] |
81 |
ifFalse:[self error:'Unsupported format: ', formatSymbol]. |
|
82 |
||
83 |
"Modified (comment): / 30-07-2011 / 09:37:31 / cg" |
|
222 | 84 |
! |
85 |
||
86 |
report: aTestResult format: format as: stringOrFilename |
|
87 |
||
88 |
| s | |
|
89 |
s := stringOrFilename asFilename writeStream. |
|
90 |
[ self report: aTestResult format: format on: s] |
|
91 |
ensure:[s close]. |
|
92 |
! |
|
93 |
||
94 |
report: aTestResult format: aSymbol on: aStream |
|
95 |
||
96 |
result := aTestResult. |
|
97 |
stream := aStream. |
|
98 |
self report: aSymbol |
|
99 |
! |
|
100 |
||
101 |
reportFormatSelector:format |
|
102 |
^ ('report' , format asString capitalized) asSymbol |
|
103 |
! ! |
|
104 |
||
268
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
105 |
!TestResultReporter methodsFor:'reporting - tap'! |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
106 |
|
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
107 |
reportTap |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
108 |
"TAP (perl unit test) report format" |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
109 |
|
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
110 |
|idx reportWith| |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
111 |
|
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
112 |
"example: |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
113 |
1..4 |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
114 |
ok 1 - Input file opened |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
115 |
not ok 2 - First line of the input valid |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
116 |
ok 3 - Read the rest of the file |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
117 |
not ok 4 - Summarized correctly # TODO Not written yet |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
118 |
" |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
119 |
|
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
120 |
"/ what about not-executed tests - why only runCount ? |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
121 |
stream nextPutLine: ('1..%1' bindWith:result runCount). |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
122 |
|
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
123 |
reportWith := |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
124 |
[:tests :status | |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
125 |
tests do:[:each | self reportTapTest: each index: idx result: status. idx := idx + 1 ] |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
126 |
]. |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
127 |
|
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
128 |
idx := 1. |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
129 |
reportWith value:result passed value:#success. |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
130 |
reportWith value:result failures value:#failure. |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
131 |
reportWith value:result errors value:#error. |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
132 |
|
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
133 |
"Created: / 30-07-2011 / 10:12:31 / cg" |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
134 |
! |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
135 |
|
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
136 |
reportTapTest: test index:index result: testResult |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
137 |
| testClassName executionTime testDescription statusString| |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
138 |
|
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
139 |
testClassName := self sunitNameOf: test class. |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
140 |
|
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
141 |
"most tests do not know, and return nil here!!" |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
142 |
executionTime := test executionTime ? 0.0. |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
143 |
|
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
144 |
testDescription := '%1-%2 (%3ms)' |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
145 |
bindWith:testClassName |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
146 |
with:test selector |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
147 |
with:executionTime. |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
148 |
|
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
149 |
statusString := (testResult == #success) |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
150 |
ifTrue:['ok'] |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
151 |
ifFalse:['not ok']. |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
152 |
|
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
153 |
stream nextPutLine:('%1 %2 - %3' |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
154 |
bindWith:statusString |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
155 |
with:index |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
156 |
with:testDescription). |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
157 |
|
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
158 |
"Created: / 30-07-2011 / 10:28:06 / cg" |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
159 |
! ! |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
160 |
|
222 | 161 |
!TestResultReporter methodsFor:'reporting - xml'! |
162 |
||
163 |
reportXml |
|
267 | 164 |
"JUnit-like XML unittest report format" |
222 | 165 |
|
166 |
stream |
|
267 | 167 |
nextPutLine: '<?xml version="1.0"?>'; |
168 |
nextPutLine: '<unittest-results>'. |
|
222 | 169 |
|
170 |
result passed do:[:each|self reportXmlTest: each result: #success]. |
|
171 |
result failures do:[:each|self reportXmlTest: each result: #failure]. |
|
172 |
result errors do:[:each|self reportXmlTest: each result: #error]. |
|
173 |
||
174 |
stream |
|
267 | 175 |
nextPutLine: '</unittest-results>' |
176 |
||
177 |
"Modified (format): / 30-07-2011 / 09:54:16 / cg" |
|
222 | 178 |
! |
179 |
||
180 |
reportXmlTest: test result: testResult |
|
181 |
||
182 |
" |
|
183 |
Example: |
|
184 |
<test |
|
267 | 185 |
duration='0.0188629627228' |
186 |
status='error' |
|
187 |
fixture='bitten.tests.web_ui.SourceFileLinkFormatterTestCase' |
|
188 |
name='test_format_link_not_in_repos_with_line' |
|
189 |
file='/usr/src/trac-bitten-0.6b2.dfsg/bitten/tests/web_ui.py'> |
|
222 | 190 |
" |
191 |
||
267 | 192 |
| testClassName executionTime | |
193 |
||
222 | 194 |
testClassName := self sunitNameOf: test class. |
195 |
||
267 | 196 |
"most tests do not know, and return nil here!!" |
197 |
executionTime := test executionTime ? 0.0. |
|
198 |
||
222 | 199 |
stream |
267 | 200 |
nextPutAll:'<test duration="'; nextPutAll:executionTime; nextPutLine:'"'; |
201 |
tab; nextPutAll:'status="'; nextPutAll: testResult; nextPutLine:'"'; |
|
202 |
tab; nextPutAll:'ficture="'; nextPutAll: testClassName; nextPutLine:'"'; |
|
203 |
tab; nextPutAll:'name="'; nextPutAll: test selector; nextPutLine:'"'; |
|
204 |
"It seems that some tools requires the file attributes. So we supply one :-)" |
|
205 |
tab; nextPutAll:'file="'; nextPutAll: testClassName , '.st'; nextPutLine:'">'. |
|
222 | 206 |
|
207 |
testResult ~= #success ifTrue:[self reportXmlTraceback: test]. |
|
208 |
||
209 |
stream nextPutLine:'</test>'. |
|
267 | 210 |
|
211 |
"Modified: / 30-07-2011 / 10:10:02 / cg" |
|
222 | 212 |
! |
213 |
||
214 |
reportXmlTraceback: test |
|
215 |
||
216 |
" |
|
217 |
Prints a traceback to the stream. |
|
218 |
This is dialect-specific, so we have to check... |
|
219 |
" |
|
220 |
||
221 |
"Smalltalk/X dialect detection..." |
|
222 |
((Smalltalk respondsTo: #isSmalltalkX) and:[Smalltalk isSmalltalkX]) |
|
223 |
ifTrue:[^self reportXmlTracebackStX: test] |
|
224 |
! |
|
225 |
||
226 |
reportXmlTracebackStX: test |
|
227 |
||
228 |
stream nextPutLine:'<traceback><!![CDATA['. |
|
229 |
||
230 |
[ test debug ] |
|
231 |
on: GenericException |
|
232 |
do: [:ex| |
|
233 |
ex suspendedContext fullPrintAllOn: stream]. |
|
234 |
||
235 |
stream nextPutLine:']]></traceback>'. |
|
236 |
||
237 |
"Modified: / 07-12-2009 / 14:06:48 / Jan Vrany <jan.vrant@fit.cvut.cz>" |
|
238 |
! ! |
|
239 |
||
240 |
!TestResultReporter methodsFor:'utilities'! |
|
241 |
||
242 |
sunitNameOf: aClass |
|
243 |
||
244 |
"No all SUnit versions comes with sunitName |
|
245 |
(at least Smalltalk/X 3.1)" |
|
246 |
||
247 |
^(aClass respondsTo:#sunitName) |
|
248 |
ifTrue:[aClass sunitName] |
|
249 |
ifFalse:[aClass printString] |
|
250 |
! ! |
|
251 |
||
252 |
!TestResultReporter class methodsFor:'documentation'! |
|
253 |
||
254 |
version |
|
268
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
255 |
^ '$Header: /cvs/stx/stx/goodies/sunit/TestResultReporter.st,v 1.3 2011-07-30 08:32:26 cg Exp $' |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
256 |
! |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
257 |
|
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
258 |
version_CVS |
02c41854a7b8
added tap (perl unit test) output format
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
259 |
^ '$Header: /cvs/stx/stx/goodies/sunit/TestResultReporter.st,v 1.3 2011-07-30 08:32:26 cg Exp $' |
222 | 260 |
! |
261 |
||
262 |
version_SVN |
|
263 |
^ '§Id§' |
|
264 |
! ! |