Skip to content

Commit

Permalink
Add tests for failures
Browse files Browse the repository at this point in the history
  • Loading branch information
lukedeo committed Jan 3, 2020
1 parent 19dc7b3 commit f7811a4
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/test_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
#include <iterator>

#include "doctest.h"

// Makes sure we don't exit on failures.
#define OPTIONPARSER_THROW_ON_FAILURE
#include "optionparser.h"

template <class T, size_t N> constexpr size_t length(T (&)[N]) { return N; }



TEST_CASE("test substring names") {
SUBCASE("test boolean arg with long arg") {
const char *argv[] = {"tests", "--boolean"};
Expand Down Expand Up @@ -69,6 +74,16 @@ TEST_CASE("test substring names") {
CHECK(!p.get_value("pass"));
}

SUBCASE("test boolean positional arg which is not passed but is required") {
const char *argv[] = {"tests"};
int argc = length(argv);
optionparser::OptionParser p(
"A test to make sure that this option parser works");
p.add_option("pass").help(" positional boolean value").required(true);

CHECK_THROWS(p.eat_arguments(argc, argv));
}

SUBCASE("test many boolean arg which ") {
const char *argv[] = {
"tests",
Expand Down Expand Up @@ -244,6 +259,10 @@ TEST_CASE("test parser functionality") {
if (p.get_value("boolean")) {
CHECK(p.get_value<bool>("boolean"));
}

SUBCASE("fail on invalid arg") {
CHECK_THROWS(p.get_value("this-isnt-in-parser"));
}
}

TEST_CASE("test OO functionality") {
Expand Down

0 comments on commit f7811a4

Please sign in to comment.