Skip to content

Commit

Permalink
fix: fixed confusing error message, also added test for it
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinatorul committed Aug 22, 2015
1 parent af6b58f commit fc7a31a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/args/arg.rs
Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions src/lib.rs
Expand Up @@ -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'"));
}
}
5 changes: 4 additions & 1 deletion src/usageparser.rs
Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit fc7a31a

Please sign in to comment.