diff options
author | cjihrig <cjihrig@gmail.com> | 2017-01-20 14:42:55 -0500 |
---|---|---|
committer | cjihrig <cjihrig@gmail.com> | 2017-01-23 12:37:57 -0500 |
commit | 71f541411d56b3dceb087c0c0c50b86fc451e069 (patch) | |
tree | 8533d5bc67fbe7f48a16489858df6fd4110d44fb /test/parallel/test-child-process-spawnsync-shell.js | |
parent | 00679c377962e3258b0c6c0d9e0ffcfe18e8fa46 (diff) | |
download | android-node-v8-71f541411d56b3dceb087c0c0c50b86fc451e069.tar.gz android-node-v8-71f541411d56b3dceb087c0c0c50b86fc451e069.tar.bz2 android-node-v8-71f541411d56b3dceb087c0c0c50b86fc451e069.zip |
test: verify shell option internals
This commit adds code coverage to the internals associated with
the child_process shell option. This achieves the following:
- Increased code coverage, which is currently only reported
for Unix.
- Ensures that all six code paths are covered, including the
three Windows variations, and Android which is not tested at
all on CI.
PR-URL: https://github.com/nodejs/node/pull/10924
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'test/parallel/test-child-process-spawnsync-shell.js')
-rw-r--r-- | test/parallel/test-child-process-spawnsync-shell.js | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/test/parallel/test-child-process-spawnsync-shell.js b/test/parallel/test-child-process-spawnsync-shell.js index 7048308924..1d92767a8b 100644 --- a/test/parallel/test-child-process-spawnsync-shell.js +++ b/test/parallel/test-child-process-spawnsync-shell.js @@ -35,3 +35,59 @@ const env = cp.spawnSync(`"${process.execPath}" -pe process.env.BAZ`, { }); assert.strictEqual(env.stdout.toString().trim(), 'buzz'); + +// Verify that the shell internals work properly across platforms. +{ + const originalComspec = process.env.comspec; + + // Enable monkey patching process.platform. + const originalPlatform = process.platform; + let platform = null; + Object.defineProperty(process, 'platform', { get: () => platform }); + + function test(testPlatform, shell, shellOutput) { + platform = testPlatform; + + const cmd = 'not_a_real_command'; + const shellFlags = platform === 'win32' ? ['/d', '/s', '/c'] : ['-c']; + const outputCmd = platform === 'win32' ? `"${cmd}"` : cmd; + const windowsVerbatim = platform === 'win32' ? true : undefined; + const result = cp.spawnSync(cmd, { shell }); + + assert.strictEqual(result.file, shellOutput); + assert.deepStrictEqual(result.args, + [shellOutput, ...shellFlags, outputCmd]); + assert.strictEqual(result.options.shell, shell); + assert.strictEqual(result.options.file, result.file); + assert.deepStrictEqual(result.options.args, result.args); + assert.strictEqual(result.options.windowsVerbatimArguments, + windowsVerbatim); + } + + // Test Unix platforms with the default shell. + test('darwin', true, '/bin/sh'); + + // Test Unix platforms with a user specified shell. + test('darwin', '/bin/csh', '/bin/csh'); + + // Test Android platforms. + test('android', true, '/system/bin/sh'); + + // Test Windows platforms with a user specified shell. + test('win32', 'powershell.exe', 'powershell.exe'); + + // Test Windows platforms with the default shell and no comspec. + delete process.env.comspec; + test('win32', true, 'cmd.exe'); + + // Test Windows platforms with the default shell and a comspec value. + process.env.comspec = 'powershell.exe'; + test('win32', true, process.env.comspec); + + // Restore the original value of process.platform. + platform = originalPlatform; + + // Restore the original comspec environment variable if necessary. + if (originalComspec) + process.env.comspec = originalComspec; +} |