From be6fb847855513581d931e3c2a73b7113241b192 Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Fri, 25 Oct 2024 15:44:15 -0400 Subject: [PATCH] Always set shell to cmd.exe on Windows --- vscode/src/ruby/versionManager.ts | 4 ++- .../src/test/suite/ruby/rubyInstaller.test.ts | 25 ++++++++----------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/vscode/src/ruby/versionManager.ts b/vscode/src/ruby/versionManager.ts index 428fb5c82..51d411357 100644 --- a/vscode/src/ruby/versionManager.ts +++ b/vscode/src/ruby/versionManager.ts @@ -88,7 +88,9 @@ export abstract class VersionManager { // If the user has configured a default shell, we use that one since they are probably sourcing their version // manager scripts in that shell's configuration files. On Windows, we never set the shell no matter what to ensure // that activation runs on `cmd.exe` and not PowerShell, which avoids complex quoting and escaping issues. - if (vscode.env.shell.length > 0 && os.platform() !== "win32") { + if (os.platform() === "win32") { + shell = "cmd.exe"; + } else if (vscode.env.shell.length > 0) { shell = vscode.env.shell; } diff --git a/vscode/src/test/suite/ruby/rubyInstaller.test.ts b/vscode/src/test/suite/ruby/rubyInstaller.test.ts index 6e478da36..eec0e6c69 100644 --- a/vscode/src/test/suite/ruby/rubyInstaller.test.ts +++ b/vscode/src/test/suite/ruby/rubyInstaller.test.ts @@ -12,7 +12,6 @@ import { RubyInstaller } from "../../../ruby/rubyInstaller"; import { WorkspaceChannel } from "../../../workspaceChannel"; import { LOG_CHANNEL } from "../../../common"; import { RUBY_VERSION } from "../../rubyVersion"; -import { ACTIVATION_SEPARATOR } from "../../../ruby/versionManager"; suite("RubyInstaller", () => { if (os.platform() !== "win32") { @@ -104,7 +103,7 @@ suite("RubyInstaller", () => { }); }); - test("Doesn't set the shell when invoking activation script", async () => { + test("Sets shell to cmd.exe when invoking activation script", async () => { const [major, minor, _patch] = RUBY_VERSION.split(".").map(Number); fs.symlinkSync( path.join( @@ -121,20 +120,18 @@ suite("RubyInstaller", () => { fs.writeFileSync(path.join(workspacePath, ".ruby-version"), RUBY_VERSION); const windows = new RubyInstaller(workspaceFolder, outputChannel); - const result = ["/fake/dir", "/other/fake/dir", true, RUBY_VERSION].join( - ACTIVATION_SEPARATOR, - ); - const execStub = sinon.stub(common, "asyncExec").resolves({ - stdout: "", - stderr: result, - }); + const execSpy = sinon.spy(common, "asyncExec"); + const { env, version, yjit } = await windows.activate(); + execSpy.restore(); - await windows.activate(); - execStub.restore(); + assert.strictEqual(execSpy.callCount, 1); + const callArgs = execSpy.getCall(0).args; + assert.strictEqual(callArgs[1]?.shell, "cmd.exe"); - assert.strictEqual(execStub.callCount, 1); - const callArgs = execStub.getCall(0).args; - assert.strictEqual(callArgs[1]?.shell, undefined); + assert.match(env.GEM_PATH!, /ruby\/3\.3\.0/); + assert.match(env.GEM_PATH!, /lib\/ruby\/gems\/3\.3\.0/); + assert.strictEqual(version, RUBY_VERSION); + assert.notStrictEqual(yjit, undefined); fs.rmSync(path.join(os.homedir(), `Ruby${major}${minor}-${os.arch()}`), { recursive: true,