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

Side by Side Diff: pkg/unittest/lib/src/config.dart

Issue 11785026: Fixing unittest: ensure 'wait-until-done' is posted before we reach the end of (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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/html_enhanced_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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 part of unittest; 5 part of unittest;
6 6
7 /** 7 /**
8 * Hooks to configure the unittest library for different platforms. This class 8 * Hooks to configure the unittest library for different platforms. This class
9 * implements the API in a platform-independent way. Tests that want to take 9 * implements the API in a platform-independent way. Tests that want to take
10 * advantage of the platform can create a subclass and override methods from 10 * advantage of the platform can create a subclass and override methods from
(...skipping 15 matching lines...) Expand all
26 /** 26 /**
27 * If true, then tests are started automatically (otherwise [runTests] 27 * If true, then tests are started automatically (otherwise [runTests]
28 * must be called explicitly after the tests are set up. 28 * must be called explicitly after the tests are set up.
29 */ 29 */
30 get autoStart => true; 30 get autoStart => true;
31 31
32 /** 32 /**
33 * Called as soon as the unittest framework becomes initialized. This is done 33 * Called as soon as the unittest framework becomes initialized. This is done
34 * even before tests are added to the test framework. It might be used to 34 * even before tests are added to the test framework. It might be used to
35 * determine/debug errors that occur before the test harness starts executing. 35 * determine/debug errors that occur before the test harness starts executing.
36 * It is also used to tell the vm or browser that tests are going to be run
37 * asynchronously and that the process should wait until they are done.
36 */ 38 */
37 void onInit() {} 39 void onInit() {
38
39 /**
40 * Called as soon as the unittest framework starts running. Used commonly to
41 * tell the vm or browser that tests are still running and the process should
42 * wait until they are done.
43 */
44 void onStart() {
45 _receivePort = new ReceivePort(); 40 _receivePort = new ReceivePort();
46 _postMessage('unittest-suite-wait-for-done'); 41 _postMessage('unittest-suite-wait-for-done');
47 } 42 }
48 43
44 /** Called as soon as the unittest framework starts running. */
45 void onStart() {}
46
49 /** 47 /**
50 * Called when each test starts. Useful to show intermediate progress on 48 * Called when each test starts. Useful to show intermediate progress on
51 * a test suite. 49 * a test suite.
52 */ 50 */
53 void onTestStart(TestCase testCase) { 51 void onTestStart(TestCase testCase) {
54 currentTestCase = testCase; 52 currentTestCase = testCase;
55 } 53 }
56 54
57 /** 55 /**
58 * Called when each test is completed. Useful to show intermediate progress on 56 * Called when each test is completed. Useful to show intermediate progress on
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 } else if (failed == 0 && errors == 0 && uncaughtError == null) { 120 } else if (failed == 0 && errors == 0 && uncaughtError == null) {
123 print('All $passed tests passed.'); 121 print('All $passed tests passed.');
124 success = true; 122 success = true;
125 } else { 123 } else {
126 if (uncaughtError != null) { 124 if (uncaughtError != null) {
127 print('Top-level uncaught error: $uncaughtError'); 125 print('Top-level uncaught error: $uncaughtError');
128 } 126 }
129 print('$passed PASSED, $failed FAILED, $errors ERRORS'); 127 print('$passed PASSED, $failed FAILED, $errors ERRORS');
130 } 128 }
131 129
132 _receivePort.close();
133 if (success) { 130 if (success) {
134 _postMessage('unittest-suite-success'); 131 _postMessage('unittest-suite-success');
132 _receivePort.close();
135 } else { 133 } else {
134 _receivePort.close();
136 throw new Exception('Some tests failed.'); 135 throw new Exception('Some tests failed.');
137 } 136 }
138 } 137 }
139 138
140 String _indent(String str) { 139 String _indent(String str) {
141 // TODO(nweiz): Use this simpler code once issue 2980 is fixed. 140 // TODO(nweiz): Use this simpler code once issue 2980 is fixed.
142 // return str.replaceAll(new RegExp("^", multiLine: true), " "); 141 // return str.replaceAll(new RegExp("^", multiLine: true), " ");
143 142
144 return Strings.join(str.split("\n").mappedBy((line) => " $line"), "\n"); 143 return Strings.join(str.split("\n").mappedBy((line) => " $line"), "\n");
145 } 144 }
146 145
147 /** Handle errors that happen outside the tests. */ 146 /** Handle errors that happen outside the tests. */
148 // TODO(vsm): figure out how to expose the stack trace here 147 // TODO(vsm): figure out how to expose the stack trace here
149 // Currently e.message works in dartium, but not in dartc. 148 // Currently e.message works in dartium, but not in dartc.
150 handleExternalError(e, String message) => 149 handleExternalError(e, String message) =>
151 _reportTestError('$message\nCaught $e', ''); 150 _reportTestError('$message\nCaught $e', '');
152 151
153 _postMessage(String message) { 152 _postMessage(String message) {
154 // In dart2js browser tests, the JavaScript-based test controller 153 // In dart2js browser tests, the JavaScript-based test controller
155 // intercepts calls to print and listens for "secret" messages. 154 // intercepts calls to print and listens for "secret" messages.
156 print(message); 155 print(message);
157 } 156 }
158 } 157 }
OLDNEW
« no previous file with comments | « pkg/unittest/lib/html_enhanced_config.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698