Skip to content

add more helpful panic on empty names #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,9 @@ impl<'parser, 'refer, T> Ref<'parser, 'refer, T> {
-> &'x mut Ref<'parser, 'refer, T>
{
{
if names.is_empty() {
panic!("At least one name for option must be specified");
}
let var = &mut self.parser.vars[self.varid];
if var.metavar.is_empty() {
let mut longest_name = names[0];
Expand Down
9 changes: 9 additions & 0 deletions src/test_usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ fn test_options() {
from_utf8(&buf[..]).unwrap());
}

#[test]
#[should_panic(expected="At least one name for option must be specified")]
fn test_option_empty_names() {
let mut val = 0;
let mut ap = ArgumentParser::new();
ap.refer(&mut val)
.add_option(&[], Store, "Set integer value");
}

#[test]
fn test_argument() {
let mut val = 0;
Expand Down