| 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 /** This file is sourced by unitest.dart. */ | 5 /** This file is sourced by unitest.dart. */ |
| 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 17 matching lines...) Expand all Loading... |
| 28 /** | 28 /** |
| 29 * Called when each test is completed. Useful to show intermediate progress on | 29 * Called when each test is completed. Useful to show intermediate progress on |
| 30 * a test suite. | 30 * a test suite. |
| 31 */ | 31 */ |
| 32 void onTestResult(TestCase testCase) {} | 32 void onTestResult(TestCase testCase) {} |
| 33 | 33 |
| 34 /** | 34 /** |
| 35 * Called with the result of all test cases. The default implementation prints | 35 * Called with the result of all test cases. The default implementation prints |
| 36 * the result summary using the built-in [print] command. Browser tests | 36 * the result summary using the built-in [print] command. Browser tests |
| 37 * commonly override this to reformat the output. | 37 * commonly override this to reformat the output. |
| 38 * |
| 39 * When [uncaughtError] is not null, it contains an error that occured outside |
| 40 * of tests (e.g. setting up the test). |
| 38 */ | 41 */ |
| 39 void onDone(int passed, int failed, int errors, List<TestCase> results) { | 42 void onDone(int passed, int failed, int errors, List<TestCase> results, |
| 43 String uncaughtError) { |
| 40 // Print each test's result. | 44 // Print each test's result. |
| 41 for (final t in _tests) { | 45 for (final t in _tests) { |
| 42 print('${t.result.toUpperCase()}: ${t.description}'); | 46 print('${t.result.toUpperCase()}: ${t.description}'); |
| 43 | 47 |
| 44 if (t.message != '') { | 48 if (t.message != '') { |
| 45 print(' ${t.message}'); | 49 print(' ${t.message}'); |
| 46 } | 50 } |
| 47 } | 51 } |
| 48 | 52 |
| 49 // Show the summary. | 53 // Show the summary. |
| 50 print(''); | 54 print(''); |
| 51 | 55 |
| 52 var success = false; | 56 var success = false; |
| 53 if (passed == 0 && failed == 0 && errors == 0) { | 57 if (passed == 0 && failed == 0 && errors == 0) { |
| 54 print('No tests found.'); | 58 print('No tests found.'); |
| 55 // This is considered a failure too: if this happens you probably have a | 59 // This is considered a failure too: if this happens you probably have a |
| 56 // bug in your unit tests. | 60 // bug in your unit tests. |
| 57 } else if (failed == 0 && errors == 0) { | 61 } else if (failed == 0 && errors == 0 && uncaughtError == null) { |
| 58 print('All $passed tests passed.'); | 62 print('All $passed tests passed.'); |
| 59 success = true; | 63 success = true; |
| 60 } else { | 64 } else { |
| 65 if (uncaughtError != null) { |
| 66 print('Top-level uncaught error: $uncaughtError'); |
| 67 } |
| 61 print('$passed PASSED, $failed FAILED, $errors ERRORS'); | 68 print('$passed PASSED, $failed FAILED, $errors ERRORS'); |
| 62 } | 69 } |
| 63 | 70 |
| 64 // An exception is used by the test infrastructure to detect failure. | 71 // An exception is used by the test infrastructure to detect failure. |
| 65 if (!success) throw new Exception("Some tests failed."); | 72 if (!success) throw new Exception("Some tests failed."); |
| 66 } | 73 } |
| 67 } | 74 } |
| OLD | NEW |