Skip to content

Commit

Permalink
feat: expose test-tool command (#4224)
Browse files Browse the repository at this point in the history
* feat: expose `test-tool` command

Also added --all-config option

* feat: expose `test-tool` command

Also added --all-config option

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
jdx and autofix-ci[bot] authored Jan 25, 2025
1 parent 9f26db8 commit 3ca3d9c
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/.vitepress/cli_commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ export const commands: { [key: string]: Command } = {
},
},
"test-tool": {
hide: true,
hide: false,
},
tool: {
hide: false,
Expand Down
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
22 changes: 17 additions & 5 deletions src/cli/test_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,22 @@ use crate::toolset::{InstallOptions, ToolsetBuilder};
use crate::ui::time;
use crate::{dirs, env, file};
use eyre::{bail, eyre, Result};
use std::collections::BTreeSet;
use std::path::PathBuf;

/// Test a tool installs and executes
#[derive(Debug, clap::Args)]
#[clap(verbatim_doc_comment, after_long_help = AFTER_LONG_HELP, hide = true)]
#[clap(verbatim_doc_comment, after_long_help = AFTER_LONG_HELP)]
pub struct TestTool {
#[clap(required_unless_present = "all")]
/// Tool name to test
#[clap(required_unless_present_any = ["all", "all_config"])]
pub tool: Option<ToolArg>,
#[clap(long, short, conflicts_with = "tool")]
/// Test every tool specified in registry.toml
#[clap(long, short, conflicts_with = "tool", conflicts_with = "all_config")]
pub all: bool,
/// Test all tools specified in config files
#[clap(long, conflicts_with = "tool", conflicts_with = "all")]
pub all_config: bool,
/// Also test tools not defined in registry.toml, guessing how to test it
#[clap(long)]
pub include_non_defined: bool,
Expand All @@ -43,7 +49,10 @@ impl TestTool {
"---".to_string(),
"---".to_string(),
])?;
let mut found = self.all;
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 = false;
for (i, (short, rt)) in REGISTRY.iter().enumerate() {
if *env::TEST_TRANCHE_COUNT > 0 && (i % *env::TEST_TRANCHE_COUNT) != *env::TEST_TRANCHE
{
Expand All @@ -57,6 +66,9 @@ impl TestTool {
found = true;
tool = t.clone();
}
if self.all_config && !tools.contains(rt.short) {
continue;
}
if self.all && rt.short != *short {
// means this is an alias
continue;
Expand Down Expand Up @@ -89,7 +101,7 @@ impl TestTool {
}
};
}
if !found {
if !found && self.tool.is_some() {
bail!("{} not found", self.tool.unwrap().short);
}
if !errored.is_empty() {
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 3ca3d9c

Please sign in to comment.