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

Added Default User Shell when executing Commands #131

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
16 changes: 12 additions & 4 deletions src/minitestTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ export class MinitestTests extends Tests {
* @return The raw output from the Minitest JSON formatter.
*/
initTests = async () => new Promise<string>((resolve, reject) => {
let cmd = `${this.getTestCommand()} vscode:minitest:list`;
let cmd = this.withDefaultShell(
`${this.getTestCommand()} vscode:minitest:list`
);

// Allow a buffer of 64MB.
const execArgs: childProcess.ExecOptions = {
Expand Down Expand Up @@ -144,7 +146,9 @@ export class MinitestTests extends Tests {
env: this.getProcessEnv()
};

let testCommand = `${this.testCommandWithDebugger(debuggerConfig)} '${relativeLocation}:${line}'`;
let testCommand = this.withDefaultShell(
`${this.testCommandWithDebugger(debuggerConfig)} '${relativeLocation}:${line}'`
);
this.log.info(`Running command: ${testCommand}`);

let testProcess = childProcess.spawn(
Expand Down Expand Up @@ -172,7 +176,9 @@ export class MinitestTests extends Tests {
};

// Run tests for a given file at once with a single command.
let testCommand = `${this.testCommandWithDebugger(debuggerConfig)} '${relativeFile}'`;
let testCommand = this.withDefaultShell(
`${this.testCommandWithDebugger(debuggerConfig)} '${relativeFile}'`
);
this.log.info(`Running command: ${testCommand}`);

let testProcess = childProcess.spawn(
Expand All @@ -197,7 +203,9 @@ export class MinitestTests extends Tests {
env: this.getProcessEnv()
};

let testCommand = this.testCommandWithDebugger(debuggerConfig);
let testCommand = this.withDefaultShell(
this.testCommandWithDebugger(debuggerConfig)
);
this.log.info(`Running command: ${testCommand}`);

let testProcess = childProcess.spawn(
Expand Down
21 changes: 16 additions & 5 deletions src/rspecTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ export class RspecTests extends Tests {
* @return The raw output from the RSpec JSON formatter.
*/
initTests = async () => new Promise<string>((resolve, reject) => {
let cmd = `${this.getTestCommandWithFilePattern()} --require ${this.getCustomFormatterLocation()}`
+ ` --format CustomFormatter --order defined --dry-run`;
let cmd = this.withDefaultShell(
`${this.getTestCommandWithFilePattern()} \
--require ${this.getCustomFormatterLocation()} \
--format CustomFormatter \
--order defined \
--dry-run`
);

this.log.info(`Running dry-run of RSpec test suite with the following command: ${cmd}`);

Expand Down Expand Up @@ -170,7 +175,9 @@ export class RspecTests extends Tests {
env: this.getProcessEnv()
};

let testCommand = `${this.testCommandWithFormatterAndDebugger(debuggerConfig)} '${testLocation}'`;
let testCommand = this.withDefaultShell(
`${this.testCommandWithFormatterAndDebugger(debuggerConfig)} '${testLocation}'`
);
this.log.info(`Running command: ${testCommand}`);

let testProcess = childProcess.spawn(
Expand All @@ -196,7 +203,9 @@ export class RspecTests extends Tests {
};

// Run tests for a given file at once with a single command.
let testCommand = `${this.testCommandWithFormatterAndDebugger(debuggerConfig)} '${testFile}'`;
let testCommand = this.withDefaultShell(
`${this.testCommandWithFormatterAndDebugger(debuggerConfig)} '${testFile}'`
);
this.log.info(`Running command: ${testCommand}`);

let testProcess = childProcess.spawn(
Expand All @@ -220,7 +229,9 @@ export class RspecTests extends Tests {
shell: true
};

let testCommand = this.testCommandWithFormatterAndDebugger(debuggerConfig);
let testCommand = this.withDefaultShell(
this.testCommandWithFormatterAndDebugger(debuggerConfig)
);
this.log.info(`Running command: ${testCommand}`);

let testProcess = childProcess.spawn(
Expand Down
11 changes: 11 additions & 0 deletions src/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export abstract class Tests {
protected workspace: vscode.WorkspaceFolder;
abstract testFrameworkName: string;
protected debugCommandStartedResolver: Function | undefined;
// The path to the user's preferred command-line shell (like /bin/bash, /bin/zsh, etc.)
private readonly shell = process.env.SHELL?.replace(/(\s+)/g, "\\$1");

/**
* @param context Extension context provided by vscode.
Expand Down Expand Up @@ -519,6 +521,15 @@ export abstract class Tests {
return this.context.asAbsolutePath('./ruby');
}

/**
* Wrap a command in the user's default shell (if there is one).
*
* @return The wrapped command (or the original command if there is no default shell)
*/
protected withDefaultShell = (command: string) => {
return this.shell ? `${this.shell} -ic "${command}"` : command;
}

/**
* Runs a single test.
*
Expand Down