OLD | NEW |
(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 (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); /// forceAwait: continued |
| 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 int i = 0; |
| 207 while (true) { |
| 208 try { |
| 209 try { |
| 210 tracer.trace("a"); |
| 211 throw "Error"; |
| 212 } catch (error) { |
| 213 tracer.trace("b"); |
| 214 try { |
| 215 await new Future.value(3); /// forceAwait: continued |
| 216 throw "Error2"; |
| 217 } catch(error) { |
| 218 tracer.trace("c"); |
| 219 } finally { |
| 220 tracer.trace("d"); |
| 221 } |
| 222 tracer.trace("e"); |
| 223 throw "Error3"; |
| 224 } finally { |
| 225 tracer.trace("f"); |
| 226 // Continue and breaks 'eats' Error3. |
| 227 if (i == 0) continue; |
| 228 if (i == 1) break; |
| 229 } |
| 230 } finally { |
| 231 tracer.trace("g"); |
| 232 i++; |
| 233 } |
| 234 } |
| 235 } finally { |
| 236 tracer.trace("h"); |
| 237 } |
| 238 tracer.trace("i"); |
| 239 } |
| 240 |
| 241 foo11(Tracer tracer) async { |
| 242 try { |
| 243 bool firstTime = true; |
| 244 while(true) { |
| 245 tracer.trace("a"); |
| 246 if (firstTime) { |
| 247 try { |
| 248 await new Future.value(3); /// forceAwait: continued |
| 249 tracer.trace("b"); |
| 250 throw "Error"; |
| 251 } catch(error) { |
| 252 Expect.equals("Error", error); |
| 253 tracer.trace("c"); |
| 254 firstTime = false; |
| 255 continue; |
| 256 } finally { |
| 257 tracer.trace("d"); |
| 258 } |
| 259 } else { |
| 260 tracer.trace("e"); |
| 261 return; |
| 262 } |
| 263 } |
| 264 } finally { |
| 265 tracer.trace("f"); |
| 266 } |
| 267 tracer.trace("g"); |
| 268 } |
| 269 |
| 270 foo12(Tracer tracer) async { |
| 271 try { |
| 272 bool firstTime = true; |
| 273 while(true) { |
| 274 tracer.trace("a"); |
| 275 if (firstTime) { |
| 276 try { |
| 277 await new Future.value(3); /// forceAwait: continued |
| 278 tracer.trace("b"); |
| 279 throw "Error"; |
| 280 } catch(error) { |
| 281 Expect.equals("Error", error); |
| 282 tracer.trace("c"); |
| 283 firstTime = false; |
| 284 continue; |
| 285 } finally { |
| 286 tracer.trace("d"); |
| 287 break; |
| 288 } |
| 289 } else { |
| 290 tracer.trace("e"); |
| 291 return; |
| 292 } |
| 293 } |
| 294 } finally { |
| 295 tracer.trace("f"); |
| 296 } |
| 297 tracer.trace("g"); |
| 298 } |
| 299 |
| 300 foo13(Tracer tracer) async { |
| 301 try { |
| 302 try { |
| 303 tracer.trace("a"); |
| 304 return; |
| 305 } catch (error) { |
| 306 tracer.trace("b"); |
| 307 } finally { |
| 308 tracer.trace("c"); |
| 309 try { |
| 310 try { |
| 311 await new Future.value(3); /// forceAwait: continued |
| 312 tracer.trace("d"); |
| 313 throw "Error"; |
| 314 } finally { |
| 315 tracer.trace("e"); |
| 316 } |
| 317 } finally { |
| 318 tracer.trace("f"); |
| 319 } |
| 320 } |
| 321 } finally { |
| 322 tracer.trace("g"); |
| 323 } |
| 324 tracer.trace("h"); |
| 325 } |
| 326 |
| 327 foo14(Tracer tracer) async { |
| 328 try { |
| 329 try { |
| 330 tracer.trace("a"); |
| 331 throw "Error"; |
| 332 } catch (error) { |
| 333 tracer.trace("b"); |
| 334 try { |
| 335 await new Future.value(3); /// forceAwait: continued |
| 336 throw "Error2"; |
| 337 } catch(error) { |
| 338 tracer.trace("c"); |
| 339 } finally { |
| 340 tracer.trace("d"); |
| 341 } |
| 342 tracer.trace("e"); |
| 343 throw "Error3"; |
| 344 } finally { |
| 345 tracer.trace("f"); |
| 346 } |
| 347 } finally { |
| 348 tracer.trace("g"); |
| 349 } |
| 350 tracer.trace("h"); |
| 351 } |
| 352 |
| 353 foo15(Tracer tracer) async { |
| 354 try { |
| 355 try { |
| 356 tracer.trace("a"); |
| 357 throw "Error"; |
| 358 } catch (error) { |
| 359 tracer.trace("b"); |
| 360 try { |
| 361 await new Future.value(3); /// forceAwait: continued |
| 362 throw "Error2"; |
| 363 } catch(error) { |
| 364 tracer.trace("c"); |
| 365 } finally { |
| 366 tracer.trace("d"); |
| 367 } |
| 368 tracer.trace("e"); |
| 369 throw "Error3"; |
| 370 } finally { |
| 371 tracer.trace("f"); |
| 372 return; |
| 373 } |
| 374 } finally { |
| 375 tracer.trace("g"); |
| 376 } |
| 377 tracer.trace("h"); |
| 378 } |
| 379 |
| 380 foo16(Tracer tracer) async { |
| 381 try { |
| 382 try { |
| 383 tracer.trace("a"); |
| 384 throw "Error"; |
| 385 } catch (error) { |
| 386 tracer.trace("b"); |
| 387 try { |
| 388 await new Future.value(3); /// forceAwait: continued |
| 389 throw "Error2"; |
| 390 } catch(error) { |
| 391 tracer.trace("c"); |
| 392 } finally { |
| 393 tracer.trace("d"); |
| 394 return; |
| 395 } |
| 396 tracer.trace("e"); |
| 397 throw "Error3"; |
| 398 } finally { |
| 399 tracer.trace("f"); |
| 400 } |
| 401 } finally { |
| 402 tracer.trace("g"); |
| 403 } |
| 404 tracer.trace("h"); |
| 405 } |
| 406 |
| 407 foo17(Tracer tracer) async { |
| 408 try { |
| 409 tracer.trace("a"); |
| 410 } finally { |
| 411 try { |
| 412 tracer.trace("b"); |
| 413 throw "Error"; |
| 414 } catch (error) { |
| 415 await new Future.value(3); /// forceAwait: continued |
| 416 Expect.equals("Error", error); |
| 417 tracer.trace("c"); |
| 418 } finally { |
| 419 tracer.trace("d"); |
| 420 } |
| 421 tracer.trace("e"); |
| 422 } |
| 423 tracer.trace("f"); |
| 424 } |
| 425 |
| 426 foo18(Tracer tracer) async { |
| 427 try { |
| 428 tracer.trace("a"); |
| 429 } finally { |
| 430 try { |
| 431 tracer.trace("b"); |
| 432 } finally { |
| 433 await new Future.value(3); /// forceAwait: continued |
| 434 tracer.trace("c"); |
| 435 } |
| 436 tracer.trace("d"); |
| 437 } |
| 438 tracer.trace("e"); |
| 439 } |
| 440 |
| 441 runTest(expectedTrace, fun, [expectedError]) async { |
| 442 Tracer tracer = new Tracer(expectedTrace, expectedTrace); |
| 443 try { |
| 444 await fun(tracer); |
| 445 } catch (error) { |
| 446 Expect.equals(expectedError, error); |
| 447 tracer.trace("X"); |
| 448 } |
| 449 tracer.done(); |
| 450 } |
| 451 |
| 452 test() async { |
| 453 await runTest("abceX", foo1, "Error2"); |
| 454 await runTest("abdeX", foo2, "Error2"); |
| 455 await runTest("abde", foo3); |
| 456 await runTest("abcd", foo4); |
| 457 await runTest("abcdX", foo5, "Error2"); |
| 458 await runTest("abcde", foo6); |
| 459 await runTest("abcdX", foo7, "Error3"); |
| 460 await runTest("abcdX", foo8, "Error3"); |
| 461 await runTest("abcef", foo9); |
| 462 await runTest("abcdefgabcdefghi", foo10); |
| 463 await runTest("abcdaef", foo11); |
| 464 await runTest("abcdfg", foo12); |
| 465 await runTest("acdefgX", foo13, "Error"); |
| 466 await runTest("abcdefgX", foo14, "Error3"); |
| 467 await runTest("abcdefgX", foo14, "Error3"); |
| 468 await runTest("abcdefg", foo15); |
| 469 await runTest("abcdfg", foo16); |
| 470 await runTest("abcdef", foo17); |
| 471 await runTest("abcde", foo18); |
| 472 } |
| 473 |
| 474 void main() { |
| 475 asyncTest(test); |
| 476 } |
OLD | NEW |