| 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 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 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>(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, bool devNull) { |
| 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 |
| 37 // number of different redirections of stdio. | 37 // number of different redirections of stdio. |
| 38 String pipeOutFile = "${dir.path}/pipe"; | 38 String pipeOutFile = "${dir.path}/pipe"; |
| 39 if (devNull) pipeOutFile = "/dev/null"; |
| 39 String redirectOutFile = "${dir.path}/redirect"; | 40 String redirectOutFile = "${dir.path}/redirect"; |
| 40 String executable = new Options().executable; | 41 String executable = new Options().executable; |
| 41 List args = | 42 List args = |
| 42 [executable, dartScript, type, pipeOutFile, redirectOutFile]; | 43 [executable, dartScript, type, pipeOutFile, redirectOutFile]; |
| 43 var future = Process.start(shellScript, args); | 44 var future = Process.start(shellScript, args); |
| 44 future.then((process) { | 45 future.then((process) { |
| 45 process.exitCode.then((exitCode) { | 46 process.exitCode.then((exitCode) { |
| 46 Expect.equals(0, exitCode); | 47 Expect.equals(0, exitCode); |
| 47 | 48 |
| 48 // Check the expected file contents. | 49 // Check the expected file contents. |
| 49 if (type == "0") { | 50 if (type == "0") { |
| 50 checkFileContent("${pipeOutFile}", "Hello\n"); | 51 if (devNull) { |
| 52 checkFileEmpty("${redirectOutFile}.stdout"); |
| 53 } else { |
| 54 checkFileContent("${pipeOutFile}", "Hello\n"); |
| 55 checkFileContent("${redirectOutFile}.stdout", "Hello\nHello\n"); |
| 56 } |
| 51 checkFileEmpty("${redirectOutFile}.stderr"); | 57 checkFileEmpty("${redirectOutFile}.stderr"); |
| 52 checkFileContent("${redirectOutFile}.stdout", "Hello\nHello\n"); | |
| 53 } | 58 } |
| 54 if (type == "1") { | 59 if (type == "1") { |
| 55 checkFileContent("${pipeOutFile}", "Hello\n"); | 60 if (devNull) { |
| 61 checkFileEmpty("${redirectOutFile}.stderr"); |
| 62 } else { |
| 63 checkFileContent("${pipeOutFile}", "Hello\n"); |
| 64 checkFileContent("${redirectOutFile}.stderr", "Hello\nHello\n"); |
| 65 } |
| 56 checkFileEmpty("${redirectOutFile}.stdout"); | 66 checkFileEmpty("${redirectOutFile}.stdout"); |
| 57 checkFileContent("${redirectOutFile}.stderr", "Hello\nHello\n"); | |
| 58 } | 67 } |
| 59 if (type == "2") { | 68 if (type == "2") { |
| 60 checkFileContent("${pipeOutFile}", "Hello\nHello\n"); | 69 if (devNull) { |
| 61 checkFileContent("${redirectOutFile}.stdout", | 70 checkFileEmpty("${redirectOutFile}.stdout"); |
| 62 "Hello\nHello\nHello\nHello\n"); | 71 checkFileEmpty("${redirectOutFile}.stderr"); |
| 63 checkFileContent("${redirectOutFile}.stderr", | 72 } else { |
| 64 "Hello\nHello\nHello\nHello\n"); | 73 checkFileContent("${pipeOutFile}", "Hello\nHello\n"); |
| 74 checkFileContent("${redirectOutFile}.stdout", |
| 75 "Hello\nHello\nHello\nHello\n"); |
| 76 checkFileContent("${redirectOutFile}.stderr", |
| 77 "Hello\nHello\nHello\nHello\n"); |
| 78 } |
| 65 } | 79 } |
| 66 | 80 |
| 67 // Cleanup test directory. | 81 // Cleanup test directory. |
| 68 dir.deleteSync(recursive: true); | 82 dir.deleteSync(recursive: true); |
| 69 }); | 83 }); |
| 70 // Drain out and err streams so they close. | 84 // Drain out and err streams so they close. |
| 71 process.stdout.listen((_) {}); | 85 process.stdout.listen((_) {}); |
| 72 process.stderr.listen((_) {}); | 86 process.stderr.listen((_) {}); |
| 73 }); | 87 }); |
| 74 future.catchError((error) { | 88 future.catchError((error) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 90 if (!shellScript.existsSync()) { | 104 if (!shellScript.existsSync()) { |
| 91 shellScript = new File("../tests/standalone/io/dart_std_io_pipe_test.sh"); | 105 shellScript = new File("../tests/standalone/io/dart_std_io_pipe_test.sh"); |
| 92 } | 106 } |
| 93 // Get the Dart script file which echoes stdin to stdout or stderr or both. | 107 // 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"); | 108 var scriptFile = new File("tests/standalone/io/process_std_io_script.dart"); |
| 95 if (!scriptFile.existsSync()) { | 109 if (!scriptFile.existsSync()) { |
| 96 scriptFile = new File("../tests/standalone/io/process_std_io_script.dart"); | 110 scriptFile = new File("../tests/standalone/io/process_std_io_script.dart"); |
| 97 } | 111 } |
| 98 | 112 |
| 99 // Run the shell script. | 113 // Run the shell script. |
| 100 test(shellScript.path, scriptFile.path, "0"); | 114 test(shellScript.path, scriptFile.path, "0", false); |
| 101 test(shellScript.path, scriptFile.path, "1"); | 115 test(shellScript.path, scriptFile.path, "0", true); |
| 102 test(shellScript.path, scriptFile.path, "2"); | 116 test(shellScript.path, scriptFile.path, "1", false); |
| 117 test(shellScript.path, scriptFile.path, "1", true); |
| 118 test(shellScript.path, scriptFile.path, "2", false); |
| 119 test(shellScript.path, scriptFile.path, "2", true); |
| 103 } | 120 } |
| OLD | NEW |