tests: adds tests for AppSettings::AllowMissingPositional

This commit is contained in:
Kevin K 2017-01-03 21:58:12 -05:00
parent 6edde30b8e
commit e80fd4d671
No known key found for this signature in database
GPG key ID: 17218E4B3692F01A
2 changed files with 32 additions and 0 deletions

View file

@ -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"));
}

View 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);
}