Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: pkg/unittest/test/unittest_test.dart

Issue 13212008: "Reverting 20670" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.
11 11
12 library unittestTest; 12 library unittestTest;
13 import 'dart:isolate'; 13 import 'dart:isolate';
14 import 'dart:async'; 14 import 'dart:async';
15 import 'package:unittest/unittest.dart'; 15 import 'package:unittest/unittest.dart';
16 16
17 var tests; // array of test names
18 var expected; // array of test expected results (from buildStatusString)
19 var actual; // actual test results (from buildStatusString in config.onDone)
20
17 Future _defer(void fn()) { 21 Future _defer(void fn()) {
18 return new Future.of(fn); 22 return new Future.of(fn);
19 } 23 }
20 24
21 String buildStatusString(int passed, int failed, int errors, 25 String buildStatusString(int passed, int failed, int errors,
22 var results, 26 var results,
23 {int count: 0, 27 {int count: 0,
24 String setup: '', String teardown: '', 28 String setup: '', String teardown: '',
25 String uncaughtError: null, 29 String uncaughtError: null,
26 String message: ''}) { 30 String message: ''}) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 count: count, setup: setup, teardown: teardown, 64 count: count, setup: setup, teardown: teardown,
61 uncaughtError: uncaughtError); 65 uncaughtError: uncaughtError);
62 } 66 }
63 67
64 void onDone(bool success) { 68 void onDone(bool success) {
65 _port.send(_result); 69 _port.send(_result);
66 } 70 }
67 } 71 }
68 72
69 runTest() { 73 runTest() {
70 port.receive((String testName, sendport) { 74 port.receive((testName, sendport) {
71 var _testconfig= new TestConfiguration(sendport); 75 var _testconfig= new TestConfiguration(sendport);
72 unittestConfiguration = _testconfig; 76 unittestConfiguration = _testconfig;
73 77
74 if (testName == 'single correct test') { 78 if (testName == 'single correct test') {
75 test(testName, () => expect(2 + 3, equals(5))); 79 test(testName, () => expect(2 + 3, equals(5)));
76 } else if (testName == 'single failing test') { 80 } else if (testName == 'single failing test') {
77 test(testName, () => expect(2 + 2, equals(5))); 81 test(testName, () => expect(2 + 2, equals(5)));
78 } else if (testName == 'exception test') { 82 } else if (testName == 'exception test') {
79 test(testName, () { throw new Exception('Fail.'); }); 83 test(testName, () { throw new Exception('Fail.'); });
80 } else if (testName == 'group name test') { 84 } else if (testName == 'group name test') {
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 }); 296 });
293 } else if (testName == 'testCases immutable') { 297 } else if (testName == 'testCases immutable') {
294 test(testName, () { 298 test(testName, () {
295 expect(() => testCases.clear(), throwsUnsupportedError); 299 expect(() => testCases.clear(), throwsUnsupportedError);
296 expect(() => testCases.removeLast(), throwsUnsupportedError); 300 expect(() => testCases.removeLast(), throwsUnsupportedError);
297 }); 301 });
298 } 302 }
299 }); 303 });
300 } 304 }
301 305
306 void nextTest(int testNum) {
307 SendPort sport = spawnFunction(runTest);
308 sport.call(tests[testNum]).then((msg) {
309 actual.add(msg);
310 if (actual.length == expected.length) {
311 for (var i = 0; i < tests.length; i++) {
312 test(tests[i], () => expect(actual[i].trim(), equals(expected[i])));
313 }
314 } else {
315 nextTest(testNum+1);
316 }
317 });
318 }
319
302 main() { 320 main() {
303 var tests = { 321 tests = [
304 'single correct test': buildStatusString(1, 0, 0, 'single correct test'), 322 'single correct test',
305 'single failing test': buildStatusString(0, 1, 0, 'single failing test', 323 'single failing test',
324 'exception test',
325 'group name test',
326 'setup test',
327 'teardown test',
328 'setup and teardown test',
329 'correct callback test',
330 'excess callback test',
331 'completion test',
332 'async exception test',
333 'late exception test',
334 'middle exception test',
335 'async setup/teardown test',
336 'test returning future',
337 'test returning future using Timer',
338 'testCases immutable'
339 ];
340
341 expected = [
342 buildStatusString(1, 0, 0, tests[0]),
343 buildStatusString(0, 1, 0, tests[1],
306 message: 'Expected: <5> but: was <4>.'), 344 message: 'Expected: <5> but: was <4>.'),
307 'exception test': buildStatusString(0, 1, 0, 'exception test', 345 buildStatusString(0, 1, 0, tests[2], message: 'Caught Exception: Fail.'),
308 message: 'Caught Exception: Fail.'), 346 buildStatusString(2, 0, 0, 'a a::a b b'),
309 'group name test': buildStatusString(2, 0, 0, 'a a::a b b'), 347 buildStatusString(1, 0, 0, 'a ${tests[4]}', count: 0, setup: 'setup'),
310 'setup test': buildStatusString(1, 0, 0, 'a setup test', 348 buildStatusString(1, 0, 0, 'a ${tests[5]}', count: 0, setup: '',
311 count: 0, setup: 'setup'),
312 'teardown test': buildStatusString(1, 0, 0, 'a teardown test',
313 count: 0, setup: '', teardown: 'teardown'),
314 'setup and teardown test': buildStatusString(1, 0, 0,
315 'a setup and teardown test', count: 0, setup: 'setup',
316 teardown: 'teardown'), 349 teardown: 'teardown'),
317 'correct callback test': buildStatusString(1, 0, 0, 'correct callback test', 350 buildStatusString(1, 0, 0, 'a ${tests[6]}', count: 0,
318 count: 1), 351 setup: 'setup', teardown: 'teardown'),
319 'excess callback test': buildStatusString(0, 1, 0, 'excess callback test', 352 buildStatusString(1, 0, 0, tests[7], count: 1),
320 count: 1, message: 'Callback called more times than expected (1).'), 353 buildStatusString(0, 1, 0, tests[8], count: 1,
321 'completion test': buildStatusString(1, 0, 0, 'completion test', count: 10), 354 message: 'Callback called more times than expected (1).'),
322 'async exception test': buildStatusString(0, 1, 0, 'async exception test', 355 buildStatusString(1, 0, 0, tests[9], count: 10),
323 message: 'Caught error!'), 356 buildStatusString(0, 1, 0, tests[10], message: 'Caught error!'),
324 'late exception test': buildStatusString(1, 0, 1, 'testOne', 357 buildStatusString(1, 0, 1, 'testOne',
325 message: 'Callback called (2) after test case testOne has already ' 358 message: 'Callback called (2) after test case testOne has already '
326 'been marked as pass.:testTwo:'), 359 'been marked as pass.:testTwo:'),
327 'middle exception test': buildStatusString(2, 1, 0, 360 buildStatusString(2, 1, 0,
328 'testOne::testTwo:Expected: false but: was <true>.:testThree'), 361 'testOne::testTwo:Expected: false but: was <true>.:testThree'),
329 'async setup/teardown test': buildStatusString(2, 0, 3, 362 buildStatusString(2, 0, 3,
330 'good setup/good teardown foo1::' 363 'good setup/good teardown foo1::'
331 'good setup/bad teardown foo2:good setup/bad teardown ' 364 'good setup/bad teardown foo2:good setup/bad teardown '
332 'foo2: Test teardown failed: Failed to complete tearDown:' 365 'foo2: Test teardown failed: Failed to complete tearDown:'
333 'bad setup/good teardown foo3:bad setup/good teardown ' 366 'bad setup/good teardown foo3:bad setup/good teardown '
334 'foo3: Test setup failed: Failed to complete setUp:' 367 'foo3: Test setup failed: Failed to complete setUp:'
335 'bad setup/bad teardown foo4:bad setup/bad teardown ' 368 'bad setup/bad teardown foo4:bad setup/bad teardown '
336 'foo4: Test teardown failed: Failed to complete tearDown:' 369 'foo4: Test teardown failed: Failed to complete tearDown:'
337 'post groups'), 370 'post groups'),
338 'test returning future': buildStatusString(2, 4, 0, 371 buildStatusString(2, 4, 0,
339 'successful::' 372 'successful::'
340 'error1:Callback called more times than expected (1).:' 373 'error1:Callback called more times than expected (1).:'
341 'fail1:Expected: <false> but: was <true>.:' 374 'fail1:Expected: <false> but: was <true>.:'
342 'error2:Callback called more times than expected (1).:' 375 'error2:Callback called more times than expected (1).:'
343 'fail2:failure:' 376 'fail2:failure:'
344 'foo5'), 377 'foo5'),
345 'test returning future using Timer': buildStatusString(2, 4, 0, 378 buildStatusString(2, 4, 0,
346 'successful::' 379 'successful::'
347 'fail1:Expected: <false> but: was <true>.:' 380 'fail1:Expected: <false> but: was <true>.:'
348 'error1:Callback called more times than expected (1).:' 381 'error1:Callback called more times than expected (1).:'
349 'fail2:failure:' 382 'fail2:failure:'
350 'error2:Callback called more times than expected (1).:' 383 'error2:Callback called more times than expected (1).:'
351 'foo6'), 384 'foo6'),
352 'testCases immutable': 385 buildStatusString(1, 0, 0, 'testCases immutable'),
353 buildStatusString(1, 0, 0, 'testCases immutable'), 386 ];
354 };
355 387
356 tests.forEach((String name, String expected) { 388 actual = [];
357 test(name, () => spawnFunction(runTest) 389
358 .call(name) 390 nextTest(0);
359 .then((String msg) => expect(msg.trim(), equals(expected))));
360 });
361 } 391 }
362 392
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698