Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 import 'dart:async'; | 6 import 'dart:async'; |
| 7 import 'dart:isolate'; | 7 import 'dart:isolate'; |
| 8 | 8 |
| 9 main() { | 9 main() { |
| 10 // We keep a ReceivePort open until all tests are done. This way the VM will | 10 // We keep a ReceivePort open until all tests are done. This way the VM will |
| 11 // hang if the callbacks are not invoked and the test will time out. | 11 // hang if the callbacks are not invoked and the test will time out. |
| 12 var port = new ReceivePort(); | 12 var port = new ReceivePort(); |
| 13 var events = []; | 13 var events = []; |
| 14 // Test nested `catchErrors`. | 14 // Test that the outer `catchErrors` waits for the nested `catchErrors` stream |
| 15 // The nested `catchErrors` throws all kinds of different errors (synchronous | 15 // to be done. |
| 16 // and asynchronous). The body of the outer `catchErrors` furthermore has a | |
| 17 // synchronous `throw`. | |
| 18 catchErrors(() { | 16 catchErrors(() { |
| 19 events.add("catch error entry"); | 17 events.add("catch error entry"); |
| 20 catchErrors(() { | 18 catchErrors(() { |
| 21 events.add("catch error entry2"); | 19 events.add("catch error entry2"); |
| 22 new Future.error("future error"); | 20 new Future.error("future error"); |
| 23 new Future.error("future error2"); | 21 new Future.error("future error2"); |
| 24 new Future.value(499).then((x) => throw x); | 22 new Future.value(499).then((x) => throw x); |
| 25 new Future.delayed(const Duration(milliseconds: 50), () { | 23 new Future.delayed(const Duration(milliseconds: 50), () { |
| 26 throw "delayed error"; | 24 throw "delayed error"; |
| 27 }); | 25 }); |
| 28 throw "catch error"; | 26 throw "catch error"; |
| 29 }).listen((x) { events.add(x); }) | 27 }).listen((x) { events.add("i $x"); }, |
| 30 .asFuture() | 28 onDone: () => events.add("inner done")); |
| 31 .then((_) => events.add("inner done")) | |
| 32 .then((_) { throw "inner done throw"; }); | |
| 33 events.add("after inner"); | 29 events.add("after inner"); |
| 34 throw "inner throw"; | 30 throw "inner throw"; |
| 35 }).listen((x) { | 31 }).listen((x) { |
| 36 events.add(x); | 32 events.add("o $x"); |
| 37 }, | 33 }, |
| 38 onDone: () { | 34 onDone: () { |
| 39 Expect.listEquals(["catch error entry", | 35 Expect.listEquals(["catch error entry", |
| 40 "catch error entry2", | 36 "catch error entry2", |
|
Lasse Reichstein Nielsen
2013/06/13 11:58:47
Space is off-by-one.
floitsch
2013/06/13 13:36:51
Done.
| |
| 41 "after inner", | 37 "after inner", |
| 42 "main exit", | 38 "main exit", |
| 43 "catch error", | 39 "i catch error", |
| 44 "inner throw", | 40 "o inner throw", |
| 45 "future error", | 41 "i future error", |
| 46 "future error2", | 42 "i future error2", |
| 47 499, | 43 "i 499", |
| 48 "delayed error", | 44 "i delayed error", |
| 49 "inner done", | 45 "inner done", |
| 50 "inner done throw" | 46 ], |
| 51 ], | 47 events); |
| 52 events); | |
| 53 port.close(); | 48 port.close(); |
| 54 }); | 49 }); |
| 55 events.add("main exit"); | 50 events.add("main exit"); |
| 56 } | 51 } |
| OLD | NEW |