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

Unified Diff: tests/lib/async/future_test.dart

Issue 1025133004: Make Completer.complete handle a Future with a misbehaving "then" call. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Expand explanation Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/async/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/lib/async/future_test.dart
diff --git a/tests/lib/async/future_test.dart b/tests/lib/async/future_test.dart
index 108cbcd52992d25ab337dce054b12d78a98328bb..900eea65c3cb2524111728aa9aaec4a0056ba8e6 100644
--- a/tests/lib/async/future_test.dart
+++ b/tests/lib/async/future_test.dart
@@ -876,6 +876,26 @@ void testWaitCleanUpError() {
});
}
+void testBadFuture() {
+ var bad = new BadFuture();
+ // Completing with bad future (then call throws) puts error in result.
+ asyncStart();
+ Completer completer = new Completer();
+ completer.complete(bad);
+ completer.future.then((_) { fail("unreachable"); },
+ onError: (e, s) {
+ Expect.isTrue(completer.isCompleted);
+ asyncEnd();
+ });
+
+ asyncStart();
+ var f = new Future.value().then((_) => bad);
+ f.then((_) { fail("unreachable"); },
+ onError: (e, s) {
+ asyncEnd();
+ });
+}
+
main() {
asyncStart();
@@ -935,6 +955,8 @@ main() {
testWaitCleanUp();
testWaitCleanUpError();
+ testBadFuture();
+
asyncEnd();
}
@@ -953,3 +975,15 @@ class CustomFuture<T> implements Future<T> {
String toString() => "CustomFuture@${_realFuture.hashCode}";
int get hashCode => _realFuture.hashCode;
}
+
+class BadFuture<T> implements Future<T> {
+ Future then(action(result)) {
+ throw "then GOTCHA!";
+ }
+ Future catchError(Function onError) {
+ throw "catch GOTCHA!";
+ }
+ Future whenComplete(action()) {
+ throw "finally GOTCHA!";
+ }
+}
« no previous file with comments | « sdk/lib/async/future_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698