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)
|
||||
.global_setting(AppSettings::VersionlessSubcommands)
|
||||
.global_setting(AppSettings::ColoredHelp)
|
||||
.global_setting(AppSettings::GlobalVersion)
|
||||
.global_setting(AppSettings::StrictUtf8)
|
||||
.arg(Arg::with_name("verbose")
|
||||
.global(true)
|
||||
|
@ -24,8 +23,7 @@ fn build() -> App<'static, 'static> {
|
|||
.help("Show verbose output")
|
||||
.multiple(true)
|
||||
)
|
||||
.subcommand(get_build_command())
|
||||
|
||||
.subcommand(get_build_command());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,9 +1,17 @@
|
|||
use args;
|
||||
|
||||
use std::error::Error;
|
||||
use clap::ErrorKind;
|
||||
|
||||
#[test]
|
||||
fn incorrect_subcommand() {
|
||||
assert!(args::get_matches_for(vec!("mdp")).is_err());
|
||||
assert!(args::get_matches_for(vec!("mdp", "invalid")).is_err());
|
||||
let out = args::get_matches_for(vec!("mdp"));
|
||||
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]
|
||||
|
@ -29,3 +37,15 @@ fn build_subcommand() {
|
|||
assert!(out.is_ok());
|
||||
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