Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: move test-specific function out of common #3871

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,6 @@ exports.mustCall = function(fn, expected) {
};
};

exports.checkSpawnSyncRet = function(ret) {
assert.strictEqual(ret.status, 0);
assert.strictEqual(ret.error, undefined);
};

var etcServicesFileName = path.join('/etc', 'services');
if (exports.isWindows) {
etcServicesFileName = path.join(process.env.SystemRoot, 'System32', 'drivers',
Expand Down
47 changes: 25 additions & 22 deletions test/parallel/test-child-process-spawnsync-input.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,53 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var os = require('os');
require('../common');

var spawnSync = require('child_process').spawnSync;
const assert = require('assert');

var msgOut = 'this is stdout';
var msgErr = 'this is stderr';
const spawnSync = require('child_process').spawnSync;

const msgOut = 'this is stdout';
const msgErr = 'this is stderr';

// this is actually not os.EOL?
var msgOutBuf = new Buffer(msgOut + '\n');
var msgErrBuf = new Buffer(msgErr + '\n');
const msgOutBuf = new Buffer(msgOut + '\n');
const msgErrBuf = new Buffer(msgErr + '\n');

var args = [
const args = [
'-e',
`console.log("${msgOut}"); console.error("${msgErr}");`
];

var ret;


function checkSpawnSyncRet(ret) {
assert.strictEqual(ret.status, 0);
assert.strictEqual(ret.error, undefined);
};

function verifyBufOutput(ret) {
checkSpawnSyncRet(ret);
assert.deepEqual(ret.stdout, msgOutBuf);
assert.deepEqual(ret.stderr, msgErrBuf);
}

if (process.argv.indexOf('spawnchild') !== -1) {
switch (process.argv[3]) {
case '1':
ret = spawnSync(process.execPath, args, { stdio: 'inherit' });
common.checkSpawnSyncRet(ret);
checkSpawnSyncRet(ret);
break;
case '2':
ret = spawnSync(process.execPath, args, {
stdio: ['inherit', 'inherit', 'inherit']
});
common.checkSpawnSyncRet(ret);
checkSpawnSyncRet(ret);
break;
}
process.exit(0);
return;
}


function verifyBufOutput(ret) {
common.checkSpawnSyncRet(ret);
assert.deepEqual(ret.stdout, msgOutBuf);
assert.deepEqual(ret.stderr, msgErrBuf);
}


verifyBufOutput(spawnSync(process.execPath, [__filename, 'spawnchild', 1]));
verifyBufOutput(spawnSync(process.execPath, [__filename, 'spawnchild', 2]));

Expand All @@ -63,7 +66,7 @@ options = {

ret = spawnSync('cat', [], options);

common.checkSpawnSyncRet(ret);
checkSpawnSyncRet(ret);
assert.strictEqual(ret.stdout.toString('utf8'), options.input);
assert.strictEqual(ret.stderr.toString('utf8'), '');

Expand All @@ -73,15 +76,15 @@ options = {

ret = spawnSync('cat', [], options);

common.checkSpawnSyncRet(ret);
checkSpawnSyncRet(ret);
assert.deepEqual(ret.stdout, options.input);
assert.deepEqual(ret.stderr, new Buffer(''));

verifyBufOutput(spawnSync(process.execPath, args));

ret = spawnSync(process.execPath, args, { encoding: 'utf8' });

common.checkSpawnSyncRet(ret);
checkSpawnSyncRet(ret);
assert.strictEqual(ret.stdout, msgOut + '\n');
assert.strictEqual(ret.stderr, msgErr + '\n');

Expand Down