222
|
1 |
"{ Package: 'stx:goodies/sunit' }"
|
|
2 |
|
|
3 |
Object subclass:#TestAsserter
|
|
4 |
instanceVariableNames:''
|
|
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 |
|
|
43 |
coveredClasses
|
|
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 |
|
|
50 |
"Created: / 04-07-2011 / 18:16:08 / cg"
|
|
51 |
! !
|
|
52 |
|
222
|
53 |
!TestAsserter methodsFor:'asserting'!
|
|
54 |
|
|
55 |
assert: aBoolean
|
|
56 |
|
|
57 |
<resource: #skipInDebuggersWalkBack>
|
|
58 |
|
|
59 |
aBoolean ifFalse:
|
|
60 |
[self logFailure: 'Assertion failed'.
|
|
61 |
TestResult failure sunitSignalWith: 'Assertion failed'].
|
|
62 |
|
|
63 |
"Modified: / 05-12-2009 / 18:14:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
64 |
!
|
|
65 |
|
|
66 |
assert:aBoolean description:aString
|
|
67 |
<resource: #skipInDebuggersWalkBack>
|
|
68 |
|
|
69 |
^self assert:aBoolean description:aString resumable: false.
|
|
70 |
|
|
71 |
"Modified: / 06-08-2006 / 22:56:27 / cg"
|
|
72 |
"Modified: / 11-09-2010 / 15:34:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
73 |
!
|
|
74 |
|
|
75 |
assert: aBoolean description: aString resumable: resumableBoolean
|
|
76 |
|
|
77 |
<resource: #skipInDebuggersWalkBack>
|
|
78 |
| exception |
|
|
79 |
aBoolean ifFalse:
|
|
80 |
[self logFailure: aString.
|
|
81 |
exception := resumableBoolean
|
|
82 |
ifTrue: [TestResult resumableFailure]
|
|
83 |
ifFalse: [TestResult failure].
|
|
84 |
exception sunitSignalWith: aString].
|
|
85 |
|
|
86 |
"Modified: / 05-12-2009 / 18:15:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
87 |
!
|
|
88 |
|
|
89 |
deny: aBoolean
|
|
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
|
|
99 |
|
|
100 |
<resource: #skipInDebuggersWalkBack>
|
|
101 |
self assert: aBoolean not description: aString.
|
|
102 |
|
|
103 |
"Modified: / 05-12-2009 / 18:17:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
104 |
!
|
|
105 |
|
|
106 |
deny: aBoolean description: aString resumable: resumableBoolean
|
|
107 |
|
|
108 |
<resource: #skipInDebuggersWalkBack>
|
|
109 |
|
|
110 |
self assert: aBoolean not description: aString resumable: resumableBoolean.
|
|
111 |
|
|
112 |
"Modified: / 05-12-2009 / 18:17:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
113 |
!
|
|
114 |
|
|
115 |
should: aBlock raise: anExceptionalEvent
|
|
116 |
|
|
117 |
<resource: #skipInDebuggersWalkBack>
|
|
118 |
|
|
119 |
self assert: (self executeShould: aBlock inScopeOf: anExceptionalEvent).
|
|
120 |
|
|
121 |
"Modified: / 05-12-2009 / 18:18:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
122 |
!
|
|
123 |
|
|
124 |
should: aBlock raise: anExceptionalEvent description: aString
|
|
125 |
|
|
126 |
<resource: #skipInDebuggersWalkBack>
|
|
127 |
|
|
128 |
self
|
|
129 |
assert: (self executeShould: aBlock inScopeOf: anExceptionalEvent)
|
|
130 |
description: aString.
|
|
131 |
|
|
132 |
"Modified: / 05-12-2009 / 18:18:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
133 |
!
|
|
134 |
|
|
135 |
should: aBlock raise: anExceptionalEvent suchThat: condBlock
|
|
136 |
|
|
137 |
<resource: #skipInDebuggersWalkBack>
|
|
138 |
|
|
139 |
self assert: (self executeShould: aBlock inScopeOf: anExceptionalEvent suchThat: condBlock).
|
|
140 |
|
|
141 |
"Created: / 05-05-2011 / 20:14:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
142 |
!
|
|
143 |
|
|
144 |
should: aBlock raise: anExceptionalEvent suchThat: condBlock description: description
|
|
145 |
|
|
146 |
<resource: #skipInDebuggersWalkBack>
|
|
147 |
|
|
148 |
self assert: (self executeShould: aBlock inScopeOf: anExceptionalEvent suchThat: condBlock)
|
|
149 |
description: description
|
|
150 |
|
|
151 |
"Created: / 05-05-2011 / 20:14:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
152 |
!
|
|
153 |
|
|
154 |
shouldnt: aBlock raise: anExceptionalEvent
|
|
155 |
|
|
156 |
<resource: #skipInDebuggersWalkBack>
|
|
157 |
|
|
158 |
self
|
|
159 |
assert: (self executeShould: aBlock inScopeOf: anExceptionalEvent) not.
|
|
160 |
|
|
161 |
"Modified: / 05-12-2009 / 18:18:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
162 |
!
|
|
163 |
|
|
164 |
shouldnt: aBlock raise: anExceptionalEvent description: aString
|
|
165 |
|
|
166 |
<resource: #skipInDebuggersWalkBack>
|
|
167 |
|
|
168 |
self
|
|
169 |
assert: (self executeShould: aBlock inScopeOf: anExceptionalEvent) not
|
|
170 |
description: aString.
|
|
171 |
|
|
172 |
"Modified: / 05-12-2009 / 18:18:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
173 |
! !
|
|
174 |
|
|
175 |
!TestAsserter methodsFor:'convenience'!
|
|
176 |
|
|
177 |
assert: anObject equals: anotherObject
|
|
178 |
self assert: anObject = anotherObject
|
|
179 |
description: anObject printString, ' is not equal to ', anotherObject printString.
|
|
180 |
! !
|
|
181 |
|
|
182 |
!TestAsserter methodsFor:'logging'!
|
|
183 |
|
|
184 |
logFailure: aString
|
|
185 |
self class logFailure: aString.
|
|
186 |
! !
|
|
187 |
|
|
188 |
!TestAsserter methodsFor:'private'!
|
|
189 |
|
|
190 |
executeShould: execBlock inScopeOf: exceptionalEvent
|
|
191 |
|
|
192 |
<resource: #skipInDebuggersWalkBack>
|
|
193 |
|
|
194 |
^ self
|
|
195 |
executeShould: execBlock
|
|
196 |
inScopeOf: exceptionalEvent
|
|
197 |
suchThat: [:ex | true ]
|
|
198 |
|
|
199 |
"Modified: / 05-05-2011 / 20:23:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
200 |
!
|
|
201 |
|
|
202 |
executeShould: execBlock inScopeOf: exceptionalEvent suchThat: conditionBlock
|
|
203 |
^[execBlock value.
|
|
204 |
false]
|
|
205 |
sunitOn: exceptionalEvent
|
|
206 |
do:
|
|
207 |
[:ex |
|
|
208 |
ex sunitExitWith:(conditionBlock value: ex)]
|
|
209 |
|
|
210 |
"Created: / 05-05-2011 / 20:08:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
211 |
! !
|
|
212 |
|
|
213 |
!TestAsserter class methodsFor:'documentation'!
|
|
214 |
|
223
|
215 |
version_CVS
|
|
216 |
^ '$Header: /cvs/stx/stx/goodies/sunit/TestAsserter.st,v 1.2 2011-07-04 16:16:29 cg Exp $'
|
|
217 |
!
|
|
218 |
|
222
|
219 |
version_SVN
|
|
220 |
^ '§Id: TestAsserter.st 217 2011-05-05 19:33:11Z vranyj1 §'
|
|
221 |
! !
|