From 3f56a377ad2a905841c0c6f63f4b71d50730f7bb Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Tue, 2 Oct 2018 16:45:08 +0100 Subject: [PATCH 1/2] Add has_option to cmdlinet This allows a user to check that a particular option is accepted, which allows validation when not using the full `parse` routine. --- src/util/cmdline.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/util/cmdline.h b/src/util/cmdline.h index 6fc55fca834..e4a34f9b71a 100644 --- a/src/util/cmdline.h +++ b/src/util/cmdline.h @@ -35,6 +35,11 @@ class cmdlinet virtual void set(const std::string &option, const std::string &value); virtual void clear(); + bool has_option(const std::string &option) const + { + return getoptnr(option).has_value(); + } + typedef std::vector argst; argst args; std::string unknown_arg; From 1225b7716582238936bca617c55d1fe6a1e00e37 Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Tue, 2 Oct 2018 17:16:36 +0100 Subject: [PATCH 2/2] Add unit test for cmdlinet::has_option --- unit/Makefile | 1 + unit/util/cmdline.cpp | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 unit/util/cmdline.cpp diff --git a/unit/Makefile b/unit/Makefile index 307d34f972a..261393bd89e 100644 --- a/unit/Makefile +++ b/unit/Makefile @@ -29,6 +29,7 @@ SRC += analyses/ai/ai.cpp \ solvers/refinement/string_refinement/sparse_array.cpp \ solvers/refinement/string_refinement/substitute_array_list.cpp \ solvers/refinement/string_refinement/union_find_replace.cpp \ + util/cmdline.cpp \ util/expr_cast/expr_cast.cpp \ util/expr.cpp \ util/file_util.cpp \ diff --git a/unit/util/cmdline.cpp b/unit/util/cmdline.cpp new file mode 100644 index 00000000000..b77f8d9f915 --- /dev/null +++ b/unit/util/cmdline.cpp @@ -0,0 +1,19 @@ +/*******************************************************************\ + + Module: cmdlinet unit tests + + Author: Diffblue Ltd. + +\*******************************************************************/ + +#include +#include + +TEST_CASE("cmdlinet::has_option", "[core][util][cmdline]") +{ + cmdlinet cmdline; + REQUIRE(!cmdline.parse(0, nullptr, "(a)(b):")); + REQUIRE(cmdline.has_option("a")); + REQUIRE(cmdline.has_option("b")); + REQUIRE(!cmdline.has_option("c")); +}