-
Notifications
You must be signed in to change notification settings - Fork 253
Decouple Ruby tests from specific machine setup #4088
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
base: 04-24-decouple_shadowenv_test_from_specific_dev_setup
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ import { Shadowenv, UntrustedWorkspaceError } from "../../ruby/shadowenv"; | |
| import { Chruby } from "../../ruby/chruby"; | ||
| import { ACTIVATION_SEPARATOR, FIELD_SEPARATOR, MissingRubyError, VALUE_SEPARATOR } from "../../ruby/versionManager"; | ||
|
|
||
| import { createContext, FakeContext } from "./helpers"; | ||
| import { createContext, FakeContext, stubWorkspaceConfiguration } from "./helpers"; | ||
| import { FAKE_TELEMETRY } from "./fakeTelemetry"; | ||
|
|
||
| suite("Ruby environment activation", () => { | ||
|
|
@@ -39,70 +39,70 @@ suite("Ruby environment activation", () => { | |
| context.dispose(); | ||
| }); | ||
|
|
||
| test("Activate fetches Ruby information when outside of Ruby LSP", async () => { | ||
| const manager = process.env.CI ? ManagerIdentifier.None : ManagerIdentifier.Chruby; | ||
| test("Populates Ruby version and YJIT support from the activation script", async () => { | ||
| stubWorkspaceConfiguration(sandbox, { | ||
| rubyLsp: { | ||
| rubyVersionManager: { identifier: ManagerIdentifier.None }, | ||
| bundleGemfile: "", | ||
| }, | ||
| }); | ||
|
|
||
| sandbox.stub(vscode.workspace, "getConfiguration").returns({ | ||
| get: (name: string) => { | ||
| if (name === "rubyVersionManager") { | ||
| return { identifier: manager }; | ||
| } else if (name === "bundleGemfile") { | ||
| return ""; | ||
| } | ||
| const envStub = [ | ||
| "3.3.5", | ||
| "~/.gem/ruby/3.3.5,/opt/rubies/3.3.5/lib/ruby/gems/3.3.0", | ||
| "true", | ||
| `ANY${VALUE_SEPARATOR}true`, | ||
| ].join(FIELD_SEPARATOR); | ||
|
|
||
| return undefined; | ||
| }, | ||
| } as unknown as vscode.WorkspaceConfiguration); | ||
| sandbox.stub(common, "asyncExec").resolves({ | ||
| stdout: "", | ||
| stderr: `${ACTIVATION_SEPARATOR}${envStub}${ACTIVATION_SEPARATOR}`, | ||
| }); | ||
|
|
||
| const ruby = new Ruby(context, workspaceFolder, outputChannel, FAKE_TELEMETRY); | ||
| await ruby.activateRuby(); | ||
|
|
||
| assert.ok(ruby.rubyVersion, "Expected Ruby version to be set"); | ||
| assert.notStrictEqual(ruby.yjitEnabled, undefined, "Expected YJIT support to be set to true or false"); | ||
| }).timeout(10000); | ||
| assert.strictEqual(ruby.rubyVersion, "3.3.5"); | ||
| assert.strictEqual(ruby.yjitEnabled, true); | ||
| }); | ||
|
|
||
| test("Deletes verbose and GC settings from activated environment", async () => { | ||
| const manager = process.env.CI ? ManagerIdentifier.None : ManagerIdentifier.Chruby; | ||
| stubWorkspaceConfiguration(sandbox, { | ||
| rubyLsp: { | ||
| rubyVersionManager: { identifier: ManagerIdentifier.None }, | ||
| bundleGemfile: "", | ||
| }, | ||
| }); | ||
|
|
||
| sandbox.stub(vscode.workspace, "getConfiguration").returns({ | ||
| get: (name: string) => { | ||
| if (name === "rubyVersionManager") { | ||
| return { identifier: manager }; | ||
| } else if (name === "bundleGemfile") { | ||
| return ""; | ||
| } | ||
| const envStub = [ | ||
| "3.3.5", | ||
| "~/.gem/ruby/3.3.5,/opt/rubies/3.3.5/lib/ruby/gems/3.3.0", | ||
| "true", | ||
| `VERBOSE${VALUE_SEPARATOR}1`, | ||
| `DEBUG${VALUE_SEPARATOR}WARN`, | ||
| `RUBY_GC_HEAP_GROWTH_FACTOR${VALUE_SEPARATOR}1.7`, | ||
| ].join(FIELD_SEPARATOR); | ||
|
|
||
| return undefined; | ||
| }, | ||
| } as unknown as vscode.WorkspaceConfiguration); | ||
| sandbox.stub(common, "asyncExec").resolves({ | ||
| stdout: "", | ||
| stderr: `${ACTIVATION_SEPARATOR}${envStub}${ACTIVATION_SEPARATOR}`, | ||
| }); | ||
|
|
||
| const ruby = new Ruby(context, workspaceFolder, outputChannel, FAKE_TELEMETRY); | ||
|
|
||
| process.env.VERBOSE = "1"; | ||
| process.env.DEBUG = "WARN"; | ||
| process.env.RUBY_GC_HEAP_GROWTH_FACTOR = "1.7"; | ||
| await ruby.activateRuby(); | ||
|
|
||
| assert.strictEqual(ruby.env.VERBOSE, undefined); | ||
| assert.strictEqual(ruby.env.DEBUG, undefined); | ||
| assert.strictEqual(ruby.env.RUBY_GC_HEAP_GROWTH_FACTOR, undefined); | ||
| delete process.env.VERBOSE; | ||
| delete process.env.DEBUG; | ||
| delete process.env.RUBY_GC_HEAP_GROWTH_FACTOR; | ||
| }); | ||
|
|
||
| test("Sets gem path for version managers based on shims", async () => { | ||
| sandbox.stub(vscode.workspace, "getConfiguration").returns({ | ||
| get: (name: string) => { | ||
| if (name === "rubyVersionManager") { | ||
| return { identifier: ManagerIdentifier.Rbenv }; | ||
| } else if (name === "bundleGemfile") { | ||
| return ""; | ||
| } | ||
|
|
||
| return undefined; | ||
| stubWorkspaceConfiguration(sandbox, { | ||
| rubyLsp: { | ||
| rubyVersionManager: { identifier: ManagerIdentifier.Rbenv }, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this stub out the |
||
| bundleGemfile: "", | ||
| }, | ||
| } as unknown as vscode.WorkspaceConfiguration); | ||
| }); | ||
|
|
||
| const envStub = [ | ||
| "3.3.5", | ||
|
|
@@ -163,19 +163,24 @@ suite("Ruby environment activation", () => { | |
| }); | ||
|
|
||
| test("Clears outdated workspace Ruby path caches", async () => { | ||
| const manager = process.env.CI ? ManagerIdentifier.None : ManagerIdentifier.Chruby; | ||
| stubWorkspaceConfiguration(sandbox, { | ||
| rubyLsp: { | ||
| rubyVersionManager: { identifier: ManagerIdentifier.None }, | ||
| bundleGemfile: "", | ||
| }, | ||
| }); | ||
|
|
||
| sandbox.stub(vscode.workspace, "getConfiguration").returns({ | ||
| get: (name: string) => { | ||
| if (name === "rubyVersionManager") { | ||
| return { identifier: manager }; | ||
| } else if (name === "bundleGemfile") { | ||
| return ""; | ||
| } | ||
| const envStub = [ | ||
| "3.3.5", | ||
| "~/.gem/ruby/3.3.5,/opt/rubies/3.3.5/lib/ruby/gems/3.3.0", | ||
|
Comment on lines
+174
to
+175
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed some of the values are repeated, could they be constants? Or defaults as part of a helper function? |
||
| "true", | ||
| `ANY${VALUE_SEPARATOR}true`, | ||
| ].join(FIELD_SEPARATOR); | ||
|
|
||
| return undefined; | ||
| }, | ||
| } as unknown as vscode.WorkspaceConfiguration); | ||
| sandbox.stub(common, "asyncExec").resolves({ | ||
| stdout: "", | ||
| stderr: `${ACTIVATION_SEPARATOR}${envStub}${ACTIVATION_SEPARATOR}`, | ||
| }); | ||
|
|
||
| await context.workspaceState.update( | ||
| `rubyLsp.workspaceRubyPath.${workspaceFolder.name}`, | ||
|
|
@@ -202,18 +207,13 @@ suite("Ruby environment activation", () => { | |
| index: 0, | ||
| }; | ||
|
|
||
| sandbox.stub(vscode.workspace, "getConfiguration").returns({ | ||
| get: (name: string) => { | ||
| if (name === "rubyVersionManager") { | ||
| return { identifier: ManagerIdentifier.None }; | ||
| } else if (name === "bundleGemfile") { | ||
| // eslint-disable-next-line no-template-curly-in-string | ||
| return "${workspaceFolder}/Gemfile"; | ||
| } | ||
|
|
||
| return undefined; | ||
| stubWorkspaceConfiguration(sandbox, { | ||
| rubyLsp: { | ||
| rubyVersionManager: { identifier: ManagerIdentifier.None }, | ||
| // eslint-disable-next-line no-template-curly-in-string | ||
| bundleGemfile: "${workspaceFolder}/Gemfile", | ||
| }, | ||
| } as unknown as vscode.WorkspaceConfiguration); | ||
| }); | ||
|
|
||
| const envStub = [ | ||
| "3.3.5", | ||
|
|
@@ -235,17 +235,12 @@ suite("Ruby environment activation", () => { | |
| }); | ||
|
|
||
| test("Appends YJIT flag to existing RUBYOPT for Ruby 3.2", async () => { | ||
| sandbox.stub(vscode.workspace, "getConfiguration").returns({ | ||
| get: (name: string) => { | ||
| if (name === "rubyVersionManager") { | ||
| return { identifier: ManagerIdentifier.None }; | ||
| } else if (name === "bundleGemfile") { | ||
| return ""; | ||
| } | ||
|
|
||
| return undefined; | ||
| stubWorkspaceConfiguration(sandbox, { | ||
| rubyLsp: { | ||
| rubyVersionManager: { identifier: ManagerIdentifier.None }, | ||
| bundleGemfile: "", | ||
| }, | ||
| } as unknown as vscode.WorkspaceConfiguration); | ||
| }); | ||
|
|
||
| const envStub = [ | ||
| "3.2.0", | ||
|
|
@@ -275,17 +270,12 @@ suite("Ruby environment activation", () => { | |
|
|
||
| const nonExistentGemfile = path.join(tmpPath, "nonexistent", "Gemfile"); | ||
|
|
||
| sandbox.stub(vscode.workspace, "getConfiguration").returns({ | ||
| get: (name: string) => { | ||
| if (name === "bundleGemfile") { | ||
| return nonExistentGemfile; | ||
| } else if (name === "rubyVersionManager") { | ||
| return { identifier: ManagerIdentifier.None }; | ||
| } | ||
|
|
||
| return undefined; | ||
| stubWorkspaceConfiguration(sandbox, { | ||
| rubyLsp: { | ||
| rubyVersionManager: { identifier: ManagerIdentifier.None }, | ||
| bundleGemfile: nonExistentGemfile, | ||
| }, | ||
| } as unknown as vscode.WorkspaceConfiguration); | ||
| }); | ||
|
|
||
| const ruby = new Ruby(context, tmpWorkspaceFolder, outputChannel, FAKE_TELEMETRY); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to make sure
hasbehave the same waygetdoes to prevent mismatching results in the future?