Skip to content

Commit 945f208

Browse files
committed
test: make the rest of tests path-independent
Permit spaces in paths to a Node.js executable and test scripts. PR-URL: #12972 Fixes: #12773 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 9516aa1 commit 945f208

14 files changed

+32
-31
lines changed

test/common/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,8 @@ exports.childShouldThrowAndAbort = function() {
285285
// continuous testing and developers' machines
286286
testCmd += 'ulimit -c 0 && ';
287287
}
288-
testCmd += `${process.argv[0]} --abort-on-uncaught-exception `;
289-
testCmd += `${process.argv[1]} child`;
288+
testCmd += `"${process.argv[0]}" --abort-on-uncaught-exception `;
289+
testCmd += `"${process.argv[1]}" child`;
290290
const child = child_process.exec(testCmd);
291291
child.on('exit', function onExit(exitCode, signal) {
292292
const errMsg = 'Test should have aborted ' +

test/known_issues/test-stdout-buffer-flush-on-exit.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ if (process.argv[2] === 'child') {
1818
[22, 21, 20, 19, 18, 17, 16, 16, 17, 18, 19, 20, 21, 22].forEach((exponent) => {
1919
const bigNum = Math.pow(2, exponent);
2020
const longLine = lineSeed.repeat(bigNum);
21-
const cmd = `${process.execPath} ${__filename} child ${exponent} ${bigNum}`;
21+
const cmd =
22+
`"${process.execPath}" "${__filename}" child ${exponent} ${bigNum}`;
2223
const stdout = execSync(cmd).toString().trim();
2324

2425
assert.strictEqual(stdout, longLine, `failed with exponent ${exponent}`);

test/parallel/test-child-process-bad-stdio.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ ChildProcess.prototype.spawn = function() {
2727
};
2828

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

3232
return cp.exec(cmd, options, common.mustCall(callback));
3333
}

test/parallel/test-child-process-exec-encoding.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ if (process.argv[2] === 'child') {
1313
console.error(stderrData);
1414
} else {
1515
function run(options, callback) {
16-
const cmd = `${process.execPath} ${__filename} child`;
16+
const cmd = `"${process.execPath}" "${__filename}" child`;
1717

1818
cp.exec(cmd, options, common.mustCall((err, stdout, stderr) => {
1919
assert.ifError(err);

test/parallel/test-child-process-exec-kill-throws.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if (process.argv[2] === 'child') {
1818
throw new Error('mock error');
1919
};
2020

21-
const cmd = `${process.execPath} ${__filename} child`;
21+
const cmd = `"${process.execPath}" "${__filename}" child`;
2222
const options = { maxBuffer: 0 };
2323
const child = cp.exec(cmd, options, common.mustCall((err, stdout, stderr) => {
2424
// Verify that if ChildProcess#kill() throws, the error is reported.

test/parallel/test-child-process-exec-timeout.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if (process.argv[2] === 'child') {
1212
return;
1313
}
1414

15-
const cmd = `${process.execPath} ${__filename} child`;
15+
const cmd = `"${process.execPath}" "${__filename}" child`;
1616

1717
// Test the case where a timeout is set, and it expires.
1818
cp.exec(cmd, { timeout: 1 }, common.mustCall((err, stdout, stderr) => {

test/parallel/test-cli-eval.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ child.exec(`${nodejs} --use-strict -p process.execArgv`,
220220
// Ensure that arguments are successfully passed to a script.
221221
// The first argument after '--' should be interpreted as a script
222222
// filename.
223-
const filecmd = `${nodejs} -- ${__filename} ${args}`;
223+
const filecmd = `${nodejs} -- "${__filename}" ${args}`;
224224
child.exec(filecmd, common.mustCall(function(err, stdout, stderr) {
225225
assert.strictEqual(stdout, `${args}\n`);
226226
assert.strictEqual(stderr, '');

test/parallel/test-domain-throw-error-then-throw-from-uncaught-exception-handler.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ function createTestCmdLine(options) {
9090
testCmd += 'ulimit -c 0 && ';
9191
}
9292

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

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

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

101101
return testCmd;
102102
}

test/parallel/test-domain-with-abort-on-uncaught-exception.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ if (process.argv[2] === 'child') {
103103
if (options.useTryCatch)
104104
useTryCatchOpt = 'useTryCatch';
105105

106-
cmdToExec += `${process.argv[0]} ${cmdLineOption ? cmdLineOption : ''} ${
107-
process.argv[1]} child ${throwInDomainErrHandlerOpt} ${useTryCatchOpt}`;
106+
cmdToExec += `"${process.argv[0]}" ${cmdLineOption ? cmdLineOption : ''} "${
107+
process.argv[1]}" child ${throwInDomainErrHandlerOpt} ${useTryCatchOpt}`;
108108

109109
const child = exec(cmdToExec);
110110

test/parallel/test-env-var-no-warnings.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if (process.argv[2] === 'child') {
77
process.emitWarning('foo');
88
} else {
99
function test(env) {
10-
const cmd = `${process.execPath} ${__filename} child`;
10+
const cmd = `"${process.execPath}" "${__filename}" child`;
1111

1212
cp.exec(cmd, { env }, common.mustCall((err, stdout, stderr) => {
1313
assert.strictEqual(err, null);

test/parallel/test-http-chunk-problem.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ const filename = require('path').join(common.tmpDir, 'big');
4242
let server;
4343

4444
function executeRequest(cb) {
45-
cp.exec([process.execPath,
46-
__filename,
45+
cp.exec([`"${process.execPath}"`,
46+
`"${__filename}"`,
4747
'request',
4848
server.address().port,
4949
'|',
50-
process.execPath,
51-
__filename,
50+
`"${process.execPath}"`,
51+
`"${__filename}"`,
5252
'shasum' ].join(' '),
5353
(err, stdout, stderr) => {
5454
assert.ifError(err);

test/parallel/test-preload.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const nodeBinary = process.argv[0];
1616
const preloadOption = (preloads) => {
1717
let option = '';
1818
preloads.forEach(function(preload, index) {
19-
option += `-r ${preload} `;
19+
option += `-r "${preload}" `;
2020
});
2121
return option;
2222
};
@@ -30,15 +30,15 @@ const fixtureD = fixture('define-global.js');
3030
const fixtureThrows = fixture('throws_error4.js');
3131

3232
// test preloading a single module works
33-
childProcess.exec(`${nodeBinary} ${preloadOption([fixtureA])} ${fixtureB}`,
33+
childProcess.exec(`"${nodeBinary}" ${preloadOption([fixtureA])} "${fixtureB}"`,
3434
function(err, stdout, stderr) {
3535
assert.ifError(err);
3636
assert.strictEqual(stdout, 'A\nB\n');
3737
});
3838

3939
// test preloading multiple modules works
4040
childProcess.exec(
41-
`${nodeBinary} ${preloadOption([fixtureA, fixtureB])} ${fixtureC}`,
41+
`"${nodeBinary}" ${preloadOption([fixtureA, fixtureB])} "${fixtureC}"`,
4242
function(err, stdout, stderr) {
4343
assert.ifError(err);
4444
assert.strictEqual(stdout, 'A\nB\nC\n');
@@ -47,7 +47,7 @@ childProcess.exec(
4747

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

6060
// test that preload can be used with --eval
6161
childProcess.exec(
62-
`${nodeBinary} ${preloadOption([fixtureA])}-e "console.log('hello');"`,
62+
`"${nodeBinary}" ${preloadOption([fixtureA])}-e "console.log('hello');"`,
6363
function(err, stdout, stderr) {
6464
assert.ifError(err);
6565
assert.strictEqual(stdout, 'A\nhello\n');
@@ -105,7 +105,7 @@ replProc.on('close', function(code) {
105105
// test that preload placement at other points in the cmdline
106106
// also test that duplicated preload only gets loaded once
107107
childProcess.exec(
108-
`${nodeBinary} ${preloadOption([fixtureA])}-e "console.log('hello');" ${
108+
`"${nodeBinary}" ${preloadOption([fixtureA])}-e "console.log('hello');" ${
109109
preloadOption([fixtureA, fixtureB])}`,
110110
function(err, stdout, stderr) {
111111
assert.ifError(err);
@@ -115,7 +115,7 @@ childProcess.exec(
115115

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

128128
childProcess.exec(
129-
`${nodeBinary} --require ${fixture('cluster-preload.js')} ${
130-
fixture('cluster-preload-test.js')}`,
129+
`"${nodeBinary}" --require "${fixture('cluster-preload.js')}" "${
130+
fixture('cluster-preload-test.js')}"`,
131131
function(err, stdout, stderr) {
132132
assert.ifError(err);
133133
assert.ok(/worker terminated with code 43/.test(stdout));
@@ -137,8 +137,8 @@ childProcess.exec(
137137
// https://github.com/nodejs/node/issues/1691
138138
process.chdir(common.fixturesDir);
139139
childProcess.exec(
140-
`${nodeBinary} --expose_natives_as=v8natives --require ` +
141-
`${fixture('cluster-preload.js')} cluster-preload-test.js`,
140+
`"${nodeBinary}" --expose_natives_as=v8natives --require ` +
141+
`"${fixture('cluster-preload.js')}" cluster-preload-test.js`,
142142
function(err, stdout, stderr) {
143143
assert.ifError(err);
144144
assert.ok(/worker terminated with code 43/.test(stdout));

test/sequential/test-domain-abort-on-uncaught.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ if (process.argv[2] === 'child') {
239239
testCmd += 'ulimit -c 0 && ';
240240
}
241241

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

245245
const child = child_process.exec(testCmd);
246246

test/sequential/test-module-loading.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ assert.throws(
103103
function() {
104104
require('../fixtures/packages/invalid');
105105
},
106-
/^SyntaxError: Error parsing \S+: Unexpected token , in JSON at position 1$/
106+
/^SyntaxError: Error parsing .+: Unexpected token , in JSON at position 1$/
107107
);
108108

109109
assert.strictEqual(require('../fixtures/packages/index').ok, 'ok',

0 commit comments

Comments
 (0)