Skip to content

Commit

Permalink
tests: adds tests for AppSettings::AllowMissingPositional
Browse files Browse the repository at this point in the history
  • Loading branch information
kbknapp committed Jan 4, 2017
1 parent 6edde30 commit e80fd4d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/app_settings.rs
Expand Up @@ -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"));
}
21 changes: 21 additions & 0 deletions tests/positionals.rs
Expand Up @@ -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);
}

0 comments on commit e80fd4d

Please sign in to comment.