Add verbose / basic subcommand tests

This commit is contained in:
Jake Howard 2017-07-13 09:45:19 +01:00
parent 9c86450a3f
commit 0a512e60ce
Signed by: jake
GPG key ID: 57AFB45680EDD477
2 changed files with 28 additions and 4 deletions

View file

@ -34,7 +34,7 @@ pub fn get_matches() -> ArgMatches<'static> {
}
#[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);
}

View file

@ -1,7 +1,31 @@
use args;
#[test]
fn error_if_no_subcommand() {
let out = args::get_matches_for(vec!("mdp".into()));
assert!(out.is_err());
fn incorrect_subcommand() {
assert!(args::get_matches_for(vec!("mdp")).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");
}