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

Unified Diff: test/codegen/language/asyncstar_throw_in_catch_test.dart

Issue 1243503007: fixes #221, initial sync*, async, async* implementation (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 5 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 | « test/codegen/language/asyncstar_concat_test.dart ('k') | test/codegen/language/asyncstar_yield_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/codegen/language/asyncstar_throw_in_catch_test.dart
diff --git a/test/codegen/language/asyncstar_throw_in_catch_test.dart b/test/codegen/language/asyncstar_throw_in_catch_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..37eb183abec90c8a28859a0ba1a484bfdd9dd1f9
--- /dev/null
+++ b/test/codegen/language/asyncstar_throw_in_catch_test.dart
@@ -0,0 +1,131 @@
+// 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;
+ String _trace = "";
+ int counter = 0;
+
+ Tracer(this.expected, [this.name]);
+
+ void trace(msg) {
+ if (name != null) {
+ print("Tracing $name: $msg");
+ }
+ _trace += msg;
+ counter++;
+ }
+
+ void done() {
+ Expect.equals(expected, _trace);
+ }
+}
+
+foo1(Tracer tracer) async* {
+ try {
+ tracer.trace("a");
+ await new Future.value(3);
+ tracer.trace("b");
+ throw "Error";
+ } catch (e) {
+ Expect.equals("Error", e);
+ tracer.trace("c");
+ yield 1;
+ tracer.trace("d");
+ yield 2;
+ tracer.trace("e");
+ yield 3;
+ tracer.trace("f");
+ } finally {
+ tracer.trace("f");
+ }
+ tracer.trace("g");
+}
+
+foo2(Tracer tracer) async* {
+ try {
+ tracer.trace("a");
+ throw "Error";
+ } catch (error) {
+ Expect.equals("Error", error);
+ tracer.trace("b");
+ rethrow;
+ } finally {
+ tracer.trace("c");
+ }
+}
+
+foo3(Tracer tracer) async* {
+ try {
+ tracer.trace("a");
+ throw "Error";
+ } catch (error) {
+ Expect.equals("Error", error);
+ tracer.trace("b");
+ rethrow;
+ } finally {
+ tracer.trace("c");
+ yield 1;
+ }
+}
+
+foo4(Tracer tracer) async* {
+ try {
+ tracer.trace("a");
+ await new Future.value(3);
+ tracer.trace("b");
+ throw "Error";
+ } catch (e) {
+ Expect.equals("Error", 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");
+}
+
+runTest(test, expectedTrace, expectedError, shouldCancel) {
+ Tracer tracer = new Tracer(expectedTrace, expectedTrace);
+ Completer done = new Completer();
+ var subscription;
+ subscription = test(tracer).listen((event) async {
+ tracer.trace("Y");
+ if (shouldCancel) {
+ await subscription.cancel();
+ tracer.trace("C");
+ done.complete(null);
+ }
+ }, onError: (error) {
+ Expect.equals(expectedError, error);
+ tracer.trace("X");
+ }, onDone: () {
+ tracer.done();
+ done.complete(null);
+ });
+ return done.future.then((_) => tracer.done());
+}
+
+test() async {
+ // TODO(sigurdm): These tests are too dependent on scheduling, and buffering
+ // behavior.
+ await runTest(foo1, "abcdYefC", null, true);
+ await runTest(foo2, "abcX", "Error", false);
+ await runTest(foo3, "abcYX", "Error", false);
+ await runTest(foo4, "abcdYeYfX", "Error2", false);
+}
+
+
+void main() {
+ asyncTest(test);
+}
« no previous file with comments | « test/codegen/language/asyncstar_concat_test.dart ('k') | test/codegen/language/asyncstar_yield_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698