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 /// Support for writing Dart unit tests. | 5 /// Support for writing Dart unit tests. |
6 /// | 6 /// |
7 /// For information on installing and importing this library, see the | 7 /// For information on installing and importing this library, see the |
8 /// [unittest package on pub.dartlang.org] | 8 /// [unittest package on pub.dartlang.org] |
9 /// (http://pub.dartlang.org/packages/unittest). | 9 /// (http://pub.dartlang.org/packages/unittest). |
10 /// | 10 /// |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 /// [expectAsync] will also ensure that errors that occur within [callback] are | 290 /// [expectAsync] will also ensure that errors that occur within [callback] are |
291 /// tracked and reported. [callback] should take 0 positional arguments (named | 291 /// tracked and reported. [callback] should take 0 positional arguments (named |
292 /// arguments are not supported). [id] can be used to provide more | 292 /// arguments are not supported). [id] can be used to provide more |
293 /// descriptive error messages if the callback is called more often than | 293 /// descriptive error messages if the callback is called more often than |
294 /// expected. [max] can be used to specify an upper bound on the number of | 294 /// expected. [max] can be used to specify an upper bound on the number of |
295 /// calls; if this is exceeded the test will fail (or be marked as in error if | 295 /// calls; if this is exceeded the test will fail (or be marked as in error if |
296 /// it was already complete). A value of 0 for [max] (the default) will set | 296 /// it was already complete). A value of 0 for [max] (the default) will set |
297 /// the upper bound to the same value as [count]; i.e. the callback should be | 297 /// the upper bound to the same value as [count]; i.e. the callback should be |
298 /// called exactly [count] times. A value of -1 for [max] will mean no upper | 298 /// called exactly [count] times. A value of -1 for [max] will mean no upper |
299 /// bound. | 299 /// bound. |
| 300 /// |
| 301 /// [reason] is optional and is typically not supplied, as a reason is generated |
| 302 /// by the unittest package; if reason is included it is appended to the |
| 303 /// generated reason. |
300 Function expectAsync(Function callback, | 304 Function expectAsync(Function callback, |
301 {int count: 1, int max: 0, String id}) => | 305 {int count: 1, int max: 0, String id, String reason}) => |
302 new _SpreadArgsHelper(callback, count, max, id).func; | 306 new _SpreadArgsHelper(callback, count, max, id, reason).func; |
303 | 307 |
304 /// Indicate that [callback] is expected to be called until [isDone] returns | 308 /// Indicate that [callback] is expected to be called until [isDone] returns |
305 /// true. The unittest framework check [isDone] after each callback and only | 309 /// true. The unittest framework check [isDone] after each callback and only |
306 /// when it returns true will it continue with the following test. Using | 310 /// when it returns true will it continue with the following test. Using |
307 /// [expectAsyncUntil] will also ensure that errors that occur within | 311 /// [expectAsyncUntil] will also ensure that errors that occur within |
308 /// [callback] are tracked and reported. [callback] should take 0 positional | 312 /// [callback] are tracked and reported. [callback] should take 0 positional |
309 /// arguments (named arguments are not supported). [id] can be used to | 313 /// arguments (named arguments are not supported). [id] can be used to |
310 /// identify the callback in error messages (for example if it is called | 314 /// identify the callback in error messages (for example if it is called |
311 /// after the test case is complete). | 315 /// after the test case is complete). |
312 Function expectAsyncUntil(Function callback, bool isDone(), {String id}) => | 316 /// |
313 new _SpreadArgsHelper(callback, 0, -1, id, isDone: isDone).func; | 317 /// [reason] is optional and is typically not supplied, as a reason is generated |
| 318 /// by the unittest package; if reason is included it is appended to the |
| 319 /// generated reason. |
| 320 Function expectAsyncUntil(Function callback, bool isDone(), |
| 321 {String id, String reason}) => |
| 322 new _SpreadArgsHelper(callback, 0, -1, id, reason, isDone: isDone).func; |
314 | 323 |
315 /// Creates a new named group of tests. Calls to group() or test() within the | 324 /// Creates a new named group of tests. Calls to group() or test() within the |
316 /// body of the function passed to this will inherit this group's description. | 325 /// body of the function passed to this will inherit this group's description. |
317 void group(String description, void body()) { | 326 void group(String description, void body()) { |
318 ensureInitialized(); | 327 ensureInitialized(); |
319 _requireNotRunning(); | 328 _requireNotRunning(); |
320 _currentContext = new _GroupContext(_currentContext, description); | 329 _currentContext = new _GroupContext(_currentContext, description); |
321 try { | 330 try { |
322 body(); | 331 body(); |
323 } catch (e, trace) { | 332 } catch (e, trace) { |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 | 564 |
556 /// A flag that controls whether we try to filter out irrelevant frames from | 565 /// A flag that controls whether we try to filter out irrelevant frames from |
557 /// the stack trace. Requires formatStacks to be set. | 566 /// the stack trace. Requires formatStacks to be set. |
558 bool filterStacks = true; | 567 bool filterStacks = true; |
559 | 568 |
560 void _requireNotRunning() { | 569 void _requireNotRunning() { |
561 if (_currentTestCaseIndex != -1) { | 570 if (_currentTestCaseIndex != -1) { |
562 throw new StateError('Not allowed when tests are running.'); | 571 throw new StateError('Not allowed when tests are running.'); |
563 } | 572 } |
564 } | 573 } |
OLD | NEW |