author | Claus Gittinger <cg@exept.de> |
Sat, 06 Aug 2011 09:34:48 +0200 | |
changeset 316 | d01820e6d817 |
parent 303 | 6d21e7a22412 |
child 318 | 96ce5904bba6 |
permissions | -rw-r--r-- |
0 | 1 |
"{ Package: 'stx:goodies/sunit' }" |
2 |
||
3 |
Object subclass:#TestResult |
|
222 | 4 |
instanceVariableNames:'name timestamp failures errors passed' |
104 | 5 |
classVariableNames:'' |
6 |
poolDictionaries:'' |
|
7 |
category:'SUnit-Base' |
|
8 |
! |
|
9 |
||
222 | 10 |
TestResult comment:'' |
0 | 11 |
! |
12 |
||
14 | 13 |
|
222 | 14 |
!TestResult class methodsFor:'instance creation'! |
15 |
||
16 |
new |
|
17 |
^super new initialize |
|
18 |
! ! |
|
19 |
||
68 | 20 |
!TestResult class methodsFor:'exceptions'! |
0 | 21 |
|
22 |
error |
|
104 | 23 |
^self exError |
0 | 24 |
! |
25 |
||
26 |
exError |
|
104 | 27 |
^SUnitNameResolver errorObject |
0 | 28 |
! |
29 |
||
30 |
failure |
|
104 | 31 |
^TestFailure |
32 |
! |
|
0 | 33 |
|
104 | 34 |
resumableFailure |
35 |
^ResumableTestFailure |
|
0 | 36 |
! |
37 |
||
222 | 38 |
signalErrorWith: aString |
39 |
self error sunitSignalWith: aString |
|
40 |
! |
|
0 | 41 |
|
222 | 42 |
signalFailureWith: aString |
43 |
self failure sunitSignalWith: aString |
|
0 | 44 |
! ! |
45 |
||
68 | 46 |
!TestResult methodsFor:'accessing'! |
0 | 47 |
|
48 |
defects |
|
104 | 49 |
^OrderedCollection new |
50 |
addAll: self errors; |
|
51 |
addAll: self failures; yourself |
|
0 | 52 |
! |
53 |
||
54 |
errorCount |
|
104 | 55 |
|
56 |
^self errors size |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
57 |
! |
0 | 58 |
|
59 |
errors |
|
222 | 60 |
errors isNil ifTrue: [errors := OrderedCollection new]. |
104 | 61 |
^errors |
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
62 |
! |
0 | 63 |
|
300
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
64 |
exceptions |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
65 |
|
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
66 |
"Returns a set of exceptions to be handled. Bu default, |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
67 |
failure and generic error is handled. This method may |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
68 |
be overriden by custom TestResult subclasses to add more. |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
69 |
For example, a 'self halt' is not handled by default |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
70 |
exceptions set" |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
71 |
|
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
72 |
^self class failure , self class error |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
73 |
|
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
74 |
"Created: / 03-08-2011 / 14:11:00 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
75 |
! |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
76 |
|
0 | 77 |
failureCount |
78 |
||
104 | 79 |
^self failures size |
0 | 80 |
! |
81 |
||
82 |
failures |
|
222 | 83 |
"We use a Set, not an OrderedCollection as #errors and #passed do, because a resumable test failure in a loop can raise many failures against the same test. In current Sunit UIs, this could result in bizarre test count reporting (-27 tests run, and suchlike). This will be reviewed." |
84 |
||
85 |
failures isNil ifTrue: [failures := Set new]. |
|
104 | 86 |
^failures |
222 | 87 |
! |
88 |
||
89 |
name |
|
90 |
^ name |
|
91 |
! |
|
92 |
||
93 |
name:aString |
|
94 |
name := aString. |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
95 |
! |
0 | 96 |
|
53 | 97 |
passed |
222 | 98 |
passed isNil ifTrue: [passed := OrderedCollection new]. |
104 | 99 |
^passed |
53 | 100 |
! |
101 |
||
102 |
passedCount |
|
103 |
||
104 | 104 |
^self passed size |
53 | 105 |
! |
106 |
||
0 | 107 |
runCount |
53 | 108 |
|
104 | 109 |
^self passedCount + self failureCount + self errorCount |
53 | 110 |
! |
111 |
||
112 |
tests |
|
104 | 113 |
|
114 |
^(OrderedCollection new: self runCount) |
|
115 |
addAll: self passed; |
|
116 |
addAll: self errors; |
|
117 |
addAll: self failures; |
|
118 |
yourself |
|
222 | 119 |
! |
120 |
||
121 |
timestamp |
|
122 |
^ timestamp |
|
270 | 123 |
! |
124 |
||
125 |
timestamp:something |
|
126 |
timestamp := something. |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
127 |
! ! |
0 | 128 |
|
222 | 129 |
!TestResult methodsFor:'adding'! |
130 |
||
300
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
131 |
addError: testcase detail: detail |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
132 |
|
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
133 |
"Called when a test outcome is error. testCase |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
134 |
is the errorneous testcase, detail is platform |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
135 |
specific object describing the error. Actually, |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
136 |
on all platforms exept GemStone, detail is an instance |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
137 |
of an exception that caused the error" |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
138 |
|
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
139 |
"JV2011-08-03: TODO: Validate the comment above with GS, |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
140 |
possibly change name to 'exception'" |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
141 |
|
316 | 142 |
testcase exceptionInfoString:(self exceptionInfoStringFor:detail in:testcase). |
143 |
||
300
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
144 |
testcase class rememberErrorTest: testcase selector. |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
145 |
^self errors add: testcase |
222 | 146 |
|
147 |
"Modified: / 11-09-2010 / 17:19:24 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
300
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
148 |
"Created: / 03-08-2011 / 13:50:42 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
316 | 149 |
"Modified: / 06-08-2011 / 09:33:53 / cg" |
222 | 150 |
! |
151 |
||
300
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
152 |
addFailure: testcase detail: detail |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
153 |
|
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
154 |
"Called when a test fails. testCase is the failed |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
155 |
testcase, detail is platform specific object describing |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
156 |
the failure. Actually, on all platforms exept GemStone, |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
157 |
detail is an instance of an exception that caused the failure" |
222 | 158 |
|
300
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
159 |
"JV2011-08-03: TODO: Validate the comment above with GS, |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
160 |
possibly change name to 'exception'" |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
161 |
|
316 | 162 |
testcase exceptionInfoString:(self exceptionInfoStringFor:detail in:testcase). |
300
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
163 |
testcase class rememberFailedTest: testcase selector. |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
164 |
^self failures add: testcase |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
165 |
|
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
166 |
"Created: / 03-08-2011 / 13:53:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
316 | 167 |
"Modified: / 06-08-2011 / 09:34:17 / cg" |
222 | 168 |
! |
169 |
||
300
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
170 |
addPass: testcase |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
171 |
testcase class rememberPassedTest: testcase selector. |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
172 |
^self passed add: testcase |
222 | 173 |
|
174 |
"Modified: / 11-09-2010 / 17:19:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
175 |
! ! |
|
176 |
||
177 |
!TestResult methodsFor:'deprecated'! |
|
178 |
||
179 |
correctCount |
|
180 |
"deprecated - use #passedCount" |
|
181 |
||
182 |
^self passedCount |
|
183 |
! ! |
|
184 |
||
185 |
!TestResult methodsFor:'initialize-release'! |
|
0 | 186 |
|
187 |
initialize |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
188 |
! ! |
0 | 189 |
|
68 | 190 |
!TestResult methodsFor:'printing'! |
0 | 191 |
|
297
87eb8f911bcf
changed: #exceptionInfoStringFor:in:
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
192 |
exceptionInfoStringFor:anException in:aTestCase |
87eb8f911bcf
changed: #exceptionInfoStringFor:in:
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
193 |
"the following should be pretty portable; |
87eb8f911bcf
changed: #exceptionInfoStringFor:in:
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
194 |
if not, comment the following, and uncomment the false |
87eb8f911bcf
changed: #exceptionInfoStringFor:in:
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
195 |
to return nil (thats what you had before)" |
87eb8f911bcf
changed: #exceptionInfoStringFor:in:
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
196 |
|
87eb8f911bcf
changed: #exceptionInfoStringFor:in:
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
197 |
((Smalltalk respondsTo:#isSmalltalkX) and:[Smalltalk isSmalltalkX]) |
87eb8f911bcf
changed: #exceptionInfoStringFor:in:
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
198 |
"false" |
87eb8f911bcf
changed: #exceptionInfoStringFor:in:
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
199 |
ifTrue:[ |
87eb8f911bcf
changed: #exceptionInfoStringFor:in:
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
200 |
^ String streamContents:[:s | |
87eb8f911bcf
changed: #exceptionInfoStringFor:in:
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
201 |
|con endReached| |
292 | 202 |
|
297
87eb8f911bcf
changed: #exceptionInfoStringFor:in:
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
203 |
endReached := false. |
87eb8f911bcf
changed: #exceptionInfoStringFor:in:
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
204 |
con := anException suspendedContext. |
87eb8f911bcf
changed: #exceptionInfoStringFor:in:
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
205 |
[ con isNil or:[ endReached ]] whileFalse:[ |
87eb8f911bcf
changed: #exceptionInfoStringFor:in:
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
206 |
con printOn:s. |
87eb8f911bcf
changed: #exceptionInfoStringFor:in:
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
207 |
s cr. |
87eb8f911bcf
changed: #exceptionInfoStringFor:in:
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
208 |
((con selector == aTestCase selector) |
87eb8f911bcf
changed: #exceptionInfoStringFor:in:
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
209 |
and:[ con receiver == aTestCase ]) ifTrue:[ |
87eb8f911bcf
changed: #exceptionInfoStringFor:in:
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
210 |
endReached := true. |
87eb8f911bcf
changed: #exceptionInfoStringFor:in:
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
211 |
]. |
87eb8f911bcf
changed: #exceptionInfoStringFor:in:
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
212 |
con := con sender. |
87eb8f911bcf
changed: #exceptionInfoStringFor:in:
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
213 |
] |
87eb8f911bcf
changed: #exceptionInfoStringFor:in:
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
214 |
]. |
292 | 215 |
]. |
216 |
||
297
87eb8f911bcf
changed: #exceptionInfoStringFor:in:
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
217 |
^ nil |
292 | 218 |
|
219 |
"Created: / 02-08-2011 / 18:10:46 / cg" |
|
220 |
! |
|
221 |
||
0 | 222 |
printOn: aStream |
104 | 223 |
|
224 |
aStream |
|
225 |
nextPutAll: self runCount printString; |
|
226 |
nextPutAll: ' run, '; |
|
227 |
nextPutAll: self correctCount printString; |
|
228 |
nextPutAll: ' passed, '; |
|
229 |
nextPutAll: self failureCount printString; |
|
230 |
nextPutAll: ' failed, '; |
|
231 |
nextPutAll: self errorCount printString; |
|
232 |
nextPutAll: ' error'. |
|
233 |
||
234 |
self errorCount ~= 1 |
|
235 |
ifTrue: [aStream nextPut: $s] |
|
0 | 236 |
! ! |
237 |
||
68 | 238 |
!TestResult methodsFor:'running'! |
0 | 239 |
|
303 | 240 |
performCase:aTestCase |
241 |
"Actually performs the case. The TestCase>>runCase itself calls |
|
300
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
242 |
a setUp/tearDown methods. The possible error/failure is handled |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
243 |
in TestResult>>runCase:. This method is meant to be overriden by |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
244 |
custom TestResult subclasses." |
303 | 245 |
|
300
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
246 |
aTestCase runCase. |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
247 |
|
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
248 |
"Modified: / 02-08-2011 / 18:10:09 / cg" |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
249 |
"Created: / 03-08-2011 / 14:02:14 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
250 |
! |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
251 |
|
303 | 252 |
runCase:aTestCase |
316 | 253 |
"run a testcase, catching exceptions" |
254 |
||
303 | 255 |
[ |
256 |
self performCase:aTestCase. |
|
257 |
self addPass:aTestCase |
|
258 |
] sunitOn:self exceptions do: [:ex | |
|
259 |
ex sunitAnnounce:aTestCase toResult:self |
|
260 |
]. |
|
292 | 261 |
|
300
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
262 |
"Modified: / 03-08-2011 / 14:08:08 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
303 | 263 |
"Modified (format): / 03-08-2011 / 17:20:12 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
316 | 264 |
"Modified: / 06-08-2011 / 09:32:32 / cg" |
0 | 265 |
! ! |
266 |
||
68 | 267 |
!TestResult methodsFor:'testing'! |
0 | 268 |
|
53 | 269 |
hasErrors |
270 |
||
104 | 271 |
^self errors size > 0 |
53 | 272 |
! |
273 |
||
274 |
hasFailures |
|
275 |
||
104 | 276 |
^self failures size > 0 |
53 | 277 |
! |
278 |
||
0 | 279 |
hasPassed |
104 | 280 |
|
281 |
^self hasErrors not and: [self hasFailures not] |
|
53 | 282 |
! |
283 |
||
284 |
isError: aTestCase |
|
285 |
||
104 | 286 |
^self errors includes: aTestCase |
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
287 |
! |
0 | 288 |
|
289 |
isFailure: aTestCase |
|
104 | 290 |
^self failures includes: aTestCase |
53 | 291 |
! |
292 |
||
293 |
isPassed: aTestCase |
|
294 |
||
104 | 295 |
^self passed includes: aTestCase |
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
296 |
! ! |
0 | 297 |
|
14 | 298 |
!TestResult class methodsFor:'documentation'! |
299 |
||
300 |
version |
|
316 | 301 |
^ '$Header: /cvs/stx/stx/goodies/sunit/TestResult.st,v 1.27 2011-08-06 07:34:48 cg Exp $' |
297
87eb8f911bcf
changed: #exceptionInfoStringFor:in:
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
302 |
! |
87eb8f911bcf
changed: #exceptionInfoStringFor:in:
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
303 |
|
87eb8f911bcf
changed: #exceptionInfoStringFor:in:
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
304 |
version_CVS |
316 | 305 |
^ '$Header: /cvs/stx/stx/goodies/sunit/TestResult.st,v 1.27 2011-08-06 07:34:48 cg Exp $' |
222 | 306 |
! |
307 |
||
308 |
version_SVN |
|
309 |
^ '§Id: TestResult.st 205 2010-09-11 15:23:01Z vranyj1 §' |
|
14 | 310 |
! ! |