Skip to content

Commit

Permalink
feat: expose test-tool command
Browse files Browse the repository at this point in the history
Also added --all-config option
  • Loading branch information
jdx committed Jan 25, 2025
1 parent 1c36957 commit a6e2762
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 8 deletions.
1 change: 1 addition & 0 deletions docs/cli/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ Can also use `MISE_NO_CONFIG=1`
- [`mise tasks info [-J --json] <TASK>`](/cli/tasks/info.md)
- [`mise tasks ls [FLAGS]`](/cli/tasks/ls.md)
- [`mise tasks run [FLAGS] [TASK] [ARGS]...`](/cli/tasks/run.md)
- [`mise test-tool [FLAGS] [TOOL]`](/cli/test-tool.md)
- [`mise tool [FLAGS] <TOOL>`](/cli/tool.md)
- [`mise trust [FLAGS] [CONFIG_FILE]`](/cli/trust.md)
- [`mise uninstall [-a --all] [-n --dry-run] [INSTALLED_TOOL@VERSION]...`](/cli/uninstall.md)
Expand Down
41 changes: 41 additions & 0 deletions docs/cli/test-tool.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# `mise test-tool`

- **Usage**: `mise test-tool [FLAGS] [TOOL]`
- **Source code**: [`src/cli/test_tool.rs`](https://github.com/jdx/mise/blob/main/src/cli/test_tool.rs)

Test a tool installs and executes

## Arguments

### `[TOOL]`

Tool name to test

## Flags

### `-a --all`

Test every tool specified in registry.toml

### `--all-config`

Test all tools specified in config files

### `--include-non-defined`

Also test tools not defined in registry.toml, guessing how to test it

### `-j --jobs <JOBS>`

Number of jobs to run in parallel
[default: 4]

### `--raw`

Directly pipe stdin/stdout/stderr from plugin to user Sets --jobs=1

Examples:

```
mise test-tool ripgrep
```
3 changes: 3 additions & 0 deletions man/man1/mise.1
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ Synchronize tools from other version managers with mise
mise\-tasks(1)
Manage tasks
.TP
mise\-test\-tool(1)
Test a tool installs and executes
.TP
mise\-tool(1)
Gets information about a tool
.TP
Expand Down
7 changes: 4 additions & 3 deletions mise.usage.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -852,15 +852,16 @@ cmd tasks help="Manage tasks" {
mount run="mise tasks --usage"
}
}
cmd test-tool hide=#true help="Test a tool installs and executes" {
cmd test-tool help="Test a tool installs and executes" {
after_long_help "Examples:\n\n $ mise test-tool ripgrep\n"
flag "-a --all"
flag "-a --all" help="Test every tool specified in registry.toml"
flag --all-config help="Test all tools specified in config files"
flag --include-non-defined help="Also test tools not defined in registry.toml, guessing how to test it"
flag "-j --jobs" help="Number of jobs to run in parallel\n[default: 4]" {
arg <JOBS>
}
flag --raw help="Directly pipe stdin/stdout/stderr from plugin to user Sets --jobs=1"
arg "[TOOL]" required=#false
arg "[TOOL]" help="Tool name to test" required=#false
}
cmd tool help="Gets information about a tool" {
after_long_help "Examples:\n\n $ mise tool node\n Backend: core\n Installed Versions: 20.0.0 22.0.0\n Active Version: 20.0.0\n Requested Version: 20\n Config Source: ~/.config/mise/mise.toml\n Tool Options: [none]\n"
Expand Down
4 changes: 4 additions & 0 deletions schema/mise.json
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,10 @@
}
}
},
"os": {
"description": "OS to use for precompiled binaries.",
"type": "string"
},
"override_config_filenames": {
"default": [],
"description": "If set, mise will ignore default config files like `mise.toml` and use these filenames instead. This must be an env var.",
Expand Down
5 changes: 4 additions & 1 deletion scripts/render-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ process.env.MISE_ASDF = 1;
process.env.MISE_VFOX = 1;
process.env.MISE_EXPERIMENTAL = 1;

const stdout = execSync("mise registry --hide-aliased", { encoding: "utf-8" });
const stdout = execSync("mise registry --hide-aliased", {
encoding: "utf-8",
env: { ...process.env, MISE_OS: "linux" },
});

const output = [
`---
Expand Down
7 changes: 7 additions & 0 deletions settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,13 @@ mise use -g bun
```
"""

[os]
env = "MISE_OS"
type = "String"
optional = true
description = "OS to use for precompiled binaries."
default_docs = '"linux" | "macos" | "windows"'

[override_config_filenames]
env = "MISE_OVERRIDE_CONFIG_FILENAMES"
type = "ListString"
Expand Down
2 changes: 1 addition & 1 deletion src/cli/test_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl TestTool {
let config = Config::get();
let ts = ToolsetBuilder::new().build(&config)?;
let tools: BTreeSet<String> = ts.versions.keys().map(|t| t.short.clone()).collect();
let mut found = self.all;
let mut found = false;
for (i, (short, rt)) in REGISTRY.iter().enumerate() {
if *env::TEST_TRANCHE_COUNT > 0 && (i % *env::TEST_TRANCHE_COUNT) != *env::TEST_TRANCHE
{
Expand Down
8 changes: 5 additions & 3 deletions src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ impl RegistryTool {
}
backend_types
});
let platform = format!("{OS}-{ARCH}");
let os = SETTINGS.os.clone().unwrap_or(OS.to_string());
let arch = SETTINGS.arch.clone().unwrap_or(ARCH.to_string());
let platform = format!("{os}-{arch}");
self.backends
.iter()
.filter(|rb| {
rb.platforms.is_empty()
|| rb.platforms.contains(&OS)
|| rb.platforms.contains(&ARCH)
|| rb.platforms.contains(&&*os)
|| rb.platforms.contains(&&*arch)
|| rb.platforms.contains(&&*platform)
})
.map(|rb| rb.full)
Expand Down
43 changes: 43 additions & 0 deletions xtasks/fig/src/mise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2480,6 +2480,49 @@ const completionSpec: Fig.Spec = {
debounce: true,
},
},
{
name: "test-tool",
description: "Test a tool installs and executes",
options: [
{
name: ["-a", "--all"],
description: "Test every tool specified in registry.toml",
isRepeatable: false,
},
{
name: "--all-config",
description: "Test all tools specified in config files",
isRepeatable: false,
},
{
name: "--include-non-defined",
description:
"Also test tools not defined in registry.toml, guessing how to test it",
isRepeatable: false,
},
{
name: ["-j", "--jobs"],
description: "Number of jobs to run in parallel\n[default: 4]",
isRepeatable: false,
args: {
name: "jobs",
},
},
{
name: "--raw",
description:
"Directly pipe stdin/stdout/stderr from plugin to user Sets --jobs=1",
isRepeatable: false,
},
],
args: {
name: "tool",
description: "Tool name to test",
isOptional: true,
generators: completionGeneratorTemplate(`mise registry --complete`),
debounce: true,
},
},
{
name: "tool",
description: "Gets information about a tool",
Expand Down

0 comments on commit a6e2762

Please sign in to comment.