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

Side by Side Diff: tests/lib/async/future_test.dart

Issue 11826050: Consider a thrown AsyncError from a future/stream handler a rethrow. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Add tests. 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 | « sdk/lib/async/stream_controller.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 library future_test; 5 library future_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:isolate'; 8 import 'dart:isolate';
9 9
10 testImmediate() { 10 testImmediate() {
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 }).then((v) { 436 }).then((v) {
437 Expect.fail("should fail async"); 437 Expect.fail("should fail async");
438 }, onError: (AsyncError e) { 438 }, onError: (AsyncError e) {
439 Expect.equals("Fail", e.error); 439 Expect.equals("Fail", e.error);
440 countDown(1); 440 countDown(1);
441 }); 441 });
442 442
443 completer.completeError("Error"); 443 completer.completeError("Error");
444 } 444 }
445 445
446 testFutureThenThrowsAsync() {
447 final completer = new Completer<int>();
448 final future = completer.future;
449 AsyncError error = new AsyncError(42, "st");
446 450
451 var port = new ReceivePort();
452 future.then((v) {
453 throw error;
454 }).catchError((AsyncError e) {
455 Expect.identical(error, e);
456 port.close();
457 });
458 completer.complete(0);
459 }
460
461 testFutureCatchThrowsAsync() {
462 final completer = new Completer<int>();
463 final future = completer.future;
464 AsyncError error = new AsyncError(42, "st");
465
466 var port = new ReceivePort();
467 future.catchError((AsyncError e) {
468 throw error;
469 }).catchError((AsyncError e) {
470 Expect.identical(error, e);
471 port.close();
472 });
473 completer.completeError(0);
474 }
475
476 testFutureCatchRethrowsAsync() {
477 final completer = new Completer<int>();
478 final future = completer.future;
479 AsyncError error;
480
481 var port = new ReceivePort();
482 future.catchError((AsyncError e) {
483 error = e;
484 throw e;
485 }).catchError((AsyncError e) {
486 Expect.identical(error, e);
487 port.close();
488 });
489 completer.completeError(0);
490 }
491
492 testFutureWhenThrowsAsync() {
493 final completer = new Completer<int>();
494 final future = completer.future;
495 AsyncError error = new AsyncError(42, "st");
496
497 var port = new ReceivePort();
498 future.whenComplete(() {
499 throw error;
500 }).catchError((AsyncError e) {
501 Expect.identical(error, e);
502 port.close();
503 });
504 completer.complete(0);
505 }
506
507 testCompleteWithAsyncError() {
508 final completer = new Completer<int>();
509 final future = completer.future;
510 AsyncError error = new AsyncError(42, "st");
511
512 var port = new ReceivePort();
513 future.catchError((AsyncError e) {
514 Expect.identical(error, e);
515 port.close();
516 });
517
518 completer.completeError(error);
519 }
447 520
448 main() { 521 main() {
449 testImmediate(); 522 testImmediate();
450 testNeverComplete(); 523 testNeverComplete();
451 524
452 testComplete(); 525 testComplete();
453 testCompleteWithSuccessHandlerBeforeComplete(); 526 testCompleteWithSuccessHandlerBeforeComplete();
454 testCompleteWithSuccessHandlerAfterComplete(); 527 testCompleteWithSuccessHandlerAfterComplete();
455 testCompleteManySuccessHandlers(); 528 testCompleteManySuccessHandlers();
529 testCompleteWithAsyncError();
456 530
457 testException(); 531 testException();
458 testExceptionHandler(); 532 testExceptionHandler();
459 testExceptionHandlerReturnsTrue(); 533 testExceptionHandlerReturnsTrue();
460 testExceptionHandlerReturnsTrue2(); 534 testExceptionHandlerReturnsTrue2();
461 testExceptionHandlerReturnsFalse(); 535 testExceptionHandlerReturnsFalse();
462 536
463 testFutureAsStreamCompleteAfter(); 537 testFutureAsStreamCompleteAfter();
464 testFutureAsStreamCompleteBefore(); 538 testFutureAsStreamCompleteBefore();
465 testFutureAsStreamCompleteImmediate(); 539 testFutureAsStreamCompleteImmediate();
466 testFutureAsStreamCompleteErrorAfter(); 540 testFutureAsStreamCompleteErrorAfter();
467 testFutureAsStreamWrapper(); 541 testFutureAsStreamWrapper();
468 542
469 testFutureWhenCompleteValue(); 543 testFutureWhenCompleteValue();
470 testFutureWhenCompleteError(); 544 testFutureWhenCompleteError();
471 testFutureWhenCompleteValueNewError(); 545 testFutureWhenCompleteValueNewError();
472 testFutureWhenCompleteErrorNewError(); 546 testFutureWhenCompleteErrorNewError();
473 547
474 testFutureWhenValueFutureValue(); 548 testFutureWhenValueFutureValue();
475 testFutureWhenErrorFutureValue(); 549 testFutureWhenErrorFutureValue();
476 testFutureWhenValueFutureError(); 550 testFutureWhenValueFutureError();
477 testFutureWhenErrorFutureError(); 551 testFutureWhenErrorFutureError();
552
553 testFutureThenThrowsAsync();
554 testFutureCatchThrowsAsync();
555 testFutureWhenThrowsAsync();
556 testFutureCatchRethrowsAsync();
478 } 557 }
479 558
OLDNEW
« no previous file with comments | « sdk/lib/async/stream_controller.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698