From a3ce88b4d71ebee0a4aa991420906ec5c5edf0ad Mon Sep 17 00:00:00 2001 From: Jane Lusby Date: Wed, 15 Apr 2020 09:20:41 -0700 Subject: [PATCH] add some tests --- src/main.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/main.rs b/src/main.rs index 6a06ef7437c..3e29c02e4b2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -181,3 +181,40 @@ where Err(exit_status.code().unwrap_or(-1)) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + #[should_panic] + fn fix_without_unstable() { + let args = "cargo clippy --fix".split_whitespace().map(ToString::to_string); + let _ = ClippyCmd::new(args); + } + + #[test] + fn fix_unstable() { + let args = "cargo clippy --fix -Zunstable-options".split_whitespace().map(ToString::to_string); + let cmd = ClippyCmd::new(args); + assert_eq!("fix", cmd.cmd); + assert_eq!("RUSTC_WORKSPACE_WRAPPER", cmd.path_env()); + assert!(cmd.args.iter().find(|arg| arg.ends_with("unstable-options")).is_some()); + } + + #[test] + fn check() { + let args = "cargo clippy".split_whitespace().map(ToString::to_string); + let cmd = ClippyCmd::new(args); + assert_eq!("check", cmd.cmd); + assert_eq!("RUSTC_WRAPPER", cmd.path_env()); + } + + #[test] + fn check_unstable() { + let args = "cargo clippy -Zunstable-options".split_whitespace().map(ToString::to_string); + let cmd = ClippyCmd::new(args); + assert_eq!("check", cmd.cmd); + assert_eq!("RUSTC_WORKSPACE_WRAPPER", cmd.path_env()); + } +}