author | Jan Vrany <jan.vrany@labware.com> |
Fri, 07 Oct 2022 12:27:15 +0100 | |
branch | jv |
changeset 773 | 5e936bce7857 |
parent 724 | 4dae63fce9f9 |
permissions | -rw-r--r-- |
724
4dae63fce9f9
vIssue #239: Fix all Smalltak/X source files to be in unicode (UTF8 without BOM) and prefixed by "{ Encoding: utf8 }" when any unicode character is present
Patrik Svestka <patrik.svestka@gmail.com>
parents:
664
diff
changeset
|
1 |
"{ Encoding: utf8 }" |
4dae63fce9f9
vIssue #239: Fix all Smalltak/X source files to be in unicode (UTF8 without BOM) and prefixed by "{ Encoding: utf8 }" when any unicode character is present
Patrik Svestka <patrik.svestka@gmail.com>
parents:
664
diff
changeset
|
2 |
|
0 | 3 |
"{ Package: 'stx:goodies/sunit' }" |
4 |
||
664
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
5 |
"{ NameSpace: Smalltalk }" |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
6 |
|
0 | 7 |
TestCase subclass:#SUnitTest |
8 |
instanceVariableNames:'hasRun hasSetup hasRanOnce' |
|
9 |
classVariableNames:'' |
|
10 |
poolDictionaries:'' |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
11 |
category:'SUnit-Tests' |
0 | 12 |
! |
13 |
||
222 | 14 |
SUnitTest comment:'This is both an example of writing tests and a self test for the SUnit. The tests |
15 |
here are pretty strange, since you want to make sure things blow up. You should |
|
16 |
not generally have to write tests this complicated in structure, although they |
|
17 |
will be far more complicated in terms of your own objects- more assertions, more |
|
18 |
complicated setup. Kent says: "Never forget, however, that if the tests are hard |
|
109 | 19 |
to write, something is probably wrong with the design".' |
20 |
! |
|
9 | 21 |
|
58 | 22 |
|
68 | 23 |
!SUnitTest methodsFor:'accessing'! |
0 | 24 |
|
25 |
hasRun |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
26 |
^hasRun |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
27 |
! |
0 | 28 |
|
29 |
hasSetup |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
30 |
^hasSetup |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
31 |
! ! |
0 | 32 |
|
68 | 33 |
!SUnitTest methodsFor:'private'! |
0 | 34 |
|
58 | 35 |
assertForTestResult: aResult runCount: aRunCount passed: aPassedCount failed: aFailureCount errors: anErrorCount |
664
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
36 |
self assertForTestResult: aResult runCount: aRunCount passed: aPassedCount failed: aFailureCount errors: anErrorCount skipped: 0 |
58 | 37 |
|
664
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
38 |
"Modified: / 03-09-2016 / 08:54:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
39 |
! |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
40 |
|
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
41 |
assertForTestResult: aResult runCount: aRunCount passed: aPassedCount failed: aFailureCount errors: anErrorCount skipped: skippedCount |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
42 |
|
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
43 |
self |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
44 |
assert: aResult runCount = aRunCount; |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
45 |
assert: aResult passedCount = aPassedCount; |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
46 |
assert: aResult failureCount = aFailureCount; |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
47 |
assert: aResult errorCount = anErrorCount; |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
48 |
assert: aResult skippedCount = skippedCount |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
49 |
|
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
50 |
"Created: / 03-09-2016 / 08:54:15 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
58 | 51 |
! |
52 |
||
0 | 53 |
error |
54 |
3 zork |
|
55 |
! |
|
56 |
||
57 |
fail |
|
109 | 58 |
self assert: false |
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
59 |
! |
0 | 60 |
|
135 | 61 |
failAndError |
222 | 62 |
self assert: false. |
63 |
self assert: false. " second failure " |
|
64 |
self error. |
|
135 | 65 |
! |
66 |
||
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
67 |
noop |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
68 |
! |
0 | 69 |
|
70 |
setRun |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
71 |
hasRun := true |
664
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
72 |
! |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
73 |
|
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
74 |
skipped |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
75 |
self skipIf: true description: 'Skipped' |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
76 |
|
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
77 |
"Created: / 03-09-2016 / 08:55:32 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
78 |
! ! |
0 | 79 |
|
68 | 80 |
!SUnitTest methodsFor:'running'! |
0 | 81 |
|
82 |
setUp |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
83 |
hasSetup := true |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
84 |
! ! |
0 | 85 |
|
68 | 86 |
!SUnitTest methodsFor:'testing'! |
0 | 87 |
|
109 | 88 |
errorShouldntRaise |
222 | 89 |
self |
90 |
shouldnt: [self someMessageThatIsntUnderstood] |
|
91 |
raise: SUnitNameResolver notificationObject |
|
109 | 92 |
! |
93 |
||
0 | 94 |
testAssert |
95 |
self assert: true. |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
96 |
self deny: false |
0 | 97 |
! |
98 |
||
99 |
testDefects |
|
100 |
| result suite error failure | |
|
101 |
suite := TestSuite new. |
|
102 |
suite addTest: (error := self class selector: #error). |
|
103 |
suite addTest: (failure := self class selector: #fail). |
|
104 |
result := suite run. |
|
58 | 105 |
self assert: result defects asArray = (Array with: error with: failure). |
106 |
self |
|
107 |
assertForTestResult: result |
|
108 |
runCount: 2 |
|
109 |
passed: 0 |
|
110 |
failed: 1 |
|
111 |
errors: 1 |
|
0 | 112 |
! |
113 |
||
114 |
testDialectLocalizedException |
|
115 |
||
109 | 116 |
self |
117 |
should: [TestResult signalFailureWith: 'Foo'] |
|
118 |
raise: TestResult failure. |
|
119 |
self |
|
120 |
should: [TestResult signalErrorWith: 'Foo'] |
|
121 |
raise: TestResult error. |
|
0 | 122 |
! |
123 |
||
124 |
testError |
|
109 | 125 |
|
0 | 126 |
| case result | |
109 | 127 |
|
0 | 128 |
case := self class selector: #error. |
129 |
result := case run. |
|
58 | 130 |
self |
131 |
assertForTestResult: result |
|
132 |
runCount: 1 |
|
133 |
passed: 0 |
|
134 |
failed: 0 |
|
109 | 135 |
errors: 1. |
136 |
||
137 |
case := self class selector: #errorShouldntRaise. |
|
138 |
result := case run. |
|
222 | 139 |
self |
109 | 140 |
assertForTestResult: result |
141 |
runCount: 1 |
|
142 |
passed: 0 |
|
143 |
failed: 0 |
|
58 | 144 |
errors: 1 |
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
145 |
! |
0 | 146 |
|
147 |
testException |
|
148 |
||
109 | 149 |
self |
150 |
should: [self error: 'foo'] |
|
151 |
raise: TestResult error |
|
0 | 152 |
! |
153 |
||
154 |
testFail |
|
109 | 155 |
|
0 | 156 |
| case result | |
109 | 157 |
|
0 | 158 |
case := self class selector: #fail. |
159 |
result := case run. |
|
109 | 160 |
|
58 | 161 |
self |
162 |
assertForTestResult: result |
|
163 |
runCount: 1 |
|
164 |
passed: 0 |
|
165 |
failed: 1 |
|
166 |
errors: 0 |
|
135 | 167 |
! |
168 |
||
0 | 169 |
testIsNotRerunOnDebug |
109 | 170 |
|
0 | 171 |
| case | |
109 | 172 |
|
0 | 173 |
case := self class selector: #testRanOnlyOnce. |
174 |
case run. |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
175 |
case debug |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
176 |
! |
0 | 177 |
|
178 |
testRan |
|
109 | 179 |
|
0 | 180 |
| case | |
109 | 181 |
|
0 | 182 |
case := self class selector: #setRun. |
183 |
case run. |
|
184 |
self assert: case hasSetup. |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
185 |
self assert: case hasRun |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
186 |
! |
0 | 187 |
|
188 |
testRanOnlyOnce |
|
109 | 189 |
|
0 | 190 |
self assert: hasRanOnce ~= true. |
109 | 191 |
hasRanOnce := true |
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
192 |
! |
0 | 193 |
|
194 |
testResult |
|
109 | 195 |
|
0 | 196 |
| case result | |
109 | 197 |
|
0 | 198 |
case := self class selector: #noop. |
199 |
result := case run. |
|
109 | 200 |
|
58 | 201 |
self |
202 |
assertForTestResult: result |
|
203 |
runCount: 1 |
|
204 |
passed: 1 |
|
205 |
failed: 0 |
|
206 |
errors: 0 |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
207 |
! |
0 | 208 |
|
209 |
testRunning |
|
210 |
||
222 | 211 |
(SUnitDelay forSeconds: 2) wait |
0 | 212 |
! |
213 |
||
214 |
testShould |
|
109 | 215 |
|
216 |
self |
|
217 |
should: [true]; |
|
218 |
shouldnt: [false] |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
219 |
! |
0 | 220 |
|
664
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
221 |
testSkip |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
222 |
|
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
223 |
| case result | |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
224 |
|
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
225 |
case := self class selector: #skipped. |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
226 |
result := case run. |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
227 |
|
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
228 |
self |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
229 |
assertForTestResult: result |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
230 |
runCount: 1 |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
231 |
passed: 0 |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
232 |
failed: 0 |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
233 |
errors: 0 |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
234 |
skipped: 1 |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
235 |
|
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
236 |
"Created: / 03-09-2016 / 08:53:25 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
237 |
! |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
238 |
|
0 | 239 |
testSuite |
109 | 240 |
|
0 | 241 |
| suite result | |
109 | 242 |
|
0 | 243 |
suite := TestSuite new. |
222 | 244 |
suite |
109 | 245 |
addTest: (self class selector: #noop); |
246 |
addTest: (self class selector: #fail); |
|
247 |
addTest: (self class selector: #error). |
|
248 |
||
0 | 249 |
result := suite run. |
109 | 250 |
|
58 | 251 |
self |
252 |
assertForTestResult: result |
|
253 |
runCount: 3 |
|
254 |
passed: 1 |
|
255 |
failed: 1 |
|
256 |
errors: 1 |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
257 |
! ! |
0 | 258 |
|
14 | 259 |
!SUnitTest class methodsFor:'documentation'! |
260 |
||
261 |
version |
|
222 | 262 |
^ '$Header: /cvs/stx/stx/goodies/sunit/SUnitTest.st,v 1.11 2011-06-29 19:15:49 cg Exp $' |
263 |
! |
|
264 |
||
664
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
265 |
version_HG |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
266 |
|
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
267 |
^ '$Changeset: <not expanded> $' |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
268 |
! |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
269 |
|
222 | 270 |
version_SVN |
724
4dae63fce9f9
vIssue #239: Fix all Smalltak/X source files to be in unicode (UTF8 without BOM) and prefixed by "{ Encoding: utf8 }" when any unicode character is present
Patrik Svestka <patrik.svestka@gmail.com>
parents:
664
diff
changeset
|
271 |
^ '§Id: SUnitTest.st 214 2011-03-14 12:22:21Z vranyj1 §' |
14 | 272 |
! ! |
664
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
273 |