Better tests on error
This commit is contained in:
parent
0a512e60ce
commit
00f7de96b6
2 changed files with 23 additions and 5 deletions
|
@ -15,7 +15,6 @@ fn build() -> App<'static, 'static> {
|
||||||
.setting(AppSettings::SubcommandRequiredElseHelp)
|
.setting(AppSettings::SubcommandRequiredElseHelp)
|
||||||
.global_setting(AppSettings::VersionlessSubcommands)
|
.global_setting(AppSettings::VersionlessSubcommands)
|
||||||
.global_setting(AppSettings::ColoredHelp)
|
.global_setting(AppSettings::ColoredHelp)
|
||||||
.global_setting(AppSettings::GlobalVersion)
|
|
||||||
.global_setting(AppSettings::StrictUtf8)
|
.global_setting(AppSettings::StrictUtf8)
|
||||||
.arg(Arg::with_name("verbose")
|
.arg(Arg::with_name("verbose")
|
||||||
.global(true)
|
.global(true)
|
||||||
|
@ -24,8 +23,7 @@ fn build() -> App<'static, 'static> {
|
||||||
.help("Show verbose output")
|
.help("Show verbose output")
|
||||||
.multiple(true)
|
.multiple(true)
|
||||||
)
|
)
|
||||||
.subcommand(get_build_command())
|
.subcommand(get_build_command());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,17 @@
|
||||||
use args;
|
use args;
|
||||||
|
|
||||||
|
use std::error::Error;
|
||||||
|
use clap::ErrorKind;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn incorrect_subcommand() {
|
fn incorrect_subcommand() {
|
||||||
assert!(args::get_matches_for(vec!("mdp")).is_err());
|
let out = args::get_matches_for(vec!("mdp"));
|
||||||
assert!(args::get_matches_for(vec!("mdp", "invalid")).is_err());
|
assert!(out.is_err());
|
||||||
|
assert_eq!(out.unwrap_err().kind, ErrorKind::MissingArgumentOrSubcommand);
|
||||||
|
|
||||||
|
let out = args::get_matches_for(vec!("mdp", "invalid"));
|
||||||
|
assert!(out.is_err());
|
||||||
|
assert_eq!(out.unwrap_err().kind, ErrorKind::UnknownArgument);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -29,3 +37,15 @@ fn build_subcommand() {
|
||||||
assert!(out.is_ok());
|
assert!(out.is_ok());
|
||||||
assert_eq!(out.unwrap().subcommand_name().unwrap(), "build");
|
assert_eq!(out.unwrap().subcommand_name().unwrap(), "build");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn version_string() {
|
||||||
|
let out = args::get_matches_for(vec!("mdp", "--version"));
|
||||||
|
assert!(out.is_err());
|
||||||
|
assert_eq!(out.unwrap_err().kind, ErrorKind::VersionDisplayed);
|
||||||
|
|
||||||
|
let out = args::get_matches_for(vec!("mdp", "build", "--version"));
|
||||||
|
assert!(out.is_err());
|
||||||
|
assert_eq!(out.unwrap_err().kind, ErrorKind::UnknownArgument);
|
||||||
|
}
|
||||||
|
|
Reference in a new issue