Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: ensure tests reset #2134

Merged
merged 1 commit into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/cli/latest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,35 +66,44 @@ static AFTER_LONG_HELP: &str = color_print::cstr!(

#[cfg(test)]
mod tests {
use crate::test::reset;
use test_log::test;

#[test]
fn test_latest() {
reset();
assert_cli_snapshot!("latest", "dummy@1");
}

#[test]
fn test_latest_asdf_format() {
reset();
assert_cli_snapshot!("latest", "dummy", "1");
}

#[test]
fn test_latest_system() {
reset();
let err = assert_cli_err!("latest", "dummy@system");
assert_snapshot!(err);
}

#[test]
fn test_latest_installed() {
reset();
assert_cli_snapshot!("latest", "dummy");
}

#[test]
fn test_latest_missing_plugin() {
reset();
let stdout = assert_cli_err!("latest", "invalid_plugin");
assert_snapshot!(stdout);
}

#[test]
fn test_latest_alias() {
reset();
let stdout = assert_cli!("latest", "tiny@lts");
assert_str_eq!(stdout, "3.1.0");
}
Expand Down
6 changes: 6 additions & 0 deletions src/cli/plugins/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,26 +120,32 @@ static AFTER_LONG_HELP: &str = color_print::cstr!(
#[cfg(test)]
mod tests {
use crate::cli::tests::grep;
use crate::test::reset;
use test_log::test;

#[test]
fn test_plugin_list() {
reset();
assert_cli_snapshot!("plugin", "list");
}

#[test]
fn test_plugin_list_urls() {
reset();
let stdout = assert_cli!("plugin", "list", "--urls");
assert!(stdout.contains("dummy"))
}

#[test]
fn test_plugin_list_all() {
reset();
let stdout = assert_cli!("plugin", "list", "--all", "--urls");
assert_snapshot!(grep(stdout, "zephyr"));
}

#[test]
fn test_plugin_refs() {
reset();
let stdout = assert_cli!("plugin", "list", "--refs");
assert!(stdout.contains("dummy"))
}
Expand Down
4 changes: 4 additions & 0 deletions src/cli/render_help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,15 @@ fn remove_trailing_spaces(s: &str) -> String {

#[cfg(test)]
mod tests {
use crate::test::reset;
use std::fs;

use crate::file;
use test_log::test;

#[test]
fn test_render_help() {
reset();
file::create_dir_all("docs").unwrap();
file::write(
"docs/cli-reference.md",
Expand All @@ -131,5 +134,6 @@ mod tests {
assert_cli!("render-help");
let readme = fs::read_to_string("docs/cli-reference.md").unwrap();
assert!(readme.contains("# Commands"));
file::remove_file("docs/cli-reference.md").unwrap();
}
}
1 change: 1 addition & 0 deletions src/cli/which.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ static AFTER_LONG_HELP: &str = color_print::cstr!(
#[cfg(test)]
mod tests {
use crate::test::reset;
use test_log::test;

#[test]
fn test_which() {
Expand Down
4 changes: 4 additions & 0 deletions src/path_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,12 @@ impl FromIterator<PathBuf> for PathEnv {
#[cfg(test)]
mod tests {
use super::*;
use crate::test::reset;
use test_log::test;

#[test]
fn test_path_env() {
reset();
let mut path_env = PathEnv::from_iter(
[
"/before-1",
Expand All @@ -113,6 +116,7 @@ mod tests {

#[test]
fn test_path_env_no_mise() {
reset();
let mut path_env = PathEnv::from_iter(
[
"/before-1",
Expand Down
8 changes: 7 additions & 1 deletion src/shell/bash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,35 +99,41 @@ impl Shell for Bash {

#[cfg(test)]
mod tests {
use crate::test::replace_path;
use crate::test::{replace_path, reset};
use test_log::test;

use super::*;

#[test]
fn test_activate() {
reset();
let bash = Bash::default();
let exe = Path::new("/some/dir/mise");
assert_snapshot!(bash.activate(exe, " --status".into()));
}

#[test]
fn test_set_env() {
reset();
assert_snapshot!(Bash::default().set_env("FOO", "1"));
}

#[test]
fn test_prepend_env() {
reset();
let bash = Bash::default();
assert_snapshot!(replace_path(&bash.prepend_env("PATH", "/some/dir:/2/dir")));
}

#[test]
fn test_unset_env() {
reset();
assert_snapshot!(Bash::default().unset_env("FOO"));
}

#[test]
fn test_deactivate() {
reset();
let deactivate = Bash::default().deactivate();
assert_snapshot!(replace_path(&deactivate));
}
Expand Down
3 changes: 3 additions & 0 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ fn init() {
}

pub fn reset() {
Config::reset();
forge::reset();
config_file::reset();
env::set_current_dir(env::HOME.join("cwd")).unwrap();
env::remove_var("MISE_FAILURE");
file::remove_all(&*dirs::TRUSTED_CONFIGS).unwrap();
Expand Down
Loading
Loading