author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Fri, 05 Jul 2013 18:15:04 +0200 | |
changeset 191 | cc00c3e2019c |
parent 104 | 7b1b26108f1f |
child 235 | 3769ae14139a |
permissions | -rw-r--r-- |
67 | 1 |
"{ Package: 'stx:goodies/builder/reports' }" |
2 |
||
3 |
"{ NameSpace: Builder }" |
|
4 |
||
5 |
ReportFormat subclass:#TestReportFormat |
|
6 |
instanceVariableNames:'' |
|
7 |
classVariableNames:'' |
|
8 |
poolDictionaries:'' |
|
9 |
category:'Builder-Reports-Formats' |
|
10 |
! |
|
11 |
||
12 |
TestReportFormat subclass:#JUnit |
|
104
7b1b26108f1f
Added support for skipped/ignored tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
91
diff
changeset
|
13 |
instanceVariableNames:'position failures errors skipped startTime stopTime' |
67 | 14 |
classVariableNames:'' |
15 |
poolDictionaries:'' |
|
16 |
privateIn:TestReportFormat |
|
17 |
! |
|
18 |
||
19 |
TestReportFormat subclass:#PerfPublisher |
|
20 |
instanceVariableNames:'' |
|
21 |
classVariableNames:'' |
|
22 |
poolDictionaries:'' |
|
23 |
privateIn:TestReportFormat |
|
24 |
! |
|
25 |
||
26 |
TestReportFormat subclass:#PythonUnittest |
|
27 |
instanceVariableNames:'index' |
|
28 |
classVariableNames:'' |
|
29 |
poolDictionaries:'' |
|
30 |
privateIn:TestReportFormat |
|
31 |
! |
|
32 |
||
33 |
TestReportFormat subclass:#TAP |
|
34 |
instanceVariableNames:'index' |
|
35 |
classVariableNames:'' |
|
36 |
poolDictionaries:'' |
|
37 |
privateIn:TestReportFormat |
|
38 |
! |
|
39 |
||
40 |
||
41 |
!TestReportFormat class methodsFor:'testing'! |
|
42 |
||
43 |
isAbstract |
|
44 |
||
45 |
^self == TestReportFormat |
|
46 |
||
47 |
"Created: / 04-08-2011 / 11:44:25 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
48 |
! ! |
|
49 |
||
50 |
!TestReportFormat methodsFor:'accessing - defaults'! |
|
51 |
||
52 |
defaultFileSuffix |
|
53 |
"superclass HDReportFormat says that I am responsible to implement this method" |
|
54 |
||
55 |
^ 'xml' |
|
56 |
||
57 |
"Modified: / 04-08-2011 / 12:48:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
58 |
! ! |
|
59 |
||
60 |
!TestReportFormat methodsFor:'writing'! |
|
61 |
||
62 |
writeTestCase: testcase outcome: outcome time: time exception: exception |
|
63 |
||
64 |
| stacktrace | |
|
65 |
exception isNil ifTrue:[ |
|
66 |
stacktrace := nil. |
|
67 |
] ifFalse:[ |
|
68 |
stacktrace := |
|
69 |
(String streamContents:[:s| |
|
70 |
self writeStackTrace: exception of: testcase on: s |
|
71 |
]) |
|
72 |
]. |
|
73 |
||
74 |
^self writeTestCase: testcase outcome: outcome time: time exception: exception |
|
75 |
stacktrace: stacktrace |
|
76 |
||
77 |
"Created: / 03-08-2011 / 19:44:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
78 |
! |
|
79 |
||
80 |
writeTestCase: testcase outcome: outcome time: time exception: exception stacktrace: stacktrace |
|
81 |
||
82 |
"Write an outcome of a given test. |
|
83 |
Argumments: |
|
84 |
testcase....the testcase |
|
85 |
outcome.....one of #pass, #failure, #error |
|
86 |
time........time taken to run the test in milliseconds |
|
87 |
exception...exception that caused error/failure or nil if N/A |
|
88 |
backtrace...stacktrace info or nil if N/A" |
|
89 |
||
90 |
self subclassResponsibility |
|
91 |
||
92 |
"Created: / 03-08-2011 / 19:43:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
93 |
! ! |
|
94 |
||
95 |
!TestReportFormat methodsFor:'writing - utilities'! |
|
96 |
||
97 |
writeContext: context on: s |
|
98 |
||
99 |
|home mthd src| |
|
100 |
[ |
|
101 |
context printOn: s. |
|
102 |
s cr. |
|
86 | 103 |
s nextPutAll:'receiver: '. context receiver printOn: s. s cr. |
104 |
s nextPutAll:'selector: '. context selector printOn: s. s cr. |
|
67 | 105 |
s nextPutAll:'args: '; cr. |
106 |
context args keysAndValuesDo:[:idx :eachArg | |
|
86 | 107 |
s nextPutAll:' '. idx printOn: s. s nextPutAll:': '. eachArg printOn: s.s cr. |
67 | 108 |
]. |
109 |
s nextPutAll:'vars: '; cr. |
|
110 |
context vars keysAndValuesDo:[:idx :eachVar | |
|
91 | 111 |
s nextPutAll:' '. idx printOn: s. s nextPutAll:': '. |
112 |
eachVar isString ifTrue:[ |
|
113 |
eachVar storeOn: s. |
|
114 |
] ifFalse:[ |
|
115 |
eachVar printOn: s. |
|
116 |
]. |
|
117 |
s cr. |
|
67 | 118 |
]. |
119 |
s nextPutAll:'source: '; cr. |
|
120 |
||
121 |
[ |
|
122 |
home := context methodHome. |
|
123 |
mthd := home method. |
|
124 |
mthd isNil ifTrue:[ |
|
125 |
s nextPutAll: '** no source **'. s cr. s cr. |
|
126 |
^ self. |
|
127 |
]. |
|
128 |
src := mthd source. |
|
129 |
src isNil ifTrue:[ |
|
130 |
s nextPutAll: '** no source **'. s cr. s cr. |
|
131 |
^ self. |
|
132 |
]. |
|
133 |
] on: Error do:[:ex| |
|
134 |
s |
|
135 |
nextPutAll: '** error when getting source: '; |
|
136 |
nextPutAll: ex description; |
|
137 |
nextPutAll: '**'; |
|
138 |
cr; cr. |
|
139 |
^ self. |
|
140 |
]. |
|
141 |
src := src asCollectionOfLines. |
|
142 |
src keysAndValuesDo:[:lNr :line | |
|
143 |
lNr == context lineNumber ifTrue:[ |
|
144 |
s nextPutAll:'>> '. |
|
145 |
] ifFalse:[ |
|
146 |
s nextPutAll:' '. |
|
147 |
]. |
|
148 |
s nextPutAll: line; cr. |
|
149 |
]. |
|
150 |
s cr. |
|
151 |
] on: Error do:[:ex| |
|
152 |
s cr; |
|
153 |
nextPutAll:'!!!!!!ERROR WHEN GETTING STACK TRACE!!!!!!'; cr; |
|
154 |
nextPutAll: ex description; cr |
|
155 |
] |
|
156 |
||
157 |
"Created: / 03-08-2011 / 14:53:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
158 |
! |
|
159 |
||
160 |
writeStackTrace:err of:aTestCase on: str |
|
161 |
||
91 | 162 |
| context stop | |
67 | 163 |
|
164 |
context := err signalerContext. |
|
91 | 165 |
stop := false. |
166 |
||
167 |
[ context notNil ] whileTrue:[ |
|
168 |
self writeContext: context on: str. |
|
169 |
str cr; cr. |
|
170 |
||
171 |
context receiver == aTestCase ifTrue:[ |
|
172 |
context selector == aTestCase selector ifTrue:[ ^ self ]. |
|
173 |
context selector == #setUp ifTrue:[ ^ self ]. |
|
174 |
]. |
|
175 |
context := context sender. |
|
176 |
||
177 |
]. |
|
67 | 178 |
|
179 |
"Created: / 03-08-2011 / 14:53:42 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
180 |
! ! |
|
181 |
||
182 |
!TestReportFormat::JUnit class methodsFor:'accessing'! |
|
183 |
||
184 |
symbolicNames |
|
185 |
^ #( #junit #junit40 ) |
|
186 |
||
187 |
"Created: / 04-08-2011 / 11:45:07 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
188 |
! ! |
|
189 |
||
190 |
!TestReportFormat::JUnit class methodsFor:'documentation'! |
|
191 |
||
192 |
version_SVN |
|
191
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
193 |
^ '$Id$' |
67 | 194 |
! ! |
195 |
||
196 |
!TestReportFormat::JUnit methodsFor:'initialization'! |
|
197 |
||
198 |
initialize |
|
199 |
||
200 |
super initialize. |
|
201 |
errors := 0. |
|
202 |
failures := 0. |
|
104
7b1b26108f1f
Added support for skipped/ignored tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
91
diff
changeset
|
203 |
skipped := 0. |
67 | 204 |
|
205 |
"Created: / 03-08-2011 / 15:26:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
104
7b1b26108f1f
Added support for skipped/ignored tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
91
diff
changeset
|
206 |
"Modified: / 21-11-2012 / 15:33:47 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
67 | 207 |
! ! |
208 |
||
209 |
!TestReportFormat::JUnit methodsFor:'writing'! |
|
210 |
||
211 |
writeFooter |
|
212 |
stopTime := OperatingSystem getMillisecondTime. |
|
213 |
stream |
|
214 |
tab; |
|
215 |
nextPutAll:'<system-out><!![CDATA[]]></system-out>'; |
|
216 |
nextPut:Character lf. |
|
217 |
stream |
|
218 |
tab; |
|
219 |
nextPutAll:'<system-err><!![CDATA[]]></system-err>'; |
|
220 |
nextPut:Character lf. |
|
221 |
stream nextPutAll:'</testsuite>'. |
|
222 |
stream stream position:position. |
|
223 |
stream |
|
224 |
nextPutAll:' failures="'; |
|
225 |
print:failures; |
|
226 |
nextPutAll:'" errors="'; |
|
227 |
print:errors; |
|
104
7b1b26108f1f
Added support for skipped/ignored tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
91
diff
changeset
|
228 |
nextPutAll:'" skipped="'; |
7b1b26108f1f
Added support for skipped/ignored tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
91
diff
changeset
|
229 |
print:skipped; |
67 | 230 |
nextPutAll:'" time="'; |
231 |
print:(Time milliseconds:stopTime since:startTime) / 1000.0; |
|
232 |
nextPutAll:'">'. |
|
233 |
stream close. |
|
234 |
||
235 |
"Created: / 03-08-2011 / 14:22:37 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
104
7b1b26108f1f
Added support for skipped/ignored tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
91
diff
changeset
|
236 |
"Modified: / 21-11-2012 / 15:34:32 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
67 | 237 |
! |
238 |
||
239 |
writeHeader |
|
240 |
stream |
|
241 |
nextPutAll:'<?xml version="1.0" encoding="UTF-8"?>'; |
|
242 |
nextPut:Character lf. |
|
243 |
stream |
|
244 |
nextPutAll:'<testsuite name="'; |
|
245 |
nextPutAll:(Report encode:report name); |
|
246 |
nextPutAll:'" tests="'; |
|
247 |
print:report suite testCount; |
|
248 |
nextPutAll:'">'. |
|
249 |
"Now this is ugly. We want to update the time and the number of failures and errors, but still at the same time stream a valid XML. So remember this position and add some whitespace, that we can fill later." |
|
250 |
position := stream stream position - 1. |
|
251 |
stream |
|
252 |
nextPutAll:(String new:100 withAll:$ ); |
|
253 |
nextPut:Character lf. |
|
254 |
startTime := OperatingSystem getMillisecondTime. |
|
255 |
||
256 |
"Created: / 03-08-2011 / 19:14:37 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
257 |
! |
|
258 |
||
259 |
writeTestCase:testcase outcome:outcome time:time exception: exception stacktrace:stacktrace |
|
260 |
||
261 |
outcome == #failure ifTrue:[failures := failures + 1]. |
|
262 |
outcome == #error ifTrue:[errors := errors + 1]. |
|
104
7b1b26108f1f
Added support for skipped/ignored tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
91
diff
changeset
|
263 |
outcome == #skip ifTrue:[skipped := skipped + 1]. |
67 | 264 |
|
265 |
stream tab; |
|
266 |
nextPutAll: '<testcase classname="'; |
|
267 |
nextPutAll: (self encode: testcase nameForHDTestReport); |
|
268 |
nextPutAll: '" name="'; |
|
269 |
nextPutAll: (self encode: testcase selectorForHDTestReport); |
|
270 |
nextPutAll: '" time="'; print: (time ? 0) / 1000.0; nextPutAll: '">'; cr. |
|
271 |
||
104
7b1b26108f1f
Added support for skipped/ignored tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
91
diff
changeset
|
272 |
outcome == #skip ifTrue:[ |
7b1b26108f1f
Added support for skipped/ignored tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
91
diff
changeset
|
273 |
stream tab; tab; nextPutAll: '<skipped/>'. |
7b1b26108f1f
Added support for skipped/ignored tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
91
diff
changeset
|
274 |
] ifFalse:[ |
7b1b26108f1f
Added support for skipped/ignored tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
91
diff
changeset
|
275 |
outcome ~~ #pass ifTrue:[ |
7b1b26108f1f
Added support for skipped/ignored tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
91
diff
changeset
|
276 |
| type message | |
67 | 277 |
|
104
7b1b26108f1f
Added support for skipped/ignored tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
91
diff
changeset
|
278 |
exception isNil ifTrue:[ |
7b1b26108f1f
Added support for skipped/ignored tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
91
diff
changeset
|
279 |
type := 'unknown exception'. |
7b1b26108f1f
Added support for skipped/ignored tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
91
diff
changeset
|
280 |
message := 'unknown exception occured (no exception details available)' |
7b1b26108f1f
Added support for skipped/ignored tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
91
diff
changeset
|
281 |
] ifFalse:[ |
7b1b26108f1f
Added support for skipped/ignored tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
91
diff
changeset
|
282 |
type := exception class name. |
7b1b26108f1f
Added support for skipped/ignored tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
91
diff
changeset
|
283 |
message := exception messageText ifNil:[ exception description ]. |
7b1b26108f1f
Added support for skipped/ignored tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
91
diff
changeset
|
284 |
]. |
7b1b26108f1f
Added support for skipped/ignored tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
91
diff
changeset
|
285 |
|
67 | 286 |
|
104
7b1b26108f1f
Added support for skipped/ignored tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
91
diff
changeset
|
287 |
stream tab; tab; |
7b1b26108f1f
Added support for skipped/ignored tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
91
diff
changeset
|
288 |
nextPut:$<; nextPutAll: outcome; |
7b1b26108f1f
Added support for skipped/ignored tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
91
diff
changeset
|
289 |
nextPutAll:' type="'; |
7b1b26108f1f
Added support for skipped/ignored tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
91
diff
changeset
|
290 |
nextPutAll:(self encode:type); |
7b1b26108f1f
Added support for skipped/ignored tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
91
diff
changeset
|
291 |
nextPutAll:'" message="'; |
7b1b26108f1f
Added support for skipped/ignored tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
91
diff
changeset
|
292 |
nextPutAll:(self encode: message); |
7b1b26108f1f
Added support for skipped/ignored tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
91
diff
changeset
|
293 |
nextPutAll:'"><!![CDATA['; cr. |
191
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
294 |
self writeCDATA: (stacktrace ? 'stacktrace not available'). |
104
7b1b26108f1f
Added support for skipped/ignored tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
91
diff
changeset
|
295 |
stream |
7b1b26108f1f
Added support for skipped/ignored tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
91
diff
changeset
|
296 |
nextPutAll:']]></'; nextPutAll: outcome; nextPutAll:'>'; |
7b1b26108f1f
Added support for skipped/ignored tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
91
diff
changeset
|
297 |
nextPut:Character lf |
7b1b26108f1f
Added support for skipped/ignored tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
91
diff
changeset
|
298 |
]. |
67 | 299 |
]. |
104
7b1b26108f1f
Added support for skipped/ignored tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
91
diff
changeset
|
300 |
|
67 | 301 |
stream tab; |
302 |
nextPutAll: '</testcase>'; cr. |
|
303 |
||
304 |
||
305 |
stream flush |
|
306 |
||
307 |
"Created: / 03-08-2011 / 19:42:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
191
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
308 |
"Modified: / 05-07-2013 / 16:54:24 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
309 |
! ! |
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
310 |
|
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
311 |
!TestReportFormat::JUnit methodsFor:'writing - utilities'! |
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
312 |
|
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
313 |
writeCDATA: string |
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
314 |
| start stop | |
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
315 |
|
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
316 |
start := 1. |
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
317 |
stop := start. |
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
318 |
[ (stop := (string indexOf: $] startingAt: stop)) ~~ 0 ] whileTrue:[ |
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
319 |
((stop < (string size - 1)) |
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
320 |
and:[(string at: stop + 1) == $] |
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
321 |
and:[(string at: stop + 2) == $>]]) ifTrue:[ |
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
322 |
" Okay, found CDATA end token " |
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
323 |
stream nextPutAll: string startingAt: start to: stop + 1. |
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
324 |
stream nextPutAll: ']]><!![CDATA[>'. |
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
325 |
start := stop := stop + 3. |
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
326 |
] ifFalse:[ |
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
327 |
stop := stop + 1. |
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
328 |
]. |
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
329 |
]. |
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
330 |
start < string size ifTrue:[ |
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
331 |
stream nextPutAll: string startingAt: start to: string size. |
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
332 |
]. |
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
333 |
|
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
334 |
" |
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
335 |
String streamContents:[:s | Builder::TestReportFormat::JUnit new report: nil stream: s; writeCDATA:'ABCD'] |
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
336 |
String streamContents:[:s | Builder::TestReportFormat::JUnit new report: nil stream: s; writeCDATA:']]]]'] |
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
337 |
String streamContents:[:s | Builder::TestReportFormat::JUnit new report: nil stream: s; writeCDATA:'Some <[CDATA[ CDATA ]]> Some Text and stray terminator ]]> here'] |
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
338 |
" |
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
339 |
|
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
340 |
"Created: / 05-07-2013 / 16:54:24 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
67 | 341 |
! ! |
342 |
||
343 |
!TestReportFormat::PerfPublisher class methodsFor:'accessing'! |
|
344 |
||
345 |
symbolicNames |
|
346 |
"Returns a collection of symbolic names for this format" |
|
347 |
||
348 |
^ #(perfPublisher) |
|
349 |
||
350 |
"Modified: / 04-08-2011 / 11:52:03 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
351 |
! ! |
|
352 |
||
353 |
!TestReportFormat::PerfPublisher class methodsFor:'documentation'! |
|
354 |
||
355 |
version_SVN |
|
191
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
356 |
^ '$Id$' |
67 | 357 |
! ! |
358 |
||
359 |
!TestReportFormat::PerfPublisher methodsFor:'writing'! |
|
360 |
||
361 |
writeFooter |
|
362 |
||
363 |
stream nextPutLine: '</report>' |
|
364 |
||
365 |
"Modified: / 03-08-2011 / 20:12:51 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
366 |
! |
|
367 |
||
368 |
writeHeader |
|
369 |
||
370 |
|reportName reportCategory testClass| |
|
371 |
||
372 |
reportName := report suite name. |
|
373 |
reportCategory := 'uncategorized'. "/ it is a required attribute; so what should we use ? |
|
374 |
||
375 |
(testClass := Smalltalk at:reportName asSymbol) isBehavior ifTrue:[ |
|
376 |
reportCategory := testClass category. "/ at least, something to show |
|
377 |
]. |
|
378 |
||
379 |
stream |
|
380 |
nextPutLine: '<?xml version="1.0"?>'; |
|
381 |
nextPutLine:('<report name="%1" categ="%2">' bindWith:reportName with:reportCategory); |
|
382 |
nextPutLine:(' <start>'); |
|
383 |
nextPutLine:(' <date format="YYYYMMDD" val="%1" />' bindWith:(Date today printStringFormat:'%y%m%d')); |
|
384 |
nextPutLine:(' <time format="HHMMSS" val="%1" />' bindWith:(Time now printStringFormat:'%h%m%s')); |
|
385 |
nextPutLine:(' </start>'). |
|
386 |
||
387 |
"Modified: / 03-08-2011 / 20:12:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
388 |
! |
|
389 |
||
390 |
writeTestCase:testcase outcome:outcome time:time exception:exception stacktrace:stacktrace |
|
391 |
||
392 |
" |
|
393 |
Example: |
|
394 |
<test |
|
395 |
name='test_format_link_not_in_repos_with_line' |
|
396 |
executed='exec-status' |
|
397 |
<result> |
|
398 |
<success passed='result-status' state='result-state'/> |
|
399 |
<errorlog><!![CDATA[EXEMPLE OF ERROR LOG]]></errorlog> |
|
400 |
</result> |
|
401 |
</test> |
|
402 |
" |
|
403 |
||
404 |
|testClassName executionTime testName testDescription |
|
405 |
successPassed successState exceptionInfo |
|
406 |
compilerName compilerVersion compilerConfiguration compilerVersionDate |
|
407 |
timeUnit timeMeasure |
|
408 |
sysInfo osType osVersion cpuType| |
|
409 |
||
410 |
testClassName := testcase printString. |
|
411 |
testName := testcase selector. |
|
412 |
||
413 |
"most tests do not know, and return nil here!!" |
|
414 |
executionTime := time. "/ millis |
|
415 |
testDescription := '%1-%2' bindWith:testClassName with:testName. |
|
416 |
||
417 |
successPassed := (outcome == #pass) ifTrue:['yes'] ifFalse:['no']. |
|
418 |
outcome ~~ #pass ifTrue:[ |
|
419 |
exceptionInfo := stacktrace ? 'No stacktrace available'. |
|
420 |
]. |
|
421 |
||
422 |
successState := 'foo'. |
|
423 |
||
424 |
"/ caveat: the following needs to be made dialect-specific |
|
425 |
compilerName := 'Smalltalk/X'. |
|
426 |
compilerVersion := Smalltalk versionString. |
|
427 |
compilerConfiguration := Smalltalk configuration. |
|
428 |
compilerVersionDate := Smalltalk versionDate. |
|
429 |
||
430 |
sysInfo := OperatingSystem getSystemInfo. |
|
431 |
osType := (sysInfo at:#osType ifAbsent:'?'). |
|
432 |
osVersion := (sysInfo at:#release ifAbsent:'?'). |
|
433 |
||
434 |
cpuType := (sysInfo at:#cpuType ifAbsent:'?'). |
|
435 |
"/ cpuSpeed := (sysInfo at:#cpuSpeed ifAbsent:'?'). |
|
436 |
||
437 |
timeUnit := 'ms'. |
|
438 |
timeMeasure := executionTime. |
|
439 |
||
440 |
stream |
|
441 |
nextPutLine:('<test name="%1" executed="yes">' bindWith: testName); |
|
442 |
nextPutLine:(' <description><!![CDATA[%1]]></description>' bindWith: testDescription); |
|
443 |
nextPutLine:' <platform>'; |
|
444 |
nextPutLine:' <os>'; |
|
445 |
nextPutLine:(' <type><!![CDATA[%1]]></type>' bindWith:osType); |
|
446 |
nextPutLine:(' <version><!![CDATA[%1]]></version>' bindWith:osVersion); |
|
447 |
nextPutLine:' </os>'; |
|
448 |
nextPutLine:(' <processor arch="%1">' bindWith:cpuType); |
|
449 |
"/ nextPutLine:(' <frequency> unit="Mhz" cpufreq="%1" />' bindWith:cpuSpeed); |
|
450 |
nextPutLine:' </processor>'; |
|
451 |
nextPutLine:(' <compiler name="%1" version="%2" versiondate="%3" configuration="%4" />' |
|
452 |
bindWith:compilerName with:compilerVersion |
|
453 |
with:compilerVersionDate with:compilerConfiguration); |
|
454 |
"/ nextPutLine:' <environment />'; |
|
455 |
nextPutLine:' </platform>'; |
|
456 |
nextPutLine:' <result>'; |
|
457 |
nextPutLine:(' <success passed="%1" state="100" />' |
|
458 |
bindWith:successPassed with:successState); |
|
459 |
"/ cg: in the perfPublisher documentation, I found "mesure". |
|
460 |
"/ I am not sure, if that was a typo, or is actually what is expected... |
|
461 |
"/ to be on the save side, I generate both a mesure and a measure attribute, |
|
462 |
"/ so it will work, even if they ever fix perfPublisher's xml parser. |
|
463 |
nextPutLine:(' <executiontime unit="%1" mesure="%2" measure="%2" isRelevant="yes" />' |
|
464 |
bindWith:timeUnit with:timeMeasure). |
|
465 |
||
466 |
exceptionInfo notNil ifTrue:[ |
|
467 |
stream |
|
468 |
nextPutLine:' <errorlog><!![CDATA['; |
|
469 |
nextPutAll:exceptionInfo; |
|
470 |
nextPutLine:']]></errorlog>'. |
|
471 |
]. |
|
472 |
stream |
|
473 |
nextPutLine:' </result>'. |
|
474 |
||
475 |
stream nextPutLine:'</test>'. |
|
476 |
||
477 |
"Modified: / 03-08-2011 / 20:15:02 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
478 |
! ! |
|
479 |
||
480 |
!TestReportFormat::PythonUnittest class methodsFor:'accessing'! |
|
481 |
||
482 |
symbolicNames |
|
483 |
"Returns a collection of symbolic names for this format" |
|
484 |
||
485 |
^ #(python python-unittest) |
|
486 |
||
487 |
"Modified: / 04-08-2011 / 11:52:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
488 |
! ! |
|
489 |
||
490 |
!TestReportFormat::PythonUnittest class methodsFor:'documentation'! |
|
491 |
||
492 |
version_SVN |
|
191
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
493 |
^ '$Id$' |
67 | 494 |
! ! |
495 |
||
496 |
!TestReportFormat::PythonUnittest methodsFor:'writing'! |
|
497 |
||
498 |
writeFooter |
|
499 |
||
500 |
stream |
|
501 |
nextPutLine: '</unittest-results>' |
|
502 |
||
503 |
"Modified: / 03-08-2011 / 20:19:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
504 |
! |
|
505 |
||
506 |
writeHeader |
|
507 |
||
508 |
stream |
|
509 |
nextPutLine: '<?xml version="1.0"?>'; |
|
510 |
nextPutLine: '<unittest-results>'. |
|
511 |
||
512 |
"Modified: / 03-08-2011 / 20:19:08 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
513 |
! |
|
514 |
||
515 |
writeTestCase:testcase outcome:outcome time:time exception:exception stacktrace:stacktrace |
|
516 |
||
517 |
" |
|
518 |
Example: |
|
519 |
<test |
|
520 |
duration='0.0188629627228' |
|
521 |
status='error' |
|
522 |
fixture='bitten.tests.web_ui.SourceFileLinkFormatterTestCase' |
|
523 |
name='test_format_link_not_in_repos_with_line' |
|
524 |
file='/usr/src/trac-bitten-0.6b2.dfsg/bitten/tests/web_ui.py'> |
|
525 |
" |
|
526 |
||
527 |
| testClassName status | |
|
528 |
||
529 |
testClassName := testcase class printString. |
|
530 |
||
531 |
status := outcome == #pass ifTrue:[#success] ifFalse:[outcome]. |
|
532 |
||
533 |
stream |
|
534 |
nextPutAll:'<test duration="'; nextPutAll:time; nextPutLine:'"'; |
|
535 |
tab; nextPutAll:'status="'; nextPutAll: status; nextPutLine:'"'; |
|
536 |
tab; nextPutAll:'ficture="'; nextPutAll: testClassName; nextPutLine:'"'; |
|
537 |
tab; nextPutAll:'name="'; nextPutAll: testcase selector; nextPutLine:'"'; |
|
538 |
"It seems that some tools requires the file attributes. So we supply one :-)" |
|
539 |
tab; nextPutAll:'file="'; nextPutAll: testClassName , '.st'; nextPutLine:'">'. |
|
540 |
||
541 |
outcome == #pass ifFalse:[ |
|
542 |
stream nextPutLine:'<traceback><!![CDATA['. |
|
543 |
stream nextPutAll: stacktrace ? 'No stacktrace available'. |
|
544 |
stream nextPutLine:']]></traceback>'. |
|
545 |
]. |
|
546 |
||
547 |
stream nextPutLine:'</test>'. |
|
548 |
||
549 |
"Modified: / 03-08-2011 / 20:23:12 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
550 |
! ! |
|
551 |
||
552 |
!TestReportFormat::TAP class methodsFor:'accessing'! |
|
553 |
||
554 |
symbolicNames |
|
555 |
"Returns a collection of symbolic names for this format" |
|
556 |
||
557 |
^ #(tap TAP) |
|
558 |
||
559 |
"Modified: / 04-08-2011 / 11:52:31 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
560 |
! ! |
|
561 |
||
562 |
!TestReportFormat::TAP class methodsFor:'documentation'! |
|
563 |
||
564 |
version_SVN |
|
191
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
565 |
^ '$Id$' |
67 | 566 |
! ! |
567 |
||
568 |
!TestReportFormat::TAP methodsFor:'accessing - defaults'! |
|
569 |
||
570 |
defaultFileSuffix |
|
571 |
"superclass HDReportFormat says that I am responsible to implement this method" |
|
572 |
||
573 |
^ 'tap' |
|
574 |
||
575 |
"Modified: / 04-08-2011 / 12:47:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
576 |
! ! |
|
577 |
||
578 |
!TestReportFormat::TAP methodsFor:'writing'! |
|
579 |
||
580 |
writeFooter |
|
581 |
||
582 |
"nothing to do" |
|
583 |
||
584 |
"Modified: / 03-08-2011 / 20:05:14 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
585 |
! |
|
586 |
||
587 |
writeHeader |
|
588 |
||
589 |
stream nextPutAll: '1..'; nextPutAll: report suite testCount printString; cr. |
|
590 |
index := 0 |
|
591 |
||
592 |
"Modified: / 04-08-2011 / 13:49:23 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
593 |
! |
|
594 |
||
595 |
writeTestCase:testcase outcome:outcome time:time exception:exception stacktrace:stacktrace |
|
596 |
||
597 |
| testDescription statusString| |
|
598 |
||
599 |
index := index + 1. |
|
600 |
||
601 |
testDescription := '%1-%2 (%3ms)' |
|
602 |
bindWith:testcase printString |
|
603 |
with:testcase selector |
|
604 |
with:time. |
|
605 |
||
606 |
statusString := (outcome == #pass) |
|
607 |
ifTrue:['ok'] |
|
608 |
ifFalse:['not ok']. |
|
609 |
||
610 |
stream nextPutLine:('%1 %2 - %3' |
|
611 |
bindWith:statusString |
|
612 |
with:index |
|
613 |
with:testDescription). |
|
614 |
||
615 |
"Modified: / 03-08-2011 / 20:08:03 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
616 |
! ! |
|
617 |
||
618 |
!TestReportFormat class methodsFor:'documentation'! |
|
619 |
||
620 |
version |
|
621 |
^ '$Header$' |
|
622 |
! |
|
623 |
||
624 |
version_CVS |
|
625 |
^ '$Header$' |
|
626 |
! |
|
627 |
||
628 |
version_SVN |
|
191
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
629 |
^ '$Id$' |
67 | 630 |
! ! |
191
cc00c3e2019c
Fix for JUnit XML report.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
104
diff
changeset
|
631 |