| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 // Process test program to test process communication. | 5 // Process test program to test process communication. |
| 6 // | 6 // |
| 7 // VMOptions= | 7 // VMOptions= |
| 8 // VMOptions=--short_socket_read | 8 // VMOptions=--short_socket_read |
| 9 // VMOptions=--short_socket_write | 9 // VMOptions=--short_socket_write |
| 10 // VMOptions=--short_socket_read --short_socket_write | 10 // VMOptions=--short_socket_read --short_socket_write |
| 11 | 11 |
| 12 #import("dart:io"); | 12 #import("dart:io"); |
| 13 #import("dart:math"); | 13 #import("dart:math"); |
| 14 | 14 |
| 15 #source("process_test_util.dart"); | 15 #source("process_test_util.dart"); |
| 16 | 16 |
| 17 void test(Process process, int expectedExitCode) { | 17 void test(Future<Process> future, int expectedExitCode) { |
| 18 // Wait for the process to start and then interact with it. | 18 future.then((process) { |
| 19 process.onStart = () { | 19 process.onExit = (exitCode) { |
| 20 Expect.equals(expectedExitCode, exitCode); |
| 21 }; |
| 22 |
| 20 List<int> data = "ABCDEFGHI\n".charCodes(); | 23 List<int> data = "ABCDEFGHI\n".charCodes(); |
| 21 final int dataSize = data.length; | 24 final int dataSize = data.length; |
| 22 | 25 |
| 23 InputStream input = process.stdout; | 26 InputStream input = process.stdout; |
| 24 OutputStream output = process.stdin; | 27 OutputStream output = process.stdin; |
| 25 | 28 |
| 26 int received = 0; | 29 int received = 0; |
| 27 List<int> buffer = []; | 30 List<int> buffer = []; |
| 28 | 31 |
| 29 void readData() { | 32 void readData() { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 43 process.close(); | 46 process.close(); |
| 44 } else if (received === dataSize) { | 47 } else if (received === dataSize) { |
| 45 process.close(); | 48 process.close(); |
| 46 } | 49 } |
| 47 } | 50 } |
| 48 } | 51 } |
| 49 | 52 |
| 50 output.write(data); | 53 output.write(data); |
| 51 output.close(); | 54 output.close(); |
| 52 input.onData = readData; | 55 input.onData = readData; |
| 53 }; | 56 }); |
| 54 | |
| 55 process.onExit = (exitCode) { | |
| 56 Expect.equals(expectedExitCode, exitCode); | |
| 57 }; | |
| 58 } | 57 } |
| 59 | 58 |
| 60 main() { | 59 main() { |
| 61 // Run the test using the process_test binary. | 60 // Run the test using the process_test binary. |
| 62 test(Process.start(getProcessTestFileName(), | 61 test(Process.start(getProcessTestFileName(), |
| 63 const ["0", "1", "99", "0"]), 99); | 62 const ["0", "1", "99", "0"]), 99); |
| 64 | 63 |
| 65 // Run the test using the dart binary with an echo script. | 64 // Run the test using the dart binary with an echo script. |
| 66 // The test runner can be run from either the root or from runtime. | 65 // The test runner can be run from either the root or from runtime. |
| 67 var scriptFile = new File("tests/standalone/io/process_std_io_script.dart"); | 66 var scriptFile = new File("tests/standalone/io/process_std_io_script.dart"); |
| 68 if (!scriptFile.existsSync()) { | 67 if (!scriptFile.existsSync()) { |
| 69 scriptFile = new File("../tests/standalone/io/process_std_io_script.dart"); | 68 scriptFile = new File("../tests/standalone/io/process_std_io_script.dart"); |
| 70 } | 69 } |
| 71 Expect.isTrue(scriptFile.existsSync()); | 70 Expect.isTrue(scriptFile.existsSync()); |
| 72 test(Process.start(new Options().executable, [scriptFile.name, "0"]), 0); | 71 test(Process.start(new Options().executable, [scriptFile.name, "0"]), 0); |
| 73 } | 72 } |
| OLD | NEW |