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

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

Issue 11791031: Some minor small fixes to unittest (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') | no next file » | 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.then((value) { 38 item.then(wrapAsync((value) {
39 if (_matcher != null) expect(value, _matcher); 39 if (_matcher != null) expect(value, _matcher);
40 }); 40 }));
41 41
42 item.catchError((e) { 42 item.catchError((e) {
43 var reason = 'Expected future to complete successfully, but it failed ' 43 var reason = 'Expected future to complete successfully, but it failed '
44 'with ${e.error}'; 44 'with ${e.error}';
45 if (future.stackTrace != null) { 45 if (future.stackTrace != null) {
46 var stackTrace = e.stackTrace.toString(); 46 var stackTrace = e.stackTrace.toString();
47 stackTrace = ' ${stackTrace.replaceAll('\n', '\n ')}'; 47 stackTrace = ' ${stackTrace.replaceAll('\n', '\n ')}';
48 reason = '$reason\nStack trace:\n$stackTrace'; 48 reason = '$reason\nStack trace:\n$stackTrace';
49 } 49 }
50 expect(false, isTrue, reason: reason); 50 expect(false, isTrue, reason: reason);
51 }); 51 });
52 52
53 return true; 53 return true;
54 } 54 }
55 55
56 Description describe(Description description) { 56 Description describe(Description description) {
57 if (_matcher == null) { 57 if (_matcher == null) {
58 description.add('completes successfully'); 58 description.add('completes successfully');
59 } else { 59 } else {
60 description.add('completes to a value that ').addDescriptionOf(_matcher); 60 description.add('completes to a value that ').addDescriptionOf(_matcher);
61 } 61 }
62 return description; 62 return description;
63 } 63 }
64 } 64 }
OLDNEW
« no previous file with comments | « pkg/unittest/lib/src/core_matchers.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698