author | tm |
Mon, 25 Aug 2003 13:44:02 +0200 | |
changeset 101 | 3eac160a3c2f |
parent 100 | 472b7bea9cad |
child 104 | 974f57e122c1 |
permissions | -rw-r--r-- |
0 | 1 |
"{ Package: 'stx:goodies/sunit' }" |
2 |
||
3 |
Object subclass:#TestResult |
|
101 | 4 |
instanceVariableNames:'runCount passed failures errors' |
5 |
classVariableNames:'' |
|
6 |
poolDictionaries:'' |
|
7 |
category:'SUnit-Base' |
|
0 | 8 |
! |
9 |
||
14 | 10 |
|
68 | 11 |
!TestResult class methodsFor:'exceptions'! |
0 | 12 |
|
13 |
error |
|
14 |
^self exError |
|
15 |
||
16 |
"Modified: / 21.6.2000 / 10:07:16 / Sames" |
|
17 |
! |
|
18 |
||
19 |
exError |
|
74 | 20 |
"Change for Dialect" |
21 |
Smalltalk dialectName = 'SmalltalkX' ifTrue:[ |
|
22 |
^ Exception |
|
23 |
]. |
|
24 |
^Error |
|
0 | 25 |
|
26 |
"Modified: / 21.6.2000 / 10:10:45 / Sames" |
|
27 |
! |
|
28 |
||
29 |
failure |
|
30 |
^TestFailure |
|
31 |
||
32 |
"Modified: / 21.6.2000 / 10:07:03 / Sames" |
|
33 |
! |
|
34 |
||
35 |
signalErrorWith: aString |
|
101 | 36 |
self exError raiseErrorString: aString |
0 | 37 |
|
38 |
"Modified: / 21.6.2000 / 10:11:07 / Sames" |
|
39 |
! |
|
40 |
||
41 |
signalFailureWith: aString |
|
33 | 42 |
self failure raiseErrorString: aString |
0 | 43 |
|
44 |
"Modified: / 21.6.2000 / 10:11:20 / Sames" |
|
45 |
! ! |
|
46 |
||
68 | 47 |
!TestResult class methodsFor:'init / release'! |
0 | 48 |
|
49 |
new |
|
101 | 50 |
^super new initialize |
0 | 51 |
|
52 |
"Modified: / 21.6.2000 / 10:11:50 / Sames" |
|
53 |
! ! |
|
54 |
||
68 | 55 |
!TestResult methodsFor:'accessing'! |
0 | 56 |
|
57 |
correctCount |
|
53 | 58 |
"depreciated - use #passedCount" |
59 |
^self passedCount |
|
60 |
"/ ^self runCount - self failureCount - self errorCount |
|
0 | 61 |
! |
62 |
||
63 |
defects |
|
101 | 64 |
^self errors, self failures |
0 | 65 |
|
66 |
"Modified: / 21.6.2000 / 10:07:56 / Sames" |
|
67 |
! |
|
68 |
||
69 |
errorCount |
|
101 | 70 |
^self errors size |
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
71 |
! |
0 | 72 |
|
73 |
errors |
|
101 | 74 |
errors isNil ifTrue: [errors := OrderedCollection new]. |
75 |
^errors |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
76 |
! |
0 | 77 |
|
78 |
failureCount |
|
101 | 79 |
^self failures size |
0 | 80 |
|
81 |
"Modified: / 21.6.2000 / 10:08:34 / Sames" |
|
82 |
! |
|
83 |
||
84 |
failures |
|
101 | 85 |
failures isNil ifTrue: [failures := OrderedCollection new]. |
86 |
^failures |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
87 |
! |
0 | 88 |
|
53 | 89 |
passed |
101 | 90 |
passed isNil ifTrue: [passed := OrderedCollection new]. |
91 |
^passed |
|
53 | 92 |
! |
93 |
||
94 |
passedCount |
|
95 |
^ self passed size |
|
96 |
"/ ^self runCount - self failureCount - self errorCount |
|
97 |
||
98 |
"Modified: / 21.6.2000 / 10:07:48 / Sames" |
|
99 |
! |
|
100 |
||
0 | 101 |
runCount |
53 | 102 |
(self passedCount + self failureCount + self errorCount) ~~ runCount |
103 |
ifTrue:[ |
|
70 | 104 |
Transcript showCR:'oops - inconsistent runCount (errors in cleanup-ensures)'. |
105 |
"/ self halt:'oops - inconsistent runCount (errors in cleanup-ensures)' |
|
53 | 106 |
]. |
107 |
||
108 |
"/ ^self passedCount + self failureCount + self errorCount |
|
109 |
^runCount |
|
110 |
! |
|
111 |
||
112 |
tests |
|
101 | 113 |
^(OrderedCollection new: self runCount) |
114 |
addAll: self passed; |
|
115 |
addAll: self errors; |
|
116 |
addAll: self defects; |
|
117 |
yourself |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
118 |
! ! |
0 | 119 |
|
68 | 120 |
!TestResult methodsFor:'init / release'! |
0 | 121 |
|
122 |
initialize |
|
101 | 123 |
runCount := 0 |
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
124 |
! ! |
0 | 125 |
|
68 | 126 |
!TestResult methodsFor:'printing'! |
0 | 127 |
|
128 |
printOn: aStream |
|
101 | 129 |
aStream |
130 |
nextPutAll: self runCount printString; |
|
131 |
nextPutAll: ' run, '; |
|
132 |
nextPutAll: self passedCount printString; |
|
133 |
nextPutAll: ' passed, '; |
|
134 |
nextPutAll: self failureCount printString; |
|
135 |
nextPutAll: ' failed, '; |
|
136 |
nextPutAll: self errorCount printString; |
|
137 |
nextPutAll:' error'. |
|
138 |
self errorCount ~= 1 |
|
139 |
ifTrue: [aStream nextPut: $s]. |
|
0 | 140 |
! ! |
141 |
||
68 | 142 |
!TestResult methodsFor:'running'! |
0 | 143 |
|
144 |
runCase: aTestCase |
|
53 | 145 |
|testCasePassed| |
146 |
||
18 | 147 |
runCount := runCount + 1. |
53 | 148 |
[ |
149 |
[aTestCase runCase. |
|
150 |
testCasePassed := true.] |
|
18 | 151 |
on: self class failure |
100 | 152 |
do:[:ex | |
53 | 153 |
self failures add: aTestCase. |
154 |
testCasePassed := false. |
|
100 | 155 |
ex returnWith: false] |
53 | 156 |
] |
101 | 157 |
on: self class exError |
100 | 158 |
do:[:ex | |
159 |
ex signal isQuerySignal ifTrue:[ |
|
160 |
ex proceed. |
|
161 |
]. |
|
53 | 162 |
self errors add: aTestCase. |
163 |
testCasePassed := false. |
|
100 | 164 |
ex returnWith: false]. |
53 | 165 |
|
166 |
testCasePassed ifTrue: [self passed add: aTestCase] |
|
0 | 167 |
|
168 |
"Modified: / 21.6.2000 / 10:10:06 / Sames" |
|
169 |
! ! |
|
170 |
||
68 | 171 |
!TestResult methodsFor:'testing'! |
0 | 172 |
|
53 | 173 |
hasErrors |
174 |
||
101 | 175 |
^self errors size > 0 |
53 | 176 |
! |
177 |
||
178 |
hasFailures |
|
179 |
||
101 | 180 |
^self failures size > 0 |
53 | 181 |
! |
182 |
||
0 | 183 |
hasPassed |
53 | 184 |
^self hasErrors not and: [self hasFailures not] |
185 |
"/ ^self runCount = self correctCount |
|
186 |
! |
|
187 |
||
188 |
isError: aTestCase |
|
189 |
||
101 | 190 |
^self errors includes: aTestCase |
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
191 |
! |
0 | 192 |
|
193 |
isFailure: aTestCase |
|
101 | 194 |
^self failures includes: aTestCase |
53 | 195 |
! |
196 |
||
197 |
isPassed: aTestCase |
|
198 |
||
101 | 199 |
^self passed includes: aTestCase |
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
200 |
! ! |
0 | 201 |
|
14 | 202 |
!TestResult class methodsFor:'documentation'! |
203 |
||
204 |
version |
|
101 | 205 |
^ '$Header: /cvs/stx/stx/goodies/sunit/TestResult.st,v 1.13 2003-08-25 11:43:57 tm Exp $' |
14 | 206 |
! ! |