Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1356)

Unified Diff: pkg/unittest/lib/src/future_matchers.dart

Issue 12393017: Fix issue with async callbacks that get called synchronously while running test case function causi… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/unittest/lib/src/expect.dart ('k') | pkg/unittest/lib/src/test_case.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)
+ : 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 ')}';
« no previous file with comments | « pkg/unittest/lib/src/expect.dart ('k') | pkg/unittest/lib/src/test_case.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698