mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 06:44:16 +00:00
tests: adds tests for AppSettings::AllowMissingPositional
This commit is contained in:
parent
6edde30b8e
commit
e80fd4d671
2 changed files with 32 additions and 0 deletions
|
@ -456,4 +456,15 @@ fn propagate_vals_down() {
|
|||
assert_eq!(m.value_of("cmd"), Some("set"));
|
||||
let sub_m = m.subcommand_matches("foo").unwrap();
|
||||
assert_eq!(sub_m.value_of("cmd"), Some("set"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn allow_missing_positional() {
|
||||
let m = App::new("test")
|
||||
.setting(AppSettings::AllowMissingPositional)
|
||||
.arg(Arg::from_usage("[src] 'some file'").default_value("src"))
|
||||
.arg_from_usage("<dest> 'some file'")
|
||||
.get_matches_from(vec!["test", "file"]);
|
||||
assert_eq!(m.value_of("src"), Some("src"));
|
||||
assert_eq!(m.value_of("dest"), Some("file"));
|
||||
}
|
|
@ -190,3 +190,24 @@ fn single_positional_required_usage_string() {
|
|||
.get_matches_from(vec!["test", "file"]);
|
||||
assert_eq!(m.usage(), "USAGE:\n test <FILE>");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn missing_required() {
|
||||
let r = App::new("test")
|
||||
.arg_from_usage("[FILE1] 'some file'")
|
||||
.arg_from_usage("<FILE2> 'some file'")
|
||||
.get_matches_from_safe(vec!["test", "file"]);
|
||||
assert!(r.is_err());
|
||||
assert_eq!(r.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_required_2() {
|
||||
let r = App::new("test")
|
||||
.arg_from_usage("<FILE1> 'some file'")
|
||||
.arg_from_usage("<FILE2> 'some file'")
|
||||
.get_matches_from_safe(vec!["test", "file"]);
|
||||
assert!(r.is_err());
|
||||
assert_eq!(r.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue