diff --git a/test/options.cpp b/test/options.cpp index acb2ba0..f43d3e3 100644 --- a/test/options.cpp +++ b/test/options.cpp @@ -473,3 +473,30 @@ TEST_CASE("std::optional", "[optional]") { CHECK(*optional == "foo"); } #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)); + } +} \ No newline at end of file