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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 print(_indent(t.stackTrace)); | 97 print(_indent(t.stackTrace)); |
98 } | 98 } |
99 } | 99 } |
100 | 100 |
101 // Show the summary. | 101 // Show the summary. |
102 print(''); | 102 print(''); |
103 | 103 |
104 var success = false; | 104 var success = false; |
105 if (passed == 0 && failed == 0 && errors == 0) { | 105 if (passed == 0 && failed == 0 && errors == 0) { |
106 print('No tests found.'); | 106 print('No tests found.'); |
107 // This is considered a failure too: if this happens you probably have a | 107 // This is considered a failure too. |
108 // bug in your unit tests, unless you are filtering. | |
109 if (filter != null) { | |
110 success = true; | |
111 } | |
112 } else if (failed == 0 && errors == 0 && uncaughtError == null) { | 108 } else if (failed == 0 && errors == 0 && uncaughtError == null) { |
113 print('All $passed tests passed.'); | 109 print('All $passed tests passed.'); |
114 success = true; | 110 success = true; |
115 } else { | 111 } else { |
116 if (uncaughtError != null) { | 112 if (uncaughtError != null) { |
117 print('Top-level uncaught error: $uncaughtError'); | 113 print('Top-level uncaught error: $uncaughtError'); |
118 } | 114 } |
119 print('$passed PASSED, $failed FAILED, $errors ERRORS'); | 115 print('$passed PASSED, $failed FAILED, $errors ERRORS'); |
120 } | 116 } |
121 | 117 |
122 // An exception is used by the test infrastructure to detect failure. | 118 // An exception is used by the test infrastructure to detect failure. |
123 if (!success) throw new Exception("Some tests failed."); | 119 if (!success) throw new Exception("Some tests failed."); |
124 } | 120 } |
125 | 121 |
126 String _indent(String str) { | 122 String _indent(String str) { |
127 // TODO(nweiz): Use this simpler code once issue 2980 is fixed. | 123 // TODO(nweiz): Use this simpler code once issue 2980 is fixed. |
128 // return str.replaceAll(const RegExp("^", multiLine: true), " "); | 124 // return str.replaceAll(const RegExp("^", multiLine: true), " "); |
129 | 125 |
130 return Strings.join(str.split("\n").map((line) => " $line"), "\n"); | 126 return Strings.join(str.split("\n").map((line) => " $line"), "\n"); |
131 } | 127 } |
132 | 128 |
133 /** Handle errors that happen outside the tests. */ | 129 /** Handle errors that happen outside the tests. */ |
134 // TODO(vsm): figure out how to expose the stack trace here | 130 // TODO(vsm): figure out how to expose the stack trace here |
135 // Currently e.message works in dartium, but not in dartc. | 131 // Currently e.message works in dartium, but not in dartc. |
136 handleExternalError(e, String message) => | 132 handleExternalError(e, String message) => |
137 _reportTestError('$message\nCaught $e', ''); | 133 _reportTestError('$message\nCaught $e', ''); |
138 } | 134 } |
OLD | NEW |