Skip to content

Commit

Permalink
test: move ls tests to e2e (#3146)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx authored Nov 22, 2024
1 parent b5bdf53 commit c107066
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 141 deletions.
30 changes: 30 additions & 0 deletions e2e/cli/test_ls
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
#!/usr/bin/env bash

assert "mise use -g dummy@ref:master"
assert "mise use tiny@3"
assert_contains "mise ls" "dummy ref:master ~/.config/mise/config.toml ref:master"
assert_contains "mise ls tiny" "tiny 3.1.0 ~/workdir/mise.toml 3"
assert "mise i [email protected]"
assert_contains "mise ls" "tiny 2.0.0"
assert_not_contains "mise ls -c" "tiny 2.0.0"
assert_contains "mise ls --prefix=3 tiny" "3.1.0"
assert_not_contains "mise ls --prefix=2 tiny" "3.1.0"
assert_contains "mise ls --global" "dummy"
assert_not_contains "mise ls --global" "tiny"

mise ls tiny --json >json
assert "cat json | jq -r '.[0].installed'" "true"
assert "cat json | jq -r '.[0].active'" "false"
assert "cat json | jq -r '.[0].version'" "2.0.0"
assert "cat json | jq -r '.[0].install_path'" "$MISE_DATA_DIR/installs/tiny/2.0.0"
mise ls --json >json
assert "cat json | jq -r '.tiny[1].installed'" "true"
assert "cat json | jq -r '.tiny[1].active'" "true"
assert "cat json | jq -r '.tiny[1].version'" "3.1.0"
assert "cat json | jq -r '.tiny[1].install_path'" "$MISE_DATA_DIR/installs/tiny/3.1.0"

assert "mise rm [email protected]"
assert_contains "mise ls tiny" "tiny 3.1.0 (missing) ~/workdir/mise.toml 3"
assert_contains "mise ls --missing tiny" "tiny 3.1.0 (missing) ~/workdir/mise.toml 3"
assert_not_contains "mise ls --missing tiny" "2.0.0"

assert_fail "mise ls missing-tool" "missing-tool not found in mise tool registry"

mise use cargo-binstall
mise i cargo:usage-cli
assert_contains "mise ls" "cargo:usage-cli"
Expand Down
2 changes: 1 addition & 1 deletion e2e/run_test
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ within_isolated_env() {
MISE_TMP_DIR="$TEST_TMPDIR" \
MISE_TRACE="${MISE_TRACE:-0}" \
MISE_TRUSTED_CONFIG_PATHS="$TEST_ISOLATED_DIR" \
MISE_USE_VERSIONS_HOST="${MISE_USE_VERSIONS_HOST:-0}" \
MISE_USE_VERSIONS_HOST="${MISE_USE_VERSIONS_HOST:-1}" \
MISE_YES=1 \
PATH="${CARGO_TARGET_DIR:-$ROOT/target}/debug:$HOME/mise/bin:$CARGO_HOME/bin:$TEST_HOME/bin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin" \
ROOT="$ROOT" \
Expand Down
1 change: 0 additions & 1 deletion mise.usage.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,6 @@ It's a useful command to get the current state of your tools."#
flag "-g --global" help="Only show tool versions currently specified in the global mise.toml"
flag "-i --installed" help="Only show tool versions that are installed (Hides tools defined in mise.toml but not installed)"
flag "-o --offline" help="Don't fetch information such as outdated versions"
flag "--parseable" help="Output in an easily parseable format" hide=true
flag "-J --json" help="Output in JSON format"
flag "-m --missing" help="Display missing tool versions"
flag "--prefix" help="Display versions matching this prefix" {
Expand Down
141 changes: 2 additions & 139 deletions src/cli/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,8 @@ pub struct Ls {
#[clap(long, short)]
offline: bool,

/// Output in an easily parseable format
#[clap(long, hide = true, conflicts_with = "json")]
parseable: bool,

/// Output in JSON format
#[clap(long, short = 'J', overrides_with = "parseable")]
#[clap(long, short = 'J')]
json: bool,

/// Display missing tool versions
Expand All @@ -70,7 +66,7 @@ pub struct Ls {
prefix: Option<String>,

/// Don't display headers
#[clap(long, alias = "no-headers", verbatim_doc_comment, conflicts_with_all = & ["json", "parseable"])]
#[clap(long, alias = "no-headers", verbatim_doc_comment, conflicts_with_all = &["json"])]
no_header: bool,
}

Expand Down Expand Up @@ -99,8 +95,6 @@ impl Ls {
}
if self.json {
self.display_json(runtimes)
} else if self.parseable {
self.display_parseable(runtimes)
} else {
self.display_user(runtimes)
}
Expand Down Expand Up @@ -141,25 +135,6 @@ impl Ls {
Ok(())
}

fn display_parseable(&self, runtimes: Vec<RuntimeRow>) -> Result<()> {
warn!("The parseable output format is deprecated and will be removed in a future release.");
warn!("Please use the regular output format instead which has been modified to be more easily parseable.");
let tvs = runtimes
.into_iter()
.map(|(_, p, tv, _)| (p, tv))
.filter(|(p, tv)| p.is_version_installed(tv, true))
.map(|(_, tv)| tv);
for tv in tvs {
if self.plugin.is_some() {
// only displaying 1 plugin so only show the version
miseprintln!("{}", tv.version);
} else {
miseprintln!("{} {}", tv.ba(), tv.version);
}
}
Ok(())
}

fn display_user(&self, runtimes: Vec<RuntimeRow>) -> Result<()> {
// let data = runtimes
// .into_iter()
Expand Down Expand Up @@ -400,115 +375,3 @@ static AFTER_LONG_HELP: &str = color_print::cstr!(
}
"#
);

#[cfg(test)]
mod tests {
use pretty_assertions::assert_str_eq;

use crate::dirs;
use crate::file::remove_all;
use crate::test::reset;

#[test]
fn test_ls() {
reset();
let _ = remove_all(*dirs::INSTALLS);
assert_cli!("install");
assert_cli_snapshot!("list", @r"
dummy ref:master ~/.test-tool-versions ref:master
tiny 3.1.0 ~/cwd/.test-tool-versions 3
");

assert_cli!("install", "[email protected]");
assert_cli_snapshot!("list", @r"
dummy ref:master ~/.test-tool-versions ref:master
tiny 2.0.0
tiny 3.1.0 ~/cwd/.test-tool-versions 3
");

assert_cli!("uninstall", "[email protected]");
assert_cli_snapshot!("list", @r"
dummy ref:master ~/.test-tool-versions ref:master
tiny 2.0.0
tiny 3.1.0 (missing) ~/cwd/.test-tool-versions 3
");

assert_cli!("uninstall", "[email protected]");
assert_cli_snapshot!("list", @r"
dummy ref:master ~/.test-tool-versions ref:master
tiny 3.1.0 (missing) ~/cwd/.test-tool-versions 3
");

assert_cli!("install");
assert_cli_snapshot!("list", @r"
dummy ref:master ~/.test-tool-versions ref:master
tiny 3.1.0 ~/cwd/.test-tool-versions 3
");
}

#[test]
fn test_ls_current() {
reset();
assert_cli_snapshot!("ls", "-c", @r"
dummy ref:master ~/.test-tool-versions ref:master
tiny 3.1.0 ~/cwd/.test-tool-versions 3
");
}

#[test]
fn test_ls_json() {
reset();
let _ = remove_all(*dirs::INSTALLS);
assert_cli!("install");
assert_cli_snapshot!("ls", "--json");
assert_cli_snapshot!("ls", "--json", "tiny");
}

#[test]
fn test_ls_parseable() {
reset();
let _ = remove_all(*dirs::INSTALLS);
assert_cli!("install");
assert_cli_snapshot!("ls", "--parseable", @r"
dummy ref:master
tiny 3.1.0
mise The parseable output format is deprecated and will be removed in a future release.
mise Please use the regular output format instead which has been modified to be more easily parseable.
");
assert_cli_snapshot!("ls", "--parseable", "tiny", @r"
3.1.0
mise The parseable output format is deprecated and will be removed in a future release.
mise Please use the regular output format instead which has been modified to be more easily parseable.
");
}

#[test]
fn test_ls_missing() {
reset();
assert_cli!("install");
assert_cli_snapshot!("ls", "--missing", @"");
}

#[test]
fn test_ls_missing_plugin() {
reset();
let err = assert_cli_err!("ls", "missing-plugin");
assert_str_eq!(
err.to_string(),
r#"missing-plugin not found in mise tool registry"#
);
}

#[test]
fn test_ls_prefix() {
reset();
assert_cli!("install");
assert_cli_snapshot!("ls", "--plugin=tiny", "--prefix=3", @"tiny 3.1.0 ~/cwd/.test-tool-versions 3");
}

#[test]
fn test_global() {
reset();
assert_cli_snapshot!("ls", "--global", @"");
}
}

0 comments on commit c107066

Please sign in to comment.