mirror of
https://github.com/jarro2783/cxxopts.git
synced 2026-08-29 01:25:31 +02:00
Allow unrecognised options. (#105)
Allows unrecognised options to be left alone by the parser without throwing an exception.
This commit is contained in:
committed by
jarro2783
parent
00e8ecc482
commit
ca6e9f70eb
@@ -473,3 +473,33 @@ TEST_CASE("std::optional", "[optional]") {
|
||||
CHECK(*optional == "foo");
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_CASE("Unrecognised options", "[options]") {
|
||||
cxxopts::Options options("unknown_options", " - test unknown options");
|
||||
|
||||
options.add_options()
|
||||
("long", "a long option")
|
||||
("s,short", "a short option");
|
||||
|
||||
Argv av({
|
||||
"unknown_options",
|
||||
"--unknown",
|
||||
"--long",
|
||||
"-su",
|
||||
"--another_unknown",
|
||||
});
|
||||
|
||||
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));
|
||||
REQUIRE(argc == 3);
|
||||
CHECK_THAT(argv[1], Catch::Equals("--unknown"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user