Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Side by Side Diff: tests/standalone/io/dart_std_io_pipe_test.dart

Issue 11091070: Change Process.start to return a future that completes with a (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 22 matching lines...) Expand all
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
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 String redirectOutFile = "${dir.path}/redirect"; 39 String redirectOutFile = "${dir.path}/redirect";
40 String executable = new Options().executable; 40 String executable = new Options().executable;
41 List args = 41 List args =
42 [executable, dartScript, type, pipeOutFile, redirectOutFile]; 42 [executable, dartScript, type, pipeOutFile, redirectOutFile];
43 Process process = Process.start(shellScript, args); 43 var future = Process.start(shellScript, args);
44 future.then((process) {
45 process.onExit = (exitCode) {
46 Expect.equals(0, exitCode);
47 process.close();
44 48
45 // Wait for the process to exit and then check result. 49 // Check the expected file contents.
46 process.onExit = (exitCode) { 50 if (type == "0") {
47 Expect.equals(0, exitCode); 51 checkFileContent("${pipeOutFile}", "Hello\n");
48 process.close(); 52 checkFileEmpty("${redirectOutFile}.stderr");
53 checkFileContent("${redirectOutFile}.stdout", "Hello\nHello\n");
54 }
55 if (type == "1") {
56 checkFileContent("${pipeOutFile}", "Hello\n");
57 checkFileEmpty("${redirectOutFile}.stdout");
58 checkFileContent("${redirectOutFile}.stderr", "Hello\nHello\n");
59 }
60 if (type == "2") {
61 checkFileContent("${pipeOutFile}", "Hello\nHello\n");
62 checkFileContent("${redirectOutFile}.stdout",
63 "Hello\nHello\nHello\nHello\n");
64 checkFileContent("${redirectOutFile}.stderr",
65 "Hello\nHello\nHello\nHello\n");
66 }
49 67
50 // Check the expected file contents. 68 // Cleanup test directory.
51 if (type == "0") { 69 dir.deleteRecursivelySync();
52 checkFileContent("${pipeOutFile}", "Hello\n"); 70 };
53 checkFileEmpty("${redirectOutFile}.stderr"); 71 });
54 checkFileContent("${redirectOutFile}.stdout", "Hello\nHello\n"); 72 future.handleException((ProcessException error) {
55 }
56 if (type == "1") {
57 checkFileContent("${pipeOutFile}", "Hello\n");
58 checkFileEmpty("${redirectOutFile}.stdout");
59 checkFileContent("${redirectOutFile}.stderr", "Hello\nHello\n");
60 }
61 if (type == "2") {
62 checkFileContent("${pipeOutFile}", "Hello\nHello\n");
63 checkFileContent("${redirectOutFile}.stdout",
64 "Hello\nHello\nHello\nHello\n");
65 checkFileContent("${redirectOutFile}.stderr",
66 "Hello\nHello\nHello\nHello\n");
67 }
68
69 // Cleanup test directory.
70 dir.deleteRecursivelySync();
71 };
72
73 process.onError = (ProcessException error) {
74 Expect.fail(error.toString()); 73 Expect.fail(error.toString());
ricow1 2012/10/11 17:27:34 we should probably do a dir.deleteRecursivelySync(
Mads Ager (google) 2012/10/12 08:44:46 Done for this particular test. I'm pretty sure tha
75 }; 74 });
76 } 75 }
77 76
78 // This tests that the Dart standalone VM can handle piping to stdin 77 // This tests that the Dart standalone VM can handle piping to stdin
79 // and can pipe to stdout. 78 // and can pipe to stdout.
80 main() { 79 main() {
81 // Don't try to run shell scripts on Windows. 80 // Don't try to run shell scripts on Windows.
82 var os = Platform.operatingSystem; 81 var os = Platform.operatingSystem;
83 if (os == 'windows') return; 82 if (os == 'windows') return;
84 83
85 // Get the shell script for testing the Standalone Dart VM with 84 // Get the shell script for testing the Standalone Dart VM with
86 // piping and redirections of stdio. 85 // piping and redirections of stdio.
87 var shellScript = new File("tests/standalone/io/dart_std_io_pipe_test.sh"); 86 var shellScript = new File("tests/standalone/io/dart_std_io_pipe_test.sh");
88 if (!shellScript.existsSync()) { 87 if (!shellScript.existsSync()) {
89 shellScript = new File("../tests/standalone/io/dart_std_io_pipe_test.sh"); 88 shellScript = new File("../tests/standalone/io/dart_std_io_pipe_test.sh");
90 } 89 }
91 // Get the Dart script file which echoes stdin to stdout or stderr or both. 90 // Get the Dart script file which echoes stdin to stdout or stderr or both.
92 var scriptFile = new File("tests/standalone/io/process_std_io_script.dart"); 91 var scriptFile = new File("tests/standalone/io/process_std_io_script.dart");
93 if (!scriptFile.existsSync()) { 92 if (!scriptFile.existsSync()) {
94 scriptFile = new File("../tests/standalone/io/process_std_io_script.dart"); 93 scriptFile = new File("../tests/standalone/io/process_std_io_script.dart");
95 } 94 }
96 95
97 // Run the shell script. 96 // Run the shell script.
98 test(shellScript.name, scriptFile.name, "0"); 97 test(shellScript.name, scriptFile.name, "0");
99 test(shellScript.name, scriptFile.name, "1"); 98 test(shellScript.name, scriptFile.name, "1");
100 test(shellScript.name, scriptFile.name, "2"); 99 test(shellScript.name, scriptFile.name, "2");
101 } 100 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698