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

Unified Diff: tests/standalone/src/ProcessStdoutTest.dart

Issue 8662006: Fix a number of issues with the process handling (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase Created 9 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: tests/standalone/src/ProcessStdoutTest.dart
diff --git a/tests/standalone/src/ProcessStdoutTest.dart b/tests/standalone/src/ProcessStdoutTest.dart
index 9c0f016cd12819b581a6aa4d8d49b7bff92fd679..5ca33d31d499efbcef7e74f04aa08863a4454f02 100644
--- a/tests/standalone/src/ProcessStdoutTest.dart
+++ b/tests/standalone/src/ProcessStdoutTest.dart
@@ -11,61 +11,52 @@
#source("ProcessTestUtil.dart");
-class ProcessStdoutTest {
+void test(Process process) {
+ List<int> data = "ABCDEFGHI\n".charCodes();
+ final int dataSize = data.length;
- static void testExit() {
- Process process = new Process(getProcessTestFileName(),
- const ["0", "1", "99", "0"]);
- final int BUFFERSIZE = 10;
- final int STARTCHAR = 65;
- List<int> data = new List<int>(BUFFERSIZE);
- for (int i = 0; (i < BUFFERSIZE - 1); i++) {
- data[i] = STARTCHAR + i;
- }
- data[BUFFERSIZE - 1] = 10;
-
- InputStream input = process.stdout;
- OutputStream output = process.stdin;
-
- process.start();
+ InputStream input = process.stdout;
+ OutputStream output = process.stdin;
+ process.start();
- int received = 0;
- List<int> buffer = [];
+ int received = 0;
+ List<int> buffer = [];
- void readData() {
- buffer.addAll(input.read());
- for (int i = received; i < Math.min(data.length, buffer.length) - 1; i++) {
- Expect.equals(data[i], buffer[i]);
- }
- received = buffer.length;
- if (received >= BUFFERSIZE) {
- // We expect an extra character on windows due to carriage return.
- if (13 === buffer[BUFFERSIZE - 1] && BUFFERSIZE + 1 === received) {
- Expect.equals(13, buffer[BUFFERSIZE - 1]);
- Expect.equals(10, buffer[BUFFERSIZE]);
- buffer.removeLast();
- process.close();
- } else if (received === BUFFERSIZE) {
- process.close();
- }
- }
+ void readData() {
+ buffer.addAll(input.read());
+ for (int i = received; i < Math.min(data.length, buffer.length) - 1; i++) {
+ Expect.equals(data[i], buffer[i]);
}
-
- void streamClosed() {
- Expect.equals(BUFFERSIZE, received);
+ received = buffer.length;
+ if (received >= dataSize) {
+ // We expect an extra character on windows due to carriage return.
+ if (13 === buffer[dataSize - 1] && dataSize + 1 === received) {
+ Expect.equals(13, buffer[dataSize - 1]);
+ Expect.equals(10, buffer[dataSize]);
+ buffer.removeLast();
+ process.close();
+ } else if (received === dataSize) {
+ process.close();
+ }
}
-
- output.write(data);
- output.close();
- input.dataHandler = readData;
- input.closeHandler = streamClosed;
}
- static void testMain() {
- testExit();
- }
+ output.write(data);
+ output.close();
+ input.dataHandler = readData;
}
main() {
- ProcessStdoutTest.testMain();
+ // Run the test using the process_test binary.
+ test(new Process(getProcessTestFileName(),
+ const ["0", "1", "99", "0"]));
+
+ // Run the test using the dart binary with an echo script.
+ // The test runner can be run from either the root or from runtime.
+ var scriptFile = new File("tests/standalone/src/ProcessStdIOScript.dart");
+ if (!scriptFile.existsSync()) {
+ scriptFile = new File("../tests/standalone/src/ProcessStdIOScript.dart");
+ }
+ Expect.isTrue(scriptFile.existsSync());
+ test(new Process(getDartFileName(), [scriptFile.name, "0"]));
}

Powered by Google App Engine
This is Rietveld 408576698