From bde8bad6dc020e7253259d0f97b55aefe2759991 Mon Sep 17 00:00:00 2001 From: Brandt Lareau Date: Tue, 19 Dec 2023 14:51:04 -0800 Subject: [PATCH 1/3] Added Default User Shell when executing Commands --- src/minitestTests.ts | 16 ++++++++++++---- src/rspecTests.ts | 22 +++++++++++++++++----- src/tests.ts | 12 ++++++++++++ 3 files changed, 41 insertions(+), 9 deletions(-) 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..c5778f9 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}`); @@ -72,6 +77,7 @@ export class RspecTests extends Tests { }); }); + /** * Get the user-configured RSpec command, if there is one. * @@ -170,7 +176,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 +204,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 +230,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..5465f8a 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,16 @@ 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. * From c9cac77d824c9807a0704ab99089fcc244103d3c Mon Sep 17 00:00:00 2001 From: Brandt Lareau Date: Tue, 19 Dec 2023 15:23:08 -0800 Subject: [PATCH 2/3] Removed a extra space Update src/rspecTests.ts --- src/rspecTests.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/rspecTests.ts b/src/rspecTests.ts index c5778f9..e168169 100644 --- a/src/rspecTests.ts +++ b/src/rspecTests.ts @@ -77,7 +77,6 @@ export class RspecTests extends Tests { }); }); - /** * Get the user-configured RSpec command, if there is one. * From 1bed398c04a378c669b5a115fd034ed4c8e260df Mon Sep 17 00:00:00 2001 From: Brandt Lareau Date: Tue, 19 Dec 2023 15:23:45 -0800 Subject: [PATCH 3/3] Removed a extra space Update src/tests.ts --- src/tests.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/tests.ts b/src/tests.ts index 5465f8a..502fa56 100644 --- a/src/tests.ts +++ b/src/tests.ts @@ -530,7 +530,6 @@ export abstract class Tests { return this.shell ? `${this.shell} -ic "${command}"` : command; } - /** * Runs a single test. *