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

test: make a test path-independent #12945

Closed

Conversation

@vsemozhetbyt
Copy link
Contributor

commented May 10, 2017

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected 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

@vsemozhetbyt

This comment has been minimized.

Copy link
Contributor Author

commented May 10, 2017

@vsemozhetbyt

This comment has been minimized.

Copy link
Contributor Author

commented May 10, 2017

The test runs only on Windows and Windows is OK in CI. One Linux fail must be irrelevant.

@cjihrig
Copy link
Contributor

left a comment

If we go this route, the test may need to be renamed since it no longer uses spawn().

test/parallel/test-spawn-cmd-named-pipe.js Outdated
'<', stdinPipeName, '>', stdoutPipeName];

const child = spawn(comspec, args);
const child = exec(`"${process.execPath}" "${__filename}" child < ${

This comment has been minimized.

Copy link
@cjihrig

cjihrig May 10, 2017

Contributor

Would quoting the args and specifying the shell work with spawn()?

This comment has been minimized.

Copy link
@vsemozhetbyt

vsemozhetbyt May 10, 2017

Author Contributor

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?

This comment has been minimized.

Copy link
@cjihrig

cjihrig May 10, 2017

Contributor

Does windowsVerbatimArguments make a difference?

This comment has been minimized.

Copy link
@vsemozhetbyt

vsemozhetbyt May 10, 2017

Author Contributor

Is this documented? I can't find.

This comment has been minimized.

Copy link
@vsemozhetbyt

vsemozhetbyt May 10, 2017

Author Contributor

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?

This comment has been minimized.

Copy link
@cjihrig

cjihrig May 10, 2017

Contributor

windowsVerbatimArguments is not documented. See

node/lib/child_process.js

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.

This comment has been minimized.

Copy link
@vsemozhetbyt

vsemozhetbyt May 10, 2017

Author Contributor

Another way:

  const args =
    [`"${__filename}"`, 'child', '<', stdinPipeName, '>', stdoutPipeName];

  const child = spawn(`"${process.execPath}"`, args, { shell: true });

Slightly better maybe than the previous one.

This comment has been minimized.

Copy link
@vsemozhetbyt

vsemozhetbyt May 10, 2017

Author Contributor

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()?

This comment has been minimized.

Copy link
@cjihrig

cjihrig May 10, 2017

Contributor

The variant in #12945 (comment) seems reasonable enough.

test: make a test path-independent
parallel/test-spawn-cmd-named-pipe.js failed with spaces
both in node.exe and test paths.

@vsemozhetbyt vsemozhetbyt force-pushed the vsemozhetbyt:test-spawn-cmd-named-pipe branch to e597b39 May 10, 2017

@vsemozhetbyt

This comment has been minimized.

Copy link
Contributor Author

commented May 10, 2017

@refack
refack approved these changes May 10, 2017
Copy link
Member

left a comment

LGTM if CI is green

@refack

This comment has been minimized.

Copy link
Member

commented May 10, 2017

@vsemozhetbyt you could update the first comment, since you eventually found a way to use spawn
IMHO you could also change title to something simpler like: test: make test path-robust or path agnostic

@vsemozhetbyt vsemozhetbyt changed the title test: make parallel/test-spawn-cmd-named-pipe.js path-independent test: make a test path-independent May 10, 2017

@cjihrig
Copy link
Contributor

left a comment

LGTM pending CI

@vsemozhetbyt

This comment has been minimized.

Copy link
Contributor Author

commented May 10, 2017

@refack I've unified with the #12812

@vsemozhetbyt

This comment has been minimized.

Copy link
Contributor Author

commented May 10, 2017

Windows CI is green.

@vsemozhetbyt

This comment has been minimized.

Copy link
Contributor Author

commented May 12, 2017

Landed in 529e4f2

@vsemozhetbyt vsemozhetbyt deleted the vsemozhetbyt:test-spawn-cmd-named-pipe branch May 12, 2017

vsemozhetbyt added a commit that referenced this pull request May 12, 2017
test: make a test path-independent
parallel/test-spawn-cmd-named-pipe.js failed with spaces
both in node.exe and test paths.

PR-URL: #12945
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
anchnk pushed a commit to anchnk/node that referenced this pull request May 19, 2017
test: make a test path-independent
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 <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
@jasnell jasnell referenced this pull request May 28, 2017
@gibfahn gibfahn referenced this pull request Jun 15, 2017
2 of 3 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.