Chromium Code Reviews| Index: tests/standalone/io/named_pipe_script_test.dart |
| diff --git a/tests/standalone/io/named_pipe_script_test.dart b/tests/standalone/io/named_pipe_script_test.dart |
| index 83df7375b3726db33a26aca744e9f3604e9f87ce..8da51545283a27a260d9049d1c5f7d709adb268d 100644 |
| --- a/tests/standalone/io/named_pipe_script_test.dart |
| +++ b/tests/standalone/io/named_pipe_script_test.dart |
| @@ -6,27 +6,51 @@ |
| import "dart:convert"; |
| import "dart:io"; |
| +import "package:async_helper/async_helper.dart"; |
| import "package:expect/expect.dart"; |
| -main() { |
| +main() async { |
| + asyncStart(); |
| // Reading a script from a named pipe is only supported on Linux and MacOS. |
| if (!Platform.isLinux && !Platform.isMacOS) { |
| + print("This test is only supported on Linux and MacOS."); |
| return; |
| } |
| - final String script = 'int main() {print("Hello, World!");}'; |
| + final String script = 'main() { print("Hello, World!"); }'; |
| final String stdinPipePath = '/dev/fd/0'; |
| + |
| + // If there's no file system access to the pipe, then we can't do a meaningful |
| + // test. |
| + if (!await (new File(stdinPipePath).exists())) { |
| + print("Couldn't find $stdinPipePath."); |
|
Cutch
2017/01/17 23:37:19
A think /dev/fd/0 is part of the UNIX spec. We sho
zra
2017/01/17 23:44:31
Leaving as-is so that we only fail when the behavi
|
| + return; |
| + } |
| + |
| StringBuffer output = new StringBuffer(); |
| - Process.start(Platform.executable, [stdinPipePath]).then((Process process) { |
| - process.stdout.transform(UTF8.decoder).listen(output.write); |
| - process.stderr.transform(UTF8.decoder).listen((data) { |
| + Process process = |
| + await Process.start(Platform.executable, ['--checked', stdinPipePath]); |
| + bool stdinWriteFailed = false; |
| + process.stdout.transform(UTF8.decoder).listen(output.write); |
| + process.stderr.transform(UTF8.decoder).listen((data) { |
| + if (!stdinWriteFailed) { |
| Expect.fail(data); |
| - }); |
| - process.stdin.writeln(script); |
| - process.stdin.close(); |
| - process.exitCode.then((int status) { |
| - Expect.equals(0, status); |
| - Expect.equals("Hello, World!\n", output.toString()); |
| - }); |
| + process.kill(); |
| + } |
| }); |
| + process.stdin.done.catchError((e) { |
| + // If the write to stdin fails, then give up. We can't test the thing we |
| + // wanted to test. |
| + stdinWriteFailed = true; |
| + process.kill(); |
| + }); |
| + process.stdin.writeln(script); |
| + process.stdin.close(); |
| + |
| + int status = await process.exitCode; |
| + if (!stdinWriteFailed) { |
| + Expect.equals(0, status); |
| + Expect.equals("Hello, World!\n", output.toString()); |
| + } |
| + asyncEnd(); |
| } |