Chromium Code Reviews| Index: pkg/unittest/lib/src/future_matchers.dart |
| =================================================================== |
| --- pkg/unittest/lib/src/future_matchers.dart (revision 19336) |
| +++ pkg/unittest/lib/src/future_matchers.dart (working copy) |
| @@ -13,7 +13,7 @@ |
| * To test that a Future completes with an exception, you can use [throws] and |
| * [throwsA]. |
| */ |
| -Matcher completes = const _Completes(null); |
| +Matcher completes = const _Completes(null, ''); |
| /** |
| * Matches a [Future] that completes succesfully with a value that matches |
| @@ -23,23 +23,29 @@ |
| * |
| * To test that a Future completes with an exception, you can use [throws] and |
| * [throwsA]. |
| + * |
| + * [id] is an optional tag that can be used to identify the completion matcher |
| + * in error messages. |
| */ |
| -Matcher completion(matcher) => new _Completes(wrapMatcher(matcher)); |
| +Matcher completion(matcher, [String id = '']) => |
| + new _Completes(wrapMatcher(matcher), id); |
| class _Completes extends BaseMatcher { |
| final Matcher _matcher; |
| + final String _id; |
| - const _Completes(this._matcher); |
| + const _Completes(this._matcher, String id) : |
|
Siggi Cherem (dart-lang)
2013/03/01 21:11:20
style nit: move the ':' to the next line:
cons
gram
2013/03/04 19:53:40
Done.
|
| + this._id = (id == '') ? '' : '$id '; |
| bool matches(item, MatchState matchState) { |
| if (item is! Future) return false; |
| - var done = wrapAsync((fn) => fn()); |
| + var done = wrapAsync((fn) => fn(), _id); |
| item.then((value) { |
| done(() { if (_matcher != null) expect(value, _matcher); }); |
| }, onError: (e) { |
| - var reason = 'Expected future to complete successfully, but it failed ' |
| - 'with ${e.error}'; |
| + var reason = 'Expected future ${_id}to complete successfully, ' |
| + 'but it failed with ${e.error}'; |
| if (e.stackTrace != null) { |
| var stackTrace = e.stackTrace.toString(); |
| stackTrace = ' ${stackTrace.replaceAll('\n', '\n ')}'; |