Added test cases for unrecognised options.
This commit is contained in:
parent
1c237223f4
commit
b5f07c4edf
@ -473,3 +473,30 @@ TEST_CASE("std::optional", "[optional]") {
|
|||||||
CHECK(*optional == "foo");
|
CHECK(*optional == "foo");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
TEST_CASE("Unrecognised options", "[options]") {
|
||||||
|
cxxopts::Options options("unknown_options", " - test basic options");
|
||||||
|
|
||||||
|
options.add_options()
|
||||||
|
("long", "a long option")
|
||||||
|
("s,short", "a short option");
|
||||||
|
|
||||||
|
Argv av({
|
||||||
|
"unknown_options",
|
||||||
|
"--long",
|
||||||
|
"-su",
|
||||||
|
"--unknown",
|
||||||
|
});
|
||||||
|
|
||||||
|
const char** argv = av.argv();
|
||||||
|
auto argc = av.argc();
|
||||||
|
|
||||||
|
SECTION("Default behaviour") {
|
||||||
|
CHECK_THROWS_AS(options.parse(argc, argv), cxxopts::option_not_exists_exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("After allowing unrecognised options") {
|
||||||
|
options.allow_unrecognised_options();
|
||||||
|
CHECK_NOTHROW(options.parse(argc, argv));
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user