OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 // TODO(gram): | 5 // TODO(gram): |
6 // Unfortunately I can't seem to test anything that involves timeouts, e.g. | 6 // Unfortunately I can't seem to test anything that involves timeouts, e.g. |
7 // insufficient callbacks, because the timeout is controlled externally | 7 // insufficient callbacks, because the timeout is controlled externally |
8 // (test.dart?), and we would need to use a shorter timeout for the inner tests | 8 // (test.dart?), and we would need to use a shorter timeout for the inner tests |
9 // so the outer timeout doesn't fire. So I removed all such tests. | 9 // so the outer timeout doesn't fire. So I removed all such tests. |
10 // I'd like to revisit this at some point. | 10 // I'd like to revisit this at some point. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 _result = buildStatusString(passed, failed, errors, results, | 61 _result = buildStatusString(passed, failed, errors, results, |
62 count: count, setup: setup, teardown: teardown, | 62 count: count, setup: setup, teardown: teardown, |
63 uncaughtError: uncaughtError); | 63 uncaughtError: uncaughtError); |
64 } | 64 } |
65 | 65 |
66 void onDone(bool success) { | 66 void onDone(bool success) { |
67 _port.send(_result); | 67 _port.send(_result); |
68 } | 68 } |
69 } | 69 } |
70 | 70 |
| 71 makeDelayedSetup(index, s) => () { |
| 72 return new Future.delayed(new Duration(milliseconds:1), () { |
| 73 s.write('l$index U '); |
| 74 }); |
| 75 }; |
| 76 |
| 77 makeDelayedTeardown(index, s) => () { |
| 78 return new Future.delayed(new Duration(milliseconds:1), () { |
| 79 s.write('l$index D '); |
| 80 }); |
| 81 }; |
| 82 |
| 83 makeImmediateSetup(index, s) => () { |
| 84 s.write('l$index U '); |
| 85 }; |
| 86 |
| 87 makeImmediateTeardown(index, s) => () { |
| 88 s.write('l$index D '); |
| 89 }; |
| 90 |
71 runTest() { | 91 runTest() { |
72 port.receive((String testName, sendport) { | 92 port.receive((String testName, sendport) { |
73 var testConfig = new TestConfiguration(sendport); | 93 var testConfig = new TestConfiguration(sendport); |
74 unittestConfiguration = testConfig; | 94 unittestConfiguration = testConfig; |
75 | 95 |
76 if (testName == 'single correct test') { | 96 if (testName == 'single correct test') { |
77 test(testName, () => expect(2 + 3, equals(5))); | 97 test(testName, () => expect(2 + 3, equals(5))); |
78 } else if (testName == 'single failing test') { | 98 } else if (testName == 'single failing test') { |
79 test(testName, () => expect(2 + 2, equals(5))); | 99 test(testName, () => expect(2 + 2, equals(5))); |
80 } else if (testName == 'exception test') { | 100 } else if (testName == 'exception test') { |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 }); | 312 }); |
293 test('foo6', () { | 313 test('foo6', () { |
294 }); | 314 }); |
295 } else if (testName == 'testCases immutable') { | 315 } else if (testName == 'testCases immutable') { |
296 test(testName, () { | 316 test(testName, () { |
297 expect(() => testCases.clear(), throwsUnsupportedError); | 317 expect(() => testCases.clear(), throwsUnsupportedError); |
298 expect(() => testCases.removeLast(), throwsUnsupportedError); | 318 expect(() => testCases.removeLast(), throwsUnsupportedError); |
299 }); | 319 }); |
300 } else if (testName == 'runTests without tests') { | 320 } else if (testName == 'runTests without tests') { |
301 runTests(); | 321 runTests(); |
| 322 } else if (testName == 'nested groups setup/teardown') { |
| 323 StringBuffer s = new StringBuffer(); |
| 324 group('level 1', () { |
| 325 setUp(makeDelayedSetup(1, s)); |
| 326 group('level 2', () { |
| 327 setUp(makeImmediateSetup(2, s)); |
| 328 tearDown(makeDelayedTeardown(2, s)); |
| 329 group('level 3', () { |
| 330 group('level 4', () { |
| 331 setUp(makeDelayedSetup(4, s)); |
| 332 tearDown(makeImmediateTeardown(4, s)); |
| 333 group('level 5', () { |
| 334 setUp(makeImmediateSetup(5, s)); |
| 335 group('level 6', () { |
| 336 tearDown(makeDelayedTeardown(6, s)); |
| 337 test('inner', () {}); |
| 338 }); |
| 339 }); |
| 340 }); |
| 341 }); |
| 342 }); |
| 343 }); |
| 344 test('after nest', () { |
| 345 expect(s.toString(), "l1 U l2 U l4 U l5 U l6 D l4 D l2 D "); |
| 346 }); |
302 } | 347 } |
303 }); | 348 }); |
304 } | 349 } |
305 | 350 |
306 main() { | 351 main() { |
307 var tests = { | 352 var tests = { |
308 'single correct test': buildStatusString(1, 0, 0, 'single correct test'), | 353 'single correct test': buildStatusString(1, 0, 0, 'single correct test'), |
309 'single failing test': buildStatusString(0, 1, 0, 'single failing test', | 354 'single failing test': buildStatusString(0, 1, 0, 'single failing test', |
310 message: 'Expected: <5> but: was <4>.'), | 355 message: 'Expected: <5> but: was <4>.'), |
311 'exception test': buildStatusString(0, 1, 0, 'exception test', | 356 'exception test': buildStatusString(0, 1, 0, 'exception test', |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 'foo5'), | 393 'foo5'), |
349 'test returning future using Timer': buildStatusString(2, 4, 0, | 394 'test returning future using Timer': buildStatusString(2, 4, 0, |
350 'successful::' | 395 'successful::' |
351 'fail1:Expected: <false> but: was <true>.:' | 396 'fail1:Expected: <false> but: was <true>.:' |
352 'error1:Callback called more times than expected (1).:' | 397 'error1:Callback called more times than expected (1).:' |
353 'fail2:failure:' | 398 'fail2:failure:' |
354 'error2:Callback called more times than expected (1).:' | 399 'error2:Callback called more times than expected (1).:' |
355 'foo6'), | 400 'foo6'), |
356 'testCases immutable': | 401 'testCases immutable': |
357 buildStatusString(1, 0, 0, 'testCases immutable'), | 402 buildStatusString(1, 0, 0, 'testCases immutable'), |
358 'runTests without tests': buildStatusString(0, 0, 0, null) | 403 'runTests without tests': buildStatusString(0, 0, 0, null), |
| 404 'nested groups setup/teardown': |
| 405 buildStatusString(2, 0, 0, |
| 406 'level 1 level 2 level 3 level 4 level 5 level 6 inner::after nest') |
359 }; | 407 }; |
360 | 408 |
361 tests.forEach((String name, String expected) { | 409 tests.forEach((String name, String expected) { |
362 test(name, () => spawnFunction(runTest) | 410 test(name, () => spawnFunction(runTest) |
363 .call(name) | 411 .call(name) |
364 .then((String msg) => expect(msg.trim(), equals(expected)))); | 412 .then((String msg) => expect(msg.trim(), equals(expected)))); |
365 }); | 413 }); |
366 } | 414 } |
367 | 415 |
OLD | NEW |