Skip to content

Commit d164a20

Browse files
committed
Additional test for error reporting.
Closes #30.
1 parent 3e1d260 commit d164a20

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

test/exception_txt_test.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,27 @@ void test_invalid_command_line_style_exception_msg()
620620
}
621621
}
622622

623+
void test_empty_value_inner(options_description &opts, variables_map& vm) {
624+
positional_options_description popts;
625+
opts.add_options()("foo", value<uint32_t>()->value_name("<time>")->required());
626+
popts.add("foo", 1);
627+
vector<string> tokens{""};
628+
parsed_options parsed = command_line_parser(tokens)
629+
.style(command_line_style::default_style & ~command_line_style::allow_guessing)
630+
.options(opts)
631+
.positional(popts)
632+
.run();
633+
store(parsed, vm);
634+
}
623635

636+
void test_empty_value() {
637+
// Test that passing empty token for an option that requires integer does not result
638+
// in out-of-range error in error reporting code.
639+
test_exception<invalid_option_value>(
640+
"test_empty_value",
641+
"the argument for option '--foo' is invalid",
642+
test_empty_value_inner);
643+
}
624644

625645
int main(int /*ac*/, char** /*av*/)
626646
{
@@ -633,6 +653,7 @@ int main(int /*ac*/, char** /*av*/)
633653
test_multiple_values_not_allowed_exception_msg();
634654
test_required_option_exception_msg();
635655
test_at_least_one_value_required_exception_msg();
656+
test_empty_value();
636657

637658
string test_name;
638659
string expected_message;

0 commit comments

Comments
 (0)