Skip to content

Add tests for xoptions #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}