diff --git a/include/xeus-cpp/xoptions.hpp b/include/xeus-cpp/xoptions.hpp index b833b1b1..47bd73f0 100644 --- a/include/xeus-cpp/xoptions.hpp +++ b/include/xeus-cpp/xoptions.hpp @@ -23,6 +23,7 @@ namespace xcpp using base_type = argparse::ArgumentParser; using base_type::ArgumentParser; + XEUS_CPP_API void parse(const std::string& line); }; } diff --git a/test/test_interpreter.cpp b/test/test_interpreter.cpp index bc54fc1d..ae162683 100644 --- a/test/test_interpreter.cpp +++ b/test/test_interpreter.cpp @@ -11,6 +11,7 @@ #include "xeus-cpp/xholder.hpp" #include "xeus-cpp/xmanager.hpp" #include "xeus-cpp/xutils.hpp" +#include "xeus-cpp/xoptions.hpp" #include "../src/xparser.hpp" @@ -396,3 +397,32 @@ TEST_SUITE("xbuffer") REQUIRE(null_stream.good() == true); } } + +TEST_SUITE("xotions") +{ + TEST_CASE("good_status") { + xcpp::argparser parser("test"); + parser.add_argument("--verbose").help("increase output verbosity").default_value(false).implicit_value(true); + std::string line = "./main --verbose"; + + parser.parse(line); + + REQUIRE(parser["--verbose"] == true); + } + + TEST_CASE("bad_status") { + xcpp::argparser parser("test"); + parser.add_argument("--verbose"); + std::string line = "./main --verbose"; + + parser.parse(line); + + bool exceptionThrown = false; + try { + bool isVerbose = (parser["--verbose"] == false); + } catch (const std::exception& e) { + exceptionThrown = true; + } + REQUIRE(exceptionThrown); + } +}