mirror of
https://github.com/ariya/phantomjs.git
synced 2025-01-05 21:13:43 +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:
parent
ebc51f5969
commit
3d9a327df3
4
test/lib/fixtures/cat.py
Normal file
4
test/lib/fixtures/cat.py
Normal 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())
|
4
test/lib/fixtures/echo.py
Normal file
4
test/lib/fixtures/echo.py
Normal 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:]))
|
36
test/module/child_process/basics.js
Normal file
36
test/module/child_process/basics.js
Normal 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");
|
Loading…
Reference in New Issue
Block a user