diff --git a/src/minitestTests.ts b/src/minitestTests.ts index da92249..d071bef 100644 --- a/src/minitestTests.ts +++ b/src/minitestTests.ts @@ -30,7 +30,9 @@ export class MinitestTests extends Tests { * @return The raw output from the Minitest JSON formatter. */ initTests = async () => new Promise((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 = { @@ -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( @@ -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( @@ -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( diff --git a/src/rspecTests.ts b/src/rspecTests.ts index 12217ca..e168169 100644 --- a/src/rspecTests.ts +++ b/src/rspecTests.ts @@ -30,8 +30,13 @@ export class RspecTests extends Tests { * @return The raw output from the RSpec JSON formatter. */ initTests = async () => new Promise((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}`); @@ -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( @@ -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( @@ -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( diff --git a/src/tests.ts b/src/tests.ts index ce29bd3..502fa56 100644 --- a/src/tests.ts +++ b/src/tests.ts @@ -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. @@ -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. *