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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 import "dart:async";
6 import "package:expect/expect.dart";
7 import "package:async_helper/async_helper.dart";
8
9 class Tracer {
10 final String expected;
11 final String name;
12 String _trace = "";
13 int counter = 0;
14
15 Tracer(this.expected, [this.name]);
16
17 void trace(msg) {
18 if (name != null) {
19 print("Tracing $name: $msg");
20 }
21 _trace += msg;
22 counter++;
23 }
24
25 void done() {
26 Expect.equals(expected, _trace);
27 }
28 }
29
30 foo1(Tracer tracer) async* {
31 try {
32 tracer.trace("a");
33 await new Future.value(3);
34 tracer.trace("b");
35 throw "Error";
36 } catch (e) {
37 Expect.equals("Error", e);
38 tracer.trace("c");
39 yield 1;
40 tracer.trace("d");
41 yield 2;
42 tracer.trace("e");
43 yield 3;
44 tracer.trace("f");
45 } finally {
46 tracer.trace("f");
47 }
48 tracer.trace("g");
49 }
50
51 foo2(Tracer tracer) async* {
52 try {
53 tracer.trace("a");
54 throw "Error";
55 } catch (error) {
56 Expect.equals("Error", error);
57 tracer.trace("b");
58 rethrow;
59 } finally {
60 tracer.trace("c");
61 }
62 }
63
64 foo3(Tracer tracer) async* {
65 try {
66 tracer.trace("a");
67 throw "Error";
68 } catch (error) {
69 Expect.equals("Error", error);
70 tracer.trace("b");
71 rethrow;
72 } finally {
73 tracer.trace("c");
74 yield 1;
75 }
76 }
77
78 foo4(Tracer tracer) async* {
79 try {
80 tracer.trace("a");
81 await new Future.value(3);
82 tracer.trace("b");
83 throw "Error";
84 } catch (e) {
85 Expect.equals("Error", e);
86 tracer.trace("c");
87 yield 1;
88 tracer.trace("d");
89 yield 2;
90 tracer.trace("e");
91 await new Future.error("Error2");
92 } finally {
93 tracer.trace("f");
94 }
95 tracer.trace("g");
96 }
97
98 runTest(test, expectedTrace, expectedError, shouldCancel) {
99 Tracer tracer = new Tracer(expectedTrace, expectedTrace);
100 Completer done = new Completer();
101 var subscription;
102 subscription = test(tracer).listen((event) async {
103 tracer.trace("Y");
104 if (shouldCancel) {
105 await subscription.cancel();
106 tracer.trace("C");
107 done.complete(null);
108 }
109 }, onError: (error) {
110 Expect.equals(expectedError, error);
111 tracer.trace("X");
112 }, onDone: () {
113 tracer.done();
114 done.complete(null);
115 });
116 return done.future.then((_) => tracer.done());
117 }
118
119 test() async {
120 // TODO(sigurdm): These tests are too dependent on scheduling, and buffering
121 // behavior.
122 await runTest(foo1, "abcdYefC", null, true);
123 await runTest(foo2, "abcX", "Error", false);
124 await runTest(foo3, "abcYX", "Error", false);
125 await runTest(foo4, "abcdYeYfX", "Error2", false);
126 }
127
128
129 void main() {
130 asyncTest(test);
131 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698