Skip to content

Commit

Permalink
test: move use tests to e2e (#2924)
Browse files Browse the repository at this point in the history
* test: move use tests to e2e

* [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 Nov 5, 2024
1 parent 4927c37 commit 5a288f2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 172 deletions.
31 changes: 31 additions & 0 deletions e2e/cli/test_use
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,34 @@ assert_contains "mise use --env local dummy@2" "dummy@2."
assert "cat .mise.local.toml" '[tools]
dummy = "2"'
assert "mise current dummy" "2.0.0"
rm .mise.local.toml

mise use dummy@1 dummy@2
assert "mise current dummy" "1.0.0 2.0.0"

mise use --pin dummy@1
assert "cat .mise.toml" '[tools]
dummy = "1.0.0"'

MISE_PIN=1 mise use --fuzzy dummy@1
assert "cat .mise.toml" '[tools]
dummy = "1"'

MISE_PIN=1 mise use dummy@1 --path .mise.local.toml
assert "cat .mise.local.toml" '[tools]
dummy = "1.0.0"'

mise use --rm dummy --path .mise.local.toml
assert "cat .mise.local.toml" ""

rm -f .mise.local.toml .mise.toml
echo "dummy 1.0.0" >.tool-versions
mise use dummy@2
assert "cat .tool-versions" "dummy 2"

rm -f .tool-versions

mise use -g dummy@1
assert "cat ~/.config/mise/config.toml" '[tools]
dummy = "1"'
rm -f ~/.config/mise/config.toml
172 changes: 0 additions & 172 deletions src/cli/use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,175 +235,3 @@ static AFTER_LONG_HELP: &str = color_print::cstr!(
$ <bold>mise use --env staging node@20</bold>
"#
);

#[cfg(test)]
mod tests {
use insta::assert_snapshot;

use crate::test::reset;
use crate::{dirs, env, file};

#[test]
fn test_use_local_reuse() {
reset();
let cf_path = env::current_dir().unwrap().join(".test.mise.toml");
file::write(&cf_path, "").unwrap();

assert_cli_snapshot!("use", "tiny@2", @"mise ~/cwd/.test.mise.toml tools: [email protected]");
assert_snapshot!(file::read_to_string(&cf_path).unwrap(), @r###"
[tools]
tiny = "2"
"###);

assert_cli_snapshot!("use", "tiny@1", "tiny@2", "tiny@3", @r"
mise ~/cwd/.test.mise.toml tools: [email protected], [email protected], [email protected]
mise mise [email protected] installing
mise mise [email protected] installing
mise mise [email protected] ~/data/plugins/tiny/bin/install
mise mise [email protected] ✓ installed
");
assert_snapshot!(file::read_to_string(&cf_path).unwrap(), @r###"
[tools]
tiny = ["1", "2", "3"]
"###);

assert_cli_snapshot!("use", "--pin", "tiny", @"mise ~/cwd/.test.mise.toml tools: [email protected]");
assert_snapshot!(file::read_to_string(&cf_path).unwrap(), @r###"
[tools]
tiny = "3.1.0"
"###);

assert_cli_snapshot!("use", "--fuzzy", "tiny@2", @"mise ~/cwd/.test.mise.toml tools: [email protected]");
assert_snapshot!(file::read_to_string(&cf_path).unwrap(), @r###"
[tools]
tiny = "2"
"###);

let p = cf_path.to_string_lossy().to_string();
assert_cli_snapshot!("use", "--rm", "tiny", "--path", &p, @"mise ~/cwd/.test.mise.toml tools:");
assert_snapshot!(file::read_to_string(&cf_path).unwrap(), @"");

let _ = file::remove_file(&cf_path);
}

#[test]
fn test_use_local_create() {
reset();
let _ = file::remove_file(env::current_dir().unwrap().join(".test-tool-versions"));
let cf_path = env::current_dir().unwrap().join(".test.mise.toml");

assert_cli_snapshot!("use", "tiny@2", @"mise ~/cwd/.test.mise.toml tools: [email protected]");
assert_snapshot!(file::read_to_string(&cf_path).unwrap(), @r###"
[tools]
tiny = "2"
"###);

assert_cli_snapshot!("use", "tiny@1", "tiny@2", "tiny@3", @r"
mise ~/cwd/.test.mise.toml tools: [email protected], [email protected], [email protected]
mise mise [email protected] installing
mise mise [email protected] installing
mise mise [email protected] ~/data/plugins/tiny/bin/install
mise mise [email protected] ✓ installed
");
assert_snapshot!(file::read_to_string(&cf_path).unwrap(), @r###"
[tools]
tiny = ["1", "2", "3"]
"###);

assert_cli_snapshot!("use", "--pin", "tiny", @"mise ~/cwd/.test.mise.toml tools: [email protected]");
assert_snapshot!(file::read_to_string(&cf_path).unwrap(), @r###"
[tools]
tiny = "3.1.0"
"###);

assert_cli_snapshot!("use", "--fuzzy", "tiny@2", @"mise ~/cwd/.test.mise.toml tools: [email protected]");
assert_snapshot!(file::read_to_string(&cf_path).unwrap(), @r###"
[tools]
tiny = "2"
"###);

let p = cf_path.to_string_lossy().to_string();
assert_cli_snapshot!("use", "--rm", "tiny", "--path", &p, @"mise ~/cwd/.test.mise.toml tools:");
assert_snapshot!(file::read_to_string(&cf_path).unwrap(), @"");

let _ = file::remove_file(&cf_path);
}

#[test]
fn test_use_local_tool_versions_reuse() {
reset();
let cf_path = env::current_dir().unwrap().join(".test-tool-versions");
file::write(&cf_path, "").unwrap();

assert_cli_snapshot!("use", "tiny@3", @"mise ~/cwd/.test-tool-versions tools: [email protected]");
assert_snapshot!(file::read_to_string(&cf_path).unwrap(), @r###"
tiny 3
"###);

let _ = file::remove_file(&cf_path);
}

#[test]
fn test_use_local_tool_versions_create() {
reset();
let cf_path = env::current_dir().unwrap().join(".test-tool-versions");

assert_cli_snapshot!("use", "tiny@3", @"mise ~/cwd/.test-tool-versions tools: [email protected]");
assert_snapshot!(file::read_to_string(&cf_path).unwrap(), @r###"
tiny 3
"###);

let _ = file::remove_file(&cf_path);
}

#[test]
fn test_use_global() {
reset();
let cf_path = dirs::CONFIG.join("config.toml");
let orig = file::read_to_string(&cf_path).unwrap();

assert_cli_snapshot!("use", "-g", "tiny@2", @r"
mise ~/config/config.toml tools: [email protected]
mise mise [email protected] installing
mise mise [email protected] installing
mise mise [email protected] ~/data/plugins/tiny/bin/install
mise mise [email protected] ✓ installed
mise tiny is defined in ~/cwd/.test-tool-versions which overrides the global config (~/config/config.toml)
");
assert_snapshot!(file::read_to_string(&cf_path).unwrap(), @r##"
[env]
TEST_ENV_VAR = 'test-123'
[alias.tiny]
"my/alias" = '3.0'
[tasks.configtask]
run = 'echo "configtask:"'
[tasks.lint]
run = 'echo "linting!"'
[tasks.test]
run = 'echo "testing!"'
[tasks."shell invalid"]
shell = 'bash'
run = 'echo "invalid shell"'
[tasks.shell]
shell = 'bash -c'
run = '''
#MISE outputs=["$MISE_PROJECT_ROOT/test/test-build-output.txt"]
cd "$MISE_PROJECT_ROOT" || exit 1
echo "using shell $0" > test-build-output.txt
'''
[settings]
always_keep_download= true
always_keep_install= true
legacy_version_file= true
plugin_autoupdate_last_check_duration = "20m"
jobs = 2
[tools]
tiny = "2"
"##);

file::write(&cf_path, orig).unwrap();
}
}

0 comments on commit 5a288f2

Please sign in to comment.