-
-
Notifications
You must be signed in to change notification settings - Fork 949
test(vfox): replace flaky external tests with local dummy plugin #6403
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
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 |
|---|---|---|
| @@ -1,13 +1,13 @@ | ||
| --- Return all available versions provided by this plugin | ||
| --- @param ctx table Empty table used as context, for future extension | ||
| --- @return table Descriptions of available versions and accompanying tool descriptions | ||
| --- Get the available version list. | ||
| --- @param ctx table Empty table, no data provided. Always {}. | ||
| --- @return table Version list | ||
| function PLUGIN:Available(ctx) | ||
| return { | ||
| { | ||
| version = "1.0.0", | ||
| version = "1.0.0" | ||
| }, | ||
| { | ||
| version = "1.0.1", | ||
| version = "1.0.1" | ||
| }, | ||
| } | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,16 @@ | ||
| --- Parse legacy version files like .node-version, .nvmrc, etc. | ||
| --- @param ctx table Context information | ||
| --- @field ctx.filepath string Path to the legacy file | ||
| --- @return table Version information | ||
| --- Parse the legacy file found by vfox to determine the version of the tool. | ||
| --- Useful to extract version numbers from files like JavaScript's package.json or Golangs go.mod. | ||
| function PLUGIN:ParseLegacyFile(ctx) | ||
| local filepath = ctx.filepath | ||
| local content = io.open(filepath, "r") | ||
| if content then | ||
| local version = content:read("*line") | ||
| content:close() | ||
| if version then | ||
| -- Remove any "v" prefix and trim whitespace | ||
| version = version:gsub("^v", ""):match("^%s*(.-)%s*$") | ||
| return { | ||
| version = version | ||
| } | ||
| end | ||
| local file = io.open(filepath, "r") | ||
| local content = file:read("*a") | ||
| file:close() | ||
|
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. |
||
| content = content:gsub("%s+", "") | ||
| if content == "" then | ||
| return {} | ||
| end | ||
|
|
||
| return { | ||
| version = nil | ||
| version = content | ||
| } | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,10 +2,15 @@ function PLUGIN:PostInstall(ctx) | |
| --- SDK installation root path | ||
| local rootPath = ctx.rootPath | ||
| local runtimeVersion = ctx.runtimeVersion | ||
| --- Other SDK information, the `addition` field returned in PreInstall, obtained by name | ||
| --TODO | ||
| --local sdkInfo = ctx.sdkInfo['dummy'] | ||
| --local path = sdkInfo.path | ||
| --local version = sdkInfo.version | ||
| --local name = sdkInfo.name | ||
| end | ||
|
|
||
| -- Create the installation directory structure for dummy plugin | ||
| os.execute("mkdir -p " .. rootPath .. "/bin") | ||
|
||
|
|
||
| -- Create a dummy executable | ||
| local dummy_file = io.open(rootPath .. "/bin/dummy", "w") | ||
| if dummy_file then | ||
| dummy_file:write("#!/bin/sh\necho 'dummy version 1.0.0'\n") | ||
| dummy_file:close() | ||
| os.execute("chmod +x " .. rootPath .. "/bin/dummy") | ||
|
||
| end | ||
|
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. Bug: Cross-Platform Shell Command IssuesThe |
||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,4 +9,4 @@ function PLUGIN:PreInstall(ctx) | |
| return { | ||
| version = version, | ||
| } | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| --- | ||
| source: src/vfox.rs | ||
| source: crates/vfox/src/vfox.rs | ||
| expression: output | ||
| --- | ||
| [EnvKey { key: "PATH", value: "<INSTALL_DIR>/nodejs/20.0.0/bin" }] | ||
| [EnvKey { key: "PATH", value: "<INSTALL_DIR>/dummy/1.0.0/bin" }] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,5 @@ | ||
| --- | ||
| source: src/vfox.rs | ||
| source: crates/vfox/src/vfox.rs | ||
| expression: out | ||
| snapshot_kind: text | ||
| --- | ||
| Metadata { name: "nodejs", legacy_filenames: [".node-version", ".nvmrc"], version: "0.3.0", description: Some("Node.js runtime environment."), author: None, license: Some("Apache 2.0"), homepage: Some("https://github.com/version-fox/vfox-nodejs"), hooks: {"available", "env_keys", "parse_legacy_file", "pre_install", "pre_use"} } | ||
| Metadata { name: "dummy", legacy_filenames: [".dummy-version"], version: "0.3.0", description: Some("Dummy plugin for testing."), author: None, license: Some("Apache 2.0"), homepage: Some("https://github.com/version-fox/vfox-nodejs"), hooks: {"available", "env_keys", "parse_legacy_file", "post_install", "pre_install"} } |
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.
If io.open fails and returns nil, calling file:read() and file:close() on nil will cause a runtime error. Add a nil check after io.open before proceeding with file operations.