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

(v6.x backport) test: make the rest of tests path-independent #13880

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
4 changes: 2 additions & 2 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ exports.childShouldThrowAndAbort = function() {
// continuous testing and developers' machines
testCmd += 'ulimit -c 0 && ';
}
testCmd += `${process.argv[0]} --abort-on-uncaught-exception `;
testCmd += `${process.argv[1]} child`;
testCmd += `"${process.argv[0]}" --abort-on-uncaught-exception `;
testCmd += `"${process.argv[1]}" child`;
const child = child_process.exec(testCmd);
child.on('exit', function onExit(exitCode, signal) {
const errMsg = 'Test should have aborted ' +
Expand Down
3 changes: 2 additions & 1 deletion test/known_issues/test-stdout-buffer-flush-on-exit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
const bigNum = Math.pow(2, exponent);
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();

assert.strictEqual(stdout, longLine, `failed with exponent ${exponent}`);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-child-process-bad-stdio.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ChildProcess.prototype.spawn = function() {
};

function createChild(options, callback) {
const cmd = `${process.execPath} ${__filename} child`;
const cmd = `"${process.execPath}" "${__filename}" child`;

return cp.exec(cmd, options, common.mustCall(callback));
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-child-process-exec-encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if (process.argv[2] === 'child') {
console.error(stderrData);
} else {
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) => {
assert.ifError(err);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-child-process-exec-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if (process.argv[2] === 'child') {
return;
}

const cmd = `${process.execPath} ${__filename} child`;
const cmd = `"${process.execPath}" "${__filename}" child`;

// Test the case where a timeout is set, and it expires.
cp.exec(cmd, { timeout: 1 }, common.mustCall((err, stdout, stderr) => {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-cli-eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ child.exec(`${nodejs} --use-strict -p process.execArgv`,
// Ensure that arguments are successfully passed to a script.
// The first argument after '--' should be interpreted as a script
// filename.
const filecmd = `${nodejs} -- ${__filename} ${args}`;
const filecmd = `${nodejs} -- "${__filename}" ${args}`;
child.exec(filecmd, common.mustCall(function(err, stdout, stderr) {
assert.strictEqual(stdout, args + '\n');
assert.strictEqual(stderr, '');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ function createTestCmdLine(options) {
testCmd += 'ulimit -c 0 && ';
}

testCmd += process.argv[0];
testCmd += `"${process.argv[0]}"`;

if (options && options.withAbortOnUncaughtException) {
testCmd += ' --abort-on-uncaught-exception';
}

testCmd += ` ${process.argv[1]} child`;
testCmd += ` "${process.argv[1]}" child`;

return testCmd;
}
10 changes: 2 additions & 8 deletions test/parallel/test-domain-with-abort-on-uncaught-exception.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,8 @@ if (process.argv[2] === 'child') {
if (options.useTryCatch)
useTryCatchOpt = 'useTryCatch';

cmdToExec += process.argv[0] + ' ';
cmdToExec += (cmdLineOption ? cmdLineOption : '') + ' ';
cmdToExec += process.argv[1] + ' ';
cmdToExec += [
'child',
throwInDomainErrHandlerOpt,
useTryCatchOpt
].join(' ');
cmdToExec += `"${process.argv[0]}" ${cmdLineOption ? cmdLineOption : ''} "${
process.argv[1]}" child ${throwInDomainErrHandlerOpt} ${useTryCatchOpt}`;

const child = exec(cmdToExec);

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-env-var-no-warnings.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if (process.argv[2] === 'child') {
process.emitWarning('foo');
} else {
function test(env) {
const cmd = `${process.execPath} ${__filename} child`;
const cmd = `"${process.execPath}" "${__filename}" child`;

cp.exec(cmd, { env }, common.mustCall((err, stdout, stderr) => {
assert.strictEqual(err, null);
Expand Down
8 changes: 4 additions & 4 deletions test/parallel/test-http-chunk-problem.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ const filename = require('path').join(common.tmpDir, 'big');
let server;

function executeRequest(cb) {
cp.exec([process.execPath,
__filename,
cp.exec([`"${process.execPath}"`,
`"${__filename}"`,
'request',
server.address().port,
'|',
process.execPath,
__filename,
`"${process.execPath}"`,
`"${__filename}"`,
'shasum' ].join(' '),
(err, stdout, stderr) => {
if (err) throw err;
Expand Down
24 changes: 12 additions & 12 deletions test/parallel/test-preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const nodeBinary = process.argv[0];
const preloadOption = (preloads) => {
let option = '';
preloads.forEach(function(preload, index) {
option += '-r ' + preload + ' ';
option += `-r "${preload}" `;
});
return option;
};
Expand All @@ -30,15 +30,15 @@ const fixtureD = fixture('define-global.js');
const fixtureThrows = fixture('throws_error4.js');

// test preloading a single module works
childProcess.exec(nodeBinary + ' ' + preloadOption([fixtureA]) + ' ' + fixtureB,
childProcess.exec(`"${nodeBinary}" ${preloadOption([fixtureA])} "${fixtureB}"`,
function(err, stdout, stderr) {
if (err) throw err;
assert.strictEqual(stdout, 'A\nB\n');
});

// test preloading multiple modules works
childProcess.exec(
nodeBinary + ' ' + preloadOption([fixtureA, fixtureB]) + ' ' + fixtureC,
`"${nodeBinary}" ${preloadOption([fixtureA, fixtureB])} "${fixtureC}"`,
function(err, stdout, stderr) {
if (err) throw err;
assert.strictEqual(stdout, 'A\nB\nC\n');
Expand All @@ -47,7 +47,7 @@ childProcess.exec(

// test that preloading a throwing module aborts
childProcess.exec(
nodeBinary + ' ' + preloadOption([fixtureA, fixtureThrows]) + ' ' + fixtureB,
`"${nodeBinary}" ${preloadOption([fixtureA, fixtureThrows])} "${fixtureB}"`,
function(err, stdout, stderr) {
if (err) {
assert.strictEqual(stdout, 'A\n');
Expand All @@ -59,7 +59,7 @@ childProcess.exec(

// test that preload can be used with --eval
childProcess.exec(
nodeBinary + ' ' + preloadOption([fixtureA]) + '-e "console.log(\'hello\');"',
`"${nodeBinary}" ${preloadOption([fixtureA])}-e "console.log('hello');"`,
function(err, stdout, stderr) {
if (err) throw err;
assert.strictEqual(stdout, 'A\nhello\n');
Expand Down Expand Up @@ -105,8 +105,8 @@ replProc.on('close', function(code) {
// test that preload placement at other points in the cmdline
// also test that duplicated preload only gets loaded once
childProcess.exec(
nodeBinary + ' ' + preloadOption([fixtureA]) +
'-e "console.log(\'hello\');" ' + preloadOption([fixtureA, fixtureB]),
`"${nodeBinary}" ${preloadOption([fixtureA])}-e "console.log('hello');" ${
preloadOption([fixtureA, fixtureB])}`,
function(err, stdout, stderr) {
if (err) throw err;
assert.strictEqual(stdout, 'A\nB\nhello\n');
Expand All @@ -115,7 +115,7 @@ childProcess.exec(

// test that preload works with -i
const interactive = childProcess.exec(
nodeBinary + ' ' + preloadOption([fixtureD]) + '-i',
`"${nodeBinary}" ${preloadOption([fixtureD])}-i`,
common.mustCall(function(err, stdout, stderr) {
assert.ifError(err);
assert.strictEqual(stdout, "> 'test'\n> ");
Expand All @@ -126,8 +126,8 @@ interactive.stdin.write('a\n');
interactive.stdin.write('process.exit()\n');

childProcess.exec(
`${nodeBinary} --require ${fixture('cluster-preload.js')} ` +
fixture('cluster-preload-test.js'),
`"${nodeBinary}" --require "${fixture('cluster-preload.js')}" "${
fixture('cluster-preload-test.js')}"`,
function(err, stdout, stderr) {
if (err) throw err;
assert.ok(/worker terminated with code 43/.test(stdout));
Expand All @@ -137,8 +137,8 @@ childProcess.exec(
// https://github.com/nodejs/node/issues/1691
process.chdir(common.fixturesDir);
childProcess.exec(
`${nodeBinary} --expose_natives_as=v8natives --require ` +
`${fixture('cluster-preload.js')} cluster-preload-test.js`,
`"${nodeBinary}" --expose_natives_as=v8natives --require ` +
`"${fixture('cluster-preload.js')}" cluster-preload-test.js`,
function(err, stdout, stderr) {
if (err) throw err;
assert.ok(/worker terminated with code 43/.test(stdout));
Expand Down
4 changes: 2 additions & 2 deletions test/sequential/test-domain-abort-on-uncaught.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ if (process.argv[2] === 'child') {
testCmd += 'ulimit -c 0 && ';
}

testCmd += `${process.argv[0]} --abort-on-uncaught-exception ` +
`${process.argv[1]} child ${testIndex}`;
testCmd += `"${process.argv[0]}" --abort-on-uncaught-exception ` +
`"${process.argv[1]}" child ${testIndex}`;

const child = child_process.exec(testCmd);

Expand Down
2 changes: 1 addition & 1 deletion test/sequential/test-module-loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ assert.throws(
function() {
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/main').ok, 'ok',
Expand Down