Index: tests/standalone/io/async_catch_errors_test.dart |
diff --git a/tests/standalone/io/async_catch_errors_test.dart b/tests/standalone/io/async_catch_errors_test.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3acdb668b59adde055cc33526f246e892f7c4b5b |
--- /dev/null |
+++ b/tests/standalone/io/async_catch_errors_test.dart |
@@ -0,0 +1,85 @@ |
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+ |
+import "package:expect/expect.dart"; |
+import 'dart:async'; |
+import 'dart:isolate'; |
+import 'dart:io'; |
+ |
+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.
|
+ StreamController controller; |
+ |
+ bool onError(e) { |
+ controller.add(e); |
+ return true; |
+ } |
+ |
+ void onDone() { |
+ controller.close(); |
+ } |
+ |
+ void onListen() { |
+ runZonedExperimental(body, onError: onError, onDone: onDone); |
+ } |
+ |
+ controller = new StreamController(onListen: onListen); |
+ return controller.stream; |
+} |
+ |
+var timeOutPort; |
+ |
+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.
|
+ // We keep a ReceivePort open until all tests are done. This way the VM will |
+ // hang if the callbacks are not invoked and the test will time out. |
+ timeOutPort = new ReceivePort(); |
+} |
+ |
+void finishTests() { |
+ Expect.listEquals(["SocketException", |
+ "FileException"], |
+ events); |
Lasse Reichstein Nielsen
2013/07/05 19:00:07
Indentation is off by one.
floitsch
2013/07/08 10:45:51
Done.
|
+ timeOutPort.close(); |
+} |
+ |
+void launchNextTest() { |
+ if (tests.isEmpty) { |
+ finishTests(); |
+ return; |
+ } |
+ var test = tests.last; |
Lasse Reichstein Nielsen
2013/07/05 19:00:07
removeLast() ?
floitsch
2013/07/08 10:45:51
Using iterator now.
|
+ tests.length--; |
+ test(); |
+} |
+ |
+void testSocketException() { |
+ runZonedExperimental(() { |
+ Socket.connect("4", 1).then((Socket s) { |
+ Expect.fail("Socket should not be able to connect"); |
+ }); |
+ }, onError: (err) { |
+ if (err is! SocketException) Expect.fail("Not expected error: $err"); |
+ events.add("SocketException"); |
+ launchNextTest(); |
+ }); |
+} |
+ |
+void testFileException() { |
+ runZonedExperimental(() { |
+ new File("lol it's not a file\n").openRead().listen(null); |
+ }, onError: (err) { |
+ if (err is! FileException) Expect.fail("Not expected error: $err"); |
+ events.add("FileException"); |
+ launchNextTest(); |
+ }); |
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.
|
+} |
+ |
+var events = []; |
+// 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.
|
+var tests = [testFileException, testSocketException]; |
+ |
+ |
+main() { |
+ startTests(); |
+ launchNextTest(); |
+} |