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

Side by Side Diff: tests/language/async_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: Fixed unit-test 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 {
floitsch 2015/02/17 12:40:58 You could consider removing the "async" in the ///
sigurdm 2015/02/17 14:19:49 I want to check that the async rewrite works prope
30 try {
31 tracer.trace("a");
32 // This await forces dart2js to rewrite the try into a state machine
floitsch 2015/02/17 12:40:58 nit nit. 2 spaces after "await".
sigurdm 2015/02/17 14:19:49 Done.
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 (error) {
38 tracer.trace("c");
39 Expect.equals("Error", error);
40 throw "Error2";
41 tracer.trace("d");
42 } finally {
43 tracer.trace("e");
44 }
45 tracer.trace("f");
46 }
47
48 foo2(Tracer tracer) async {
49 try {
50 tracer.trace("a");
51 await new Future.value(3); /// forceAwait: continued
52 tracer.trace("b");
53 throw "Error";
54 tracer.trace("c");
55 } catch (error) {
56 tracer.trace("d");
57 Expect.equals("Error", error);
58 await new Future.error("Error2");
59 } finally {
60 tracer.trace("e");
61 }
62 tracer.trace("f");
63 }
64
65 foo3(Tracer tracer) async {
66 try {
67 tracer.trace("a");
68 await new Future.value(3); /// forceAwait: continued
69 tracer.trace("b");
70 throw "Error";
71 tracer.trace("c");
72 } catch (error) {
73 Expect.equals("Error", error);
74 tracer.trace("d");
75 return;
76 } finally {
77 tracer.trace("e");
78 }
79 tracer.trace("f");
80 }
81
82 foo4(Tracer tracer) async {
83 try {
84 try {
85 await new Future.value(3);
floitsch 2015/02/17 12:40:58 /// forceAwait: continue ?
sigurdm 2015/02/17 14:19:49 Done.
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";
floitsch 2015/02/17 12:40:58 Please add a few tests, where the "finally" does a
sigurdm 2015/02/17 14:19:49 Done.
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 {
floitsch 2015/02/17 12:40:58 does the same as foo9.
sigurdm 2015/02/17 14:19:49 Removed
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");
341 try {
floitsch 2015/02/17 12:40:58 You could avoid a lot of the boilerplate: runTest
sigurdm 2015/02/17 14:19:49 Done.
342 await foo1(tracer);
343 } catch (e) {
344 Expect.equals("Error2", e);
floitsch 2015/02/17 12:40:58 You should trace the catching.
sigurdm 2015/02/17 14:19:49 Done.
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 tracer = new Tracer("abde");
357 await foo3(tracer);
358 tracer.done();
359
360 tracer = new Tracer("abcd");
361 var x = foo4(tracer);
362 await x;
363 print("foo4 done");
364 tracer.done();
365
366 tracer = new Tracer("abcd");
367 try {
368 await foo5(tracer);
369 } catch (e) {
370 Expect.equals("Error2", e);
371 }
372 tracer.done();
373
374 tracer = new Tracer("abcde");
375 await foo6(tracer);
376 tracer.done();
377
378 tracer = new Tracer("abcd");
379 try {
380 await foo7(tracer);
381 } catch (e) {
382 Expect.equals("Error3", e);
383 }
384 tracer.done();
385
386 tracer = new Tracer("abcd");
387 try {
388 await foo8(tracer);
389 } catch (e) {
390 Expect.equals("Error3", e);
391 }
392 tracer.done();
393
394 tracer = new Tracer("abcef");
395 await foo9(tracer);
396 tracer.done();
397
398 tracer = new Tracer("abcef");
399 await foo10(tracer);
400 tracer.done();
401
402 tracer = new Tracer("abcdaef");
403 await foo11(tracer);
404 tracer.done();
405
406 tracer = new Tracer("abcdfg");
407 await foo12(tracer);
408 tracer.done();
409
410 tracer = new Tracer("acdefg");
411 try {
412 await foo13(tracer);
413 } catch (e) {
414 Expect.equals("Error", e);
415 }
416 tracer.done();
417
418 tracer = new Tracer("abcdefg", "foo14");
419 try {
420 await foo14(tracer);
421 } catch (e) {
422 Expect.equals("Error3", e);
423 }
424 tracer.done();
425 }
426
427 void main() {
428 asyncTest(test);
429 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698