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

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

Issue 11794041: Fix expect(future, throws). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixes 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 | « no previous file | 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 part of matcher; 5 part of matcher;
6 6
7 /** 7 /**
8 * Returns a matcher that matches empty strings, maps or collections. 8 * Returns a matcher that matches empty strings, maps or collections.
9 */ 9 */
10 const Matcher isEmpty = const _Empty(); 10 const Matcher isEmpty = const _Empty();
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 const Matcher returnsNormally = const _ReturnsNormally(); 275 const Matcher returnsNormally = const _ReturnsNormally();
276 276
277 class Throws extends BaseMatcher { 277 class Throws extends BaseMatcher {
278 final Matcher _matcher; 278 final Matcher _matcher;
279 279
280 const Throws([Matcher matcher]) : 280 const Throws([Matcher matcher]) :
281 this._matcher = matcher; 281 this._matcher = matcher;
282 282
283 bool matches(item, MatchState matchState) { 283 bool matches(item, MatchState matchState) {
284 if (item is Future) { 284 if (item is Future) {
285 var done = wrapAsync((fn) => fn());
286
285 // Queue up an asynchronous expectation that validates when the future 287 // Queue up an asynchronous expectation that validates when the future
286 // completes. 288 // completes.
287 item.then(wrapAsync((value) { 289 item.then((value) {
288 expect(false, isTrue, reason: 290 done(() => expect(false, isTrue, reason:
289 "Expected future to fail, but succeeded with '$value'."); 291 "Expected future to fail, but succeeded with '$value'."));
290 })); 292 }, onError: (e) {
291
292 item.catchError((e) {
293 var reason; 293 var reason;
294 if (e.stackTrace != null) { 294 if (e.stackTrace != null) {
295 var stackTrace = e.stackTrace.toString(); 295 var stackTrace = e.stackTrace.toString();
296 stackTrace = " ${stackTrace.replaceAll("\n", "\n ")}"; 296 stackTrace = " ${stackTrace.replaceAll("\n", "\n ")}";
297 reason = "Actual exception trace:\n$stackTrace"; 297 reason = "Actual exception trace:\n$stackTrace";
298 } 298 }
299 expect(e.error, _matcher, reason: reason); 299 done(() => expect(e.error, _matcher, reason: reason));
300 }); 300 });
301 301
302 // It hasn't failed yet. 302 // It hasn't failed yet.
303 return true; 303 return true;
304 } 304 }
305 305
306 try { 306 try {
307 item(); 307 item();
308 return false; 308 return false;
309 } catch (e, s) { 309 } catch (e, s) {
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 description.add(_featureDescription).add(' ').addDescriptionOf(_matcher); 677 description.add(_featureDescription).add(' ').addDescriptionOf(_matcher);
678 678
679 Description describeMismatch(item, Description mismatchDescription, 679 Description describeMismatch(item, Description mismatchDescription,
680 MatchState matchState, bool verbose) { 680 MatchState matchState, bool verbose) {
681 mismatchDescription.add(_featureName).add(' '); 681 mismatchDescription.add(_featureName).add(' ');
682 _matcher.describeMismatch(matchState.state['feature'], mismatchDescription, 682 _matcher.describeMismatch(matchState.state['feature'], mismatchDescription,
683 matchState.state['innerState'], verbose); 683 matchState.state['innerState'], verbose);
684 return mismatchDescription; 684 return mismatchDescription;
685 } 685 }
686 } 686 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698