mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 23:04:23 +00:00
tests: add tests for flag and groups conflicts
This commit is contained in:
parent
a7eb9519b3
commit
a4a00b03e3
2 changed files with 63 additions and 2 deletions
|
@ -240,8 +240,8 @@ _bin = './target/release/claptests'
|
|||
cmds = {#'help short: ': ['{} -h'.format(_bin), _help],
|
||||
#'help long: ': ['{} --help'.format(_bin), _help],
|
||||
'help subcmd: ': ['{} help'.format(_bin), _help],
|
||||
'excluded first: ': ['{} -f -F'.format(_bin), _excluded],
|
||||
'excluded last: ': ['{} -F -f'.format(_bin), _excluded_l],
|
||||
#'excluded first: ': ['{} -f -F'.format(_bin), _excluded],
|
||||
#'excluded last: ': ['{} -F -f'.format(_bin), _excluded_l],
|
||||
'missing required: ': ['{} -F'.format(_bin), _required],
|
||||
'max_vals too many: ': ['{} --maxvals3 some other value too'.format(_bin), _max_vals_more],
|
||||
'max_vals exact: ': ['{} --maxvals3 some other value'.format(_bin), _exact],
|
||||
|
|
61
tests/conflicts.rs
Normal file
61
tests/conflicts.rs
Normal file
|
@ -0,0 +1,61 @@
|
|||
extern crate clap;
|
||||
|
||||
use clap::{App, Arg, ClapErrorType, ArgGroup};
|
||||
|
||||
#[test]
|
||||
fn flag_conflict() {
|
||||
let result = App::new("flag_conflict")
|
||||
.arg(Arg::from_usage("-f, --flag 'some flag'")
|
||||
.conflicts_with("other"))
|
||||
.arg(Arg::from_usage("-o, --other 'some flag'"))
|
||||
.get_matches_from_safe(vec!["", "-f", "-o"]);
|
||||
assert!(result.is_err());
|
||||
let err = result.err().unwrap();
|
||||
assert_eq!(err.error_type, ClapErrorType::ArgumentConflict);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flag_conflict_2() {
|
||||
let result = App::new("flag_conflict")
|
||||
.arg(Arg::from_usage("-f, --flag 'some flag'")
|
||||
.conflicts_with("other"))
|
||||
.arg(Arg::from_usage("-o, --other 'some flag'"))
|
||||
.get_matches_from_safe(vec!["", "-o", "-f"]);
|
||||
assert!(result.is_err());
|
||||
let err = result.err().unwrap();
|
||||
assert_eq!(err.error_type, ClapErrorType::ArgumentConflict);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn group_conflict() {
|
||||
let result = App::new("group_conflict")
|
||||
.arg(Arg::from_usage("-f, --flag 'some flag'")
|
||||
.conflicts_with("gr"))
|
||||
.arg_group(ArgGroup::with_name("gr")
|
||||
.required(true)
|
||||
.add("some")
|
||||
.add("other"))
|
||||
.arg(Arg::from_usage("--some 'some arg'"))
|
||||
.arg(Arg::from_usage("--other 'other arg'"))
|
||||
.get_matches_from_safe(vec!["", "--other", "-f"]);
|
||||
assert!(result.is_err());
|
||||
let err = result.err().unwrap();
|
||||
assert_eq!(err.error_type, ClapErrorType::ArgumentConflict);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn group_conflict_2() {
|
||||
let result = App::new("group_conflict")
|
||||
.arg(Arg::from_usage("-f, --flag 'some flag'")
|
||||
.conflicts_with("gr"))
|
||||
.arg_group(ArgGroup::with_name("gr")
|
||||
.required(true)
|
||||
.add("some")
|
||||
.add("other"))
|
||||
.arg(Arg::from_usage("--some 'some arg'"))
|
||||
.arg(Arg::from_usage("--other 'other arg'"))
|
||||
.get_matches_from_safe(vec!["", "-f", "--some"]);
|
||||
assert!(result.is_err());
|
||||
let err = result.err().unwrap();
|
||||
assert_eq!(err.error_type, ClapErrorType::ArgumentConflict);
|
||||
}
|
Loading…
Reference in a new issue