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

Side by Side Diff: pkg/unittest/lib/src/future_matchers.dart

Issue 11783009: Big merge from experimental to bleeding edge. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/unittest/lib/src/core_matchers.dart ('k') | pkg/unittest/lib/unittest.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 * Matches a [Future] that completes successfully with a value. Note that this 6 * Matches a [Future] that completes successfully with a value. Note that this
7 * creates an asynchronous expectation. The call to `expect()` that includes 7 * creates an asynchronous expectation. The call to `expect()` that includes
8 * this will return immediately and execution will continue. Later, when the 8 * this will return immediately and execution will continue. Later, when the
9 * future completes, the actual expectation will run. 9 * future completes, the actual expectation will run.
10 * 10 *
(...skipping 17 matching lines...) Expand all
28 Matcher completion(matcher) => new _Completes(wrapMatcher(matcher)); 28 Matcher completion(matcher) => new _Completes(wrapMatcher(matcher));
29 29
30 class _Completes extends BaseMatcher { 30 class _Completes extends BaseMatcher {
31 final Matcher _matcher; 31 final Matcher _matcher;
32 32
33 const _Completes(this._matcher); 33 const _Completes(this._matcher);
34 34
35 bool matches(item, MatchState matchState) { 35 bool matches(item, MatchState matchState) {
36 if (item is! Future) return false; 36 if (item is! Future) return false;
37 37
38 item.onComplete(wrapAsync((future) { 38 item.then((value) {
39 if (_matcher != null) expect(value, _matcher);
40 });
41
42 item.catchError((e) {
39 var reason = 'Expected future to complete successfully, but it failed ' 43 var reason = 'Expected future to complete successfully, but it failed '
40 'with ${future.exception}'; 44 'with ${e.error}';
41 if (future.stackTrace != null) { 45 if (future.stackTrace != null) {
42 var stackTrace = future.stackTrace.toString(); 46 var stackTrace = e.stackTrace.toString();
43 stackTrace = ' ${stackTrace.replaceAll('\n', '\n ')}'; 47 stackTrace = ' ${stackTrace.replaceAll('\n', '\n ')}';
44 reason = '$reason\nStack trace:\n$stackTrace'; 48 reason = '$reason\nStack trace:\n$stackTrace';
45 } 49 }
46 50 expect(false, isTrue, reason: reason);
47 expect(future.hasValue, isTrue, reason: reason); 51 });
48 if (_matcher != null) expect(future.value, _matcher);
49 }));
50 52
51 return true; 53 return true;
52 } 54 }
53 55
54 Description describe(Description description) { 56 Description describe(Description description) {
55 if (_matcher == null) { 57 if (_matcher == null) {
56 description.add('completes successfully'); 58 description.add('completes successfully');
57 } else { 59 } else {
58 description.add('completes to a value that ').addDescriptionOf(_matcher); 60 description.add('completes to a value that ').addDescriptionOf(_matcher);
59 } 61 }
60 return description; 62 return description;
61 } 63 }
62 } 64 }
OLDNEW
« no previous file with comments | « pkg/unittest/lib/src/core_matchers.dart ('k') | pkg/unittest/lib/unittest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698