Skip to content

Commit

Permalink
Adding a few tests for #224
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii committed Feb 18, 2019
1 parent 6c2df1f commit 263ab08
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ set(CLI11_TESTS
OptionalTest
DeprecatedTest
StringParseTest
TrueFalseTest
)

if(WIN32)
Expand Down
34 changes: 34 additions & 0 deletions tests/TrueFalseTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "app_helper.hpp"

/// This allows a set of strings to be run over by a test
struct TApp_TBO : public TApp, public ::testing::WithParamInterface<const char*> {};

TEST_P(TApp_TBO, TrueBoolOption) {
bool value = false; // Not used, but set just in case
app.add_option("-b,--bool", value);
args = {"--bool", GetParam()};
run();
EXPECT_EQ(1u, app.count("--bool"));
EXPECT_TRUE(value);
}

// Change to INSTANTIATE_TEST_SUITE_P in GTest master
INSTANTIATE_TEST_CASE_P(TrueBoolOptions,
TApp_TBO,
::testing::Values("true", "on", "True", "ON"),);

/// This allows a set of strings to be run over by a test
struct TApp_FBO : public TApp, public ::testing::WithParamInterface<const char*> {};

TEST_P(TApp_FBO, FalseBoolOptions) {
bool value = true; // Not used, but set just in case
app.add_option("-b,--bool", value);
args = {"--bool", GetParam()};
run();
EXPECT_EQ(1u, app.count("--bool"));
EXPECT_FALSE(value);
}

INSTANTIATE_TEST_CASE_P(FalseBoolOptions,
TApp_FBO,
::testing::Values("false", "off", "False", "OFF"),);

0 comments on commit 263ab08

Please sign in to comment.