OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 import "package:expect/expect.dart"; | |
6 import 'dart:async'; | |
7 import 'dart:isolate'; | |
8 import 'dart:io'; | |
9 | |
10 Stream catchErrors(void body()) { | |
Lasse Reichstein Nielsen
2013/07/05 19:00:07
As Anders pointed out: This function is not used.
floitsch
2013/07/08 10:45:51
Done.
| |
11 StreamController controller; | |
12 | |
13 bool onError(e) { | |
14 controller.add(e); | |
15 return true; | |
16 } | |
17 | |
18 void onDone() { | |
19 controller.close(); | |
20 } | |
21 | |
22 void onListen() { | |
23 runZonedExperimental(body, onError: onError, onDone: onDone); | |
24 } | |
25 | |
26 controller = new StreamController(onListen: onListen); | |
27 return controller.stream; | |
28 } | |
29 | |
30 var timeOutPort; | |
31 | |
32 void startTests() { | |
Lasse Reichstein Nielsen
2013/07/05 19:00:07
Could you move the boilerplate code below main, so
floitsch
2013/07/08 10:45:51
Done.
| |
33 // We keep a ReceivePort open until all tests are done. This way the VM will | |
34 // hang if the callbacks are not invoked and the test will time out. | |
35 timeOutPort = new ReceivePort(); | |
36 } | |
37 | |
38 void finishTests() { | |
39 Expect.listEquals(["SocketException", | |
40 "FileException"], | |
41 events); | |
Lasse Reichstein Nielsen
2013/07/05 19:00:07
Indentation is off by one.
floitsch
2013/07/08 10:45:51
Done.
| |
42 timeOutPort.close(); | |
43 } | |
44 | |
45 void launchNextTest() { | |
46 if (tests.isEmpty) { | |
47 finishTests(); | |
48 return; | |
49 } | |
50 var test = tests.last; | |
Lasse Reichstein Nielsen
2013/07/05 19:00:07
removeLast() ?
floitsch
2013/07/08 10:45:51
Using iterator now.
| |
51 tests.length--; | |
52 test(); | |
53 } | |
54 | |
55 void testSocketException() { | |
56 runZonedExperimental(() { | |
57 Socket.connect("4", 1).then((Socket s) { | |
58 Expect.fail("Socket should not be able to connect"); | |
59 }); | |
60 }, onError: (err) { | |
61 if (err is! SocketException) Expect.fail("Not expected error: $err"); | |
62 events.add("SocketException"); | |
63 launchNextTest(); | |
64 }); | |
65 } | |
66 | |
67 void testFileException() { | |
68 runZonedExperimental(() { | |
69 new File("lol it's not a file\n").openRead().listen(null); | |
70 }, onError: (err) { | |
71 if (err is! FileException) Expect.fail("Not expected error: $err"); | |
72 events.add("FileException"); | |
73 launchNextTest(); | |
74 }); | |
Lasse Reichstein Nielsen
2013/07/05 19:00:07
Could you return a Future that completes when you
floitsch
2013/07/08 10:45:51
Done.
| |
75 } | |
76 | |
77 var events = []; | |
78 // In reverse order: | |
Lasse Reichstein Nielsen
2013/07/05 19:00:07
Consider using a new Queue.from(your list) and use
floitsch
2013/07/08 10:45:51
Changed to iterator and then to futures.
| |
79 var tests = [testFileException, testSocketException]; | |
80 | |
81 | |
82 main() { | |
83 startTests(); | |
84 launchNextTest(); | |
85 } | |
OLD | NEW |