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

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

Issue 12328090: unittest: Updates to Configuration, one deprecation (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fix for vm_config Created 7 years, 10 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 | pkg/unittest/lib/src/core_matchers.dart » ('j') | 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
11 * this class. 11 * this class.
12 */ 12 */
13 13
14 class Configuration { 14 class Configuration {
15 // The VM won't shut down if a receive port is open. Use this to make sure 15 // The VM won't shut down if a receive port is open. Use this to make sure
16 // we correctly wait for asynchronous tests. 16 // we correctly wait for asynchronous tests.
17 ReceivePort _receivePort; 17 ReceivePort _receivePort;
18 TestCase currentTestCase = null; 18 TestCase _currentTestCase;
19
20 TestCase get currentTestCase => _currentTestCase;
19 21
20 /** 22 /**
21 * Subclasses can override this with something useful for diagnostics. 23 * Subclasses can override this with something useful for diagnostics.
22 * Particularly useful in cases where we have parent/child configurations 24 * Particularly useful in cases where we have parent/child configurations
23 * such as layout tests. 25 * such as layout tests.
24 */ 26 */
25 get name => 'Configuration'; 27 String get name => 'Configuration';
28
26 /** 29 /**
27 * If true, then tests are started automatically (otherwise [runTests] 30 * If true, then tests are started automatically (otherwise [runTests]
28 * must be called explicitly after the tests are set up. 31 * must be called explicitly after the tests are set up.
29 */ 32 */
30 get autoStart => true; 33 bool get autoStart => true;
31 34
32 /** 35 /**
33 * Called as soon as the unittest framework becomes initialized. This is done 36 * 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 37 * 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. 38 * 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 39 * 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. 40 * asynchronously and that the process should wait until they are done.
38 */ 41 */
39 void onInit() { 42 void onInit() {
40 _receivePort = new ReceivePort(); 43 _receivePort = new ReceivePort();
41 _postMessage('unittest-suite-wait-for-done'); 44 _postMessage('unittest-suite-wait-for-done');
42 } 45 }
43 46
44 /** Called as soon as the unittest framework starts running. */ 47 /** Called as soon as the unittest framework starts running. */
45 void onStart() {} 48 void onStart() {}
46 49
47 /** 50 /**
48 * Called when each test starts. Useful to show intermediate progress on 51 * Called when each test starts. Useful to show intermediate progress on
49 * a test suite. 52 * a test suite.
50 */ 53 */
51 void onTestStart(TestCase testCase) { 54 void onTestStart(TestCase testCase) {
52 currentTestCase = testCase; 55 assert(testCase != null);
56 assert(_currentTestCase == null);
57 _currentTestCase = testCase;
53 } 58 }
54 59
55 /** 60 /**
56 * Called when each test is completed. Useful to show intermediate progress on 61 * Called when each test is completed. Useful to show intermediate progress on
57 * a test suite. 62 * a test suite.
58 */ 63 */
59 void onTestResult(TestCase testCase) { 64 void onTestResult(TestCase testCase) {
60 currentTestCase = null; 65 assert(testCase != null);
66 assert(_currentTestCase == testCase);
67 _currentTestCase = null;
61 } 68 }
62 69
63 /** 70 /**
64 * Can be called by tests to log status. Tests should use this 71 * Can be called by tests to log status. Tests should use this
65 * instead of print. Subclasses should not override this; they 72 * instead of print. Subclasses should not override this; they
66 * should instead override logMessage which is passed the test case. 73 * should instead override logMessage which is passed the test case.
67 */ 74 */
68 void logMessage(String message) { 75 void logMessage(String message) {
69 if (currentTestCase == null || _currentTest >= _tests.length || 76 if (currentTestCase == null || _currentTest >= _tests.length ||
70 currentTestCase.id != _tests[_currentTest].id) { 77 currentTestCase.id != _tests[_currentTest].id) {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 155
149 return str.split("\n").map((line) => " $line").join("\n"); 156 return str.split("\n").map((line) => " $line").join("\n");
150 } 157 }
151 158
152 /** Handle errors that happen outside the tests. */ 159 /** Handle errors that happen outside the tests. */
153 // TODO(vsm): figure out how to expose the stack trace here 160 // TODO(vsm): figure out how to expose the stack trace here
154 // Currently e.message works in dartium, but not in dartc. 161 // Currently e.message works in dartium, but not in dartc.
155 handleExternalError(e, String message) => 162 handleExternalError(e, String message) =>
156 _reportTestError('$message\nCaught $e', ''); 163 _reportTestError('$message\nCaught $e', '');
157 164
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 // TODO(sigmund): find a way to unify notifyController and _postMessage
170 void notifyController(String message) {
171 }
172
173 _postMessage(String message) { 165 _postMessage(String message) {
174 // In dart2js browser tests, the JavaScript-based test controller 166 // In dart2js browser tests, the JavaScript-based test controller
175 // intercepts calls to print and listens for "secret" messages. 167 // intercepts calls to print and listens for "secret" messages.
176 print(message); 168 print(message);
177 } 169 }
178 } 170 }
OLDNEW
« no previous file with comments | « no previous file | pkg/unittest/lib/src/core_matchers.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698