| 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 * A library for writing dart unit tests. | 6 * A library for writing dart unit tests. |
| 7 * | 7 * |
| 8 * ## Installing ## | 8 * ## Installing ## |
| 9 * | 9 * |
| 10 * Use [pub][] to install this package. Add the following to your `pubspec.yaml` | 10 * Use [pub][] to install this package. Add the following to your `pubspec.yaml` |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 * Timer.run()], as the Future exception handler may not capture exceptions | 131 * Timer.run()], as the Future exception handler may not capture exceptions |
| 132 * in such code. | 132 * in such code. |
| 133 * | 133 * |
| 134 * Note: due to some language limitations we have to use different functions | 134 * Note: due to some language limitations we have to use different functions |
| 135 * depending on the number of positional arguments of the callback. In the | 135 * depending on the number of positional arguments of the callback. In the |
| 136 * future, we plan to expose a single `expectAsync` function that can be used | 136 * future, we plan to expose a single `expectAsync` function that can be used |
| 137 * regardless of the number of positional arguments. This requires new langauge | 137 * regardless of the number of positional arguments. This requires new langauge |
| 138 * features or fixes to the current spec (e.g. see | 138 * features or fixes to the current spec (e.g. see |
| 139 * [Issue 2706](http://dartbug.com/2706)). | 139 * [Issue 2706](http://dartbug.com/2706)). |
| 140 * | 140 * |
| 141 * Meanwhile, we plan to add this alternative API for callbacks of more than 2 | |
| 142 * arguments or that take named parameters. (this is not implemented yet, | |
| 143 * but will be coming here soon). | |
| 144 * | |
| 145 * import 'package:unittest/unittest.dart'; | |
| 146 * import 'dart:isolate'; | |
| 147 * main() { | |
| 148 * test('callback is executed', () { | |
| 149 * // indicate ahead of time that an async callback is expected. | |
| 150 * var async = startAsync(); | |
| 151 * Timer.run(() { | |
| 152 * // Guard the body of the callback, so errors are propagated | |
| 153 * // correctly. | |
| 154 * guardAsync(() { | |
| 155 * int x = 2 + 3; | |
| 156 * expect(x, equals(5)); | |
| 157 * }); | |
| 158 * // indicate that the asynchronous callback was invoked. | |
| 159 * async.complete(); | |
| 160 * }); | |
| 161 * }); | |
| 162 * } | |
| 163 * | |
| 164 * [pub]: http://pub.dartlang.org | 141 * [pub]: http://pub.dartlang.org |
| 165 * [pkg]: http://pub.dartlang.org/packages/unittest | 142 * [pkg]: http://pub.dartlang.org/packages/unittest |
| 166 */ | 143 */ |
| 167 library unittest; | 144 library unittest; |
| 168 | 145 |
| 169 import 'dart:async'; | 146 import 'dart:async'; |
| 170 import 'dart:collection'; | 147 import 'dart:collection'; |
| 171 import 'dart:isolate'; | 148 import 'dart:isolate'; |
| 172 import 'dart:math' show max; | 149 import 'dart:math' show max; |
| 173 import 'matcher.dart'; | 150 import 'matcher.dart'; |
| (...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 | 864 |
| 888 if (!formatStacks) return trace; | 865 if (!formatStacks) return trace; |
| 889 | 866 |
| 890 // Format the stack trace by removing everything above TestCase._runTest, | 867 // Format the stack trace by removing everything above TestCase._runTest, |
| 891 // which is usually going to be irrelevant. Also fold together unittest and | 868 // which is usually going to be irrelevant. Also fold together unittest and |
| 892 // core library calls so only the function the user called is visible. | 869 // core library calls so only the function the user called is visible. |
| 893 return new Trace(trace.frames.takeWhile((frame) { | 870 return new Trace(trace.frames.takeWhile((frame) { |
| 894 return frame.package != 'unittest' || frame.member != 'TestCase._runTest'; | 871 return frame.package != 'unittest' || frame.member != 'TestCase._runTest'; |
| 895 })).terse.foldFrames((frame) => frame.package == 'unittest' || frame.isCore); | 872 })).terse.foldFrames((frame) => frame.package == 'unittest' || frame.isCore); |
| 896 } | 873 } |
| OLD | NEW |