74
|
1 |
"{ Package: 'stx:goodies/builder/reports' }"
|
|
2 |
|
|
3 |
"{ NameSpace: Builder }"
|
|
4 |
|
|
5 |
Report subclass:#TestReport
|
|
6 |
instanceVariableNames:'suite'
|
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
|
9 |
category:'Builder-Reports'
|
|
10 |
!
|
|
11 |
|
|
12 |
TestResult subclass:#Result
|
|
13 |
instanceVariableNames:'format time'
|
|
14 |
classVariableNames:''
|
|
15 |
poolDictionaries:''
|
|
16 |
privateIn:TestReport
|
|
17 |
!
|
|
18 |
|
|
19 |
|
|
20 |
!TestReport methodsFor:'accessing'!
|
|
21 |
|
|
22 |
suite
|
|
23 |
^ suite
|
|
24 |
|
|
25 |
"Created: / 07-11-2011 / 09:41:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
26 |
! !
|
|
27 |
|
|
28 |
!TestReport methodsFor:'accessing - defaults'!
|
|
29 |
|
|
30 |
defaultFileSuffix
|
|
31 |
|
|
32 |
^'Test'
|
|
33 |
|
|
34 |
"Created: / 04-08-2011 / 12:56:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
35 |
!
|
|
36 |
|
|
37 |
defaultFormat
|
|
38 |
"superclass HDReport says that I am responsible to implement this method"
|
|
39 |
|
|
40 |
^ Builder::TestReportFormat::JUnit new
|
|
41 |
|
|
42 |
"Created: / 04-08-2011 / 11:54:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
43 |
!
|
|
44 |
|
|
45 |
defaultName
|
|
46 |
|
|
47 |
^String streamContents:[:s|
|
|
48 |
suite tests do:[:suite|
|
|
49 |
s nextPutAll: suite name
|
|
50 |
] separatedBy:[
|
|
51 |
s nextPut:$,;space
|
|
52 |
]
|
|
53 |
]
|
|
54 |
|
|
55 |
"Created: / 07-11-2011 / 09:47:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
56 |
! !
|
|
57 |
|
|
58 |
!TestReport methodsFor:'initialization'!
|
|
59 |
|
|
60 |
initialize
|
|
61 |
|
|
62 |
suite := TestSuite new.
|
|
63 |
|
|
64 |
"Modified: / 07-11-2011 / 09:40:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
65 |
!
|
|
66 |
|
|
67 |
setupForClasses:classes
|
|
68 |
|
|
69 |
| suite |
|
|
70 |
|
|
71 |
suite := TestSuite named:name.
|
|
72 |
classes do:
|
|
73 |
[:cls |
|
|
74 |
|tc|
|
|
75 |
|
|
76 |
cls isTestCaseLike
|
|
77 |
ifTrue:
|
|
78 |
[ tc := cls asTestCase.
|
|
79 |
tc isAbstract ifFalse:[ suite addTest:tc suite ] ] ].
|
|
80 |
|
|
81 |
self setupForSuite: suite.
|
|
82 |
|
|
83 |
"Created: / 04-08-2011 / 14:34:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
84 |
!
|
|
85 |
|
|
86 |
setupForPackages:packages
|
|
87 |
|
|
88 |
packages do: [:pkg |
|
|
89 |
|def |
|
|
90 |
|
|
91 |
def := ProjectDefinition definitionClassForPackage:pkg.
|
|
92 |
def isNil ifTrue:[
|
|
93 |
Smalltalk loadPackage:pkg asSymbol.
|
|
94 |
def := ProjectDefinition definitionClassForPackage:pkg.
|
|
95 |
].
|
|
96 |
(def respondsTo:#testSuite) ifTrue:[
|
|
97 |
suite addTest:def testSuite
|
|
98 |
] ifFalse:[
|
|
99 |
| classes psuite |
|
|
100 |
psuite := TestSuite named:pkg.
|
|
101 |
|
|
102 |
classes := def notNil
|
|
103 |
ifTrue:[ def classes ]
|
|
104 |
ifFalse:[ ProjectDefinition searchForClassesWithProject:pkg asSymbol ].
|
|
105 |
classes do: [:cls |
|
|
106 |
|tc|
|
|
107 |
|
|
108 |
cls isTestCaseLike ifTrue: [
|
|
109 |
tc := cls asTestCase.
|
|
110 |
tc isAbstract ifFalse:[
|
|
111 |
psuite addTest:tc suite
|
|
112 |
]
|
|
113 |
]
|
|
114 |
].
|
|
115 |
suite addTest: psuite.
|
|
116 |
]
|
|
117 |
].
|
|
118 |
|
|
119 |
"Modified: / 07-11-2011 / 09:43:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
120 |
!
|
|
121 |
|
|
122 |
setupForSuite: suite
|
|
123 |
|
|
124 |
suite addTest: suite.
|
|
125 |
|
|
126 |
"Created: / 06-11-2011 / 18:27:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
127 |
! !
|
|
128 |
|
|
129 |
!TestReport methodsFor:'private'!
|
|
130 |
|
|
131 |
print: anObject on: aStream
|
|
132 |
|
|
133 |
[ anObject printOn: aStream ]
|
|
134 |
on: Error do:
|
|
135 |
[aStream
|
|
136 |
nextPutAll: '** error when prining instance of ';
|
|
137 |
nextPutAll: anObject class name;
|
|
138 |
nextPutAll: '**']
|
|
139 |
|
|
140 |
"Created: / 15-03-2011 / 22:09:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
141 |
! !
|
|
142 |
|
|
143 |
!TestReport methodsFor:'running'!
|
|
144 |
|
|
145 |
runReport
|
|
146 |
|
|
147 |
|result|
|
|
148 |
result := Result new format:format.
|
|
149 |
suite run:result.
|
|
150 |
|
|
151 |
"Created: / 04-08-2011 / 12:39:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
152 |
! !
|
|
153 |
|
|
154 |
!TestReport::Result methodsFor:'accessing'!
|
|
155 |
|
|
156 |
exceptions
|
|
157 |
|
|
158 |
^super exceptions , HaltInterrupt
|
|
159 |
|
|
160 |
"Created: / 03-08-2011 / 14:59:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
161 |
!
|
|
162 |
|
|
163 |
format
|
|
164 |
^ format
|
|
165 |
!
|
|
166 |
|
|
167 |
format:aFormat
|
|
168 |
format := aFormat.
|
|
169 |
! !
|
|
170 |
|
|
171 |
!TestReport::Result methodsFor:'adding'!
|
|
172 |
|
|
173 |
addError: testcase detail: exception
|
|
174 |
|
|
175 |
format writeTestCase: testcase outcome: #error time: time exception: exception.
|
|
176 |
Transcript show:'ERROR'
|
|
177 |
|
|
178 |
"Created: / 03-08-2011 / 15:00:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
179 |
!
|
|
180 |
|
|
181 |
addFailure: testcase detail: exception
|
|
182 |
|
|
183 |
format writeTestCase: testcase outcome: #failure time: time exception: exception.
|
|
184 |
Transcript show:'FAILED'
|
|
185 |
|
|
186 |
"Created: / 03-08-2011 / 15:00:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
187 |
!
|
|
188 |
|
|
189 |
addPass: testcase
|
|
190 |
|
|
191 |
format writeTestCase: testcase outcome: #pass time: time exception: nil.
|
|
192 |
Transcript show:'OK'
|
|
193 |
|
|
194 |
"Created: / 03-08-2011 / 15:19:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
195 |
! !
|
|
196 |
|
|
197 |
!TestReport::Result methodsFor:'running'!
|
|
198 |
|
|
199 |
performCase:aTestCase
|
|
200 |
|
|
201 |
time := Time millisecondsToRun: [ super performCase: aTestCase ]
|
|
202 |
|
|
203 |
"Created: / 03-08-2011 / 18:40:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
204 |
!
|
|
205 |
|
|
206 |
runCase:aTestCase debugged: debugged
|
|
207 |
|
|
208 |
| timeout |
|
|
209 |
timeout := aTestCase timeout.
|
|
210 |
|
|
211 |
self runCase: aTestCase debugged: debugged
|
|
212 |
fork: (aTestCase shouldFork or:[timeout notNil])
|
|
213 |
timeout: timeout ? 60"sec"
|
|
214 |
|
|
215 |
"Created: / 22-08-2011 / 14:37:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
216 |
!
|
|
217 |
|
|
218 |
runCase:aTestCase debugged: debugged fork:doFork
|
|
219 |
|
|
220 |
^self runCase:aTestCase debugged: debugged
|
|
221 |
fork:doFork timeout: aTestCase timeout ? 60"sec"
|
|
222 |
|
|
223 |
"Created: / 22-08-2011 / 14:38:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
224 |
!
|
|
225 |
|
|
226 |
runCase:aTestCase debugged: debugged fork:doFork timeout: tout
|
|
227 |
| nm sel |
|
|
228 |
|
|
229 |
nm := aTestCase nameForHDTestReport.
|
|
230 |
nm size > 20 ifTrue:[
|
|
231 |
nm := (nm copyTo: 17) , '...'
|
|
232 |
].
|
|
233 |
sel := aTestCase selectorForHDTestReport.
|
|
234 |
sel size > 20 ifTrue:[
|
|
235 |
sel := '...' , (sel copyFrom: sel size - 16 to: sel size)
|
|
236 |
].
|
|
237 |
Transcript show:('%-20s >> %-20s : ' printfWith: nm with: sel).
|
|
238 |
|
|
239 |
outcome := self createOutcome.
|
|
240 |
outcome testCase: aTestCase.
|
|
241 |
|
|
242 |
doFork ifFalse:[
|
|
243 |
super runCase:aTestCase debugged: debugged.
|
|
244 |
Transcript cr.
|
|
245 |
^self.
|
|
246 |
].
|
|
247 |
|
|
248 |
OperatingSystem isUNIXlike ifTrue:[
|
|
249 |
"/ self unixForkCase: aTestCase debugged: debugged.
|
|
250 |
"/ Use lightweight forking
|
|
251 |
self lightForkCase: aTestCase debugged: debugged timeout: tout.
|
|
252 |
^ self.
|
|
253 |
].
|
|
254 |
OperatingSystem isMSWINDOWSlike ifTrue:[
|
|
255 |
self lightForkCase: aTestCase debugged: debugged timeout: tout.
|
|
256 |
^ self.
|
|
257 |
].
|
|
258 |
|
|
259 |
self error:'Unssuported platform'
|
|
260 |
|
|
261 |
"Created: / 12-01-2012 / 17:52:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
262 |
! !
|
|
263 |
|
|
264 |
!TestReport::Result methodsFor:'running-private'!
|
|
265 |
|
|
266 |
lightForkCase:aTestCase debugged: debugged timeout: timeout
|
|
267 |
| thread sema stime etime timeouted error stack log logPos |
|
|
268 |
|
|
269 |
Transcript show:'forking...'.
|
|
270 |
sema := Semaphore new.
|
|
271 |
stime := OperatingSystem getMillisecondTime.
|
|
272 |
log := false.
|
|
273 |
logPos := format stream stream position.
|
|
274 |
timeouted := false.
|
|
275 |
thread := [ super runCase:aTestCase debugged: debugged ] newProcess.
|
|
276 |
thread addExitAction:[sema signal].
|
|
277 |
thread resume.
|
|
278 |
|
|
279 |
Transcript show: 'waiting for child...'.
|
|
280 |
(sema waitWithTimeout:timeout) isNil ifTrue: [
|
|
281 |
Transcript show: 'timeout...'.
|
|
282 |
thread terminate.
|
|
283 |
timeouted := true.
|
|
284 |
Transcript show: 'killed...'.
|
|
285 |
].
|
|
286 |
|
|
287 |
etime := OperatingSystem getMillisecondTime.
|
|
288 |
timeouted ifTrue:[
|
|
289 |
error := TimeoutError new messageText: 'Timed out'.
|
|
290 |
stack := 'Timed out'.
|
|
291 |
format
|
|
292 |
writeTestCase: aTestCase outcome: #error
|
|
293 |
time: etime - stime
|
|
294 |
exception: error
|
|
295 |
stacktrace: stack.
|
|
296 |
Transcript show:'ERROR'
|
|
297 |
].
|
|
298 |
|
|
299 |
outcome := nil.
|
|
300 |
Transcript cr.
|
|
301 |
|
|
302 |
"Created: / 12-01-2012 / 17:42:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
303 |
!
|
|
304 |
|
|
305 |
unixForkCase:aTestCase debugged: debugged timeout: timeout
|
|
306 |
| pid status sema stime etime error stack suiteFailuresBefore suiteErrorsBefore log logPos |
|
|
307 |
|
|
308 |
Transcript show:'forking...'.
|
|
309 |
sema := Semaphore new.
|
|
310 |
stime := OperatingSystem getMillisecondTime.
|
|
311 |
log := false.
|
|
312 |
logPos := format stream stream position.
|
|
313 |
Processor monitor:
|
|
314 |
[ pid := OperatingSystem fork.
|
|
315 |
pid == 0 ifTrue:[ nil ] ifFalse:[ pid ] ]
|
|
316 |
action:
|
|
317 |
[:s |
|
|
318 |
Transcript show:'child finished...'.
|
|
319 |
status := s.
|
|
320 |
sema signal ].
|
|
321 |
pid == 0
|
|
322 |
ifTrue:
|
|
323 |
[ "Child, exit codes:
|
|
324 |
0...PASSED
|
|
325 |
1...FAILED
|
|
326 |
2...ERROR
|
|
327 |
>64...got signal <code>-64"
|
|
328 |
|
|
329 |
[ suiteFailuresBefore := failures.
|
|
330 |
suiteErrorsBefore := errors.
|
|
331 |
super runCase:aTestCase debugged: debugged.
|
|
332 |
suiteErrorsBefore ~~ errors ifTrue:[ Smalltalk exit:2 ].
|
|
333 |
suiteFailuresBefore ~~ failures ifTrue:[ Smalltalk exit:1 ].
|
|
334 |
format streamClose.
|
|
335 |
Smalltalk exit:0. ] on:OSSignalInterrupt
|
|
336 |
do:[:ex | format streamClose. Smalltalk exit:64 + ex parameter ] ]
|
|
337 |
ifFalse:
|
|
338 |
[ "Parent"
|
|
339 |
format streamClose.
|
|
340 |
Transcript show: 'waiting for child...'.
|
|
341 |
(sema waitWithTimeout:timeout) isNil
|
|
342 |
ifTrue:
|
|
343 |
[Transcript show: 'timeout...'.
|
|
344 |
OperatingSystem terminateProcess:pid.
|
|
345 |
OperatingSystem childProcessWait:true pid:pid.
|
|
346 |
Transcript show: 'killed...'.
|
|
347 |
].
|
|
348 |
etime := OperatingSystem getMillisecondTime.
|
|
349 |
(status isNil or:[ status success not ])
|
|
350 |
ifFalse:[
|
|
351 |
"/child finished, result is pass. However, it is not in my passed collection
|
|
352 |
"/since addPass: has been called in child process
|
|
353 |
super addPass: aTestCase.
|
|
354 |
] ifTrue:
|
|
355 |
[ log := true.
|
|
356 |
status isNil
|
|
357 |
ifTrue:
|
|
358 |
[ error := TimeoutError new parameter:timeout.
|
|
359 |
stack := 'Oops, timed out!! (timeout was ' , timeout printString , ' sec)'. ]
|
|
360 |
ifFalse:
|
|
361 |
[ status status == #signal
|
|
362 |
ifTrue:
|
|
363 |
[ error := OSSignalInterrupt new parameter:status code.
|
|
364 |
stack := 'Oops, VM terminated on signal ' , status code printString, ' (stactrace not awailable)' ].
|
|
365 |
status status == #exit
|
|
366 |
ifTrue:
|
|
367 |
[ status code == 1
|
|
368 |
ifTrue:
|
|
369 |
[super addFailure: aTestCase detail: nil.
|
|
370 |
log := false ].
|
|
371 |
status code == 2
|
|
372 |
ifTrue:
|
|
373 |
[super addError: aTestCase detail: nil.
|
|
374 |
log := false ].
|
|
375 |
status code > 64
|
|
376 |
ifTrue:
|
|
377 |
[ error := OSSignalInterrupt new parameter:status code - 64.
|
|
378 |
stack := 'Oops, VM terminated on signal ' , status code p ] ] ]. ].
|
|
379 |
format streamOpenForAppend.
|
|
380 |
log ifTrue:[
|
|
381 |
format stream stream position: logPos.
|
|
382 |
format
|
|
383 |
writeTestCase: aTestCase outcome: #error
|
|
384 |
time: etime - stime
|
|
385 |
exception: error
|
|
386 |
stacktrace: stack.
|
|
387 |
Transcript show:'ERROR'
|
|
388 |
]
|
|
389 |
].
|
|
390 |
outcome := nil.
|
|
391 |
Transcript cr.
|
|
392 |
|
|
393 |
"Created: / 12-01-2012 / 17:43:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
394 |
! !
|
|
395 |
|
|
396 |
!TestReport class methodsFor:'documentation'!
|
|
397 |
|
|
398 |
version
|
|
399 |
^ '$Header$'
|
|
400 |
!
|
|
401 |
|
|
402 |
version_CVS
|
|
403 |
^ '$Header$'
|
|
404 |
!
|
|
405 |
|
|
406 |
version_SVN
|
|
407 |
^ '§Id: Builder__TestReport.st 300 2012-01-12 17:53:04Z vranyj1 §'
|
|
408 |
! !
|