From b5f07c4edfa20c59b9133d3a83c8a75a2541d93a Mon Sep 17 00:00:00 2001 From: Frank Schoenmann Date: Wed, 4 Apr 2018 10:44:17 +0200 Subject: [PATCH] Added test cases for unrecognised options. --- test/options.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) 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