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

Unified Diff: tests/corelib/future_test.dart

Issue 11418104: Make exceptions propagate through multiple Future branches. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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 | « sdk/lib/core/future_impl.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/corelib/future_test.dart
diff --git a/tests/corelib/future_test.dart b/tests/corelib/future_test.dart
index 9ed1db54ed8a38e398b61fb2691a54d1067b8f12..31dbb8120c6ec400507973df27e798987bc814a6 100644
--- a/tests/corelib/future_test.dart
+++ b/tests/corelib/future_test.dart
@@ -565,6 +565,92 @@ testTransformExceptionReturnsAFuture() {
Expect.equals("transformed value", transformedFuture.value);
}
+// Tests for branching exceptions
+
+testExceptionTravelsAlongBothBranches() {
+ var results = <int>[];
+
+ var completer = new Completer();
+ var branch1 = completer.future.transform((_) => null);
+ var branch2 = completer.future.transform((_) => null);
+
+ branch1.handleException((e) {
+ results.add(1);
+ return true;
+ });
+
+ branch2.handleException((e) {
+ results.add(2);
+ return true;
+ });
+
+ completer.completeException("error");
+ Expect.listEquals([1, 2], results);
+}
+
+testExceptionTravelsAlongBothBranchesAfterComplete() {
+ var results = <int>[];
+
+ var completer = new Completer();
+ completer.completeException("error");
+
+ var branch1 = completer.future.transform((_) => null);
+ var branch2 = completer.future.transform((_) => null);
+
+ branch1.handleException((e) {
+ results.add(1);
+ return true;
+ });
+
+ branch2.handleException((e) {
+ results.add(2);
+ return true;
+ });
+
+ Expect.listEquals([2, 1], results);
Siggi Cherem (dart-lang) 2012/11/21 01:08:57 it's weird to see these in opposite order, maybe u
nweiz 2012/11/21 20:39:09 Done.
+}
+
+testExceptionIsHandledInBaseAndBranch() {
+ var results = <String>[];
+
+ var completer = new Completer();
+ var branch = completer.future.transform((_) => null);
+
+ completer.future.handleException((e) {
+ results.add("base");
+ return true;
+ });
+
+ branch.handleException((e) {
+ results.add("branch");
+ return true;
+ });
+
+ completer.completeException("error");
+ Expect.listEquals(["branch", "base"], results);
+}
+
+testExceptionIsHandledInBaseAndBranchAfterComplete() {
+ var results = <String>[];
+
+ var completer = new Completer();
+ completer.completeException("error");
+
+ var branch = completer.future.transform((_) => null);
Siggi Cherem (dart-lang) 2012/11/21 01:08:57 maybe add another test to check what happens if yo
nweiz 2012/11/21 20:39:09 That case isn't handled by this CL; it will actual
+
+ completer.future.handleException((e) {
+ results.add("base");
+ return true;
+ });
+
+ branch.handleException((e) {
+ results.add("branch");
+ return true;
+ });
+
+ Expect.listEquals(["base", "branch"], results);
+}
+
main() {
testImmediate();
testNeverComplete();
@@ -605,4 +691,6 @@ main() {
testTransformExceptionThrows();
testTransformExceptionReturns();
testTransformExceptionReturnsAFuture();
+ testExceptionTravelsAlongBothBranches();
+ testExceptionIsHandledInBaseAndBranch();
Siggi Cherem (dart-lang) 2012/11/21 01:08:57 add the other 2 tests? (...AfterComplete)
nweiz 2012/11/21 20:39:09 Done.
}
« no previous file with comments | « sdk/lib/core/future_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698