222
|
1 |
"{ Package: 'stx:goodies/sunit' }"
|
|
2 |
|
647
|
3 |
"{ NameSpace: Smalltalk }"
|
|
4 |
|
222
|
5 |
Object subclass:#TestAsserter
|
376
|
6 |
instanceVariableNames:''
|
222
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
|
9 |
category:'SUnit-Base'
|
|
10 |
!
|
|
11 |
|
|
12 |
TestAsserter comment:''
|
|
13 |
!
|
|
14 |
|
|
15 |
|
|
16 |
!TestAsserter class methodsFor:'asserting'!
|
|
17 |
|
|
18 |
assert: aBoolean description: aString
|
|
19 |
"Minimal clone of the instance-side assert protocol so that class-side methods can use it."
|
|
20 |
|
|
21 |
aBoolean ifFalse:
|
|
22 |
[self logFailure: aString.
|
|
23 |
TestResult failure sunitSignalWith: aString].
|
|
24 |
! !
|
|
25 |
|
|
26 |
!TestAsserter class methodsFor:'logging'!
|
|
27 |
|
|
28 |
failureLog
|
|
29 |
^SUnitNameResolver defaultLogDevice
|
|
30 |
!
|
|
31 |
|
|
32 |
isLogging
|
|
33 |
"By default, we're not logging failures. Override in subclasses as desired."
|
|
34 |
|
|
35 |
^false
|
|
36 |
!
|
|
37 |
|
|
38 |
logFailure: aString
|
|
39 |
self isLogging ifTrue:
|
|
40 |
[self failureLog cr; nextPutAll: aString; flush].
|
551
|
41 |
!
|
|
42 |
|
|
43 |
logSkipped: aString
|
|
44 |
self isLogging ifTrue:
|
|
45 |
[self failureLog cr; nextPutAll: aString; flush].
|
222
|
46 |
! !
|
|
47 |
|
|
48 |
!TestAsserter methodsFor:'asserting'!
|
|
49 |
|
|
50 |
assert: aBoolean
|
566
|
51 |
"fail the testcase if aBoolean is false"
|
222
|
52 |
|
|
53 |
<resource: #skipInDebuggersWalkBack>
|
|
54 |
|
|
55 |
aBoolean ifFalse:
|
566
|
56 |
[self logFailure: 'Assertion failed'.
|
|
57 |
TestResult failure sunitSignalWith: 'Assertion failed'].
|
222
|
58 |
|
|
59 |
"Modified: / 05-12-2009 / 18:14:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
60 |
!
|
|
61 |
|
|
62 |
assert:aBoolean description:aString
|
566
|
63 |
"fail the testCase if aBoolean is false,
|
|
64 |
and report aString as failure-description."
|
|
65 |
|
222
|
66 |
<resource: #skipInDebuggersWalkBack>
|
|
67 |
|
|
68 |
^self assert:aBoolean description:aString resumable: false.
|
|
69 |
|
|
70 |
"Modified: / 06-08-2006 / 22:56:27 / cg"
|
|
71 |
"Modified: / 11-09-2010 / 15:34:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
72 |
!
|
|
73 |
|
|
74 |
assert: aBoolean description: aString resumable: resumableBoolean
|
|
75 |
|
|
76 |
<resource: #skipInDebuggersWalkBack>
|
|
77 |
| exception |
|
|
78 |
aBoolean ifFalse:
|
|
79 |
[self logFailure: aString.
|
|
80 |
exception := resumableBoolean
|
|
81 |
ifTrue: [TestResult resumableFailure]
|
|
82 |
ifFalse: [TestResult failure].
|
|
83 |
exception sunitSignalWith: aString].
|
|
84 |
|
|
85 |
"Modified: / 05-12-2009 / 18:15:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
86 |
!
|
|
87 |
|
|
88 |
deny: aBoolean
|
566
|
89 |
"fail the testcase if aBoolean is true"
|
222
|
90 |
|
|
91 |
<resource: #skipInDebuggersWalkBack>
|
|
92 |
|
|
93 |
self assert: aBoolean not.
|
|
94 |
|
|
95 |
"Modified: / 05-12-2009 / 18:16:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
96 |
!
|
|
97 |
|
|
98 |
deny: aBoolean description: aString
|
566
|
99 |
"fail the testCase if aBoolean is true,
|
|
100 |
and report aString as failure-description."
|
222
|
101 |
|
|
102 |
<resource: #skipInDebuggersWalkBack>
|
566
|
103 |
|
222
|
104 |
self assert: aBoolean not description: aString.
|
|
105 |
|
|
106 |
"Modified: / 05-12-2009 / 18:17:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
107 |
!
|
|
108 |
|
|
109 |
deny: aBoolean description: aString resumable: resumableBoolean
|
|
110 |
|
|
111 |
<resource: #skipInDebuggersWalkBack>
|
|
112 |
|
|
113 |
self assert: aBoolean not description: aString resumable: resumableBoolean.
|
|
114 |
|
|
115 |
"Modified: / 05-12-2009 / 18:17:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
116 |
!
|
|
117 |
|
|
118 |
should: aBlock raise: anExceptionalEvent
|
566
|
119 |
"during the execution of aBlock, the anExceptionalEvent should be raised"
|
222
|
120 |
|
|
121 |
<resource: #skipInDebuggersWalkBack>
|
|
122 |
|
|
123 |
self assert: (self executeShould: aBlock inScopeOf: anExceptionalEvent).
|
|
124 |
|
|
125 |
"Modified: / 05-12-2009 / 18:18:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
126 |
!
|
|
127 |
|
|
128 |
should: aBlock raise: anExceptionalEvent description: aString
|
566
|
129 |
"during the execution of aBlock, the anExceptionalEvent should be raised.
|
|
130 |
If not, report aString as failure-description."
|
222
|
131 |
|
|
132 |
<resource: #skipInDebuggersWalkBack>
|
|
133 |
|
|
134 |
self
|
566
|
135 |
assert: (self executeShould: aBlock inScopeOf: anExceptionalEvent)
|
|
136 |
description: aString.
|
222
|
137 |
|
|
138 |
"Modified: / 05-12-2009 / 18:18:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
139 |
!
|
|
140 |
|
|
141 |
should: aBlock raise: anExceptionalEvent suchThat: condBlock
|
566
|
142 |
"during the execution of aBlock, the anExceptionalEvent should be raised,
|
|
143 |
and condBlock should return true on the exception instance"
|
222
|
144 |
|
|
145 |
<resource: #skipInDebuggersWalkBack>
|
|
146 |
|
|
147 |
self assert: (self executeShould: aBlock inScopeOf: anExceptionalEvent suchThat: condBlock).
|
|
148 |
|
|
149 |
"Created: / 05-05-2011 / 20:14:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
150 |
!
|
|
151 |
|
|
152 |
should: aBlock raise: anExceptionalEvent suchThat: condBlock description: description
|
566
|
153 |
"during the execution of aBlock, the anExceptionalEvent should be raised,
|
|
154 |
and condBlock should return true on the exception instance.
|
|
155 |
If not, report aString as failure-description."
|
222
|
156 |
|
|
157 |
<resource: #skipInDebuggersWalkBack>
|
|
158 |
|
|
159 |
self assert: (self executeShould: aBlock inScopeOf: anExceptionalEvent suchThat: condBlock)
|
566
|
160 |
description: description
|
222
|
161 |
|
|
162 |
"Created: / 05-05-2011 / 20:14:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
163 |
!
|
|
164 |
|
566
|
165 |
should: aBlock raise: anExceptionalEvent whoseDescriptionIncludes: aStringFragment
|
|
166 |
"during the execution of aBlock, the anExceptionalEvent should be raised,
|
|
167 |
and aStringFragment should be contained in the exception-instances description."
|
|
168 |
|
|
169 |
<resource: #skipInDebuggersWalkBack>
|
|
170 |
|
|
171 |
^ self should: aBlock
|
|
172 |
raise: anExceptionalEvent
|
|
173 |
suchThat:[:ex | ex description includesString: aStringFragment]
|
|
174 |
!
|
|
175 |
|
|
176 |
should:aBlock raise:anExceptionalEvent whoseDescriptionIncludes:aStringFragment description:aString
|
|
177 |
"during the execution of aBlock, the anExceptionalEvent should be raised,
|
|
178 |
and aStringFragment should be contained in the exception-instances description.
|
|
179 |
If not, report aString as failure-description."
|
|
180 |
|
|
181 |
<resource: #skipInDebuggersWalkBack>
|
|
182 |
|
|
183 |
^ self should: aBlock
|
|
184 |
raise: anExceptionalEvent
|
|
185 |
suchThat:[:ex | ex description includesString: aStringFragment]
|
|
186 |
description: aString.
|
|
187 |
!
|
|
188 |
|
222
|
189 |
shouldnt: aBlock raise: anExceptionalEvent
|
566
|
190 |
"during the execution of aBlock, the anExceptionalEvent should NOT be raised"
|
222
|
191 |
|
|
192 |
<resource: #skipInDebuggersWalkBack>
|
|
193 |
|
|
194 |
self
|
566
|
195 |
assert: (self executeShould: aBlock inScopeOf: anExceptionalEvent) not.
|
222
|
196 |
|
|
197 |
"Modified: / 05-12-2009 / 18:18:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
198 |
!
|
|
199 |
|
|
200 |
shouldnt: aBlock raise: anExceptionalEvent description: aString
|
566
|
201 |
"during the execution of aBlock, the anExceptionalEvent should NOT be raised.
|
|
202 |
If not, report aString as failure-description."
|
222
|
203 |
|
|
204 |
<resource: #skipInDebuggersWalkBack>
|
|
205 |
|
|
206 |
self
|
566
|
207 |
assert: (self executeShould: aBlock inScopeOf: anExceptionalEvent) not
|
|
208 |
description: aString.
|
222
|
209 |
|
|
210 |
"Modified: / 05-12-2009 / 18:18:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
551
|
211 |
!
|
|
212 |
|
647
|
213 |
skip
|
|
214 |
"skip this test"
|
|
215 |
|
649
|
216 |
self skipIf:true description:'Unconditionally'.
|
|
217 |
!
|
|
218 |
|
|
219 |
skip:aString
|
|
220 |
"skip this test"
|
|
221 |
|
|
222 |
self skipIf:true description:aString
|
647
|
223 |
!
|
|
224 |
|
551
|
225 |
skipIf:aCondition description:aString
|
647
|
226 |
"skip this test, if some condition is met"
|
|
227 |
|
|
228 |
aCondition value ifTrue: [
|
|
229 |
self logSkipped: 'Skipped - ',aString.
|
|
230 |
TestResult skipped sunitSignalWith: aString
|
|
231 |
].
|
222
|
232 |
! !
|
|
233 |
|
|
234 |
!TestAsserter methodsFor:'convenience'!
|
|
235 |
|
|
236 |
assert: anObject equals: anotherObject
|
|
237 |
self assert: anObject = anotherObject
|
|
238 |
description: anObject printString, ' is not equal to ', anotherObject printString.
|
|
239 |
! !
|
|
240 |
|
|
241 |
!TestAsserter methodsFor:'logging'!
|
|
242 |
|
|
243 |
logFailure: aString
|
|
244 |
self class logFailure: aString.
|
551
|
245 |
!
|
|
246 |
|
|
247 |
logSkipped: aString
|
|
248 |
self class logSkipped: aString.
|
222
|
249 |
! !
|
|
250 |
|
|
251 |
!TestAsserter methodsFor:'private'!
|
|
252 |
|
|
253 |
executeShould: execBlock inScopeOf: exceptionalEvent
|
|
254 |
|
|
255 |
<resource: #skipInDebuggersWalkBack>
|
|
256 |
|
|
257 |
^ self
|
|
258 |
executeShould: execBlock
|
|
259 |
inScopeOf: exceptionalEvent
|
|
260 |
suchThat: [:ex | true ]
|
|
261 |
|
|
262 |
"Modified: / 05-05-2011 / 20:23:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
263 |
!
|
|
264 |
|
|
265 |
executeShould: execBlock inScopeOf: exceptionalEvent suchThat: conditionBlock
|
|
266 |
^[execBlock value.
|
|
267 |
false]
|
|
268 |
sunitOn: exceptionalEvent
|
|
269 |
do:
|
|
270 |
[:ex |
|
|
271 |
ex sunitExitWith:(conditionBlock value: ex)]
|
|
272 |
|
|
273 |
"Created: / 05-05-2011 / 20:08:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
274 |
! !
|
|
275 |
|
|
276 |
!TestAsserter class methodsFor:'documentation'!
|
|
277 |
|
286
|
278 |
version
|
647
|
279 |
^ '$Header$'
|
286
|
280 |
!
|
|
281 |
|
223
|
282 |
version_CVS
|
647
|
283 |
^ '$Header$'
|
223
|
284 |
!
|
|
285 |
|
222
|
286 |
version_SVN
|
647
|
287 |
^ '$Id$'
|
222
|
288 |
! !
|
551
|
289 |
|