Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 | |
| 16 // we correctly wait for asynchronous tests. | |
| 17 ReceivePort _receivePort; | |
| 15 TestCase currentTestCase = null; | 18 TestCase currentTestCase = null; |
| 16 | 19 |
| 17 /** | 20 /** |
| 18 * Subclasses can override this with something useful for diagnostics. | 21 * Subclasses can override this with something useful for diagnostics. |
| 19 * Particularly useful in cases where we have parent/child configurations | 22 * Particularly useful in cases where we have parent/child configurations |
| 20 * such as layout tests. | 23 * such as layout tests. |
| 21 */ | 24 */ |
| 22 get name => 'Configuration'; | 25 get name => 'Configuration'; |
| 23 /** | 26 /** |
| 24 * If true, then tests are started automatically (otherwise [runTests] | 27 * If true, then tests are started automatically (otherwise [runTests] |
| 25 * must be called explicitly after the tests are set up. | 28 * must be called explicitly after the tests are set up. |
| 26 */ | 29 */ |
| 27 get autoStart => true; | 30 get autoStart => true; |
| 28 | 31 |
| 29 /** | 32 /** |
| 30 * 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 |
| 31 * 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 |
| 32 * determine/debug errors that occur before the test harness starts executing. | 35 * determine/debug errors that occur before the test harness starts executing. |
| 33 */ | 36 */ |
| 34 void onInit() {} | 37 void onInit() {} |
| 35 | 38 |
| 36 /** | 39 /** |
| 37 * Called as soon as the unittest framework starts running. Used commonly to | 40 * Called as soon as the unittest framework starts running. Used commonly to |
| 38 * tell the vm or browser that tests are still running and the process should | 41 * tell the vm or browser that tests are still running and the process should |
| 39 * wait until they are done. | 42 * wait until they are done. |
| 40 */ | 43 */ |
| 41 void onStart() { | 44 void onStart() { |
| 45 _receivePort = new ReceivePort(); | |
| 42 _postMessage('unittest-suite-wait-for-done'); | 46 _postMessage('unittest-suite-wait-for-done'); |
| 43 } | 47 } |
| 44 | 48 |
| 45 /** | 49 /** |
| 46 * Called when each test starts. Useful to show intermediate progress on | 50 * Called when each test starts. Useful to show intermediate progress on |
| 47 * a test suite. | 51 * a test suite. |
| 48 */ | 52 */ |
| 49 void onTestStart(TestCase testCase) { | 53 void onTestStart(TestCase testCase) { |
| 50 currentTestCase = testCase; | 54 currentTestCase = testCase; |
| 51 } | 55 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 * the result summary using the built-in [print] command. Browser tests | 93 * the result summary using the built-in [print] command. Browser tests |
| 90 * commonly override this to reformat the output. | 94 * commonly override this to reformat the output. |
| 91 * | 95 * |
| 92 * When [uncaughtError] is not null, it contains an error that occured outside | 96 * When [uncaughtError] is not null, it contains an error that occured outside |
| 93 * of tests (e.g. setting up the test). | 97 * of tests (e.g. setting up the test). |
| 94 */ | 98 */ |
| 95 void onDone(int passed, int failed, int errors, List<TestCase> results, | 99 void onDone(int passed, int failed, int errors, List<TestCase> results, |
| 96 String uncaughtError) { | 100 String uncaughtError) { |
| 97 // Print each test's result. | 101 // Print each test's result. |
| 98 for (final t in _tests) { | 102 for (final t in _tests) { |
| 99 print('${t.result.toUpperCase()}: ${t.description}'); | 103 var resultString = "${t.result}".toUpperCase(); |
|
floitsch
2012/12/05 19:39:50
I got null-pointer exceptions on "toUpperCase". Ha
| |
| 104 print('$resultString: ${t.description}'); | |
| 100 | 105 |
| 101 if (t.message != '') { | 106 if (t.message != '') { |
| 102 print(_indent(t.message)); | 107 print(_indent(t.message)); |
| 103 } | 108 } |
| 104 | 109 |
| 105 if (t.stackTrace != null && t.stackTrace != '') { | 110 if (t.stackTrace != null && t.stackTrace != '') { |
| 106 print(_indent(t.stackTrace)); | 111 print(_indent(t.stackTrace)); |
| 107 } | 112 } |
| 108 } | 113 } |
| 109 | 114 |
| 110 // Show the summary. | 115 // Show the summary. |
| 111 print(''); | 116 print(''); |
| 112 | 117 |
| 113 var success = false; | 118 var success = false; |
| 114 if (passed == 0 && failed == 0 && errors == 0) { | 119 if (passed == 0 && failed == 0 && errors == 0) { |
| 115 print('No tests found.'); | 120 print('No tests found.'); |
| 116 // This is considered a failure too. | 121 // This is considered a failure too. |
| 117 } else if (failed == 0 && errors == 0 && uncaughtError == null) { | 122 } else if (failed == 0 && errors == 0 && uncaughtError == null) { |
| 118 print('All $passed tests passed.'); | 123 print('All $passed tests passed.'); |
| 119 success = true; | 124 success = true; |
| 120 } else { | 125 } else { |
| 121 if (uncaughtError != null) { | 126 if (uncaughtError != null) { |
| 122 print('Top-level uncaught error: $uncaughtError'); | 127 print('Top-level uncaught error: $uncaughtError'); |
| 123 } | 128 } |
| 124 print('$passed PASSED, $failed FAILED, $errors ERRORS'); | 129 print('$passed PASSED, $failed FAILED, $errors ERRORS'); |
| 125 } | 130 } |
| 126 | 131 |
| 127 if (success) { | 132 if (success) { |
| 128 _postMessage('unittest-suite-success'); | 133 _postMessage('unittest-suite-success'); |
| 134 _receivePort.close(); | |
| 129 } else { | 135 } else { |
| 130 throw new Exception('Some tests failed.'); | 136 throw new Exception('Some tests failed.'); |
|
siva
2012/12/20 21:27:20
The _receivePort should be closed on the exception
floitsch
2012/12/21 08:25:43
https://codereview.chromium.org/11570065
thanks.
| |
| 131 } | 137 } |
| 132 } | 138 } |
| 133 | 139 |
| 134 String _indent(String str) { | 140 String _indent(String str) { |
| 135 // TODO(nweiz): Use this simpler code once issue 2980 is fixed. | 141 // TODO(nweiz): Use this simpler code once issue 2980 is fixed. |
| 136 // return str.replaceAll(new RegExp("^", multiLine: true), " "); | 142 // return str.replaceAll(new RegExp("^", multiLine: true), " "); |
| 137 | 143 |
| 138 return Strings.join(str.split("\n").mappedBy((line) => " $line"), "\n"); | 144 return Strings.join(str.split("\n").mappedBy((line) => " $line"), "\n"); |
| 139 } | 145 } |
| 140 | 146 |
| 141 /** Handle errors that happen outside the tests. */ | 147 /** Handle errors that happen outside the tests. */ |
| 142 // TODO(vsm): figure out how to expose the stack trace here | 148 // TODO(vsm): figure out how to expose the stack trace here |
| 143 // Currently e.message works in dartium, but not in dartc. | 149 // Currently e.message works in dartium, but not in dartc. |
| 144 handleExternalError(e, String message) => | 150 handleExternalError(e, String message) => |
| 145 _reportTestError('$message\nCaught $e', ''); | 151 _reportTestError('$message\nCaught $e', ''); |
| 146 | 152 |
| 147 _postMessage(String message) { | 153 _postMessage(String message) { |
| 148 // In dart2js browser tests, the JavaScript-based test controller | 154 // In dart2js browser tests, the JavaScript-based test controller |
| 149 // intercepts calls to print and listens for "secret" messages. | 155 // intercepts calls to print and listens for "secret" messages. |
| 150 print(message); | 156 print(message); |
| 151 } | 157 } |
| 152 } | 158 } |
| OLD | NEW |