Add verbose / basic subcommand tests
This commit is contained in:
parent
9c86450a3f
commit
0a512e60ce
2 changed files with 28 additions and 4 deletions
|
@ -34,7 +34,7 @@ pub fn get_matches() -> ArgMatches<'static> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub fn get_matches_for(args : Vec<String>) -> Result<ArgMatches<'static>> {
|
pub fn get_matches_for(args : Vec<&str>) -> Result<ArgMatches<'static>> {
|
||||||
return build().get_matches_from_safe(args);
|
return build().get_matches_from_safe(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,31 @@
|
||||||
use args;
|
use args;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn error_if_no_subcommand() {
|
fn incorrect_subcommand() {
|
||||||
let out = args::get_matches_for(vec!("mdp".into()));
|
assert!(args::get_matches_for(vec!("mdp")).is_err());
|
||||||
assert!(out.is_err());
|
assert!(args::get_matches_for(vec!("mdp", "invalid")).is_err());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn verbose_number() {
|
||||||
|
fn get_verbose_level(arg_list: Vec<&str>) -> u64 {
|
||||||
|
return args::get_verbose(args::get_matches_for(arg_list).unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_eq!(get_verbose_level(vec!("mdp", "build", "-v")), 1);
|
||||||
|
assert_eq!(get_verbose_level(vec!("mdp", "build", "-vv")), 2);
|
||||||
|
assert_eq!(get_verbose_level(vec!("mdp", "-v", "build", "-vv")), 3);
|
||||||
|
assert_eq!(get_verbose_level(vec!("mdp", "-vv", "build", "-v")), 3);
|
||||||
|
assert_eq!(get_verbose_level(vec!("mdp", "-v", "build", "-v")), 2);
|
||||||
|
assert_eq!(get_verbose_level(vec!("mdp", "-v", "build")), 1);
|
||||||
|
assert_eq!(get_verbose_level(vec!("mdp", "--verbose", "build", "-v")), 2);
|
||||||
|
assert_eq!(get_verbose_level(vec!("mdp", "-v", "build", "--verbose")), 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn build_subcommand() {
|
||||||
|
let out = args::get_matches_for(vec!("mdp", "build"));
|
||||||
|
assert!(out.is_ok());
|
||||||
|
assert_eq!(out.unwrap().subcommand_name().unwrap(), "build");
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue