OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /** | 5 /** |
6 * Support for writing Dart unit tests. | 6 * Support for writing Dart unit tests. |
7 * | 7 * |
8 * For information on installing and importing this library, see the | 8 * For information on installing and importing this library, see the |
9 * [unittest package on pub.dartlang.org] | 9 * [unittest package on pub.dartlang.org] |
10 * (http://pub.dartlang.org/packages/unittest). | 10 * (http://pub.dartlang.org/packages/unittest). |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 } | 162 } |
163 return _config; | 163 return _config; |
164 } | 164 } |
165 | 165 |
166 /** | 166 /** |
167 * Sets the [Configuration] used by the unittest library. | 167 * Sets the [Configuration] used by the unittest library. |
168 * | 168 * |
169 * Throws a [StateError] if there is an existing, incompatible value. | 169 * Throws a [StateError] if there is an existing, incompatible value. |
170 */ | 170 */ |
171 void set unittestConfiguration(Configuration value) { | 171 void set unittestConfiguration(Configuration value) { |
172 if(!identical(_config, value)) { | 172 if (!identical(_config, value)) { |
173 if(_config != null) { | 173 if (_config != null) { |
174 throw new StateError('unittestConfiguration has already been set'); | 174 throw new StateError('unittestConfiguration has already been set'); |
175 } | 175 } |
176 _config = value; | 176 _config = value; |
177 } | 177 } |
178 } | 178 } |
179 | 179 |
180 /** | 180 /** |
181 * Can be called by tests to log status. Tests should use this | 181 * Can be called by tests to log status. Tests should use this |
182 * instead of [print]. | 182 * instead of [print]. |
183 */ | 183 */ |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 | 294 |
295 /** Time since we last gave non-sync code a chance to be scheduled. */ | 295 /** Time since we last gave non-sync code a chance to be scheduled. */ |
296 var _lastBreath = new DateTime.now().millisecondsSinceEpoch; | 296 var _lastBreath = new DateTime.now().millisecondsSinceEpoch; |
297 | 297 |
298 /* Test case result strings. */ | 298 /* Test case result strings. */ |
299 // TODO(gram) we should change these constants to use a different string | 299 // TODO(gram) we should change these constants to use a different string |
300 // (so that writing 'FAIL' in the middle of a test doesn't | 300 // (so that writing 'FAIL' in the middle of a test doesn't |
301 // imply that the test fails). We can't do it without also changing | 301 // imply that the test fails). We can't do it without also changing |
302 // the testrunner and test.dart though. | 302 // the testrunner and test.dart though. |
303 /// Result string for a passing test case. | 303 /// Result string for a passing test case. |
304 const PASS = 'pass'; | 304 const PASS = 'pass'; |
305 /// Result string for a failing test case. | 305 /// Result string for a failing test case. |
306 const FAIL = 'fail'; | 306 const FAIL = 'fail'; |
307 /// Result string for an test case with an error. | 307 /// Result string for an test case with an error. |
308 const ERROR = 'error'; | 308 const ERROR = 'error'; |
309 | 309 |
310 /** | 310 /** |
311 * Creates a new test case with the given description and body. The | 311 * Creates a new test case with the given description and body. The |
312 * description will include the descriptions of any surrounding group() | 312 * description will include the descriptions of any surrounding group() |
313 * calls. | 313 * calls. |
314 */ | 314 */ |
315 void test(String spec, TestFunction body) { | 315 void test(String spec, TestFunction body) { |
316 ensureInitialized(); | 316 ensureInitialized(); |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 | 875 |
876 if (!filterStacks) return trace; | 876 if (!filterStacks) return trace; |
877 | 877 |
878 // Format the stack trace by removing everything above TestCase._runTest, | 878 // Format the stack trace by removing everything above TestCase._runTest, |
879 // which is usually going to be irrelevant. Also fold together unittest and | 879 // which is usually going to be irrelevant. Also fold together unittest and |
880 // core library calls so only the function the user called is visible. | 880 // core library calls so only the function the user called is visible. |
881 return new Trace(trace.frames.takeWhile((frame) { | 881 return new Trace(trace.frames.takeWhile((frame) { |
882 return frame.package != 'unittest' || frame.member != 'TestCase._runTest'; | 882 return frame.package != 'unittest' || frame.member != 'TestCase._runTest'; |
883 })).terse.foldFrames((frame) => frame.package == 'unittest' || frame.isCore); | 883 })).terse.foldFrames((frame) => frame.package == 'unittest' || frame.isCore); |
884 } | 884 } |
OLD | NEW |