author | vrany |
Tue, 02 Aug 2011 18:57:10 +0200 | |
changeset 295 | f41960a0ee97 |
parent 291 | ca207bd1546d |
child 317 | 81d237f7ac0c |
permissions | -rw-r--r-- |
222 | 1 |
"{ Package: 'stx:goodies/sunit' }" |
2 |
||
3 |
Object subclass:#TestAsserter |
|
291 | 4 |
instanceVariableNames:'startTime endTime backtrace exceptionInfoString' |
222 | 5 |
classVariableNames:'' |
6 |
poolDictionaries:'' |
|
7 |
category:'SUnit-Base' |
|
8 |
! |
|
9 |
||
10 |
TestAsserter comment:'' |
|
11 |
! |
|
12 |
||
13 |
||
14 |
!TestAsserter class methodsFor:'asserting'! |
|
15 |
||
16 |
assert: aBoolean description: aString |
|
17 |
"Minimal clone of the instance-side assert protocol so that class-side methods can use it." |
|
18 |
||
19 |
aBoolean ifFalse: |
|
20 |
[self logFailure: aString. |
|
21 |
TestResult failure sunitSignalWith: aString]. |
|
22 |
! ! |
|
23 |
||
24 |
!TestAsserter class methodsFor:'logging'! |
|
25 |
||
26 |
failureLog |
|
27 |
^SUnitNameResolver defaultLogDevice |
|
28 |
! |
|
29 |
||
30 |
isLogging |
|
31 |
"By default, we're not logging failures. Override in subclasses as desired." |
|
32 |
||
33 |
^false |
|
34 |
! |
|
35 |
||
36 |
logFailure: aString |
|
37 |
self isLogging ifTrue: |
|
38 |
[self failureLog cr; nextPutAll: aString; flush]. |
|
39 |
! ! |
|
40 |
||
223 | 41 |
!TestAsserter class methodsFor:'queries'! |
42 |
||
253 | 43 |
coveredClassNames |
223 | 44 |
"should be redefined to return a collection of classes which are tested by |
45 |
this suite/case. These classes can be instrumented for coverage analysis, |
|
46 |
before running the suite" |
|
47 |
||
48 |
^ #() |
|
49 |
||
253 | 50 |
"Created: / 06-07-2011 / 21:27:03 / cg" |
51 |
! |
|
52 |
||
53 |
coveredClasses |
|
54 |
"return a collection of classes which are tested by this suite/case. |
|
55 |
These classes can be instrumented for coverage analysis, |
|
56 |
before running the suite" |
|
57 |
||
58 |
^ self coveredClassNames collect:[:each | Smalltalk classNamed:each] |
|
59 |
||
223 | 60 |
"Created: / 04-07-2011 / 18:16:08 / cg" |
61 |
! ! |
|
62 |
||
266
ca61f2c647f5
remember execution time (needed to generate prober reports)
Claus Gittinger <cg@exept.de>
parents:
253
diff
changeset
|
63 |
!TestAsserter methodsFor:'accessing'! |
ca61f2c647f5
remember execution time (needed to generate prober reports)
Claus Gittinger <cg@exept.de>
parents:
253
diff
changeset
|
64 |
|
287 | 65 |
endTime |
66 |
"the end time as timestamp; nil if not yet executed or not yet finished" |
|
67 |
||
68 |
^ endTime |
|
69 |
||
70 |
"Created: / 02-08-2011 / 17:43:11 / cg" |
|
71 |
! |
|
72 |
||
291 | 73 |
exceptionInfoString |
74 |
"the stack backtrace as a string (but only if executed and not passed). |
|
75 |
(I guess, there is no standard format for context information among |
|
76 |
the smalltalks, so a string containing the backtrace is the best we can |
|
77 |
do to keep things portable AND be able to present the backtrace in a hudson page)" |
|
289 | 78 |
|
291 | 79 |
^ exceptionInfoString |
289 | 80 |
|
291 | 81 |
"Modified: / 01-08-2011 / 16:52:51 / cg" |
82 |
"Created: / 02-08-2011 / 18:13:16 / cg" |
|
289 | 83 |
! |
84 |
||
266
ca61f2c647f5
remember execution time (needed to generate prober reports)
Claus Gittinger <cg@exept.de>
parents:
253
diff
changeset
|
85 |
executionTime |
ca61f2c647f5
remember execution time (needed to generate prober reports)
Claus Gittinger <cg@exept.de>
parents:
253
diff
changeset
|
86 |
"the execution time in millis; nil if not yet executed" |
ca61f2c647f5
remember execution time (needed to generate prober reports)
Claus Gittinger <cg@exept.de>
parents:
253
diff
changeset
|
87 |
|
ca61f2c647f5
remember execution time (needed to generate prober reports)
Claus Gittinger <cg@exept.de>
parents:
253
diff
changeset
|
88 |
startTime isNil ifTrue:[ |
ca61f2c647f5
remember execution time (needed to generate prober reports)
Claus Gittinger <cg@exept.de>
parents:
253
diff
changeset
|
89 |
"/ not yet executed |
ca61f2c647f5
remember execution time (needed to generate prober reports)
Claus Gittinger <cg@exept.de>
parents:
253
diff
changeset
|
90 |
^ nil |
ca61f2c647f5
remember execution time (needed to generate prober reports)
Claus Gittinger <cg@exept.de>
parents:
253
diff
changeset
|
91 |
]. |
286 | 92 |
^ (endTime deltaFrom:startTime) getMilliseconds |
266
ca61f2c647f5
remember execution time (needed to generate prober reports)
Claus Gittinger <cg@exept.de>
parents:
253
diff
changeset
|
93 |
|
286 | 94 |
"Modified: / 01-08-2011 / 16:52:51 / cg" |
266
ca61f2c647f5
remember execution time (needed to generate prober reports)
Claus Gittinger <cg@exept.de>
parents:
253
diff
changeset
|
95 |
! |
ca61f2c647f5
remember execution time (needed to generate prober reports)
Claus Gittinger <cg@exept.de>
parents:
253
diff
changeset
|
96 |
|
ca61f2c647f5
remember execution time (needed to generate prober reports)
Claus Gittinger <cg@exept.de>
parents:
253
diff
changeset
|
97 |
startTime |
ca61f2c647f5
remember execution time (needed to generate prober reports)
Claus Gittinger <cg@exept.de>
parents:
253
diff
changeset
|
98 |
"the start time as timestamp; nil if not yet executed" |
ca61f2c647f5
remember execution time (needed to generate prober reports)
Claus Gittinger <cg@exept.de>
parents:
253
diff
changeset
|
99 |
|
ca61f2c647f5
remember execution time (needed to generate prober reports)
Claus Gittinger <cg@exept.de>
parents:
253
diff
changeset
|
100 |
^ startTime |
ca61f2c647f5
remember execution time (needed to generate prober reports)
Claus Gittinger <cg@exept.de>
parents:
253
diff
changeset
|
101 |
|
ca61f2c647f5
remember execution time (needed to generate prober reports)
Claus Gittinger <cg@exept.de>
parents:
253
diff
changeset
|
102 |
"Created: / 30-07-2011 / 10:06:05 / cg" |
ca61f2c647f5
remember execution time (needed to generate prober reports)
Claus Gittinger <cg@exept.de>
parents:
253
diff
changeset
|
103 |
! ! |
ca61f2c647f5
remember execution time (needed to generate prober reports)
Claus Gittinger <cg@exept.de>
parents:
253
diff
changeset
|
104 |
|
222 | 105 |
!TestAsserter methodsFor:'asserting'! |
106 |
||
107 |
assert: aBoolean |
|
108 |
||
109 |
<resource: #skipInDebuggersWalkBack> |
|
110 |
||
111 |
aBoolean ifFalse: |
|
112 |
[self logFailure: 'Assertion failed'. |
|
113 |
TestResult failure sunitSignalWith: 'Assertion failed']. |
|
114 |
||
115 |
"Modified: / 05-12-2009 / 18:14:08 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
116 |
! |
|
117 |
||
118 |
assert:aBoolean description:aString |
|
119 |
<resource: #skipInDebuggersWalkBack> |
|
120 |
||
121 |
^self assert:aBoolean description:aString resumable: false. |
|
122 |
||
123 |
"Modified: / 06-08-2006 / 22:56:27 / cg" |
|
124 |
"Modified: / 11-09-2010 / 15:34:11 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
125 |
! |
|
126 |
||
127 |
assert: aBoolean description: aString resumable: resumableBoolean |
|
128 |
||
129 |
<resource: #skipInDebuggersWalkBack> |
|
130 |
| exception | |
|
131 |
aBoolean ifFalse: |
|
132 |
[self logFailure: aString. |
|
133 |
exception := resumableBoolean |
|
134 |
ifTrue: [TestResult resumableFailure] |
|
135 |
ifFalse: [TestResult failure]. |
|
136 |
exception sunitSignalWith: aString]. |
|
137 |
||
138 |
"Modified: / 05-12-2009 / 18:15:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
139 |
! |
|
140 |
||
141 |
deny: aBoolean |
|
142 |
||
143 |
<resource: #skipInDebuggersWalkBack> |
|
144 |
||
145 |
self assert: aBoolean not. |
|
146 |
||
147 |
"Modified: / 05-12-2009 / 18:16:47 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
148 |
! |
|
149 |
||
150 |
deny: aBoolean description: aString |
|
151 |
||
152 |
<resource: #skipInDebuggersWalkBack> |
|
153 |
self assert: aBoolean not description: aString. |
|
154 |
||
155 |
"Modified: / 05-12-2009 / 18:17:02 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
156 |
! |
|
157 |
||
158 |
deny: aBoolean description: aString resumable: resumableBoolean |
|
159 |
||
160 |
<resource: #skipInDebuggersWalkBack> |
|
161 |
||
162 |
self assert: aBoolean not description: aString resumable: resumableBoolean. |
|
163 |
||
164 |
"Modified: / 05-12-2009 / 18:17:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
165 |
! |
|
166 |
||
167 |
should: aBlock raise: anExceptionalEvent |
|
168 |
||
169 |
<resource: #skipInDebuggersWalkBack> |
|
170 |
||
171 |
self assert: (self executeShould: aBlock inScopeOf: anExceptionalEvent). |
|
172 |
||
173 |
"Modified: / 05-12-2009 / 18:18:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
174 |
! |
|
175 |
||
176 |
should: aBlock raise: anExceptionalEvent description: aString |
|
177 |
||
178 |
<resource: #skipInDebuggersWalkBack> |
|
179 |
||
180 |
self |
|
181 |
assert: (self executeShould: aBlock inScopeOf: anExceptionalEvent) |
|
182 |
description: aString. |
|
183 |
||
184 |
"Modified: / 05-12-2009 / 18:18:08 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
185 |
! |
|
186 |
||
187 |
should: aBlock raise: anExceptionalEvent suchThat: condBlock |
|
188 |
||
189 |
<resource: #skipInDebuggersWalkBack> |
|
190 |
||
191 |
self assert: (self executeShould: aBlock inScopeOf: anExceptionalEvent suchThat: condBlock). |
|
192 |
||
193 |
"Created: / 05-05-2011 / 20:14:14 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
194 |
! |
|
195 |
||
196 |
should: aBlock raise: anExceptionalEvent suchThat: condBlock description: description |
|
197 |
||
198 |
<resource: #skipInDebuggersWalkBack> |
|
199 |
||
200 |
self assert: (self executeShould: aBlock inScopeOf: anExceptionalEvent suchThat: condBlock) |
|
201 |
description: description |
|
202 |
||
203 |
"Created: / 05-05-2011 / 20:14:55 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
204 |
! |
|
205 |
||
206 |
shouldnt: aBlock raise: anExceptionalEvent |
|
207 |
||
208 |
<resource: #skipInDebuggersWalkBack> |
|
209 |
||
210 |
self |
|
211 |
assert: (self executeShould: aBlock inScopeOf: anExceptionalEvent) not. |
|
212 |
||
213 |
"Modified: / 05-12-2009 / 18:18:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
214 |
! |
|
215 |
||
216 |
shouldnt: aBlock raise: anExceptionalEvent description: aString |
|
217 |
||
218 |
<resource: #skipInDebuggersWalkBack> |
|
219 |
||
220 |
self |
|
221 |
assert: (self executeShould: aBlock inScopeOf: anExceptionalEvent) not |
|
222 |
description: aString. |
|
223 |
||
224 |
"Modified: / 05-12-2009 / 18:18:53 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
225 |
! ! |
|
226 |
||
227 |
!TestAsserter methodsFor:'convenience'! |
|
228 |
||
229 |
assert: anObject equals: anotherObject |
|
230 |
self assert: anObject = anotherObject |
|
231 |
description: anObject printString, ' is not equal to ', anotherObject printString. |
|
232 |
! ! |
|
233 |
||
234 |
!TestAsserter methodsFor:'logging'! |
|
235 |
||
291 | 236 |
exceptionInfoString:exceptionInfoStringArg |
237 |
"remember the exception info, a string containing the stack backtrace |
|
238 |
(I guess, there is no standard format for context information among |
|
239 |
the smalltalks, so a string containing the backtrace is the best we can |
|
240 |
do to keep things portable AND be able to present the backtrace in a hudson page. |
|
241 |
It is the caller's responsibility to generate something human readable)" |
|
289 | 242 |
|
291 | 243 |
exceptionInfoString := exceptionInfoStringArg |
289 | 244 |
|
291 | 245 |
"Created: / 02-08-2011 / 17:57:16 / cg" |
289 | 246 |
! |
247 |
||
222 | 248 |
logFailure: aString |
249 |
self class logFailure: aString. |
|
250 |
! ! |
|
251 |
||
252 |
!TestAsserter methodsFor:'private'! |
|
253 |
||
254 |
executeShould: execBlock inScopeOf: exceptionalEvent |
|
255 |
||
256 |
<resource: #skipInDebuggersWalkBack> |
|
257 |
||
258 |
^ self |
|
259 |
executeShould: execBlock |
|
260 |
inScopeOf: exceptionalEvent |
|
261 |
suchThat: [:ex | true ] |
|
262 |
||
263 |
"Modified: / 05-05-2011 / 20:23:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
264 |
! |
|
265 |
||
266 |
executeShould: execBlock inScopeOf: exceptionalEvent suchThat: conditionBlock |
|
267 |
^[execBlock value. |
|
268 |
false] |
|
269 |
sunitOn: exceptionalEvent |
|
270 |
do: |
|
271 |
[:ex | |
|
272 |
ex sunitExitWith:(conditionBlock value: ex)] |
|
273 |
||
274 |
"Created: / 05-05-2011 / 20:08:46 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
275 |
! ! |
|
276 |
||
277 |
!TestAsserter class methodsFor:'documentation'! |
|
278 |
||
286 | 279 |
version |
291 | 280 |
^ '$Header: /cvs/stx/stx/goodies/sunit/TestAsserter.st,v 1.9 2011-08-02 16:14:37 cg Exp $' |
286 | 281 |
! |
282 |
||
223 | 283 |
version_CVS |
291 | 284 |
^ '$Header: /cvs/stx/stx/goodies/sunit/TestAsserter.st,v 1.9 2011-08-02 16:14:37 cg Exp $' |
223 | 285 |
! |
286 |
||
222 | 287 |
version_SVN |
288 |
^ '§Id: TestAsserter.st 217 2011-05-05 19:33:11Z vranyj1 §' |
|
289 |
! ! |