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

Unified Diff: tests/language/async_throw_in_catch_test.dart

Issue 925973002: Fix error handling in dart2js async-await (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixed unit-test Created 5 years, 10 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
Index: tests/language/async_throw_in_catch_test.dart
diff --git a/tests/language/async_throw_in_catch_test.dart b/tests/language/async_throw_in_catch_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..9cb665a7a9051b5a74ed11fb738c6a6a6404af10
--- /dev/null
+++ b/tests/language/async_throw_in_catch_test.dart
@@ -0,0 +1,429 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import "dart:async";
+import "package:expect/expect.dart";
+import "package:async_helper/async_helper.dart";
+
+class Tracer {
+ final String expected;
+ final String name;
+ int counter = 0;
+
+ Tracer(this.expected, [this.name]);
+
+ void trace(msg) {
+ if (name != null) {
+ print("Tracing $name: $msg");
+ }
+ Expect.equals(expected[counter], msg);
+ counter++;
+ }
+
+ void done() {
+ Expect.equals(expected.length, counter, "Received too few traces");
+ }
+}
+
+foo1(Tracer tracer) async {
floitsch 2015/02/17 12:40:58 You could consider removing the "async" in the ///
sigurdm 2015/02/17 14:19:49 I want to check that the async rewrite works prope
+ try {
+ tracer.trace("a");
+ // This await forces dart2js to rewrite the try into a state machine
floitsch 2015/02/17 12:40:58 nit nit. 2 spaces after "await".
sigurdm 2015/02/17 14:19:49 Done.
+ // instead of relying on the existing structure.
+ await new Future.value(3); /// forceAwait: ok
+ tracer.trace("b");
+ throw "Error";
+ } catch (error) {
+ tracer.trace("c");
+ Expect.equals("Error", error);
+ throw "Error2";
+ tracer.trace("d");
+ } finally {
+ tracer.trace("e");
+ }
+ tracer.trace("f");
+}
+
+foo2(Tracer tracer) async {
+ try {
+ tracer.trace("a");
+ await new Future.value(3); /// forceAwait: continued
+ tracer.trace("b");
+ throw "Error";
+ tracer.trace("c");
+ } catch (error) {
+ tracer.trace("d");
+ Expect.equals("Error", error);
+ await new Future.error("Error2");
+ } finally {
+ tracer.trace("e");
+ }
+ tracer.trace("f");
+}
+
+foo3(Tracer tracer) async {
+ try {
+ tracer.trace("a");
+ await new Future.value(3); /// forceAwait: continued
+ tracer.trace("b");
+ throw "Error";
+ tracer.trace("c");
+ } catch (error) {
+ Expect.equals("Error", error);
+ tracer.trace("d");
+ return;
+ } finally {
+ tracer.trace("e");
+ }
+ tracer.trace("f");
+}
+
+foo4(Tracer tracer) async {
+ try {
+ try {
+ await new Future.value(3);
floitsch 2015/02/17 12:40:58 /// forceAwait: continue ?
sigurdm 2015/02/17 14:19:49 Done.
+ tracer.trace("a");
+ throw "Error";
+ } catch(error) {
+ tracer.trace("b");
+ Expect.equals("Error", error);
+ throw "Error2";
+ }
+ } catch(error) {
+ Expect.equals("Error2", error);
+ tracer.trace("c");
+ }
+ tracer.trace("d");
+
+}
+
+foo5(Tracer tracer) async {
+ try {
+ tracer.trace("a");
+ try {
+ await new Future.value(3); /// forceAwait: continued
+ tracer.trace("b");
+ throw "Error";
+ } catch(error) {
+ tracer.trace("c");
+ Expect.equals("Error", error);
+ throw "Error2";
+ }
+ } finally {
+ tracer.trace("d");
+ }
+ tracer.trace("e");
+
+}
+
+foo6(Tracer tracer) async {
+ try {
+ try {
+ await new Future.value(3); /// forceAwait: continued
+ tracer.trace("a");
+ throw "Error";
+ } catch(error) {
+ tracer.trace("b");
+ Expect.equals("Error", error);
+ throw "Error2";
+ } finally {
+ tracer.trace("c");
+ throw "Error3";
floitsch 2015/02/17 12:40:58 Please add a few tests, where the "finally" does a
sigurdm 2015/02/17 14:19:49 Done.
+ }
+ } catch(error) {
+ tracer.trace("d");
+ Expect.equals("Error3", error);
+ }
+ tracer.trace("e");
+}
+
+foo7(Tracer tracer) async {
+ try {
+ try {
+ await new Future.value(3); /// forceAwait: continued
+ tracer.trace("a");
+ throw "Error";
+ } catch(error) {
+ Expect.equals("Error", error);
+ tracer.trace("b");
+ throw "Error2";
+ } finally {
+ tracer.trace("c");
+ throw "Error3";
+ }
+ } finally {
+ tracer.trace("d");
+ }
+ tracer.trace("e");
+}
+
+foo8(Tracer tracer) async {
+ try {
+ try {
+ await new Future.value(3); /// forceAwait: continued
+ tracer.trace("a");
+ throw "Error";
+ } catch(error) {
+ Expect.equals("Error", error);
+ tracer.trace("b");
+ return;
+ } finally {
+ tracer.trace("c");
+ throw "Error3";
+ }
+ } finally {
+ tracer.trace("d");
+ }
+ tracer.trace("e");
+}
+
+foo9(Tracer tracer) async {
+ try {
+ while(true) {
+ try {
+ await new Future.value(3); /// forceAwait: continued
+ tracer.trace("a");
+ throw "Error";
+ } catch(error) {
+ Expect.equals("Error", error);
+ tracer.trace("b");
+ return;
+ } finally {
+ tracer.trace("c");
+ break;
+ }
+ tracer.trace("d");
+ }
+ } finally {
+ tracer.trace("e");
+ }
+ tracer.trace("f");
+}
+
+foo10(Tracer tracer) async {
floitsch 2015/02/17 12:40:58 does the same as foo9.
sigurdm 2015/02/17 14:19:49 Removed
+ try {
+ while(true) {
+ try {
+ await new Future.value(3); /// forceAwait: continued
+ tracer.trace("a");
+ throw "Error";
+ } catch(error) {
+ Expect.equals("Error", error);
+ tracer.trace("b");
+ return;
+ } finally {
+ tracer.trace("c");
+ break;
+ }
+ tracer.trace("d");
+ }
+ } finally {
+ tracer.trace("e");
+ }
+ tracer.trace("f");
+}
+
+foo11(Tracer tracer) async {
+ try {
+ bool firstTime = true;
+ while(true) {
+ tracer.trace("a");
+ if (firstTime) {
+ try {
+ await new Future.value(3); /// forceAwait: continued
+ tracer.trace("b");
+ throw "Error";
+ } catch(error) {
+ Expect.equals("Error", error);
+ tracer.trace("c");
+ firstTime = false;
+ continue;
+ } finally {
+ tracer.trace("d");
+ }
+ } else {
+ tracer.trace("e");
+ return;
+ }
+ }
+ } finally {
+ tracer.trace("f");
+ }
+ tracer.trace("g");
+}
+
+foo12(Tracer tracer) async {
+ try {
+ bool firstTime = true;
+ while(true) {
+ tracer.trace("a");
+ if (firstTime) {
+ try {
+ await new Future.value(3); /// forceAwait: continued
+ tracer.trace("b");
+ throw "Error";
+ } catch(error) {
+ Expect.equals("Error", error);
+ tracer.trace("c");
+ firstTime = false;
+ continue;
+ } finally {
+ tracer.trace("d");
+ break;
+ }
+ } else {
+ tracer.trace("e");
+ return;
+ }
+ }
+ } finally {
+ tracer.trace("f");
+ }
+ tracer.trace("g");
+}
+
+foo13(Tracer tracer) async {
+ try {
+ try {
+ tracer.trace("a");
+ return;
+ } catch (error) {
+ tracer.trace("b");
+ } finally {
+ tracer.trace("c");
+ try {
+ try {
+ await new Future.value(3); /// forceAwait: continued
+ tracer.trace("d");
+ throw "Error";
+ } finally {
+ tracer.trace("e");
+ }
+ } finally {
+ tracer.trace("f");
+ }
+ }
+ } finally {
+ tracer.trace("g");
+ }
+ tracer.trace("h");
+}
+
+foo14(Tracer tracer) async {
+ try {
+ try {
+ tracer.trace("a");
+ throw "Error";
+ } catch (error) {
+ tracer.trace("b");
+ try {
+ await new Future.value(3); /// forceAwait: continued
+ throw "Error2";
+ } catch(error) {
+ tracer.trace("c");
+ } finally {
+ tracer.trace("d");
+ }
+ tracer.trace("e");
+ throw "Error3";
+ } finally {
+ tracer.trace("f");
+ }
+ } finally {
+ tracer.trace("g");
+ }
+ tracer.trace("h");
+}
+
+test() async {
+ Tracer tracer = new Tracer("abce");
+ try {
floitsch 2015/02/17 12:40:58 You could avoid a lot of the boilerplate: runTest
sigurdm 2015/02/17 14:19:49 Done.
+ await foo1(tracer);
+ } catch (e) {
+ Expect.equals("Error2", e);
floitsch 2015/02/17 12:40:58 You should trace the catching.
sigurdm 2015/02/17 14:19:49 Done.
+ }
+ tracer.done();
+
+ tracer = new Tracer("abde");
+ try {
+ await foo2(tracer);
+ } catch (e) {
+ Expect.equals("Error2", e);
+ }
+ tracer.done();
+
+ tracer = new Tracer("abde");
+ await foo3(tracer);
+ tracer.done();
+
+ tracer = new Tracer("abcd");
+ var x = foo4(tracer);
+ await x;
+ print("foo4 done");
+ tracer.done();
+
+ tracer = new Tracer("abcd");
+ try {
+ await foo5(tracer);
+ } catch (e) {
+ Expect.equals("Error2", e);
+ }
+ tracer.done();
+
+ tracer = new Tracer("abcde");
+ await foo6(tracer);
+ tracer.done();
+
+ tracer = new Tracer("abcd");
+ try {
+ await foo7(tracer);
+ } catch (e) {
+ Expect.equals("Error3", e);
+ }
+ tracer.done();
+
+ tracer = new Tracer("abcd");
+ try {
+ await foo8(tracer);
+ } catch (e) {
+ Expect.equals("Error3", e);
+ }
+ tracer.done();
+
+ tracer = new Tracer("abcef");
+ await foo9(tracer);
+ tracer.done();
+
+ tracer = new Tracer("abcef");
+ await foo10(tracer);
+ tracer.done();
+
+ tracer = new Tracer("abcdaef");
+ await foo11(tracer);
+ tracer.done();
+
+ tracer = new Tracer("abcdfg");
+ await foo12(tracer);
+ tracer.done();
+
+ tracer = new Tracer("acdefg");
+ try {
+ await foo13(tracer);
+ } catch (e) {
+ Expect.equals("Error", e);
+ }
+ tracer.done();
+
+ tracer = new Tracer("abcdefg", "foo14");
+ try {
+ await foo14(tracer);
+ } catch (e) {
+ Expect.equals("Error3", e);
+ }
+ tracer.done();
+}
+
+void main() {
+ asyncTest(test);
+}

Powered by Google App Engine
This is Rietveld 408576698