-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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: make a test path-independent #12945
Conversation
The test runs only on Windows and Windows is OK in CI. One Linux fail must be irrelevant. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we go this route, the test may need to be renamed since it no longer uses spawn()
.
'<', stdinPipeName, '>', stdoutPipeName]; | ||
|
||
const child = spawn(comspec, args); | ||
const child = exec(`"${process.execPath}" "${__filename}" child < ${ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would quoting the args and specifying the shell work with spawn()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried and failed. It seems the args are re-quoted internally in an inappropriate way for this case. But I may miss some variants. Can anybody else test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does windowsVerbatimArguments
make a difference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this documented? I can't find.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've found out a way with spawn()
:
const args = ['/c', `""${process.execPath}"`, `"${__filename}"`, 'child',
'<', stdinPipeName, '>', `${stdoutPipeName}"`];
const child = spawn(comspec, args, { shell: true });
But it seems strange. And we execute cmd.exe with cmd.exe first, if I get this right. Is this way better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
windowsVerbatimArguments
is not documented. See
Lines 424 to 428 in cfe7b34
if (process.platform === 'win32') { | |
file = typeof options.shell === 'string' ? options.shell : | |
process.env.comspec || 'cmd.exe'; | |
args = ['/d', '/s', '/c', '"' + command + '"']; | |
options.windowsVerbatimArguments = true; |
When you run exec()
or spawn()
with shell: true
, this code path is hit. It's probably what you're looking for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another way:
const args =
[`"${__filename}"`, 'child', '<', stdinPipeName, '>', stdoutPipeName];
const child = spawn(`"${process.execPath}"`, args, { shell: true });
Slightly better maybe than the previous one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not work:
const args = ['/c', `"${process.execPath}"`, `"${__filename}"`, 'child',
'<', stdinPipeName, '>', stdoutPipeName];
const child = spawn(comspec, args,
{ shell: true, windowsVerbatimArguments: true });
Should I prefer one of the beforementioned variants with spawn()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variant in #12945 (comment) seems reasonable enough.
parallel/test-spawn-cmd-named-pipe.js failed with spaces both in node.exe and test paths.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM if CI is green
@vsemozhetbyt you could update the first comment, since you eventually found a way to use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM pending CI
Windows CI is green. |
Landed in 529e4f2 |
parallel/test-spawn-cmd-named-pipe.js failed with spaces both in node.exe and test paths. PR-URL: #12945 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
parallel/test-spawn-cmd-named-pipe.js failed with spaces both in node.exe and test paths. PR-URL: nodejs#12945 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
test, child_process
This is the first step to fix the #12773.
I've decided to start from the most whimsical one (section 4 in the #12773):
parallel/test-spawn-cmd-named-pipe.js
fails if spaces exist both in node.exe and the test paths. If there are no spaces or there are spaces only in one of the paths (either), the test passes.If I get it right, the cause is the very complicated rules for
cmd.exe
command line syntax concerning spaces and quotes: see "Quote Characters in a command" here and "Examples:" here.The fixed test passes with all 4 paths variants (spaceless + spaceless, spacy + spaceless, spaceless + spacy, and spacy + spacy).
Please, test in more environments and propose better fixes if you have some)
cc @nodejs/testing, @nodejs/platform-windows, @bnoordhuis, @cjihrig