author | Stefan Vogel <sv@exept.de> |
Tue, 23 Apr 2013 12:33:43 +0200 | |
changeset 577 | 3dea1e941af7 |
parent 571 | d5a1ac6d1743 |
child 580 | d86ef51e98ab |
permissions | -rw-r--r-- |
345 | 1 |
"{ Package: 'stx:goodies/sunit' }" |
2 |
||
3 |
TestResult subclass:#TestResultStX |
|
493 | 4 |
instanceVariableNames:'endTime' |
345 | 5 |
classVariableNames:'' |
6 |
poolDictionaries:'' |
|
7 |
category:'SUnit-Smalltalk/X' |
|
8 |
! |
|
9 |
||
10 |
||
500 | 11 |
!TestResultStX class methodsFor:'utilities'! |
12 |
||
13 |
sourceFilenameOfClass:aClass |
|
14 |
"that is ST/X specific" |
|
15 |
"no Smalltalk/X dialect detection needed..." |
|
16 |
||
17 |
|sourceStream testClassSourceFile| |
|
18 |
||
19 |
sourceStream := aClass sourceStream. |
|
20 |
sourceStream notNil ifTrue:[ |
|
21 |
[ |
|
22 |
sourceStream := sourceStream stream. |
|
23 |
sourceStream isFileStream ifTrue:[ |
|
24 |
testClassSourceFile := sourceStream pathName asFilename pathName. |
|
25 |
]. |
|
26 |
] ensure:[ |
|
27 |
sourceStream close. |
|
28 |
] |
|
29 |
]. |
|
30 |
^ testClassSourceFile |
|
31 |
! ! |
|
32 |
||
479 | 33 |
!TestResultStX methodsFor:'accessing'! |
34 |
||
35 |
endTime |
|
36 |
^ endTime |
|
37 |
! |
|
38 |
||
39 |
endTime:aTimestamp |
|
40 |
"sets the overall (suite) end time" |
|
41 |
||
42 |
endTime := aTimestamp. |
|
43 |
! |
|
44 |
||
482 | 45 |
executionTime |
46 |
"return the execution time (in seconds). If asked before or during a run, return nil" |
|
47 |
||
493 | 48 |
|t1 t2| |
49 |
||
50 |
(t1 := self startTime) isNil ifTrue:[^ nil]. |
|
51 |
(t2 := self endTime) isNil ifTrue:[^ nil]. |
|
52 |
^ t2 secondDeltaFrom: t1 |
|
482 | 53 |
|
54 |
" |
|
55 |
|a b| |
|
56 |
||
57 |
a := Timestamp now. |
|
58 |
Delay waitForMilliseconds:567. |
|
59 |
b := Timestamp now. |
|
60 |
b - a |
|
61 |
" |
|
62 |
! |
|
63 |
||
479 | 64 |
startTime |
493 | 65 |
^ timestamp |
479 | 66 |
! |
67 |
||
68 |
startTime:aTimestamp |
|
493 | 69 |
"sets the overall (suite) start time" |
479 | 70 |
|
493 | 71 |
timestamp := aTimestamp. |
479 | 72 |
! ! |
73 |
||
345 | 74 |
!TestResultStX methodsFor:'outcome'! |
75 |
||
500 | 76 |
printLineForContextForJavaCompatibleStackTrace:con on:aStream |
77 |
"why in java-backtrace format? |
|
78 |
Because then jenkins will be able to extract sourcefile and linenumber |
|
79 |
and generate links in the report page. |
|
80 |
I am not willing to write another plugin for this - using junit compatible format" |
|
81 |
||
82 |
|cls classSourceFile method s lineNumberOfMethod lineNumberInFile relPath| |
|
83 |
||
84 |
"/ used to be: |
|
85 |
"/ con printOn:aStream. |
|
86 |
||
87 |
"/ be careful: some tests generate methods on the fly, which are unbound!! |
|
88 |
"/ or even (javascript/other languages) may not have a method at all!!!! |
|
89 |
||
90 |
con fixAllLineNumbers. |
|
91 |
(method := con method) notNil ifTrue:[ |
|
92 |
cls := method mclass. |
|
93 |
cls notNil ifTrue:[ |
|
94 |
relPath := cls package copyReplaceAll:$: with:$/. |
|
95 |
relPath := relPath copyReplaceAll:$\ with:$/. |
|
505 | 96 |
relPath := (relPath asFilename construct:cls theNonMetaclass classFilename) name. |
508 | 97 |
classSourceFile := relPath. |
500 | 98 |
|
526 | 99 |
classSourceFile := Smalltalk getPackageFileName:relPath. |
100 |
classSourceFile isNil ifTrue:[ |
|
101 |
classSourceFile := self class sourceFilenameOfClass:cls. |
|
102 |
]. |
|
500 | 103 |
classSourceFile notNil ifTrue:[ |
104 |
method sourcePosition notNil ifTrue:[ |
|
105 |
"/ sigh - we have the lineNumber within the method, |
|
106 |
"/ and the characterPosition of the method's start. |
|
107 |
"/ need to calculate the absolute lineNumber in the file |
|
108 |
s := LineNumberReadStream on:(classSourceFile asFilename readStream). |
|
109 |
[ |
|
110 |
[s position < method sourcePosition] whileTrue:[ |
|
111 |
s nextLine |
|
112 |
]. |
|
113 |
lineNumberOfMethod := s lineNumber. |
|
114 |
] ensure:[ |
|
115 |
s close. |
|
116 |
]. |
|
117 |
] |
|
118 |
] |
|
119 |
]. |
|
120 |
]. |
|
121 |
||
122 |
"/ output something (will not generate a ref to the source file) |
|
123 |
aStream nextPutAll:('%1 >> %2 [%3]' |
|
124 |
bindWith: (con receiverPrintString) |
|
125 |
with: (con selector) |
|
126 |
with: (con lineNumber) ). |
|
127 |
||
526 | 128 |
relPath notNil ifTrue:[ |
500 | 129 |
lineNumberOfMethod notNil ifTrue:[ |
130 |
lineNumberInFile := lineNumberOfMethod + con lineNumber - 1. |
|
131 |
aStream nextPutAll:(' (%1:%2)' |
|
526 | 132 |
bindWith: relPath |
500 | 133 |
with: lineNumberInFile) |
134 |
] ifFalse:[ |
|
135 |
aStream nextPutAll:(' (%1)' |
|
526 | 136 |
bindWith: relPath) |
500 | 137 |
]. |
138 |
]. |
|
139 |
aStream cr. |
|
140 |
||
141 |
"Modified: / 05-08-2012 / 12:00:00 / cg" |
|
142 |
! |
|
143 |
||
345 | 144 |
rememberEndTime |
479 | 145 |
"remembers the endTime of the current test (in outcome)" |
345 | 146 |
|
147 |
^outcome endTime: Timestamp now |
|
148 |
||
149 |
"Created: / 16-08-2011 / 17:36:07 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
150 |
! |
|
151 |
||
505 | 152 |
rememberException:ex |
345 | 153 |
"common for failure and error: |
154 |
called when a test fails. testCase is the failed |
|
505 | 155 |
testcase, ex is platform specific object describing |
345 | 156 |
the failure. Actually, on all platforms exeptt GemStone, |
505 | 157 |
ex is an instance of an exception that caused the failure" |
345 | 158 |
|
159 |
|backtrace| |
|
160 |
||
161 |
((Smalltalk respondsTo:#isSmalltalkX) and:[Smalltalk isSmalltalkX]) ifTrue:[ |
|
162 |
"remember the backtrace (as string, to prevent objects from being kept forwever |
|
163 |
from being garbage collected, the signal (i.e. the exception class) and the |
|
164 |
exceptions message (description). |
|
165 |
Would like to have an exceptionInfo obejct for that, but that might be hard to |
|
166 |
get returned back into the main stream sunit package..." |
|
167 |
||
168 |
backtrace := String streamContents:[:s | |
|
169 |
|con topReached| |
|
170 |
||
171 |
"could use printAllOn:s, but noone is interested in contexts above the |
|
172 |
testcase's runtest context" |
|
173 |
topReached := false. |
|
505 | 174 |
con := ex suspendedContext. |
345 | 175 |
[ |
176 |
con notNil and:[topReached not] |
|
177 |
] whileTrue:[ |
|
500 | 178 |
self printLineForContextForJavaCompatibleStackTrace:con on:s. |
345 | 179 |
topReached := (con selector == outcome selector) |
465 | 180 |
and:[con receiver == outcome |
181 |
or:[ con receiver == outcome testCase ]]. |
|
345 | 182 |
con := con sender. |
183 |
] |
|
184 |
]. |
|
465 | 185 |
|
345 | 186 |
outcome exceptionDetail:(Dictionary new |
571
d5a1ac6d1743
use #creator instead of #signal
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
187 |
at:#exception put:ex creator; |
505 | 188 |
at:#description put:ex description; |
345 | 189 |
at:#backtrace put:backtrace; |
190 |
yourself). |
|
191 |
^ self. |
|
192 |
]. |
|
193 |
||
194 |
"add other dialect specifics here" |
|
195 |
||
196 |
"Created: / 06-08-2011 / 11:29:23 / cg" |
|
197 |
"Created: / 16-08-2011 / 17:32:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
198 |
! |
|
199 |
||
200 |
rememberOutput: aString |
|
201 |
outcome collectedOutput: aString |
|
202 |
||
203 |
"Created: / 16-08-2011 / 18:18:41 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
204 |
! |
|
205 |
||
206 |
rememberStartTime |
|
479 | 207 |
"remembers the startTime of the current test (in outcome)" |
345 | 208 |
|
209 |
^outcome startTime: Timestamp now |
|
210 |
||
211 |
"Created: / 16-08-2011 / 17:36:16 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
212 |
! ! |
|
213 |
||
214 |
!TestResultStX methodsFor:'running'! |
|
215 |
||
216 |
performCase: aTestCase |
|
217 |
||
218 |
| savedStdout savedTranscript collector| |
|
219 |
||
220 |
savedStdout := Stdout. |
|
221 |
savedTranscript := Transcript. |
|
222 |
collector := WriteStream on:(String new:100). |
|
223 |
[ |
|
224 |
Stdout := SplittingWriteStream on:collector and: Stdout. |
|
225 |
Transcript := SplittingWriteStream on:collector and: Transcript. |
|
226 |
super performCase: aTestCase. |
|
227 |
] ensure:[ |
|
228 |
Stdout := savedStdout. |
|
229 |
Transcript := savedTranscript. |
|
230 |
self rememberOutput: collector contents. |
|
231 |
]. |
|
232 |
||
233 |
"Created: / 16-08-2011 / 18:18:41 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
234 |
! ! |
|
235 |
||
236 |
!TestResultStX class methodsFor:'documentation'! |
|
237 |
||
238 |
version |
|
571
d5a1ac6d1743
use #creator instead of #signal
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
239 |
^ '$Header: /cvs/stx/stx/goodies/sunit/TestResultStX.st,v 1.10 2013-04-19 09:39:24 cg Exp $' |
345 | 240 |
! |
241 |
||
242 |
version_CVS |
|
571
d5a1ac6d1743
use #creator instead of #signal
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
243 |
^ '$Header: /cvs/stx/stx/goodies/sunit/TestResultStX.st,v 1.10 2013-04-19 09:39:24 cg Exp $' |
345 | 244 |
! ! |
571
d5a1ac6d1743
use #creator instead of #signal
Claus Gittinger <cg@exept.de>
parents:
526
diff
changeset
|
245 |