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 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 _testCases.clear(); | 292 _testCases.clear(); |
293 } | 293 } |
294 ++_soloNestingLevel; | 294 ++_soloNestingLevel; |
295 try { | 295 try { |
296 test(spec, body); | 296 test(spec, body); |
297 } finally { | 297 } finally { |
298 --_soloNestingLevel; | 298 --_soloNestingLevel; |
299 } | 299 } |
300 } | 300 } |
301 | 301 |
302 /** Sentinel value for [_SpreadArgsHelper]. */ | |
303 class _Sentinel { | |
304 const _Sentinel(); | |
305 } | |
306 | |
307 /** | 302 /** |
308 * Indicate that [callback] is expected to be called a [count] number of times | 303 * Indicate that [callback] is expected to be called a [count] number of times |
309 * (by default 1). The unittest framework will wait for the callback to run the | 304 * (by default 1). The unittest framework will wait for the callback to run the |
310 * specified [count] times before it continues with the following test. Using | 305 * specified [count] times before it continues with the following test. Using |
311 * [expectAsync0] will also ensure that errors that occur within [callback] are | 306 * [expectAsync0] will also ensure that errors that occur within [callback] are |
312 * tracked and reported. [callback] should take 0 positional arguments (named | 307 * tracked and reported. [callback] should take 0 positional arguments (named |
313 * arguments are not supported). [id] can be used to provide more | 308 * arguments are not supported). [id] can be used to provide more |
314 * descriptive error messages if the callback is called more often than | 309 * descriptive error messages if the callback is called more often than |
315 * expected. [max] can be used to specify an upper bound on the number of | 310 * expected. [max] can be used to specify an upper bound on the number of |
316 * calls; if this is exceeded the test will fail (or be marked as in error if | 311 * calls; if this is exceeded the test will fail (or be marked as in error if |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 void handleExternalError(e, String message, [stack]) { | 471 void handleExternalError(e, String message, [stack]) { |
477 var msg = '$message\nCaught $e'; | 472 var msg = '$message\nCaught $e'; |
478 | 473 |
479 if (currentTestCase != null) { | 474 if (currentTestCase != null) { |
480 currentTestCase._error(msg, stack); | 475 currentTestCase._error(msg, stack); |
481 } else { | 476 } else { |
482 _uncaughtErrorMessage = "$msg: $stack"; | 477 _uncaughtErrorMessage = "$msg: $stack"; |
483 } | 478 } |
484 } | 479 } |
485 | 480 |
486 void rerunTests() { | |
487 _uncaughtErrorMessage = null; | |
488 _initialized = true; // We don't want to reset the test array. | |
489 runTests(); | |
490 } | |
491 | |
492 /** | 481 /** |
493 * Filter the tests. [testFilter] can be a [RegExp], a [String] or a | 482 * Filter the tests. [testFilter] can be a [RegExp], a [String] or a |
494 * predicate function. This is different to enabling/disabling tests | 483 * predicate function. This is different to enabling/disabling tests |
495 * in that it removes the tests completely. | 484 * in that it removes the tests completely. |
496 */ | 485 */ |
497 void filterTests(testFilter) { | 486 void filterTests(testFilter) { |
498 var filterFunction; | 487 var filterFunction; |
499 if (testFilter is String) { | 488 if (testFilter is String) { |
500 RegExp re = new RegExp(testFilter); | 489 RegExp re = new RegExp(testFilter); |
501 filterFunction = (t) => re.hasMatch(t.description); | 490 filterFunction = (t) => re.hasMatch(t.description); |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 | 700 |
712 if (!filterStacks) return trace; | 701 if (!filterStacks) return trace; |
713 | 702 |
714 // Format the stack trace by removing everything above TestCase._runTest, | 703 // Format the stack trace by removing everything above TestCase._runTest, |
715 // which is usually going to be irrelevant. Also fold together unittest and | 704 // which is usually going to be irrelevant. Also fold together unittest and |
716 // core library calls so only the function the user called is visible. | 705 // core library calls so only the function the user called is visible. |
717 return new Trace(trace.frames.takeWhile((frame) { | 706 return new Trace(trace.frames.takeWhile((frame) { |
718 return frame.package != 'unittest' || frame.member != 'TestCase._runTest'; | 707 return frame.package != 'unittest' || frame.member != 'TestCase._runTest'; |
719 })).terse.foldFrames((frame) => frame.package == 'unittest' || frame.isCore); | 708 })).terse.foldFrames((frame) => frame.package == 'unittest' || frame.isCore); |
720 } | 709 } |
OLD | NEW |