From 598db8fa72327a8d42dfc0601265abd29cae87bd Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Mon, 23 Sep 2024 23:20:12 +0200 Subject: [PATCH 1/2] test: fix more tests that fail when path contains a space --- test/parallel/test-child-process-execfile.js | 9 +++++++-- test/parallel/test-cli-node-options.js | 6 ++++-- test/parallel/test-startup-large-pages.js | 4 ++-- test/pseudo-tty/test-repl-external-module.js | 4 ++-- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/test/parallel/test-child-process-execfile.js b/test/parallel/test-child-process-execfile.js index e6e04ff61f93b8..6301f4ff3d320d 100644 --- a/test/parallel/test-child-process-execfile.js +++ b/test/parallel/test-child-process-execfile.js @@ -10,7 +10,7 @@ const os = require('os'); const fixture = fixtures.path('exit.js'); const echoFixture = fixtures.path('echo.js'); -const execOpts = { encoding: 'utf8', shell: true }; +const execOpts = { encoding: 'utf8', shell: true, env: { ...process.env, NODE: process.execPath, FIXTURE: fixture } }; { execFile( @@ -46,7 +46,12 @@ const execOpts = { encoding: 'utf8', shell: true }; { // Verify the shell option works properly - execFile(process.execPath, [fixture, 0], execOpts, common.mustSucceed()); + execFile( + `"${common.isWindows ? execOpts.env.NODE : '$NODE'}"`, + [`"${common.isWindows ? execOpts.env.FIXTURE : '$FIXTURE'}"`, 0], + execOpts, + common.mustSucceed() + ); } { diff --git a/test/parallel/test-cli-node-options.js b/test/parallel/test-cli-node-options.js index 22d5a342df5d55..69bf136559c1a8 100644 --- a/test/parallel/test-cli-node-options.js +++ b/test/parallel/test-cli-node-options.js @@ -6,14 +6,16 @@ if (process.config.variables.node_without_node_options) // Test options specified by env variable. const assert = require('assert'); +const path = require('path'); const exec = require('child_process').execFile; const { Worker } = require('worker_threads'); +const fixtures = require('../common/fixtures'); const tmpdir = require('../common/tmpdir'); tmpdir.refresh(); -const printA = require.resolve('../fixtures/printA.js'); -const printSpaceA = require.resolve('../fixtures/print A.js'); +const printA = path.relative(tmpdir.path, fixtures.path('printA.js')); +const printSpaceA = path.relative(tmpdir.path, fixtures.path('print A.js')); expectNoWorker(` -r ${printA} `, 'A\nB\n'); expectNoWorker(`-r ${printA}`, 'A\nB\n'); diff --git a/test/parallel/test-startup-large-pages.js b/test/parallel/test-startup-large-pages.js index ed0542b6c6dc68..9ebe9fa7b66804 100644 --- a/test/parallel/test-startup-large-pages.js +++ b/test/parallel/test-startup-large-pages.js @@ -22,8 +22,8 @@ const { spawnSync } = require('child_process'); [ '--use-largepages=xyzzy', '-p', '42' ]); assert.strictEqual(child.status, 9); assert.strictEqual(child.signal, null); - assert.strictEqual(child.stderr.toString().match(/\S+/g).slice(1).join(' '), - 'invalid value for --use-largepages'); + assert.match(child.stderr.toString().trim(), + /invalid value for --use-largepages$/); } // TODO(gabrielschulhof): Make assertions about the stderr, which may or may not diff --git a/test/pseudo-tty/test-repl-external-module.js b/test/pseudo-tty/test-repl-external-module.js index db9ad29712ed70..3f17cd4dee0441 100644 --- a/test/pseudo-tty/test-repl-external-module.js +++ b/test/pseudo-tty/test-repl-external-module.js @@ -2,9 +2,9 @@ require('../common'); const fixtures = require('../common/fixtures'); -const { execSync } = require('child_process'); +const { execFileSync } = require('child_process'); -execSync(process.execPath, { +execFileSync(process.execPath, { encoding: 'utf8', stdio: 'inherit', env: { From e10733a25e985cd7cd7a50d0877aff1cff2acea1 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Tue, 24 Sep 2024 10:02:24 +0200 Subject: [PATCH 2/2] Update test/parallel/test-child-process-execfile.js --- test/parallel/test-child-process-execfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-child-process-execfile.js b/test/parallel/test-child-process-execfile.js index 6301f4ff3d320d..c4dba6b3f9466f 100644 --- a/test/parallel/test-child-process-execfile.js +++ b/test/parallel/test-child-process-execfile.js @@ -50,7 +50,7 @@ const execOpts = { encoding: 'utf8', shell: true, env: { ...process.env, NODE: p `"${common.isWindows ? execOpts.env.NODE : '$NODE'}"`, [`"${common.isWindows ? execOpts.env.FIXTURE : '$FIXTURE'}"`, 0], execOpts, - common.mustSucceed() + common.mustSucceed(), ); }