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

Side by Side Diff: tests/standalone/src/DartStdIOPipeTest.dart

Issue 9500002: Rename blahHandler to onBlah throughout dart:io. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 9 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
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 #source("ProcessTestUtil.dart"); 14 #source("ProcessTestUtil.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.close(); 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>(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.close(); 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(""); 34 Directory dir = new Directory("");
35 dir.createTempSync(); 35 dir.createTempSync();
36 36
37 // The shell script will run the dart executable passed with a 37 // The shell script will run the dart executable passed with a
38 // number of different redirections of stdio. 38 // number of different redirections of stdio.
39 String pipeOutFile = "${dir.path}/pipe"; 39 String pipeOutFile = "${dir.path}/pipe";
40 String redirectOutFile = "${dir.path}/redirect"; 40 String redirectOutFile = "${dir.path}/redirect";
41 List args = 41 List args =
42 [getDartFileName(), dartScript, type, pipeOutFile, redirectOutFile]; 42 [getDartFileName(), dartScript, type, pipeOutFile, redirectOutFile];
43 Process process = new Process.start(shellScript, args); 43 Process process = new Process.start(shellScript, args);
44 44
45 // Wait for the process to exit and then check result. 45 // Wait for the process to exit and then check result.
46 process.exitHandler = (exitCode) { 46 process.onExit = (exitCode) {
47 Expect.equals(0, exitCode); 47 Expect.equals(0, exitCode);
48 process.close(); 48 process.close();
49 49
50 // Check the expected file contents. 50 // Check the expected file contents.
51 if (type == "0") { 51 if (type == "0") {
52 checkFileContent("${pipeOutFile}", "Hello\n"); 52 checkFileContent("${pipeOutFile}", "Hello\n");
53 checkFileEmpty("${redirectOutFile}.stderr"); 53 checkFileEmpty("${redirectOutFile}.stderr");
54 checkFileContent("${redirectOutFile}.stdout", "Hello\nHello\n"); 54 checkFileContent("${redirectOutFile}.stdout", "Hello\nHello\n");
55 } 55 }
56 if (type == "1") { 56 if (type == "1") {
57 checkFileContent("${pipeOutFile}", "Hello\n"); 57 checkFileContent("${pipeOutFile}", "Hello\n");
58 checkFileEmpty("${redirectOutFile}.stdout"); 58 checkFileEmpty("${redirectOutFile}.stdout");
59 checkFileContent("${redirectOutFile}.stderr", "Hello\nHello\n"); 59 checkFileContent("${redirectOutFile}.stderr", "Hello\nHello\n");
60 } 60 }
61 if (type == "2") { 61 if (type == "2") {
62 checkFileContent("${pipeOutFile}", "Hello\nHello\n"); 62 checkFileContent("${pipeOutFile}", "Hello\nHello\n");
63 checkFileContent("${redirectOutFile}.stdout", 63 checkFileContent("${redirectOutFile}.stdout",
64 "Hello\nHello\nHello\nHello\n"); 64 "Hello\nHello\nHello\nHello\n");
65 checkFileContent("${redirectOutFile}.stderr", 65 checkFileContent("${redirectOutFile}.stderr",
66 "Hello\nHello\nHello\nHello\n"); 66 "Hello\nHello\nHello\nHello\n");
67 } 67 }
68 68
69 // Cleanup test directory. 69 // Cleanup test directory.
70 dir.delete(true); 70 dir.deleteRecursivelySync();
71 }; 71 };
72 72
73 process.errorHandler = (ProcessException error) { 73 process.onError = (ProcessException error) {
74 Expect.fail(error.toString()); 74 Expect.fail(error.toString());
75 }; 75 };
76 } 76 }
77 77
78 // This tests that the Dart standalone VM can handle piping to stdin 78 // This tests that the Dart standalone VM can handle piping to stdin
79 // and can pipe to stdout. 79 // and can pipe to stdout.
80 main() { 80 main() {
81 // Don't try to run shell scripts on Windows. 81 // Don't try to run shell scripts on Windows.
82 var os = new Platform().operatingSystem(); 82 var os = new Platform().operatingSystem();
83 if (os == 'windows') return; 83 if (os == 'windows') return;
84 84
85 // Get the shell script for testing the Standalone Dart VM with 85 // Get the shell script for testing the Standalone Dart VM with
86 // piping and redirections of stdio. 86 // piping and redirections of stdio.
87 var shellScript = new File("tests/standalone/src/DartStdIOPipeTest.sh"); 87 var shellScript = new File("tests/standalone/src/DartStdIOPipeTest.sh");
88 if (!shellScript.existsSync()) { 88 if (!shellScript.existsSync()) {
89 shellScript = new File("../tests/standalone/src/DartStdIOPipeTest.sh"); 89 shellScript = new File("../tests/standalone/src/DartStdIOPipeTest.sh");
90 } 90 }
91 // Get the Dart script file which echoes stdin to stdout or stderr or both. 91 // Get the Dart script file which echoes stdin to stdout or stderr or both.
92 var scriptFile = new File("tests/standalone/src/ProcessStdIOScript.dart"); 92 var scriptFile = new File("tests/standalone/src/ProcessStdIOScript.dart");
93 if (!scriptFile.existsSync()) { 93 if (!scriptFile.existsSync()) {
94 scriptFile = new File("../tests/standalone/src/ProcessStdIOScript.dart"); 94 scriptFile = new File("../tests/standalone/src/ProcessStdIOScript.dart");
95 } 95 }
96 96
97 // Run the shell script. 97 // Run the shell script.
98 test(shellScript.name, scriptFile.name, "0"); 98 test(shellScript.name, scriptFile.name, "0");
99 test(shellScript.name, scriptFile.name, "1"); 99 test(shellScript.name, scriptFile.name, "1");
100 test(shellScript.name, scriptFile.name, "2"); 100 test(shellScript.name, scriptFile.name, "2");
101 } 101 }
OLDNEW
« no previous file with comments | « tests/standalone/src/ChunkedStreamTest.dart ('k') | tests/standalone/src/DirectoryInvalidArgumentsTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698