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

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

Issue 12770017: pkg/unittest: config refactor (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: per siggi's recomendations Created 7 years, 9 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 | « pkg/unittest/lib/vm_config.dart ('k') | 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 17 var tests; // array of test names
18 var expected; // array of test expected results (from buildStatusString) 18 var expected; // array of test expected results (from buildStatusString)
19 var actual; // actual test results (from buildStatusString in config.onDone) 19 var actual; // actual test results (from buildStatusString in config.onDone)
20 var _testconfig; // test configuration to capture onDone
21 20
22 Future _defer(void fn()) { 21 Future _defer(void fn()) {
23 return new Future.of(fn); 22 return new Future.of(fn);
24 } 23 }
25 24
26 String buildStatusString(int passed, int failed, int errors, 25 String buildStatusString(int passed, int failed, int errors,
27 var results, 26 var results,
28 {int count: 0, 27 {int count: 0,
29 String setup: '', String teardown: '', 28 String setup: '', String teardown: '',
30 String uncaughtError: null, 29 String uncaughtError: null,
(...skipping 16 matching lines...) Expand all
47 } 46 }
48 47
49 class TestConfiguration extends Configuration { 48 class TestConfiguration extends Configuration {
50 49
51 // Some test state that is captured 50 // Some test state that is captured
52 int count = 0; // a count of callbacks 51 int count = 0; // a count of callbacks
53 String setup = ''; // the name of the test group setup function, if any 52 String setup = ''; // the name of the test group setup function, if any
54 String teardown = ''; // the name of the test group teardown function, if any 53 String teardown = ''; // the name of the test group teardown function, if any
55 54
56 // The port to communicate with the parent isolate 55 // The port to communicate with the parent isolate
57 SendPort _port; 56 final SendPort _port;
58 String _result; 57 String _result;
59 58
60 TestConfiguration(this._port); 59 TestConfiguration(this._port);
61 60
62 void onSummary(int passed, int failed, int errors, List<TestCase> results, 61 void onSummary(int passed, int failed, int errors, List<TestCase> results,
63 String uncaughtError) { 62 String uncaughtError) {
64 _result = buildStatusString(passed, failed, errors, results, 63 _result = buildStatusString(passed, failed, errors, results,
65 count: count, setup: setup, teardown: teardown, 64 count: count, setup: setup, teardown: teardown,
66 uncaughtError: uncaughtError); 65 uncaughtError: uncaughtError);
67 } 66 }
68 67
69 void onDone(bool success) { 68 void onDone(bool success) {
70 _port.send(_result); 69 _port.send(_result);
71 } 70 }
72 } 71 }
73 72
74 runTest() { 73 runTest() {
75 port.receive((testName, sendport) { 74 port.receive((testName, sendport) {
76 configure(_testconfig = new TestConfiguration(sendport)); 75 var _testconfig= new TestConfiguration(sendport);
76 config = _testconfig;
gram 2013/03/25 17:09:19 I wonder if config is not too generic a name and m
kevmoo-old 2013/03/25 17:11:52 or go all the way and call it unittestConfiguratio
77
77 if (testName == 'single correct test') { 78 if (testName == 'single correct test') {
78 test(testName, () => expect(2 + 3, equals(5))); 79 test(testName, () => expect(2 + 3, equals(5)));
79 } else if (testName == 'single failing test') { 80 } else if (testName == 'single failing test') {
80 test(testName, () => expect(2 + 2, equals(5))); 81 test(testName, () => expect(2 + 2, equals(5)));
81 } else if (testName == 'exception test') { 82 } else if (testName == 'exception test') {
82 test(testName, () { throw new Exception('Fail.'); }); 83 test(testName, () { throw new Exception('Fail.'); });
83 } else if (testName == 'group name test') { 84 } else if (testName == 'group name test') {
84 group('a', () { 85 group('a', () {
85 test('a', () {}); 86 test('a', () {});
86 group('b', () { 87 group('b', () {
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 'fail2:failure:' 376 'fail2:failure:'
376 'error2:Callback called more times than expected (1).:' 377 'error2:Callback called more times than expected (1).:'
377 'foo6'), 378 'foo6'),
378 ]; 379 ];
379 380
380 actual = []; 381 actual = [];
381 382
382 nextTest(0); 383 nextTest(0);
383 } 384 }
384 385
OLDNEW
« no previous file with comments | « pkg/unittest/lib/vm_config.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698