-
Notifications
You must be signed in to change notification settings - Fork 11
/
MinitestTests.ns
387 lines (383 loc) · 11.7 KB
/
MinitestTests.ns
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
Newspeak3
'Root'
class MinitestTests usingPlatform: platform testFramework: minitest = (
(* Tests of the Minitest framework (that is, meta-tests). *)
|
private Exception = platform kernel Exception.
private testFramework = minitest.
private TestContext = minitest TestContext.
private TestCatalog = minitest TestCatalog.
private Tester = minitest Tester.
|) (
public class AssertionTests = TestContext (
|
guineaPig = GuineaPigTestModule testFramework: testFramework.
catalog = TestCatalog forModule: guineaPig.
tester
|) (
public class GuineaPigTestModule testFramework: testFramework = (|
private TestContext = testFramework TestContext.
|) (
public class AssertEqualsTestContext = TestContext (
) (
public testAssertEqualsFail = (
assert: 3 equals: 4
)
public testAssertEqualsFailWithDescription = (
assert: 3 equals: 4 description: 'custom description'
)
public testAssertEqualsPass = (
assert: 3 equals: 3
)
) : (
TEST_CONTEXT = (
)
)
public class AssertTestContext = TestContext (
) (
public testAssertErrorBlock = (
assert: [3 zork]
)
public testAssertErrorExpression = (
assert: 3 zork
)
public testAssertFailBlock = (
assert: [false]
)
public testAssertFailExpression = (
assert: false
)
public testAssertFailWithDescription = (
assert: false description: 'custom description'
)
public testAssertPassBlock = (
assert: [true]
)
public testAssertPassExpression = (
assert: true
)
) : (
TEST_CONTEXT = (
)
)
public class DenyTestContext = TestContext (
(* Trial tests to verify that the various #deny... messages work correctly. *)
) (
public testDenyErrorBlock = (
deny: [3 zork]
)
public testDenyErrorExpression = (
deny: 3 zork
)
public testDenyFailBlock = (
deny: [true]
)
public testDenyFailExpression = (
deny: true
)
public testDenyFailWithDescription = (
deny: true description: 'custom description'
)
public testDenyPassBlock = (
deny: [false]
)
public testDenyPassExpression = (
deny: false
)
) : (
TEST_CONTEXT = (
)
)
public class ResultCreationTestContext = TestContext (
(* This helps test to see if TestContext was deferred to for the creation of the TestFailure and TestError result. *)
|
private TestFailure = testFramework TestFailure.
private TestError = testFramework TestError.
|) (
class CustomTestSuccess case: testCase = (
(* A custom TestSuccess *)
|
public case ::= testCase.
public message = 'all good here'.
|) (
public isError = (
^false
)
public isFailure = (
^false
)
public isSuccess = (
^true
)
) : (
)
public createErrorResultFor: testCase <TestCase> exception: ex <Error> = (
| exception |
exception:: TestException1 new.
exception messageText: 'created here'.
^TestError case: testCase exception: exception
)
public createSuccessResultFor: testCase <TestCase> = (
^CustomTestSuccess case: testCase.
)
public testErrorCreation = (
assert: [1 zork]
)
public testFailureCreation = (
assert: false description: 'better not see this'
)
public testSuccess = (
assert: true
)
public createFailureResultFor: testCase <TestCase> description: description <String> ^ <TestFailure> = (
^TestFailure case: testCase description: 'created here'
)
) : (
TEST_CONTEXT = ()
)
public class ShouldShouldntTestContext = TestContext (
|
|) (
public testShouldFail = (
[should: [TestException1 new signal] signal: TestException2]
on: TestException1
do: [:ex | ex resume: nil]
)
public testShouldFailWithDescription = (
[should: [TestException1 new signal]
signal: TestException2
description: 'custom description']
on: TestException1
do: [:ex | ex resume: nil]
)
public testShouldPassExceptionSubclass = (
should: [TestException1 new signal] signal: Exception
)
public testShouldPassSameExceptionClass = (
should: [TestException1 new signal] signal: TestException1
)
public testShouldntFail = (
shouldnt: [TestException1 new signal] signal: TestException1
)
public testShouldntFailWithDescription = (
shouldnt: [TestException1 new signal]
signal: TestException1
description: 'custom description'
)
public testShouldntPass = (
[shouldnt: [TestException1 new signal] signal: TestException2]
on: TestException1
do: [:ex | ex resume: nil]
)
) : (
TEST_CONTEXT = (
)
)
class TestException1 = Exception (
) (
) : (
)
class TestException2 = Exception (
) (
) : (
)
) : (
)
assert: testResults containsSelector: selector = (
deny: (resultForSelector: selector in: testResults) equals: nil.
)
resultForSelector: selector in: collection = (
^collection
detect: [:some | some testCase selector = selector]
ifNone: [nil]
)
public testAssertEquals = (
tester:: Tester testSuite: (catalog testSuiteNamed: 'AssertEqualsTestContext').
tester runAll.
assert: tester errors size equals: 0.
assert: tester failures size equals: 2.
assert: tester failures containsSelector: #testAssertEqualsFail.
assert: tester failures containsSelector: #testAssertEqualsFailWithDescription.
assert: (resultForSelector: #testAssertEqualsFailWithDescription in: tester failures) description
equals: 'custom description'.
assert: tester successes size equals: 1.
assert: tester successes containsSelector: #testAssertEqualsPass.
)
public testAsserts = (
tester:: Tester testSuite: (catalog testSuiteNamed: 'AssertTestContext').
tester runAll.
assert: tester errors size equals: 2.
assert: tester errors containsSelector: #testAssertErrorBlock.
assert: tester errors containsSelector: #testAssertErrorExpression.
assert: tester failures size equals: 3.
assert: tester failures containsSelector: #testAssertFailBlock.
assert: tester failures containsSelector: #testAssertFailExpression.
assert: tester failures containsSelector: #testAssertFailWithDescription.
assert: (resultForSelector: #testAssertFailWithDescription in: tester failures) description
equals: 'custom description'.
assert: tester successes size equals: 2.
assert: tester successes containsSelector: #testAssertPassBlock.
assert: tester successes containsSelector: #testAssertPassExpression.
)
public testDenials = (
tester:: Tester testSuite: (catalog testSuiteNamed: 'DenyTestContext').
tester runAll.
assert: tester errors size equals: 2.
assert: tester errors containsSelector: #testDenyErrorBlock.
assert: tester errors containsSelector: #testDenyErrorExpression.
assert: tester failures size equals: 3.
assert: tester failures containsSelector: #testDenyFailBlock.
assert: tester failures containsSelector: #testDenyFailExpression.
assert: tester failures containsSelector: #testDenyFailWithDescription.
assert: (resultForSelector: #testDenyFailWithDescription in: tester failures) description
equals: 'custom description'.
assert: tester successes size equals: 2.
assert: tester successes containsSelector: #testDenyPassBlock.
assert: tester successes containsSelector: #testDenyPassExpression.
)
public testResultCreation = (
tester:: Tester testSuite: (catalog testSuiteNamed: 'ResultCreationTestContext').
tester runAll.
assert: tester failures size equals: 1.
assert: tester failures first description = 'created here'.
assert: tester errors size equals: 1.
assert: tester errors first exception messageText = 'created here'.
assert: tester successes size equals: 1.
assert: tester successes first message = 'all good here'.
)
public testShouldShouldnt = (
tester:: Tester testSuite: (catalog testSuiteNamed: 'ShouldShouldntTestContext').
tester runAll.
assert: tester errors size equals: 0.
assert: tester failures size equals: 4.
assert: tester failures containsSelector: #testShouldFail.
assert: tester failures containsSelector: #testShouldFailWithDescription.
assert: tester failures containsSelector: #testShouldntFail.
assert: tester failures containsSelector: #testShouldntFailWithDescription.
assert: tester successes size equals: 3.
assert: tester successes containsSelector: #testShouldPassExceptionSubclass.
assert: tester successes containsSelector: #testShouldPassSameExceptionClass.
assert: tester successes containsSelector: #testShouldntPass.
)
) : (
TEST_CONTEXT = (
)
)
public class TestLifecycleTests = TestContext (
(* Tests to verify that test cases are collected and grouped into test suites correctly across test contexts, and that test contexts and their enclosing shared state classes are instantiated the correct number of times. *)
|
guineaPig = GuineaPigTestModule minitest: testFramework.
catalog = TestCatalog forModule: guineaPig.
|) (
public class GuineaPigTestModule minitest: testFramework = (
(* A fake test module for the use by tests of the enclosing class.
Because this module is nested inside a test context, the test contexts and methods it contains are not included in the test catalog created for the enclosing test module. *)
|
private TestContext = testFramework TestContext.
public DirectlyNestedTestContextInstantiationCount ::= 0.
public OuterSharedStateClassInstantiationCount ::= 0.
public InnerSharedStateClassInstantiationCount ::= 0.
public InnerTestContextInstantiationCount ::= 0.
public OuterSharedStateCleanedUp ::= false.
public InnerSharedStateCleanedUp ::= false.
|) (
public class DirectlyNestedTestContext = TestContext (
(* A test context class directly nested inside its test module. The tests expect this class to have 3 test methods. *)
|
|DirectlyNestedTestContextInstantiationCount: DirectlyNestedTestContextInstantiationCount + 1) (
public class DoublyNestedTestContextWhichShouldBeIgnored = TestContext (
(* A test context inside a test context, should be ignored by the catalog building logic. *)
) (
public testCase1 = (
)
) : (
TEST_CONTEXT = (
)
)
public testCase1 = (
)
public testCase2 = (
)
public testCase3 = (
)
testFoo: bar = (
(* A keyword method like this should not be recognized as a test. *)
)
) : (
TEST_CONTEXT = (
)
)
public class OuterSharedStateClass = (
(* A non-test context class that serves as a container of shared state for its nested test contexts. *)
|
outerSharedState = 42.
|OuterSharedStateClassInstantiationCount: OuterSharedStateClassInstantiationCount + 1) (
public class InnerSharedStateClass = (
(* Another non-test context class. *)
|
innerSharedState = 24.
|InnerSharedStateClassInstantiationCount: InnerSharedStateClassInstantiationCount + 1) (
public class InnerTestContext = TestContext (
(* A test context class nested in some shared state classes. The tests expect this class to have 2 test methods. *)
|
|InnerTestContextInstantiationCount: InnerTestContextInstantiationCount + 1) (
public testCase1 = (
)
public testCase2 = (
)
) : (
TEST_CONTEXT = (
)
)
public cleanUp = (
InnerSharedStateCleanedUp: true.
)
) : (
)
public cleanUp = (
OuterSharedStateCleanedUp: true.
)
) : (
)
) : (
)
public testCatalogContentsForDirectlyNested = (
assert: (catalog testSuiteNames includes: 'DirectlyNestedTestContext').
assert: (catalog testSuiteNamed: 'DirectlyNestedTestContext') size equals: 3.
)
public testCatalogContentsForInnerContext = (
assert: (catalog testSuiteNames includes: 'InnerTestContext').
assert: (catalog testSuiteNamed: 'InnerTestContext') size equals: 2.
)
public testCatalogSize = (
assert: catalog testSuiteNames size equals: 2.
)
public testInstantiationCounts = (
| tester |
tester:: Tester testSuite: catalog allTests.
tester runAll.
assert: guineaPig DirectlyNestedTestContextInstantiationCount equals: 3.
assert: guineaPig OuterSharedStateClassInstantiationCount equals: 1.
assert: guineaPig InnerSharedStateClassInstantiationCount equals: 1.
assert: guineaPig InnerTestContextInstantiationCount equals: 2.
)
public testSharedStateCleanUp = (
| tester |
tester:: Tester testSuite: catalog allTests.
tester runAll.
assert: guineaPig OuterSharedStateCleanedUp.
assert: guineaPig InnerSharedStateCleanedUp.
)
public testSuiteSizes = (
assert: (catalog testSuiteNamed: 'DirectlyNestedTestContext') testCases size
equals: 3.
assert: (catalog testSuiteNamed: 'InnerTestContext') testCases size
equals: 2.
)
) : (
TEST_CONTEXT = (
(* Marking this class as a test context. *)
)
)
) : (
)