From bf841fb4b0b1ac250edf787c6337a7a771b491bc Mon Sep 17 00:00:00 2001 From: tharun571 Date: Tue, 21 May 2024 11:20:09 +0530 Subject: [PATCH 1/3] Add tests for xoptions --- test/test_interpreter.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/test_interpreter.cpp b/test/test_interpreter.cpp index bc54fc1d..3e3c546a 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; + } + CHECK(exceptionThrown); + } +} From c7a7d39539afba4af707fbcb46a228b2a741c433 Mon Sep 17 00:00:00 2001 From: tharun571 Date: Tue, 21 May 2024 11:22:03 +0530 Subject: [PATCH 2/3] Update test --- test/test_interpreter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_interpreter.cpp b/test/test_interpreter.cpp index 3e3c546a..ae162683 100644 --- a/test/test_interpreter.cpp +++ b/test/test_interpreter.cpp @@ -423,6 +423,6 @@ TEST_SUITE("xotions") } catch (const std::exception& e) { exceptionThrown = true; } - CHECK(exceptionThrown); + REQUIRE(exceptionThrown); } } From e9dd6d75d7ac4b6477720b6d1c1ecbde9d371d06 Mon Sep 17 00:00:00 2001 From: tharun571 <63015429+tharun571@users.noreply.github.com> Date: Tue, 21 May 2024 12:07:57 +0530 Subject: [PATCH 3/3] Update xoptions.hpp --- include/xeus-cpp/xoptions.hpp | 1 + 1 file changed, 1 insertion(+) 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); }; }