OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import "dart:async"; | 5 import "dart:async"; |
6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
7 import "package:async_helper/async_helper.dart"; | 7 import "package:async_helper/async_helper.dart"; |
8 | 8 |
9 class Tracer { | 9 class Tracer { |
10 final String expected; | 10 final String expected; |
(...skipping 13 matching lines...) Expand all Loading... |
24 void done() { | 24 void done() { |
25 Expect.equals(expected.length, counter, "Received too few traces"); | 25 Expect.equals(expected.length, counter, "Received too few traces"); |
26 } | 26 } |
27 } | 27 } |
28 | 28 |
29 foo1(Tracer tracer) async { | 29 foo1(Tracer tracer) async { |
30 try { | 30 try { |
31 tracer.trace("a"); | 31 tracer.trace("a"); |
32 // This await forces dart2js to rewrite the try into a state machine | 32 // This await forces dart2js to rewrite the try into a state machine |
33 // instead of relying on the existing structure. | 33 // instead of relying on the existing structure. |
34 await new Future.value(3); /// forceAwait: ok | 34 await new Future.value(3); //# forceAwait: ok |
35 tracer.trace("b"); | 35 tracer.trace("b"); |
36 throw "Error"; | 36 throw "Error"; |
37 } catch (error) { | 37 } catch (error) { |
38 tracer.trace("c"); | 38 tracer.trace("c"); |
39 Expect.equals("Error", error); | 39 Expect.equals("Error", error); |
40 throw "Error2"; | 40 throw "Error2"; |
41 tracer.trace("d"); | 41 tracer.trace("d"); |
42 } finally { | 42 } finally { |
43 tracer.trace("e"); | 43 tracer.trace("e"); |
44 } | 44 } |
45 tracer.trace("f"); | 45 tracer.trace("f"); |
46 } | 46 } |
47 | 47 |
48 foo2(Tracer tracer) async { | 48 foo2(Tracer tracer) async { |
49 try { | 49 try { |
50 tracer.trace("a"); | 50 tracer.trace("a"); |
51 await new Future.value(3); /// forceAwait: continued | 51 await new Future.value(3); //# forceAwait: continued |
52 tracer.trace("b"); | 52 tracer.trace("b"); |
53 throw "Error"; | 53 throw "Error"; |
54 tracer.trace("c"); | 54 tracer.trace("c"); |
55 } catch (error) { | 55 } catch (error) { |
56 tracer.trace("d"); | 56 tracer.trace("d"); |
57 Expect.equals("Error", error); | 57 Expect.equals("Error", error); |
58 await new Future.error("Error2"); | 58 await new Future.error("Error2"); |
59 } finally { | 59 } finally { |
60 tracer.trace("e"); | 60 tracer.trace("e"); |
61 } | 61 } |
62 tracer.trace("f"); | 62 tracer.trace("f"); |
63 } | 63 } |
64 | 64 |
65 foo3(Tracer tracer) async { | 65 foo3(Tracer tracer) async { |
66 try { | 66 try { |
67 tracer.trace("a"); | 67 tracer.trace("a"); |
68 await new Future.value(3); /// forceAwait: continued | 68 await new Future.value(3); //# forceAwait: continued |
69 tracer.trace("b"); | 69 tracer.trace("b"); |
70 throw "Error"; | 70 throw "Error"; |
71 tracer.trace("c"); | 71 tracer.trace("c"); |
72 } catch (error) { | 72 } catch (error) { |
73 Expect.equals("Error", error); | 73 Expect.equals("Error", error); |
74 tracer.trace("d"); | 74 tracer.trace("d"); |
75 return; | 75 return; |
76 } finally { | 76 } finally { |
77 tracer.trace("e"); | 77 tracer.trace("e"); |
78 } | 78 } |
79 tracer.trace("f"); | 79 tracer.trace("f"); |
80 } | 80 } |
81 | 81 |
82 foo4(Tracer tracer) async { | 82 foo4(Tracer tracer) async { |
83 try { | 83 try { |
84 try { | 84 try { |
85 await new Future.value(3); /// forceAwait: continued | 85 await new Future.value(3); //# forceAwait: continued |
86 tracer.trace("a"); | 86 tracer.trace("a"); |
87 throw "Error"; | 87 throw "Error"; |
88 } catch(error) { | 88 } catch(error) { |
89 tracer.trace("b"); | 89 tracer.trace("b"); |
90 Expect.equals("Error", error); | 90 Expect.equals("Error", error); |
91 throw "Error2"; | 91 throw "Error2"; |
92 } | 92 } |
93 } catch(error) { | 93 } catch(error) { |
94 Expect.equals("Error2", error); | 94 Expect.equals("Error2", error); |
95 tracer.trace("c"); | 95 tracer.trace("c"); |
96 } | 96 } |
97 tracer.trace("d"); | 97 tracer.trace("d"); |
98 | 98 |
99 } | 99 } |
100 | 100 |
101 foo5(Tracer tracer) async { | 101 foo5(Tracer tracer) async { |
102 try { | 102 try { |
103 tracer.trace("a"); | 103 tracer.trace("a"); |
104 try { | 104 try { |
105 await new Future.value(3); /// forceAwait: continued | 105 await new Future.value(3); //# forceAwait: continued |
106 tracer.trace("b"); | 106 tracer.trace("b"); |
107 throw "Error"; | 107 throw "Error"; |
108 } catch(error) { | 108 } catch(error) { |
109 tracer.trace("c"); | 109 tracer.trace("c"); |
110 Expect.equals("Error", error); | 110 Expect.equals("Error", error); |
111 throw "Error2"; | 111 throw "Error2"; |
112 } | 112 } |
113 } finally { | 113 } finally { |
114 tracer.trace("d"); | 114 tracer.trace("d"); |
115 } | 115 } |
116 tracer.trace("e"); | 116 tracer.trace("e"); |
117 | 117 |
118 } | 118 } |
119 | 119 |
120 foo6(Tracer tracer) async { | 120 foo6(Tracer tracer) async { |
121 try { | 121 try { |
122 try { | 122 try { |
123 await new Future.value(3); /// forceAwait: continued | 123 await new Future.value(3); //# forceAwait: continued |
124 tracer.trace("a"); | 124 tracer.trace("a"); |
125 throw "Error"; | 125 throw "Error"; |
126 } catch(error) { | 126 } catch(error) { |
127 tracer.trace("b"); | 127 tracer.trace("b"); |
128 Expect.equals("Error", error); | 128 Expect.equals("Error", error); |
129 throw "Error2"; | 129 throw "Error2"; |
130 } finally { | 130 } finally { |
131 tracer.trace("c"); | 131 tracer.trace("c"); |
132 throw "Error3"; | 132 throw "Error3"; |
133 } | 133 } |
134 } catch(error) { | 134 } catch(error) { |
135 tracer.trace("d"); | 135 tracer.trace("d"); |
136 Expect.equals("Error3", error); | 136 Expect.equals("Error3", error); |
137 } | 137 } |
138 tracer.trace("e"); | 138 tracer.trace("e"); |
139 } | 139 } |
140 | 140 |
141 foo7(Tracer tracer) async { | 141 foo7(Tracer tracer) async { |
142 try { | 142 try { |
143 try { | 143 try { |
144 await new Future.value(3); /// forceAwait: continued | 144 await new Future.value(3); //# forceAwait: continued |
145 tracer.trace("a"); | 145 tracer.trace("a"); |
146 throw "Error"; | 146 throw "Error"; |
147 } catch(error) { | 147 } catch(error) { |
148 Expect.equals("Error", error); | 148 Expect.equals("Error", error); |
149 tracer.trace("b"); | 149 tracer.trace("b"); |
150 throw "Error2"; | 150 throw "Error2"; |
151 } finally { | 151 } finally { |
152 tracer.trace("c"); | 152 tracer.trace("c"); |
153 throw "Error3"; | 153 throw "Error3"; |
154 } | 154 } |
155 } finally { | 155 } finally { |
156 tracer.trace("d"); | 156 tracer.trace("d"); |
157 } | 157 } |
158 tracer.trace("e"); | 158 tracer.trace("e"); |
159 } | 159 } |
160 | 160 |
161 foo8(Tracer tracer) async { | 161 foo8(Tracer tracer) async { |
162 try { | 162 try { |
163 try { | 163 try { |
164 await new Future.value(3); /// forceAwait: continued | 164 await new Future.value(3); //# forceAwait: continued |
165 tracer.trace("a"); | 165 tracer.trace("a"); |
166 throw "Error"; | 166 throw "Error"; |
167 } catch(error) { | 167 } catch(error) { |
168 Expect.equals("Error", error); | 168 Expect.equals("Error", error); |
169 tracer.trace("b"); | 169 tracer.trace("b"); |
170 return; | 170 return; |
171 } finally { | 171 } finally { |
172 tracer.trace("c"); | 172 tracer.trace("c"); |
173 throw "Error3"; | 173 throw "Error3"; |
174 } | 174 } |
175 } finally { | 175 } finally { |
176 tracer.trace("d"); | 176 tracer.trace("d"); |
177 } | 177 } |
178 tracer.trace("e"); | 178 tracer.trace("e"); |
179 } | 179 } |
180 | 180 |
181 foo9(Tracer tracer) async { | 181 foo9(Tracer tracer) async { |
182 try { | 182 try { |
183 while(true) { | 183 while(true) { |
184 try { | 184 try { |
185 await new Future.value(3); /// forceAwait: continued | 185 await new Future.value(3); //# forceAwait: continued |
186 tracer.trace("a"); | 186 tracer.trace("a"); |
187 throw "Error"; | 187 throw "Error"; |
188 } catch(error) { | 188 } catch(error) { |
189 Expect.equals("Error", error); | 189 Expect.equals("Error", error); |
190 tracer.trace("b"); | 190 tracer.trace("b"); |
191 return; | 191 return; |
192 } finally { | 192 } finally { |
193 tracer.trace("c"); | 193 tracer.trace("c"); |
194 break; | 194 break; |
195 } | 195 } |
196 tracer.trace("d"); | 196 tracer.trace("d"); |
197 } | 197 } |
198 } finally { | 198 } finally { |
199 tracer.trace("e"); | 199 tracer.trace("e"); |
200 } | 200 } |
201 tracer.trace("f"); | 201 tracer.trace("f"); |
202 } | 202 } |
203 | 203 |
204 foo10(Tracer tracer) async { | 204 foo10(Tracer tracer) async { |
205 try { | 205 try { |
206 int i = 0; | 206 int i = 0; |
207 while (true) { | 207 while (true) { |
208 try { | 208 try { |
209 try { | 209 try { |
210 tracer.trace("a"); | 210 tracer.trace("a"); |
211 throw "Error"; | 211 throw "Error"; |
212 } catch (error) { | 212 } catch (error) { |
213 tracer.trace("b"); | 213 tracer.trace("b"); |
214 try { | 214 try { |
215 await new Future.value(3); /// forceAwait: continued | 215 await new Future.value(3); //# forceAwait: continued |
216 throw "Error2"; | 216 throw "Error2"; |
217 } catch(error) { | 217 } catch(error) { |
218 tracer.trace("c"); | 218 tracer.trace("c"); |
219 } finally { | 219 } finally { |
220 tracer.trace("d"); | 220 tracer.trace("d"); |
221 } | 221 } |
222 tracer.trace("e"); | 222 tracer.trace("e"); |
223 throw "Error3"; | 223 throw "Error3"; |
224 } finally { | 224 } finally { |
225 tracer.trace("f"); | 225 tracer.trace("f"); |
(...skipping 12 matching lines...) Expand all Loading... |
238 tracer.trace("i"); | 238 tracer.trace("i"); |
239 } | 239 } |
240 | 240 |
241 foo11(Tracer tracer) async { | 241 foo11(Tracer tracer) async { |
242 try { | 242 try { |
243 bool firstTime = true; | 243 bool firstTime = true; |
244 while(true) { | 244 while(true) { |
245 tracer.trace("a"); | 245 tracer.trace("a"); |
246 if (firstTime) { | 246 if (firstTime) { |
247 try { | 247 try { |
248 await new Future.value(3); /// forceAwait: continued | 248 await new Future.value(3); //# forceAwait: continued |
249 tracer.trace("b"); | 249 tracer.trace("b"); |
250 throw "Error"; | 250 throw "Error"; |
251 } catch(error) { | 251 } catch(error) { |
252 Expect.equals("Error", error); | 252 Expect.equals("Error", error); |
253 tracer.trace("c"); | 253 tracer.trace("c"); |
254 firstTime = false; | 254 firstTime = false; |
255 continue; | 255 continue; |
256 } finally { | 256 } finally { |
257 tracer.trace("d"); | 257 tracer.trace("d"); |
258 } | 258 } |
259 } else { | 259 } else { |
260 tracer.trace("e"); | 260 tracer.trace("e"); |
261 return; | 261 return; |
262 } | 262 } |
263 } | 263 } |
264 } finally { | 264 } finally { |
265 tracer.trace("f"); | 265 tracer.trace("f"); |
266 } | 266 } |
267 tracer.trace("g"); | 267 tracer.trace("g"); |
268 } | 268 } |
269 | 269 |
270 foo12(Tracer tracer) async { | 270 foo12(Tracer tracer) async { |
271 try { | 271 try { |
272 bool firstTime = true; | 272 bool firstTime = true; |
273 while(true) { | 273 while(true) { |
274 tracer.trace("a"); | 274 tracer.trace("a"); |
275 if (firstTime) { | 275 if (firstTime) { |
276 try { | 276 try { |
277 await new Future.value(3); /// forceAwait: continued | 277 await new Future.value(3); //# forceAwait: continued |
278 tracer.trace("b"); | 278 tracer.trace("b"); |
279 throw "Error"; | 279 throw "Error"; |
280 } catch(error) { | 280 } catch(error) { |
281 Expect.equals("Error", error); | 281 Expect.equals("Error", error); |
282 tracer.trace("c"); | 282 tracer.trace("c"); |
283 firstTime = false; | 283 firstTime = false; |
284 continue; | 284 continue; |
285 } finally { | 285 } finally { |
286 tracer.trace("d"); | 286 tracer.trace("d"); |
287 break; | 287 break; |
(...skipping 13 matching lines...) Expand all Loading... |
301 try { | 301 try { |
302 try { | 302 try { |
303 tracer.trace("a"); | 303 tracer.trace("a"); |
304 return; | 304 return; |
305 } catch (error) { | 305 } catch (error) { |
306 tracer.trace("b"); | 306 tracer.trace("b"); |
307 } finally { | 307 } finally { |
308 tracer.trace("c"); | 308 tracer.trace("c"); |
309 try { | 309 try { |
310 try { | 310 try { |
311 await new Future.value(3); /// forceAwait: continued | 311 await new Future.value(3); //# forceAwait: continued |
312 tracer.trace("d"); | 312 tracer.trace("d"); |
313 throw "Error"; | 313 throw "Error"; |
314 } finally { | 314 } finally { |
315 tracer.trace("e"); | 315 tracer.trace("e"); |
316 } | 316 } |
317 } finally { | 317 } finally { |
318 tracer.trace("f"); | 318 tracer.trace("f"); |
319 } | 319 } |
320 } | 320 } |
321 } finally { | 321 } finally { |
322 tracer.trace("g"); | 322 tracer.trace("g"); |
323 } | 323 } |
324 tracer.trace("h"); | 324 tracer.trace("h"); |
325 } | 325 } |
326 | 326 |
327 foo14(Tracer tracer) async { | 327 foo14(Tracer tracer) async { |
328 try { | 328 try { |
329 try { | 329 try { |
330 tracer.trace("a"); | 330 tracer.trace("a"); |
331 throw "Error"; | 331 throw "Error"; |
332 } catch (error) { | 332 } catch (error) { |
333 tracer.trace("b"); | 333 tracer.trace("b"); |
334 try { | 334 try { |
335 await new Future.value(3); /// forceAwait: continued | 335 await new Future.value(3); //# forceAwait: continued |
336 throw "Error2"; | 336 throw "Error2"; |
337 } catch(error) { | 337 } catch(error) { |
338 tracer.trace("c"); | 338 tracer.trace("c"); |
339 } finally { | 339 } finally { |
340 tracer.trace("d"); | 340 tracer.trace("d"); |
341 } | 341 } |
342 tracer.trace("e"); | 342 tracer.trace("e"); |
343 throw "Error3"; | 343 throw "Error3"; |
344 } finally { | 344 } finally { |
345 tracer.trace("f"); | 345 tracer.trace("f"); |
346 } | 346 } |
347 } finally { | 347 } finally { |
348 tracer.trace("g"); | 348 tracer.trace("g"); |
349 } | 349 } |
350 tracer.trace("h"); | 350 tracer.trace("h"); |
351 } | 351 } |
352 | 352 |
353 foo15(Tracer tracer) async { | 353 foo15(Tracer tracer) async { |
354 try { | 354 try { |
355 try { | 355 try { |
356 tracer.trace("a"); | 356 tracer.trace("a"); |
357 throw "Error"; | 357 throw "Error"; |
358 } catch (error) { | 358 } catch (error) { |
359 tracer.trace("b"); | 359 tracer.trace("b"); |
360 try { | 360 try { |
361 await new Future.value(3); /// forceAwait: continued | 361 await new Future.value(3); //# forceAwait: continued |
362 throw "Error2"; | 362 throw "Error2"; |
363 } catch(error) { | 363 } catch(error) { |
364 tracer.trace("c"); | 364 tracer.trace("c"); |
365 } finally { | 365 } finally { |
366 tracer.trace("d"); | 366 tracer.trace("d"); |
367 } | 367 } |
368 tracer.trace("e"); | 368 tracer.trace("e"); |
369 throw "Error3"; | 369 throw "Error3"; |
370 } finally { | 370 } finally { |
371 tracer.trace("f"); | 371 tracer.trace("f"); |
372 return; | 372 return; |
373 } | 373 } |
374 } finally { | 374 } finally { |
375 tracer.trace("g"); | 375 tracer.trace("g"); |
376 } | 376 } |
377 tracer.trace("h"); | 377 tracer.trace("h"); |
378 } | 378 } |
379 | 379 |
380 foo16(Tracer tracer) async { | 380 foo16(Tracer tracer) async { |
381 try { | 381 try { |
382 try { | 382 try { |
383 tracer.trace("a"); | 383 tracer.trace("a"); |
384 throw "Error"; | 384 throw "Error"; |
385 } catch (error) { | 385 } catch (error) { |
386 tracer.trace("b"); | 386 tracer.trace("b"); |
387 try { | 387 try { |
388 await new Future.value(3); /// forceAwait: continued | 388 await new Future.value(3); //# forceAwait: continued |
389 throw "Error2"; | 389 throw "Error2"; |
390 } catch(error) { | 390 } catch(error) { |
391 tracer.trace("c"); | 391 tracer.trace("c"); |
392 } finally { | 392 } finally { |
393 tracer.trace("d"); | 393 tracer.trace("d"); |
394 return; | 394 return; |
395 } | 395 } |
396 tracer.trace("e"); | 396 tracer.trace("e"); |
397 throw "Error3"; | 397 throw "Error3"; |
398 } finally { | 398 } finally { |
399 tracer.trace("f"); | 399 tracer.trace("f"); |
400 } | 400 } |
401 } finally { | 401 } finally { |
402 tracer.trace("g"); | 402 tracer.trace("g"); |
403 } | 403 } |
404 tracer.trace("h"); | 404 tracer.trace("h"); |
405 } | 405 } |
406 | 406 |
407 foo17(Tracer tracer) async { | 407 foo17(Tracer tracer) async { |
408 try { | 408 try { |
409 tracer.trace("a"); | 409 tracer.trace("a"); |
410 } finally { | 410 } finally { |
411 try { | 411 try { |
412 tracer.trace("b"); | 412 tracer.trace("b"); |
413 throw "Error"; | 413 throw "Error"; |
414 } catch (error) { | 414 } catch (error) { |
415 await new Future.value(3); /// forceAwait: continued | 415 await new Future.value(3); //# forceAwait: continued |
416 Expect.equals("Error", error); | 416 Expect.equals("Error", error); |
417 tracer.trace("c"); | 417 tracer.trace("c"); |
418 } finally { | 418 } finally { |
419 tracer.trace("d"); | 419 tracer.trace("d"); |
420 } | 420 } |
421 tracer.trace("e"); | 421 tracer.trace("e"); |
422 } | 422 } |
423 tracer.trace("f"); | 423 tracer.trace("f"); |
424 } | 424 } |
425 | 425 |
426 foo18(Tracer tracer) async { | 426 foo18(Tracer tracer) async { |
427 try { | 427 try { |
428 tracer.trace("a"); | 428 tracer.trace("a"); |
429 } finally { | 429 } finally { |
430 try { | 430 try { |
431 tracer.trace("b"); | 431 tracer.trace("b"); |
432 } finally { | 432 } finally { |
433 await new Future.value(3); /// forceAwait: continued | 433 await new Future.value(3); //# forceAwait: continued |
434 tracer.trace("c"); | 434 tracer.trace("c"); |
435 } | 435 } |
436 tracer.trace("d"); | 436 tracer.trace("d"); |
437 } | 437 } |
438 tracer.trace("e"); | 438 tracer.trace("e"); |
439 } | 439 } |
440 | 440 |
441 runTest(expectedTrace, fun, [expectedError]) async { | 441 runTest(expectedTrace, fun, [expectedError]) async { |
442 Tracer tracer = new Tracer(expectedTrace, expectedTrace); | 442 Tracer tracer = new Tracer(expectedTrace, expectedTrace); |
443 try { | 443 try { |
(...skipping 23 matching lines...) Expand all Loading... |
467 await runTest("abcdefgX", foo14, "Error3"); | 467 await runTest("abcdefgX", foo14, "Error3"); |
468 await runTest("abcdefg", foo15); | 468 await runTest("abcdefg", foo15); |
469 await runTest("abcdfg", foo16); | 469 await runTest("abcdfg", foo16); |
470 await runTest("abcdef", foo17); | 470 await runTest("abcdef", foo17); |
471 await runTest("abcde", foo18); | 471 await runTest("abcde", foo18); |
472 } | 472 } |
473 | 473 |
474 void main() { | 474 void main() { |
475 asyncTest(test); | 475 asyncTest(test); |
476 } | 476 } |
OLD | NEW |