Skip to content

Commit

Permalink
Add tests for xoptions (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
tharun571 authored May 21, 2024
1 parent 48a14c3 commit e788167
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/xeus-cpp/xoptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace xcpp
using base_type = argparse::ArgumentParser;
using base_type::ArgumentParser;

XEUS_CPP_API
void parse(const std::string& line);
};
}
Expand Down
30 changes: 30 additions & 0 deletions test/test_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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);
}
}

0 comments on commit e788167

Please sign in to comment.