| 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 // Test a dart sub-process handling stdio with different types of | 5 // Test a dart sub-process handling stdio with different types of |
| 6 // redirection. | 6 // redirection. |
| 7 // | 7 // |
| 8 // VMOptions= | 8 // VMOptions= |
| 9 // VMOptions=--short_socket_read | 9 // VMOptions=--short_socket_read |
| 10 // VMOptions=--short_socket_write | 10 // VMOptions=--short_socket_write |
| 11 // VMOptions=--short_socket_read --short_socket_write | 11 // VMOptions=--short_socket_read --short_socket_write |
| 12 | 12 |
| 13 import "dart:io"; | 13 import "dart:io"; |
| 14 import "process_test_util.dart"; | 14 import "process_test_util.dart"; |
| 15 | 15 |
| 16 void checkFileEmpty(String fileName) { | 16 void checkFileEmpty(String fileName) { |
| 17 RandomAccessFile pipeOut = new File(fileName).openSync(); | 17 RandomAccessFile pipeOut = new File(fileName).openSync(); |
| 18 Expect.equals(0, pipeOut.lengthSync()); | 18 Expect.equals(0, pipeOut.lengthSync()); |
| 19 pipeOut.closeSync(); | 19 pipeOut.closeSync(); |
| 20 } | 20 } |
| 21 | 21 |
| 22 | 22 |
| 23 void checkFileContent(String fileName, String content) { | 23 void checkFileContent(String fileName, String content) { |
| 24 RandomAccessFile pipeOut = new File(fileName).openSync(); | 24 RandomAccessFile pipeOut = new File(fileName).openSync(); |
| 25 int length = pipeOut.lengthSync(); | 25 int length = pipeOut.lengthSync(); |
| 26 List data = new List<int>(length); | 26 List data = new List<int>.fixedLength(length); |
| 27 pipeOut.readListSync(data, 0, length); | 27 pipeOut.readListSync(data, 0, length); |
| 28 Expect.equals(content, new String.fromCharCodes(data)); | 28 Expect.equals(content, new String.fromCharCodes(data)); |
| 29 pipeOut.closeSync(); | 29 pipeOut.closeSync(); |
| 30 } | 30 } |
| 31 | 31 |
| 32 | 32 |
| 33 void test(String shellScript, String dartScript, String type) { | 33 void test(String shellScript, String dartScript, String type) { |
| 34 Directory dir = new Directory("").createTempSync(); | 34 Directory dir = new Directory("").createTempSync(); |
| 35 | 35 |
| 36 // The shell script will run the dart executable passed with a | 36 // The shell script will run the dart executable passed with a |
| (...skipping 27 matching lines...) Expand all Loading... |
| 64 "Hello\nHello\nHello\nHello\n"); | 64 "Hello\nHello\nHello\nHello\n"); |
| 65 } | 65 } |
| 66 | 66 |
| 67 // Cleanup test directory. | 67 // Cleanup test directory. |
| 68 dir.deleteSync(recursive: true); | 68 dir.deleteSync(recursive: true); |
| 69 }; | 69 }; |
| 70 // Drain out and err streams so they close. | 70 // Drain out and err streams so they close. |
| 71 process.stdout.onData = process.stdout.read; | 71 process.stdout.onData = process.stdout.read; |
| 72 process.stderr.onData = process.stderr.read; | 72 process.stderr.onData = process.stderr.read; |
| 73 }); | 73 }); |
| 74 future.handleException((ProcessException error) { | 74 future.catchError((error) { |
| 75 dir.deleteSync(recursive: true); | 75 dir.deleteSync(recursive: true); |
| 76 Expect.fail(error.toString()); | 76 Expect.fail(error.error.toString()); |
| 77 }); | 77 }); |
| 78 } | 78 } |
| 79 | 79 |
| 80 // This tests that the Dart standalone VM can handle piping to stdin | 80 // This tests that the Dart standalone VM can handle piping to stdin |
| 81 // and can pipe to stdout. | 81 // and can pipe to stdout. |
| 82 main() { | 82 main() { |
| 83 // Don't try to run shell scripts on Windows. | 83 // Don't try to run shell scripts on Windows. |
| 84 var os = Platform.operatingSystem; | 84 var os = Platform.operatingSystem; |
| 85 if (os == 'windows') return; | 85 if (os == 'windows') return; |
| 86 | 86 |
| 87 // Get the shell script for testing the Standalone Dart VM with | 87 // Get the shell script for testing the Standalone Dart VM with |
| 88 // piping and redirections of stdio. | 88 // piping and redirections of stdio. |
| 89 var shellScript = new File("tests/standalone/io/dart_std_io_pipe_test.sh"); | 89 var shellScript = new File("tests/standalone/io/dart_std_io_pipe_test.sh"); |
| 90 if (!shellScript.existsSync()) { | 90 if (!shellScript.existsSync()) { |
| 91 shellScript = new File("../tests/standalone/io/dart_std_io_pipe_test.sh"); | 91 shellScript = new File("../tests/standalone/io/dart_std_io_pipe_test.sh"); |
| 92 } | 92 } |
| 93 // Get the Dart script file which echoes stdin to stdout or stderr or both. | 93 // Get the Dart script file which echoes stdin to stdout or stderr or both. |
| 94 var scriptFile = new File("tests/standalone/io/process_std_io_script.dart"); | 94 var scriptFile = new File("tests/standalone/io/process_std_io_script.dart"); |
| 95 if (!scriptFile.existsSync()) { | 95 if (!scriptFile.existsSync()) { |
| 96 scriptFile = new File("../tests/standalone/io/process_std_io_script.dart"); | 96 scriptFile = new File("../tests/standalone/io/process_std_io_script.dart"); |
| 97 } | 97 } |
| 98 | 98 |
| 99 // Run the shell script. | 99 // Run the shell script. |
| 100 test(shellScript.name, scriptFile.name, "0"); | 100 test(shellScript.name, scriptFile.name, "0"); |
| 101 test(shellScript.name, scriptFile.name, "1"); | 101 test(shellScript.name, scriptFile.name, "1"); |
| 102 test(shellScript.name, scriptFile.name, "2"); | 102 test(shellScript.name, scriptFile.name, "2"); |
| 103 } | 103 } |
| OLD | NEW |