1
1
mirror of https://github.com/ariya/phantomjs.git synced 2024-09-11 12:55:33 +03:00

Tests for child process stdin

To avoid cross-platform issues, these tests spawn platform- and 2/3-agnostic
Python scripts; Python is already required to run the test suite.
This commit is contained in:
Zack Weinberg 2016-02-03 09:37:48 -05:00
parent ebc51f5969
commit 3d9a327df3
3 changed files with 44 additions and 0 deletions

4
test/lib/fixtures/cat.py Normal file
View File

@ -0,0 +1,4 @@
# Platform-agnostic replacement for 'cat' with no arguments.
# Avoids 'print' to achieve Python 2/3 agnosticism as well.
import sys
sys.stdout.write(sys.stdin.read())

View File

@ -0,0 +1,4 @@
# Platform-agnostic replacement for 'echo -n'.
# Avoids 'print' to achieve Python 2/3 agnosticism as well.
import sys
sys.stdout.write(" ".join(sys.argv[1:]))

View File

@ -0,0 +1,36 @@
// Test basic child process functionality
//
var fs = require('fs');
var process = require('child_process');
var ECHO_SCRIPT = fs.join(TEST_DIR, 'lib', 'fixtures', 'echo.py');
var CAT_SCRIPT = fs.join(TEST_DIR, 'lib', 'fixtures', 'cat.py');
async_test(function(){
var text = "hello";
var p = process.spawn(PYTHON, [ECHO_SCRIPT, text]);
var out = '';
p.stdout.on('data', function(data) { out += data; });
p.on('exit', this.step_func_done(
function(exitCode) {
assert_equals(exitCode, 0);
assert_equals(out, text);
}));
}, "call a simple subprocess");
async_test(function(){
var text = "hello";
var process = require('child_process');
var p = process.spawn(PYTHON, [CAT_SCRIPT]);
var out = '';
p.stdout.on('data', function(data) { out += data; });
p.on('exit', this.step_func_done(
function(exitCode) {
assert_equals(exitCode, 0);
assert_equals(out, text);
}));
p.stdin.write(text);
p.stdin.close();
}, "call a subprocess that reads input");