fix: fixed confusing error message, also added test for it

This commit is contained in:
Alexander Kuvaev 2015-08-22 12:25:56 +03:00
parent af6b58f97d
commit fc7a31a745
3 changed files with 18 additions and 2 deletions

View file

@ -280,7 +280,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
}
Arg {
name: name.unwrap(),
name: name.unwrap_or_else(|| panic!("Missing flag name in \"{}\", check from_usage call", u)),
short: short,
long: long,
help: help,

View file

@ -1242,4 +1242,17 @@ mod tests {
assert!(m.is_present("debug"));
}
#[test]
#[should_panic]
fn short_flag_misspel() {
App::new("short_flag")
.arg(Arg::from_usage("-f1, --flag 'some flag'"));
}
#[test]
#[should_panic]
fn short_flag_name_missing() {
App::new("short_flag")
.arg(Arg::from_usage("-f 'some flag'"));
}
}

View file

@ -124,8 +124,11 @@ impl<'u> Iterator for UsageParser<'u> {
self.e += 1;
continue
},
_ => {
None => {
return None
},
Some(c) => {
panic!("Usage parser error, unexpected \"{}\" at \"{}\", check from_usage call", c, self.usage);
}
}
}