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