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

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

Issue 1966523003: Make _Future._chainForeignFuture not cause an assert. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Address comments Created 4 years, 7 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 e8387bfd19e1a159fbda3c9c6f5e508b44d668ce..6699a6957a8c51e17f4deecaf4e31818f5073699 100644
--- a/tests/lib/async/future_test.dart
+++ b/tests/lib/async/future_test.dart
@@ -994,6 +994,29 @@ void testAnyIgnoreError() {
cs[0].completeError("BAD");
}
+void testFutureResult() {
+ asyncStart();
+ () async {
+ var f = new UglyFuture(5);
+ // Sanity check that our future is as mis-behaved as we think.
+ f.then((v) { Expect.isTrue(v is Future); });
+
+ var v = await f;
+ // The static type of await is Flatten(static-type-of-expression), so it
+ // suggests that it flattens. In practice it currently doesn't.
+ // The specification doesn't say anything special, so v should be the
+ // completion value of the UglyFuture future which is a future.
+ Expect.isTrue(v is Future);
+
+ // This used to hit an assert in checked mode.
+ // The CL adding this test changed the behavior to actually flatten the
+ // the future returned by the then-callback.
+ var w = new Future.value(42).then((_) => f);
+ Expect.equals(42, await w);
+ asyncEnd();
+ }();
+}
+
main() {
asyncStart();
@@ -1062,10 +1085,12 @@ main() {
testAnyIgnoreIncomplete();
testAnyIgnoreError();
+ testFutureResult();
+
asyncEnd();
}
-/// A Future that isn't recognizable as a _Future.
+/// A well-behaved Future that isn't recognizable as a _Future.
class CustomFuture<T> implements Future<T> {
Future _realFuture;
CustomFuture(this._realFuture);
@@ -1081,6 +1106,7 @@ class CustomFuture<T> implements Future<T> {
int get hashCode => _realFuture.hashCode;
}
+/// A bad future that throws on every method.
class BadFuture<T> implements Future<T> {
Future then(action(T result), {Function onError}) {
throw "then GOTCHA!";
@@ -1098,3 +1124,19 @@ class BadFuture<T> implements Future<T> {
throw "timeout GOTCHA!";
}
}
+
+// An evil future that completes with another future.
+class UglyFuture implements Future<dynamic> {
+ final _result;
+ UglyFuture(int badness) :
+ _result = (badness == 0) ? 42 : new UglyFuture(badness - 1);
+ Future then(action(value), {onError(error, StackTrace stack)}) {
+ var c = new Completer();
+ c.complete(new Future.microtask(() => action(_result)));
+ return c.future;
+ }
+ Future catchError(onError, {test}) {} // Never an error.
+ Future whenComplete(action()) {
+ return new Future.microtask(action).then((_) => this);
+ }
+}
« 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