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: verify shell option internals #10924

Merged
merged 1 commit into from
Jan 23, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions test/parallel/test-child-process-spawnsync-shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}