| Index: tests/language/await_throw_in_catch_test.dart
|
| diff --git a/tests/language/await_throw_in_catch_test.dart b/tests/language/await_throw_in_catch_test.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..e4c167d624147d75b40832df962a4b9b9e408201
|
| --- /dev/null
|
| +++ b/tests/language/await_throw_in_catch_test.dart
|
| @@ -0,0 +1,435 @@
|
| +// 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 {
|
| + try {
|
| + tracer.trace("a");
|
| + // This await forces dart2js to rewrite the try into a state machine
|
| + // instead of relying on the existing structure.
|
| + await new Future.value(3); /// forceAwait: ok
|
| + tracer.trace("b");
|
| + throw "Error";
|
| + } catch (e) {
|
| + tracer.trace("c");
|
| + 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 (e) {
|
| + tracer.trace("d");
|
| + 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";
|
| + } catch (e) {
|
| + tracer.trace("c");
|
| + yield 1;
|
| + tracer.trace("d");
|
| + yield 2;
|
| + tracer.trace("e");
|
| + await new Future.error("Error2");
|
| + } finally {
|
| + tracer.trace("f");
|
| + }
|
| + tracer.trace("g");
|
| +}
|
| +
|
| +foo4(Tracer tracer) async {
|
| + try {
|
| + try {
|
| + await new Future.value(3);
|
| + 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";
|
| + }
|
| + } 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 {
|
| + 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", "foo1");
|
| + try {
|
| + await foo1(tracer);
|
| + } catch (e) {
|
| + Expect.equals("Error2", e);
|
| + }
|
| + tracer.done();
|
| +
|
| + tracer = new Tracer("abde");
|
| + try {
|
| + await foo2(tracer);
|
| + } catch (e) {
|
| + Expect.equals("Error2", e);
|
| + }
|
| + tracer.done();
|
| +
|
| + Completer foo3Done = new Completer();
|
| + tracer = new Tracer("abcdf");
|
| + var subscription;
|
| + subscription = foo3(tracer).listen((event) async {
|
| + await subscription.cancel();
|
| + tracer.done();
|
| + foo3Done.complete(null);
|
| + });
|
| + await foo3Done.future;
|
| +
|
| + 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);
|
| +}
|
|
|