-
-
Notifications
You must be signed in to change notification settings - Fork 374
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
4927c37
commit 5a288f2
Showing
2 changed files
with
31 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(); | ||
} | ||
} |