test: make the rest of tests path-independent
Permit spaces in paths to a Node.js executable and test scripts. PR-URL: https://github.com/nodejs/node/pull/12972 Fixes: https://github.com/nodejs/node/issues/12773 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
9516aa19c1
commit
945f208081
@ -285,8 +285,8 @@ exports.childShouldThrowAndAbort = function() {
|
|||||||
// continuous testing and developers' machines
|
// continuous testing and developers' machines
|
||||||
testCmd += 'ulimit -c 0 && ';
|
testCmd += 'ulimit -c 0 && ';
|
||||||
}
|
}
|
||||||
testCmd += `${process.argv[0]} --abort-on-uncaught-exception `;
|
testCmd += `"${process.argv[0]}" --abort-on-uncaught-exception `;
|
||||||
testCmd += `${process.argv[1]} child`;
|
testCmd += `"${process.argv[1]}" child`;
|
||||||
const child = child_process.exec(testCmd);
|
const child = child_process.exec(testCmd);
|
||||||
child.on('exit', function onExit(exitCode, signal) {
|
child.on('exit', function onExit(exitCode, signal) {
|
||||||
const errMsg = 'Test should have aborted ' +
|
const errMsg = 'Test should have aborted ' +
|
||||||
|
@ -18,7 +18,8 @@ if (process.argv[2] === 'child') {
|
|||||||
[22, 21, 20, 19, 18, 17, 16, 16, 17, 18, 19, 20, 21, 22].forEach((exponent) => {
|
[22, 21, 20, 19, 18, 17, 16, 16, 17, 18, 19, 20, 21, 22].forEach((exponent) => {
|
||||||
const bigNum = Math.pow(2, exponent);
|
const bigNum = Math.pow(2, exponent);
|
||||||
const longLine = lineSeed.repeat(bigNum);
|
const longLine = lineSeed.repeat(bigNum);
|
||||||
const cmd = `${process.execPath} ${__filename} child ${exponent} ${bigNum}`;
|
const cmd =
|
||||||
|
`"${process.execPath}" "${__filename}" child ${exponent} ${bigNum}`;
|
||||||
const stdout = execSync(cmd).toString().trim();
|
const stdout = execSync(cmd).toString().trim();
|
||||||
|
|
||||||
assert.strictEqual(stdout, longLine, `failed with exponent ${exponent}`);
|
assert.strictEqual(stdout, longLine, `failed with exponent ${exponent}`);
|
||||||
|
@ -27,7 +27,7 @@ ChildProcess.prototype.spawn = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function createChild(options, callback) {
|
function createChild(options, callback) {
|
||||||
const cmd = `${process.execPath} ${__filename} child`;
|
const cmd = `"${process.execPath}" "${__filename}" child`;
|
||||||
|
|
||||||
return cp.exec(cmd, options, common.mustCall(callback));
|
return cp.exec(cmd, options, common.mustCall(callback));
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ if (process.argv[2] === 'child') {
|
|||||||
console.error(stderrData);
|
console.error(stderrData);
|
||||||
} else {
|
} else {
|
||||||
function run(options, callback) {
|
function run(options, callback) {
|
||||||
const cmd = `${process.execPath} ${__filename} child`;
|
const cmd = `"${process.execPath}" "${__filename}" child`;
|
||||||
|
|
||||||
cp.exec(cmd, options, common.mustCall((err, stdout, stderr) => {
|
cp.exec(cmd, options, common.mustCall((err, stdout, stderr) => {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
|
@ -18,7 +18,7 @@ if (process.argv[2] === 'child') {
|
|||||||
throw new Error('mock error');
|
throw new Error('mock error');
|
||||||
};
|
};
|
||||||
|
|
||||||
const cmd = `${process.execPath} ${__filename} child`;
|
const cmd = `"${process.execPath}" "${__filename}" child`;
|
||||||
const options = { maxBuffer: 0 };
|
const options = { maxBuffer: 0 };
|
||||||
const child = cp.exec(cmd, options, common.mustCall((err, stdout, stderr) => {
|
const child = cp.exec(cmd, options, common.mustCall((err, stdout, stderr) => {
|
||||||
// Verify that if ChildProcess#kill() throws, the error is reported.
|
// Verify that if ChildProcess#kill() throws, the error is reported.
|
||||||
|
@ -12,7 +12,7 @@ if (process.argv[2] === 'child') {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const cmd = `${process.execPath} ${__filename} child`;
|
const cmd = `"${process.execPath}" "${__filename}" child`;
|
||||||
|
|
||||||
// Test the case where a timeout is set, and it expires.
|
// Test the case where a timeout is set, and it expires.
|
||||||
cp.exec(cmd, { timeout: 1 }, common.mustCall((err, stdout, stderr) => {
|
cp.exec(cmd, { timeout: 1 }, common.mustCall((err, stdout, stderr) => {
|
||||||
|
@ -220,7 +220,7 @@ child.exec(`${nodejs} --use-strict -p process.execArgv`,
|
|||||||
// Ensure that arguments are successfully passed to a script.
|
// Ensure that arguments are successfully passed to a script.
|
||||||
// The first argument after '--' should be interpreted as a script
|
// The first argument after '--' should be interpreted as a script
|
||||||
// filename.
|
// filename.
|
||||||
const filecmd = `${nodejs} -- ${__filename} ${args}`;
|
const filecmd = `${nodejs} -- "${__filename}" ${args}`;
|
||||||
child.exec(filecmd, common.mustCall(function(err, stdout, stderr) {
|
child.exec(filecmd, common.mustCall(function(err, stdout, stderr) {
|
||||||
assert.strictEqual(stdout, `${args}\n`);
|
assert.strictEqual(stdout, `${args}\n`);
|
||||||
assert.strictEqual(stderr, '');
|
assert.strictEqual(stderr, '');
|
||||||
|
@ -90,13 +90,13 @@ function createTestCmdLine(options) {
|
|||||||
testCmd += 'ulimit -c 0 && ';
|
testCmd += 'ulimit -c 0 && ';
|
||||||
}
|
}
|
||||||
|
|
||||||
testCmd += process.argv[0];
|
testCmd += `"${process.argv[0]}"`;
|
||||||
|
|
||||||
if (options && options.withAbortOnUncaughtException) {
|
if (options && options.withAbortOnUncaughtException) {
|
||||||
testCmd += ' --abort-on-uncaught-exception';
|
testCmd += ' --abort-on-uncaught-exception';
|
||||||
}
|
}
|
||||||
|
|
||||||
testCmd += ` ${process.argv[1]} child`;
|
testCmd += ` "${process.argv[1]}" child`;
|
||||||
|
|
||||||
return testCmd;
|
return testCmd;
|
||||||
}
|
}
|
||||||
|
@ -103,8 +103,8 @@ if (process.argv[2] === 'child') {
|
|||||||
if (options.useTryCatch)
|
if (options.useTryCatch)
|
||||||
useTryCatchOpt = 'useTryCatch';
|
useTryCatchOpt = 'useTryCatch';
|
||||||
|
|
||||||
cmdToExec += `${process.argv[0]} ${cmdLineOption ? cmdLineOption : ''} ${
|
cmdToExec += `"${process.argv[0]}" ${cmdLineOption ? cmdLineOption : ''} "${
|
||||||
process.argv[1]} child ${throwInDomainErrHandlerOpt} ${useTryCatchOpt}`;
|
process.argv[1]}" child ${throwInDomainErrHandlerOpt} ${useTryCatchOpt}`;
|
||||||
|
|
||||||
const child = exec(cmdToExec);
|
const child = exec(cmdToExec);
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ if (process.argv[2] === 'child') {
|
|||||||
process.emitWarning('foo');
|
process.emitWarning('foo');
|
||||||
} else {
|
} else {
|
||||||
function test(env) {
|
function test(env) {
|
||||||
const cmd = `${process.execPath} ${__filename} child`;
|
const cmd = `"${process.execPath}" "${__filename}" child`;
|
||||||
|
|
||||||
cp.exec(cmd, { env }, common.mustCall((err, stdout, stderr) => {
|
cp.exec(cmd, { env }, common.mustCall((err, stdout, stderr) => {
|
||||||
assert.strictEqual(err, null);
|
assert.strictEqual(err, null);
|
||||||
|
@ -42,13 +42,13 @@ const filename = require('path').join(common.tmpDir, 'big');
|
|||||||
let server;
|
let server;
|
||||||
|
|
||||||
function executeRequest(cb) {
|
function executeRequest(cb) {
|
||||||
cp.exec([process.execPath,
|
cp.exec([`"${process.execPath}"`,
|
||||||
__filename,
|
`"${__filename}"`,
|
||||||
'request',
|
'request',
|
||||||
server.address().port,
|
server.address().port,
|
||||||
'|',
|
'|',
|
||||||
process.execPath,
|
`"${process.execPath}"`,
|
||||||
__filename,
|
`"${__filename}"`,
|
||||||
'shasum' ].join(' '),
|
'shasum' ].join(' '),
|
||||||
(err, stdout, stderr) => {
|
(err, stdout, stderr) => {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
|
@ -16,7 +16,7 @@ const nodeBinary = process.argv[0];
|
|||||||
const preloadOption = (preloads) => {
|
const preloadOption = (preloads) => {
|
||||||
let option = '';
|
let option = '';
|
||||||
preloads.forEach(function(preload, index) {
|
preloads.forEach(function(preload, index) {
|
||||||
option += `-r ${preload} `;
|
option += `-r "${preload}" `;
|
||||||
});
|
});
|
||||||
return option;
|
return option;
|
||||||
};
|
};
|
||||||
@ -30,7 +30,7 @@ const fixtureD = fixture('define-global.js');
|
|||||||
const fixtureThrows = fixture('throws_error4.js');
|
const fixtureThrows = fixture('throws_error4.js');
|
||||||
|
|
||||||
// test preloading a single module works
|
// test preloading a single module works
|
||||||
childProcess.exec(`${nodeBinary} ${preloadOption([fixtureA])} ${fixtureB}`,
|
childProcess.exec(`"${nodeBinary}" ${preloadOption([fixtureA])} "${fixtureB}"`,
|
||||||
function(err, stdout, stderr) {
|
function(err, stdout, stderr) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.strictEqual(stdout, 'A\nB\n');
|
assert.strictEqual(stdout, 'A\nB\n');
|
||||||
@ -38,7 +38,7 @@ childProcess.exec(`${nodeBinary} ${preloadOption([fixtureA])} ${fixtureB}`,
|
|||||||
|
|
||||||
// test preloading multiple modules works
|
// test preloading multiple modules works
|
||||||
childProcess.exec(
|
childProcess.exec(
|
||||||
`${nodeBinary} ${preloadOption([fixtureA, fixtureB])} ${fixtureC}`,
|
`"${nodeBinary}" ${preloadOption([fixtureA, fixtureB])} "${fixtureC}"`,
|
||||||
function(err, stdout, stderr) {
|
function(err, stdout, stderr) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.strictEqual(stdout, 'A\nB\nC\n');
|
assert.strictEqual(stdout, 'A\nB\nC\n');
|
||||||
@ -47,7 +47,7 @@ childProcess.exec(
|
|||||||
|
|
||||||
// test that preloading a throwing module aborts
|
// test that preloading a throwing module aborts
|
||||||
childProcess.exec(
|
childProcess.exec(
|
||||||
`${nodeBinary} ${preloadOption([fixtureA, fixtureThrows])} ${fixtureB}`,
|
`"${nodeBinary}" ${preloadOption([fixtureA, fixtureThrows])} "${fixtureB}"`,
|
||||||
function(err, stdout, stderr) {
|
function(err, stdout, stderr) {
|
||||||
if (err) {
|
if (err) {
|
||||||
assert.strictEqual(stdout, 'A\n');
|
assert.strictEqual(stdout, 'A\n');
|
||||||
@ -59,7 +59,7 @@ childProcess.exec(
|
|||||||
|
|
||||||
// test that preload can be used with --eval
|
// test that preload can be used with --eval
|
||||||
childProcess.exec(
|
childProcess.exec(
|
||||||
`${nodeBinary} ${preloadOption([fixtureA])}-e "console.log('hello');"`,
|
`"${nodeBinary}" ${preloadOption([fixtureA])}-e "console.log('hello');"`,
|
||||||
function(err, stdout, stderr) {
|
function(err, stdout, stderr) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.strictEqual(stdout, 'A\nhello\n');
|
assert.strictEqual(stdout, 'A\nhello\n');
|
||||||
@ -105,7 +105,7 @@ replProc.on('close', function(code) {
|
|||||||
// test that preload placement at other points in the cmdline
|
// test that preload placement at other points in the cmdline
|
||||||
// also test that duplicated preload only gets loaded once
|
// also test that duplicated preload only gets loaded once
|
||||||
childProcess.exec(
|
childProcess.exec(
|
||||||
`${nodeBinary} ${preloadOption([fixtureA])}-e "console.log('hello');" ${
|
`"${nodeBinary}" ${preloadOption([fixtureA])}-e "console.log('hello');" ${
|
||||||
preloadOption([fixtureA, fixtureB])}`,
|
preloadOption([fixtureA, fixtureB])}`,
|
||||||
function(err, stdout, stderr) {
|
function(err, stdout, stderr) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
@ -115,7 +115,7 @@ childProcess.exec(
|
|||||||
|
|
||||||
// test that preload works with -i
|
// test that preload works with -i
|
||||||
const interactive = childProcess.exec(
|
const interactive = childProcess.exec(
|
||||||
`${nodeBinary} ${preloadOption([fixtureD])}-i`,
|
`"${nodeBinary}" ${preloadOption([fixtureD])}-i`,
|
||||||
common.mustCall(function(err, stdout, stderr) {
|
common.mustCall(function(err, stdout, stderr) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.strictEqual(stdout, "> 'test'\n> ");
|
assert.strictEqual(stdout, "> 'test'\n> ");
|
||||||
@ -126,8 +126,8 @@ interactive.stdin.write('a\n');
|
|||||||
interactive.stdin.write('process.exit()\n');
|
interactive.stdin.write('process.exit()\n');
|
||||||
|
|
||||||
childProcess.exec(
|
childProcess.exec(
|
||||||
`${nodeBinary} --require ${fixture('cluster-preload.js')} ${
|
`"${nodeBinary}" --require "${fixture('cluster-preload.js')}" "${
|
||||||
fixture('cluster-preload-test.js')}`,
|
fixture('cluster-preload-test.js')}"`,
|
||||||
function(err, stdout, stderr) {
|
function(err, stdout, stderr) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.ok(/worker terminated with code 43/.test(stdout));
|
assert.ok(/worker terminated with code 43/.test(stdout));
|
||||||
@ -137,8 +137,8 @@ childProcess.exec(
|
|||||||
// https://github.com/nodejs/node/issues/1691
|
// https://github.com/nodejs/node/issues/1691
|
||||||
process.chdir(common.fixturesDir);
|
process.chdir(common.fixturesDir);
|
||||||
childProcess.exec(
|
childProcess.exec(
|
||||||
`${nodeBinary} --expose_natives_as=v8natives --require ` +
|
`"${nodeBinary}" --expose_natives_as=v8natives --require ` +
|
||||||
`${fixture('cluster-preload.js')} cluster-preload-test.js`,
|
`"${fixture('cluster-preload.js')}" cluster-preload-test.js`,
|
||||||
function(err, stdout, stderr) {
|
function(err, stdout, stderr) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.ok(/worker terminated with code 43/.test(stdout));
|
assert.ok(/worker terminated with code 43/.test(stdout));
|
||||||
|
@ -239,8 +239,8 @@ if (process.argv[2] === 'child') {
|
|||||||
testCmd += 'ulimit -c 0 && ';
|
testCmd += 'ulimit -c 0 && ';
|
||||||
}
|
}
|
||||||
|
|
||||||
testCmd += `${process.argv[0]} --abort-on-uncaught-exception ` +
|
testCmd += `"${process.argv[0]}" --abort-on-uncaught-exception ` +
|
||||||
`${process.argv[1]} child ${testIndex}`;
|
`"${process.argv[1]}" child ${testIndex}`;
|
||||||
|
|
||||||
const child = child_process.exec(testCmd);
|
const child = child_process.exec(testCmd);
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ assert.throws(
|
|||||||
function() {
|
function() {
|
||||||
require('../fixtures/packages/invalid');
|
require('../fixtures/packages/invalid');
|
||||||
},
|
},
|
||||||
/^SyntaxError: Error parsing \S+: Unexpected token , in JSON at position 1$/
|
/^SyntaxError: Error parsing .+: Unexpected token , in JSON at position 1$/
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.strictEqual(require('../fixtures/packages/index').ok, 'ok',
|
assert.strictEqual(require('../fixtures/packages/index').ok, 'ok',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user