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

Launch with shell on windows #1049

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"description": "Gauge support for VScode.",
"author": "ThoughtWorks",
"license": "MIT",
"version": "0.1.9",
"version": "0.1.10",
"publisher": "getgauge",
"engines": {
"vscode": "^1.71.0"
Expand Down
4 changes: 3 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@ export class CLI {
if (platform() === 'win32') validExecExt.push(".bat", ".exe", ".cmd");
for (const ext of validExecExt) {
let executable = `${command}${ext}`;
if (!spawnSync(executable).error) return executable;
const options = platform() === 'win32' ? { shell: true } : {};
if (!spawnSync(executable, options).error) return executable;
}
window.showErrorMessage(`Unable to find launch command: ${command}`);
}

private static getGradleCommand() {
Expand Down
3 changes: 2 additions & 1 deletion src/execution/gaugeExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ export class GaugeExecutor extends Disposable {
const relPath = relative(config.getProject().root(), config.getStatus());
this.preExecute.forEach((f) => { f.call(null, env, relPath); });
this.aborted = false;
let options = { cwd: config.getProject().root(), env: env , detached: false};
let options = { cwd: config.getProject().root(), env: env , detached: false, shell: true};
if (platform() !== 'win32') {
options.detached = true;
options.shell = false;
}
this.childProcess = spawn(cmd, args, options);
this.childProcess.stdout.on('data', this.filterStdoutDataDumpsToTextLines((lineText: string) => {
Expand Down
60 changes: 60 additions & 0 deletions test/maven.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import * as assert from 'assert';
import * as child_process from 'child_process';
import { platform } from 'os';
import { createSandbox, SinonSandbox } from 'sinon';
import { CLI } from '../src/cli';
import { MAVEN_COMMAND } from '../src/constants';

suite('CLI.getCommand MAVEN_COMMAND', () => {
let sandbox: SinonSandbox;

setup(() => {
sandbox = createSandbox();
});

teardown(() => {
sandbox.restore();
});

test('returns correct mvn command string', () => {
// Stub spawnSync to simulate command resolution based on platform.
sandbox.stub(child_process, 'spawnSync').callsFake(
(command: string, args?: readonly string[], options?: child_process.SpawnSyncOptions) => {
const successResult = {
pid: 1234,
output: [ '', Buffer.from(''), Buffer.from('') ],
stdout: Buffer.from(''),
stderr: Buffer.from(''),
status: 0,
signal: null,
error: null
};

const failureResult = {
pid: 1234,
output: [ '', Buffer.from(''), Buffer.from('') ],
stdout: Buffer.from(''),
stderr: Buffer.from(''),
status: 1,
signal: null,
error: new Error('command not found')
};

if (platform() === 'win32') {
// On Windows, only "mvn.cmd" should succeed.
return command === `${MAVEN_COMMAND}.cmd` ? successResult : failureResult;
} else {
// On non-Windows, only "mvn" should succeed.
return command === MAVEN_COMMAND ? successResult : failureResult;
}
}
);

const actual = (CLI as any).getCommand(MAVEN_COMMAND);
if (platform() === 'win32') {
assert.strictEqual(actual, `${MAVEN_COMMAND}.cmd`);
} else {
assert.strictEqual(actual, MAVEN_COMMAND);
}
});
});