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

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

Issue 11829045: Cleaning up unittest configurations (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
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 20 matching lines...) Expand all
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 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. 37 * asynchronously and that the process should wait until they are done.
38 */ 38 */
39 void onInit() { 39 void onInit() {
40 _receivePort = new ReceivePort(); 40 _receivePort = new ReceivePort();
41 _postMessage('unittest-suite-wait-for-done'); 41 notifyController('unittest-suite-wait-for-done');
42 } 42 }
43 43
44 /** Called as soon as the unittest framework starts running. */ 44 /** Called as soon as the unittest framework starts running. */
45 void onStart() {} 45 void onStart() {}
46 46
47 /** 47 /**
48 * Called when each test starts. Useful to show intermediate progress on 48 * Called when each test starts. Useful to show intermediate progress on
49 * a test suite. 49 * a test suite.
50 */ 50 */
51 void onTestStart(TestCase testCase) { 51 void onTestStart(TestCase testCase) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 } 87 }
88 88
89 /** 89 /**
90 * Called with the result of all test cases. The default implementation prints 90 * Called with the result of all test cases. The default implementation prints
91 * the result summary using the built-in [print] command. Browser tests 91 * the result summary using the built-in [print] command. Browser tests
92 * commonly override this to reformat the output. 92 * commonly override this to reformat the output.
93 * 93 *
94 * When [uncaughtError] is not null, it contains an error that occured outside 94 * When [uncaughtError] is not null, it contains an error that occured outside
95 * of tests (e.g. setting up the test). 95 * of tests (e.g. setting up the test).
96 */ 96 */
97 void onDone(int passed, int failed, int errors, List<TestCase> results, 97 void onSummary(int passed, int failed, int errors, List<TestCase> results,
98 String uncaughtError) { 98 String uncaughtError) {
99 // Print each test's result. 99 // Print each test's result.
100 for (final t in _tests) { 100 for (final t in _tests) {
101 var resultString = "${t.result}".toUpperCase(); 101 var resultString = "${t.result}".toUpperCase();
102 print('$resultString: ${t.description}'); 102 print('$resultString: ${t.description}');
103 103
104 if (t.message != '') { 104 if (t.message != '') {
105 print(_indent(t.message)); 105 print(_indent(t.message));
106 } 106 }
107 107
(...skipping 11 matching lines...) Expand all
119 // This is considered a failure too. 119 // This is considered a failure too.
120 } else if (failed == 0 && errors == 0 && uncaughtError == null) { 120 } else if (failed == 0 && errors == 0 && uncaughtError == null) {
121 print('All $passed tests passed.'); 121 print('All $passed tests passed.');
122 success = true; 122 success = true;
123 } else { 123 } else {
124 if (uncaughtError != null) { 124 if (uncaughtError != null) {
125 print('Top-level uncaught error: $uncaughtError'); 125 print('Top-level uncaught error: $uncaughtError');
126 } 126 }
127 print('$passed PASSED, $failed FAILED, $errors ERRORS'); 127 print('$passed PASSED, $failed FAILED, $errors ERRORS');
128 } 128 }
129 }
129 130
131 /**
132 * Called when the unittest framework is done running. [success] indicates
133 * whether all tests passed successfully.
134 */
135 void onDone(bool success) {
130 if (success) { 136 if (success) {
131 _postMessage('unittest-suite-success'); 137 notifyController('unittest-suite-success');
132 _receivePort.close(); 138 _receivePort.close();
133 } else { 139 } else {
134 _receivePort.close(); 140 _receivePort.close();
135 throw new Exception('Some tests failed.'); 141 throw new Exception('Some tests failed.');
136 } 142 }
137 } 143 }
138 144
139 String _indent(String str) { 145 String _indent(String str) {
140 // TODO(nweiz): Use this simpler code once issue 2980 is fixed. 146 // TODO(nweiz): Use this simpler code once issue 2980 is fixed.
141 // return str.replaceAll(new RegExp("^", multiLine: true), " "); 147 // return str.replaceAll(new RegExp("^", multiLine: true), " ");
142 148
143 return Strings.join(str.split("\n").mappedBy((line) => " $line"), "\n"); 149 return Strings.join(str.split("\n").mappedBy((line) => " $line"), "\n");
144 } 150 }
145 151
146 /** Handle errors that happen outside the tests. */ 152 /** Handle errors that happen outside the tests. */
147 // TODO(vsm): figure out how to expose the stack trace here 153 // TODO(vsm): figure out how to expose the stack trace here
148 // Currently e.message works in dartium, but not in dartc. 154 // Currently e.message works in dartium, but not in dartc.
149 handleExternalError(e, String message) => 155 handleExternalError(e, String message) =>
150 _reportTestError('$message\nCaught $e', ''); 156 _reportTestError('$message\nCaught $e', '');
151 157
152 _postMessage(String message) { 158 /**
159 * Send messages to the test controller code (see 'test_controller.js'). This
160 * is only needed to support browser tests with dart2js. Note: we could wrap
161 * tests and send the appropriate messages to the controller through the
162 * wrapper, but using wrappers has a noticeable overhead in the testing bots,
163 * so we use this approach instead.
164 *
165 * Configurations that will not run in DRT (such as vm_config and
166 * compact_vm_config), can safely override this method to avoid printing extra
167 * mesages in the console.
168 */
169 void notifyController(String message) {
153 // In dart2js browser tests, the JavaScript-based test controller 170 // In dart2js browser tests, the JavaScript-based test controller
154 // intercepts calls to print and listens for "secret" messages. 171 // intercepts calls to print and listens for "secret" messages.
155 print(message); 172 print(message);
156 } 173 }
157 } 174 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698