Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 // Testing file input stream, VM-only, standalone test. | 4 // Testing file input stream, VM-only, standalone test. |
| 5 | 5 |
| 6 import "dart:convert"; | 6 import "dart:convert"; |
| 7 import "dart:io"; | 7 import "dart:io"; |
| 8 | 8 |
| 9 import "package:async_helper/async_helper.dart"; | |
| 9 import "package:expect/expect.dart"; | 10 import "package:expect/expect.dart"; |
| 10 | 11 |
| 11 main() { | 12 main() async { |
| 13 asyncStart(); | |
| 12 // Reading a script from a named pipe is only supported on Linux and MacOS. | 14 // Reading a script from a named pipe is only supported on Linux and MacOS. |
| 13 if (!Platform.isLinux && !Platform.isMacOS) { | 15 if (!Platform.isLinux && !Platform.isMacOS) { |
| 16 print("This test is only supported on Linux and MacOS."); | |
| 14 return; | 17 return; |
| 15 } | 18 } |
| 16 | 19 |
| 17 final String script = 'int main() {print("Hello, World!");}'; | 20 final String script = 'main() { print("Hello, World!"); }'; |
| 18 final String stdinPipePath = '/dev/fd/0'; | 21 final String stdinPipePath = '/dev/fd/0'; |
| 22 | |
| 23 // If there's no file system access to the pipe, then we can't do a meaningful | |
| 24 // test. | |
| 25 if (!await (new File(stdinPipePath).exists())) { | |
| 26 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
| |
| 27 return; | |
| 28 } | |
| 29 | |
| 19 StringBuffer output = new StringBuffer(); | 30 StringBuffer output = new StringBuffer(); |
| 20 Process.start(Platform.executable, [stdinPipePath]).then((Process process) { | 31 Process process = |
| 21 process.stdout.transform(UTF8.decoder).listen(output.write); | 32 await Process.start(Platform.executable, ['--checked', stdinPipePath]); |
| 22 process.stderr.transform(UTF8.decoder).listen((data) { | 33 bool stdinWriteFailed = false; |
| 34 process.stdout.transform(UTF8.decoder).listen(output.write); | |
| 35 process.stderr.transform(UTF8.decoder).listen((data) { | |
| 36 if (!stdinWriteFailed) { | |
| 23 Expect.fail(data); | 37 Expect.fail(data); |
| 24 }); | 38 process.kill(); |
| 25 process.stdin.writeln(script); | 39 } |
| 26 process.stdin.close(); | |
| 27 process.exitCode.then((int status) { | |
| 28 Expect.equals(0, status); | |
| 29 Expect.equals("Hello, World!\n", output.toString()); | |
| 30 }); | |
| 31 }); | 40 }); |
| 41 process.stdin.done.catchError((e) { | |
| 42 // If the write to stdin fails, then give up. We can't test the thing we | |
| 43 // wanted to test. | |
| 44 stdinWriteFailed = true; | |
| 45 process.kill(); | |
| 46 }); | |
| 47 process.stdin.writeln(script); | |
| 48 process.stdin.close(); | |
| 49 | |
| 50 int status = await process.exitCode; | |
| 51 if (!stdinWriteFailed) { | |
| 52 Expect.equals(0, status); | |
| 53 Expect.equals("Hello, World!\n", output.toString()); | |
| 54 } | |
| 55 asyncEnd(); | |
| 32 } | 56 } |
| OLD | NEW |