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

Side by Side 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: Address review comments 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 unified diff | Download patch | Annotate | Revision Log
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 int counter = 0;
13
14 Tracer(this.expected, [this.name]);
15
16 void trace(msg) {
17 if (name != null) {
18 print("Tracing $name: $msg");
19 }
20 Expect.equals(expected[counter], msg);
21 counter++;
22 }
23
24 void done() {
25 Expect.equals(expected.length, counter, "Received too few traces");
26 }
27 }
28
29 foo1(Tracer tracer) async {
30 try {
31 tracer.trace("a");
32 // This await forces dart2js to rewrite the try into a state machine
33 // instead of relying on the existing structure.
34 await new Future.value(3); /// forceAwait: ok
35 tracer.trace("b");
36 throw "Error";
37 } catch (e) {
38 tracer.trace("c");
39 throw "Error2";
40 tracer.trace("d");
41 } finally {
42 tracer.trace("e");
43 }
44 tracer.trace("f");
45 }
46
47 foo2(Tracer tracer) async {
48 try {
49 tracer.trace("a");
50 await new Future.value(3); /// forceAwait: continued
51 tracer.trace("b");
52 throw "Error";
53 tracer.trace("c");
54 } catch (e) {
55 tracer.trace("d");
56 await new Future.error("Error2");
57 } finally {
58 tracer.trace("e");
59 }
60 tracer.trace("f");
61 }
62
63 foo3(Tracer tracer) async* {
64 try {
65 tracer.trace("a");
66 await new Future.value(3); /// forceAwait: continued
67 tracer.trace("b");
68 throw "Error";
69 } catch (e) {
70 tracer.trace("c");
71 yield 1;
72 tracer.trace("d");
73 yield 2;
74 tracer.trace("e");
75 await new Future.error("Error2");
76 } finally {
77 tracer.trace("f");
78 }
79 tracer.trace("g");
80 }
81
82 foo4(Tracer tracer) async {
83 try {
84 try {
85 await new Future.value(3);
86 tracer.trace("a");
87 throw "Error";
88 } catch(error) {
89 tracer.trace("b");
90 Expect.equals("Error", error);
91 throw "Error2";
92 }
93 } catch(error) {
94 Expect.equals("Error2", error);
95 tracer.trace("c");
96 }
97 tracer.trace("d");
98
99 }
100
101 foo5(Tracer tracer) async {
102 try {
103 tracer.trace("a");
104 try {
105 await new Future.value(3); /// forceAwait: continued
106 tracer.trace("b");
107 throw "Error";
108 } catch(error) {
109 tracer.trace("c");
110 Expect.equals("Error", error);
111 throw "Error2";
112 }
113 } finally {
114 tracer.trace("d");
115 }
116 tracer.trace("e");
117
118 }
119
120 foo6(Tracer tracer) async {
121 try {
122 try {
123 await new Future.value(3); /// forceAwait: continued
124 tracer.trace("a");
125 throw "Error";
126 } catch(error) {
127 tracer.trace("b");
128 Expect.equals("Error", error);
129 throw "Error2";
130 } finally {
131 tracer.trace("c");
132 throw "Error3";
133 }
134 } catch(error) {
135 tracer.trace("d");
136 Expect.equals("Error3", error);
137 }
138 tracer.trace("e");
139 }
140
141 foo7(Tracer tracer) async {
142 try {
143 try {
144 await new Future.value(3); /// forceAwait: continued
145 tracer.trace("a");
146 throw "Error";
147 } catch(error) {
148 Expect.equals("Error", error);
149 tracer.trace("b");
150 throw "Error2";
151 } finally {
152 tracer.trace("c");
153 throw "Error3";
154 }
155 } finally {
156 tracer.trace("d");
157 }
158 tracer.trace("e");
159 }
160
161 foo8(Tracer tracer) async {
162 try {
163 try {
164 await new Future.value(3); /// forceAwait: continued
165 tracer.trace("a");
166 throw "Error";
167 } catch(error) {
168 Expect.equals("Error", error);
169 tracer.trace("b");
170 return;
171 } finally {
172 tracer.trace("c");
173 throw "Error3";
174 }
175 } finally {
176 tracer.trace("d");
177 }
178 tracer.trace("e");
179 }
180
181 foo9(Tracer tracer) async {
182 try {
183 while(true) {
184 try {
185 await new Future.value(3); /// forceAwait: continued
186 tracer.trace("a");
187 throw "Error";
188 } catch(error) {
189 Expect.equals("Error", error);
190 tracer.trace("b");
191 return;
192 } finally {
193 tracer.trace("c");
194 break;
195 }
196 tracer.trace("d");
197 }
198 } finally {
199 tracer.trace("e");
200 }
201 tracer.trace("f");
202 }
203
204 foo10(Tracer tracer) async {
205 try {
206 while(true) {
207 try {
208 await new Future.value(3); /// forceAwait: continued
209 tracer.trace("a");
210 throw "Error";
211 } catch(error) {
212 Expect.equals("Error", error);
213 tracer.trace("b");
214 return;
215 } finally {
216 tracer.trace("c");
217 break;
218 }
219 tracer.trace("d");
220 }
221 } finally {
222 tracer.trace("e");
223 }
224 tracer.trace("f");
225 }
226
227 foo11(Tracer tracer) async {
228 try {
229 bool firstTime = true;
230 while(true) {
231 tracer.trace("a");
232 if (firstTime) {
233 try {
234 await new Future.value(3); /// forceAwait: continued
235 tracer.trace("b");
236 throw "Error";
237 } catch(error) {
238 Expect.equals("Error", error);
239 tracer.trace("c");
240 firstTime = false;
241 continue;
242 } finally {
243 tracer.trace("d");
244 }
245 } else {
246 tracer.trace("e");
247 return;
248 }
249 }
250 } finally {
251 tracer.trace("f");
252 }
253 tracer.trace("g");
254 }
255
256 foo12(Tracer tracer) async {
257 try {
258 bool firstTime = true;
259 while(true) {
260 tracer.trace("a");
261 if (firstTime) {
262 try {
263 await new Future.value(3); /// forceAwait: continued
264 tracer.trace("b");
265 throw "Error";
266 } catch(error) {
267 Expect.equals("Error", error);
268 tracer.trace("c");
269 firstTime = false;
270 continue;
271 } finally {
272 tracer.trace("d");
273 break;
274 }
275 } else {
276 tracer.trace("e");
277 return;
278 }
279 }
280 } finally {
281 tracer.trace("f");
282 }
283 tracer.trace("g");
284 }
285
286 foo13(Tracer tracer) async {
287 try {
288 try {
289 tracer.trace("a");
290 return;
291 } catch (error) {
292 tracer.trace("b");
293 } finally {
294 tracer.trace("c");
295 try {
296 try {
297 await new Future.value(3); /// forceAwait: continued
298 tracer.trace("d");
299 throw "Error";
300 } finally {
301 tracer.trace("e");
302 }
303 } finally {
304 tracer.trace("f");
305 }
306 }
307 } finally {
308 tracer.trace("g");
309 }
310 tracer.trace("h");
311 }
312
313 foo14(Tracer tracer) async {
314 try {
315 try {
316 tracer.trace("a");
317 throw "Error";
318 } catch (error) {
319 tracer.trace("b");
320 try {
321 await new Future.value(3); /// forceAwait: continued
322 throw "Error2";
323 } catch(error) {
324 tracer.trace("c");
325 } finally {
326 tracer.trace("d");
327 }
328 tracer.trace("e");
329 throw "Error3";
330 } finally {
331 tracer.trace("f");
332 }
333 } finally {
334 tracer.trace("g");
335 }
336 tracer.trace("h");
337 }
338
339 test() async {
340 Tracer tracer = new Tracer("abce", "foo1");
341 try {
342 await foo1(tracer);
343 } catch (e) {
344 Expect.equals("Error2", e);
345 }
346 tracer.done();
347
348 tracer = new Tracer("abde");
349 try {
350 await foo2(tracer);
351 } catch (e) {
352 Expect.equals("Error2", e);
353 }
354 tracer.done();
355
356 Completer foo3Done = new Completer();
357 tracer = new Tracer("abcdf");
358 var subscription;
359 subscription = foo3(tracer).listen((event) async {
360 await subscription.cancel();
361 tracer.done();
362 foo3Done.complete(null);
363 });
364 await foo3Done.future;
365
366 tracer = new Tracer("abcd");
367 var x = foo4(tracer);
368 await x;
369 print("foo4 done");
370 tracer.done();
371
372 tracer = new Tracer("abcd");
373 try {
374 await foo5(tracer);
375 } catch (e) {
376 Expect.equals("Error2", e);
377 }
378 tracer.done();
379
380 tracer = new Tracer("abcde");
381 await foo6(tracer);
382 tracer.done();
383
384 tracer = new Tracer("abcd");
385 try {
386 await foo7(tracer);
387 } catch (e) {
388 Expect.equals("Error3", e);
389 }
390 tracer.done();
391
392 tracer = new Tracer("abcd");
393 try {
394 await foo8(tracer);
395 } catch (e) {
396 Expect.equals("Error3", e);
397 }
398 tracer.done();
399
400 tracer = new Tracer("abcef");
401 await foo9(tracer);
402 tracer.done();
403
404 tracer = new Tracer("abcef");
405 await foo10(tracer);
406 tracer.done();
407
408 tracer = new Tracer("abcdaef");
409 await foo11(tracer);
410 tracer.done();
411
412 tracer = new Tracer("abcdfg");
413 await foo12(tracer);
414 tracer.done();
415
416 tracer = new Tracer("acdefg");
417 try {
418 await foo13(tracer);
419 } catch (e) {
420 Expect.equals("Error", e);
421 }
422 tracer.done();
423
424 tracer = new Tracer("abcdefg", "foo14");
425 try {
426 await foo14(tracer);
427 } catch (e) {
428 Expect.equals("Error3", e);
429 }
430 tracer.done();
431 }
432
433 void main() {
434 asyncTest(test);
435 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698