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

Unified Diff: tests/language/await_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: Added missing files (test and shared library). 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/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..4f0e51a232d0cf37ecc982f37b433dec96ef59e3
--- /dev/null
+++ b/tests/language/await_throw_in_catch_test.dart
@@ -0,0 +1,76 @@
+// 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";
+
+bool finallyRun = false;
+
+foo() async {
+ try {
+ await new Future.value(3);
+ throw "Error";
+ } catch (e) {
+ throw "Error2";
floitsch 2015/02/13 15:30:07 Add boolean to make sure we entered this catch. Or
floitsch 2015/02/13 15:30:07 before this line. Expect.isFalse(finallyRun);
sigurdm 2015/02/17 08:43:10 Done.
sigurdm 2015/02/17 08:43:10 Done.
+ } finally {
+ finallyRun = true;
+ }
+}
+
+bool finallyRun2 = false;
+
+foo2() async {
+ print("start");
+ try {
+ await new Future.value(3);
+ throw "Error";
+ } catch (e) {
+ await new Future.error("Error2");
+ } finally {
+ finallyRun2 = true;
+ }
+}
+
+bool finallyRun3 = false;
+
+foo3() async* {
+ try {
+ await new Future.value(3);
+ throw "Error";
+ } catch (e) {
+ yield 1;
+ yield 2;
+ await new Future.error("Error2");
+ } finally {
+ finallyRun3 = true;
+ }
+}
+
+test() async {
+ print("start");
+ try {
+ await foo();
+ } catch (e) {
+ Expect.equals("Error2", e);
floitsch 2015/02/13 15:30:07 indentation. ditto for the others.
floitsch 2015/02/13 15:30:07 Make sure this 'catch' is executed. ditto for the
sigurdm 2015/02/17 08:43:10 Done.
+ }
+ Expect.isTrue(finallyRun);
+ print("done");
+ try {
+ await foo2();
+ } catch (e) {
+ Expect.equals("Error2", e);
+ }
+ Expect.isTrue(finallyRun2);
+ var subscription;
+ subscription = foo3().listen((event) {
+ subscription.cancel();
+ }, onDone: () {
+ Expect.isTrue(finallyRun3);
+ });
+}
floitsch 2015/02/13 15:30:07 Add a few more tests: try { try { throw;
sigurdm 2015/02/17 08:43:10 Done.
+
+void main() {
+ asyncTest(test);
+}
« sdk/lib/_internal/compiler/js_lib/js_helper.dart ('K') | « sdk/lib/_internal/libraries.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698