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