mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-05-03 14:03:52 +00:00
tests: use catch2
This commit is contained in:
parent
b00b56061a
commit
5d12e11d8a
1
.gitignore
vendored
1
.gitignore
vendored
@ -12,3 +12,4 @@ a.out*
|
|||||||
/node_modules/*
|
/node_modules/*
|
||||||
/package.json
|
/package.json
|
||||||
/yarn.lock
|
/yarn.lock
|
||||||
|
/CLI11.hpp
|
||||||
|
@ -1,49 +0,0 @@
|
|||||||
#
|
|
||||||
#
|
|
||||||
# Includes GTest and provides a helper macro to add tests. Add make check, as well, which
|
|
||||||
# gives output on failed tests without having to set an environment variable.
|
|
||||||
#
|
|
||||||
#
|
|
||||||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
|
||||||
set(BUILD_SHARED_LIBS OFF)
|
|
||||||
|
|
||||||
add_subdirectory("${CLI11_SOURCE_DIR}/extern/googletest" "${CLI11_BINARY_DIR}/extern/googletest" EXCLUDE_FROM_ALL)
|
|
||||||
|
|
||||||
|
|
||||||
if(GOOGLE_TEST_INDIVIDUAL)
|
|
||||||
if(NOT CMAKE_VERSION VERSION_LESS 3.9)
|
|
||||||
include(GoogleTest)
|
|
||||||
else()
|
|
||||||
set(GOOGLE_TEST_INDIVIDUAL OFF)
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Target must already exist
|
|
||||||
macro(add_gtest TESTNAME)
|
|
||||||
target_link_libraries(${TESTNAME} PUBLIC gtest gmock gtest_main)
|
|
||||||
|
|
||||||
if(GOOGLE_TEST_INDIVIDUAL)
|
|
||||||
if(CMAKE_VERSION VERSION_LESS 3.10)
|
|
||||||
gtest_add_tests(TARGET ${TESTNAME}
|
|
||||||
TEST_PREFIX "${TESTNAME}."
|
|
||||||
TEST_LIST TmpTestList)
|
|
||||||
set_tests_properties(${TmpTestList} PROPERTIES FOLDER "Tests")
|
|
||||||
else()
|
|
||||||
gtest_discover_tests(${TESTNAME}
|
|
||||||
TEST_PREFIX "${TESTNAME}."
|
|
||||||
PROPERTIES FOLDER "Tests")
|
|
||||||
|
|
||||||
endif()
|
|
||||||
else()
|
|
||||||
add_test(${TESTNAME} ${TESTNAME})
|
|
||||||
set_target_properties(${TESTNAME} PROPERTIES FOLDER "Tests")
|
|
||||||
if (CLI11_FORCE_LIBCXX)
|
|
||||||
set_property(TARGET ${T} APPEND_STRING
|
|
||||||
PROPERTY LINK_FLAGS -stdlib=libc++)
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
endmacro()
|
|
||||||
|
|
||||||
set_target_properties(gtest gtest_main gmock gmock_main
|
|
||||||
PROPERTIES FOLDER "Extern")
|
|
1217
tests/AppTest.cpp
1217
tests/AppTest.cpp
File diff suppressed because it is too large
Load Diff
@ -15,137 +15,112 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "gmock/gmock.h"
|
using namespace boost::container;
|
||||||
|
|
||||||
namespace boost {
|
TEMPLATE_TEST_CASE("Boost container single",
|
||||||
namespace container {
|
"[boost][optional]",
|
||||||
|
(small_vector<int, 2>),
|
||||||
|
(small_vector<int, 3>),
|
||||||
|
flat_set<int>,
|
||||||
|
stable_vector<int>,
|
||||||
|
slist<int>) {
|
||||||
|
TApp tapp;
|
||||||
|
TestType cv;
|
||||||
|
CLI::Option *opt = tapp.app.add_option("-v", cv);
|
||||||
|
|
||||||
template <class T> class TApp_container_single_boost : public TApp {
|
tapp.args = {"-v", "1", "-1", "-v", "3", "-v", "-976"};
|
||||||
public:
|
tapp.run();
|
||||||
using container_type = T;
|
CHECK(tapp.app.count("-v") == 4u);
|
||||||
container_type cval{};
|
CHECK(cv.size() == 4u);
|
||||||
TApp_container_single_boost() : TApp() {}
|
|
||||||
};
|
|
||||||
|
|
||||||
using containerTypes_single_boost =
|
|
||||||
::testing::Types<small_vector<int, 2>, small_vector<int, 3>, flat_set<int>, stable_vector<int>, slist<int>>;
|
|
||||||
|
|
||||||
TYPED_TEST_SUITE(TApp_container_single_boost, containerTypes_single_boost, );
|
|
||||||
|
|
||||||
TYPED_TEST(TApp_container_single_boost, containerInt_boost) {
|
|
||||||
|
|
||||||
auto &cv = TApp_container_single_boost<TypeParam>::cval;
|
|
||||||
CLI::Option *opt = (TApp::app).add_option("-v", cv);
|
|
||||||
|
|
||||||
TApp::args = {"-v", "1", "-1", "-v", "3", "-v", "-976"};
|
|
||||||
TApp::run();
|
|
||||||
EXPECT_EQ(4u, (TApp::app).count("-v"));
|
|
||||||
EXPECT_EQ(4u, cv.size());
|
|
||||||
opt->check(CLI::PositiveNumber.application_index(0));
|
opt->check(CLI::PositiveNumber.application_index(0));
|
||||||
opt->check((!CLI::PositiveNumber).application_index(1));
|
opt->check((!CLI::PositiveNumber).application_index(1));
|
||||||
EXPECT_NO_THROW(TApp::run());
|
CHECK_NOTHROW(tapp.run());
|
||||||
EXPECT_EQ(4u, cv.size());
|
CHECK(cv.size() == 4u);
|
||||||
// v[3] would be negative
|
// v[3] would be negative
|
||||||
opt->check(CLI::PositiveNumber.application_index(3));
|
opt->check(CLI::PositiveNumber.application_index(3));
|
||||||
EXPECT_THROW(TApp::run(), CLI::ValidationError);
|
CHECK_THROWS_AS(tapp.run(), CLI::ValidationError);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> class TApp_container_pair_boost : public TApp {
|
|
||||||
public:
|
|
||||||
using container_type = T;
|
|
||||||
container_type cval{};
|
|
||||||
TApp_container_pair_boost() : TApp() {}
|
|
||||||
};
|
|
||||||
|
|
||||||
using isp = std::pair<int, std::string>;
|
using isp = std::pair<int, std::string>;
|
||||||
using containerTypes_pair_boost = ::testing::
|
|
||||||
Types<stable_vector<isp>, small_vector<isp, 2>, flat_set<isp>, slist<isp>, vector<isp>, flat_map<int, std::string>>;
|
|
||||||
|
|
||||||
TYPED_TEST_SUITE(TApp_container_pair_boost, containerTypes_pair_boost, );
|
TEMPLATE_TEST_CASE("Boost container pair",
|
||||||
|
"[boost][optional]",
|
||||||
|
stable_vector<isp>,
|
||||||
|
(small_vector<isp, 2>),
|
||||||
|
flat_set<isp>,
|
||||||
|
slist<isp>,
|
||||||
|
vector<isp>,
|
||||||
|
(flat_map<int, std::string>)) {
|
||||||
|
|
||||||
TYPED_TEST(TApp_container_pair_boost, containerPair_boost) {
|
TApp tapp;
|
||||||
|
TestType cv;
|
||||||
|
|
||||||
auto &cv = TApp_container_pair_boost<TypeParam>::cval;
|
tapp.app.add_option("--dict", cv);
|
||||||
(TApp::app).add_option("--dict", cv);
|
|
||||||
|
|
||||||
TApp::args = {"--dict", "1", "str1", "--dict", "3", "str3"};
|
tapp.args = {"--dict", "1", "str1", "--dict", "3", "str3"};
|
||||||
|
|
||||||
TApp::run();
|
tapp.run();
|
||||||
EXPECT_EQ(cv.size(), 2u);
|
CHECK(2u == cv.size());
|
||||||
|
|
||||||
TApp::args = {"--dict", "1", "str1", "--dict", "3", "--dict", "-1", "str4"};
|
tapp.args = {"--dict", "1", "str1", "--dict", "3", "--dict", "-1", "str4"};
|
||||||
TApp::run();
|
tapp.run();
|
||||||
EXPECT_EQ(cv.size(), 3u);
|
CHECK(3u == cv.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> class TApp_container_tuple_boost : public TApp {
|
|
||||||
public:
|
|
||||||
using container_type = T;
|
|
||||||
container_type cval{};
|
|
||||||
TApp_container_tuple_boost() : TApp() {}
|
|
||||||
};
|
|
||||||
|
|
||||||
using tup_obj = std::tuple<int, std::string, double>;
|
using tup_obj = std::tuple<int, std::string, double>;
|
||||||
using containerTypes_tuple_boost =
|
|
||||||
::testing::Types<small_vector<tup_obj, 3>, stable_vector<tup_obj>, flat_set<tup_obj>, slist<tup_obj>>;
|
|
||||||
|
|
||||||
TYPED_TEST_SUITE(TApp_container_tuple_boost, containerTypes_tuple_boost, );
|
TEMPLATE_TEST_CASE("Boost container tuple",
|
||||||
|
"[boost][optional]",
|
||||||
|
(small_vector<tup_obj, 3>),
|
||||||
|
stable_vector<tup_obj>,
|
||||||
|
flat_set<tup_obj>,
|
||||||
|
slist<tup_obj>) {
|
||||||
|
TApp tapp;
|
||||||
|
TestType cv;
|
||||||
|
|
||||||
TYPED_TEST(TApp_container_tuple_boost, containerTuple_boost) {
|
tapp.app.add_option("--dict", cv);
|
||||||
|
|
||||||
auto &cv = TApp_container_tuple_boost<TypeParam>::cval;
|
tapp.args = {"--dict", "1", "str1", "4.3", "--dict", "3", "str3", "2.7"};
|
||||||
(TApp::app).add_option("--dict", cv);
|
|
||||||
|
|
||||||
TApp::args = {"--dict", "1", "str1", "4.3", "--dict", "3", "str3", "2.7"};
|
tapp.run();
|
||||||
|
CHECK(2u == cv.size());
|
||||||
|
|
||||||
TApp::run();
|
tapp.args = {"--dict", "1", "str1", "4.3", "--dict", "3", "str3", "2.7", "--dict", "-1", "str4", "-1.87"};
|
||||||
EXPECT_EQ(cv.size(), 2u);
|
tapp.run();
|
||||||
|
CHECK(3u == cv.size());
|
||||||
TApp::args = {"--dict", "1", "str1", "4.3", "--dict", "3", "str3", "2.7", "--dict", "-1", "str4", "-1.87"};
|
|
||||||
TApp::run();
|
|
||||||
EXPECT_EQ(cv.size(), 3u);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
using icontainer1 = vector<int>;
|
using icontainer1 = vector<int>;
|
||||||
using icontainer2 = flat_set<int>;
|
using icontainer2 = flat_set<int>;
|
||||||
using icontainer3 = slist<int>;
|
using icontainer3 = slist<int>;
|
||||||
using containerTypes_container_boost = ::testing::Types<std::vector<icontainer1>,
|
|
||||||
slist<icontainer1>,
|
|
||||||
flat_set<icontainer1>,
|
|
||||||
small_vector<icontainer1, 2>,
|
|
||||||
std::vector<icontainer2>,
|
|
||||||
slist<icontainer2>,
|
|
||||||
flat_set<icontainer2>,
|
|
||||||
stable_vector<icontainer2>,
|
|
||||||
static_vector<icontainer3, 10>,
|
|
||||||
slist<icontainer3>,
|
|
||||||
flat_set<icontainer3>,
|
|
||||||
static_vector<icontainer3, 10>>;
|
|
||||||
|
|
||||||
template <class T> class TApp_container_container_boost : public TApp {
|
TEMPLATE_TEST_CASE("Boost container container",
|
||||||
public:
|
"[boost][optional]",
|
||||||
using container_type = T;
|
std::vector<icontainer1>,
|
||||||
container_type cval{};
|
slist<icontainer1>,
|
||||||
TApp_container_container_boost() : TApp() {}
|
flat_set<icontainer1>,
|
||||||
};
|
(small_vector<icontainer1, 2>),
|
||||||
|
std::vector<icontainer2>,
|
||||||
|
slist<icontainer2>,
|
||||||
|
flat_set<icontainer2>,
|
||||||
|
stable_vector<icontainer2>,
|
||||||
|
(static_vector<icontainer2, 10>),
|
||||||
|
slist<icontainer3>,
|
||||||
|
flat_set<icontainer3>,
|
||||||
|
(static_vector<icontainer3, 10>)) {
|
||||||
|
|
||||||
TYPED_TEST_SUITE(TApp_container_container_boost, containerTypes_container_boost, );
|
TApp tapp;
|
||||||
|
TestType cv;
|
||||||
|
|
||||||
TYPED_TEST(TApp_container_container_boost, containerContainer_boost) {
|
tapp.app.add_option("--dict", cv);
|
||||||
|
|
||||||
auto &cv = TApp_container_container_boost<TypeParam>::cval;
|
tapp.args = {"--dict", "1", "2", "4", "--dict", "3", "1"};
|
||||||
(TApp::app).add_option("--dict", cv);
|
|
||||||
|
|
||||||
TApp::args = {"--dict", "1", "2", "4", "--dict", "3", "1"};
|
tapp.run();
|
||||||
|
CHECK(2u == cv.size());
|
||||||
|
|
||||||
TApp::run();
|
tapp.args = {"--dict", "1", "2", "4", "--dict", "3", "1", "--dict", "3", "--dict",
|
||||||
EXPECT_EQ(cv.size(), 2u);
|
"3", "3", "3", "3", "3", "3", "3", "3", "3", "-3"};
|
||||||
|
tapp.run();
|
||||||
TApp::args = {"--dict", "1", "2", "4", "--dict", "3", "1", "--dict", "3", "--dict",
|
CHECK(4u == cv.size());
|
||||||
"3", "3", "3", "3", "3", "3", "3", "3", "3", "-3"};
|
|
||||||
TApp::run();
|
|
||||||
EXPECT_EQ(cv.size(), 4u);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace container
|
|
||||||
} // namespace boost
|
|
||||||
|
@ -1,8 +1,3 @@
|
|||||||
if(NOT EXISTS "${CLI11_SOURCE_DIR}/extern/googletest/CMakeLists.txt")
|
|
||||||
message(FATAL_ERROR "You have requested tests be built, but googletest is not downloaded. Please run:
|
|
||||||
git submodule update --init")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
list(APPEND CMAKE_MODULE_PATH "${CLI11_SOURCE_DIR}/cmake")
|
list(APPEND CMAKE_MODULE_PATH "${CLI11_SOURCE_DIR}/cmake")
|
||||||
|
|
||||||
if(CLI11_SANITIZERS)
|
if(CLI11_SANITIZERS)
|
||||||
@ -29,8 +24,6 @@ else()
|
|||||||
endmacro()
|
endmacro()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(GOOGLE_TEST_INDIVIDUAL OFF)
|
|
||||||
include(AddGoogletest)
|
|
||||||
|
|
||||||
# Add boost to test boost::optional (currently explicitly requested)"
|
# Add boost to test boost::optional (currently explicitly requested)"
|
||||||
option(CLI11_BOOST "Turn on boost test (currently may fail with Boost 1.70)" OFF)
|
option(CLI11_BOOST "Turn on boost test (currently may fail with Boost 1.70)" OFF)
|
||||||
@ -70,8 +63,32 @@ endif()
|
|||||||
|
|
||||||
set(CLI11_MULTIONLY_TESTS TimerTest)
|
set(CLI11_MULTIONLY_TESTS TimerTest)
|
||||||
|
|
||||||
# Only affects current directory, so safe
|
add_library(catch_main main.cpp)
|
||||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
target_include_directories(catch_main PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||||
|
|
||||||
|
# Currently a required download; could be make to look for existing Catch2, but
|
||||||
|
# that would require changing the includes. FetchContent would be better, but
|
||||||
|
# requires newer CMake.
|
||||||
|
|
||||||
|
set(url https://github.com/philsquared/Catch/releases/download/v2.13.4/catch.hpp)
|
||||||
|
file(DOWNLOAD ${url} "${CMAKE_CURRENT_BINARY_DIR}/catch.hpp" STATUS status EXPECTED_HASH SHA256=6e0fa3dd160891a01c1f3b34e8bcd6e0140abe08eca022e390027f27dec2050b)
|
||||||
|
list(GET status 0 error)
|
||||||
|
if(error)
|
||||||
|
message(FATAL_ERROR "Could not download ${url}")
|
||||||
|
endif()
|
||||||
|
target_include_directories(catch_main PUBLIC "${CMAKE_CURRENT_BINARY_DIR}")
|
||||||
|
|
||||||
|
# Target must already exist
|
||||||
|
macro(add_catch_test TESTNAME)
|
||||||
|
target_link_libraries(${TESTNAME} PUBLIC catch_main)
|
||||||
|
|
||||||
|
add_test(${TESTNAME} ${TESTNAME})
|
||||||
|
set_target_properties(${TESTNAME} PROPERTIES FOLDER "Tests")
|
||||||
|
if (CLI11_FORCE_LIBCXX)
|
||||||
|
set_property(TARGET ${T} APPEND_STRING
|
||||||
|
PROPERTY LINK_FLAGS -stdlib=libc++)
|
||||||
|
endif()
|
||||||
|
endmacro()
|
||||||
|
|
||||||
foreach(T IN LISTS CLI11_TESTS)
|
foreach(T IN LISTS CLI11_TESTS)
|
||||||
if(CLI11_CUDA_TESTS)
|
if(CLI11_CUDA_TESTS)
|
||||||
@ -86,12 +103,12 @@ foreach(T IN LISTS CLI11_TESTS)
|
|||||||
target_link_libraries(${T} PRIVATE CLI11_warnings)
|
target_link_libraries(${T} PRIVATE CLI11_warnings)
|
||||||
endif()
|
endif()
|
||||||
target_link_libraries(${T} PRIVATE CLI11)
|
target_link_libraries(${T} PRIVATE CLI11)
|
||||||
add_gtest(${T})
|
add_catch_test(${T})
|
||||||
|
|
||||||
if(CLI11_SINGLE_FILE AND CLI11_SINGLE_FILE_TESTS)
|
if(CLI11_SINGLE_FILE AND CLI11_SINGLE_FILE_TESTS)
|
||||||
add_executable(${T}_Single ${T}.cpp)
|
add_executable(${T}_Single ${T}.cpp)
|
||||||
target_link_libraries(${T}_Single PRIVATE CLI11_SINGLE)
|
target_link_libraries(${T}_Single PRIVATE CLI11_SINGLE)
|
||||||
add_gtest(${T}_Single)
|
add_catch_test(${T}_Single)
|
||||||
set_property(TARGET ${T}_Single PROPERTY FOLDER "Tests Single File")
|
set_property(TARGET ${T}_Single PROPERTY FOLDER "Tests Single File")
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
@ -100,7 +117,7 @@ foreach(T IN LISTS CLI11_MULTIONLY_TESTS)
|
|||||||
add_executable(${T} ${T}.cpp ${CLI11_headers})
|
add_executable(${T} ${T}.cpp ${CLI11_headers})
|
||||||
add_sanitizers(${T})
|
add_sanitizers(${T})
|
||||||
target_link_libraries(${T} PUBLIC CLI11)
|
target_link_libraries(${T} PUBLIC CLI11)
|
||||||
add_gtest(${T})
|
add_catch_test(${T})
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
# Add -Wno-deprecated-declarations to DeprecatedTest
|
# Add -Wno-deprecated-declarations to DeprecatedTest
|
||||||
@ -123,7 +140,7 @@ target_link_libraries(link_test_1 PUBLIC CLI11)
|
|||||||
set_target_properties(link_test_1 PROPERTIES FOLDER "Tests")
|
set_target_properties(link_test_1 PROPERTIES FOLDER "Tests")
|
||||||
add_executable(link_test_2 link_test_2.cpp)
|
add_executable(link_test_2 link_test_2.cpp)
|
||||||
target_link_libraries(link_test_2 PUBLIC CLI11 link_test_1)
|
target_link_libraries(link_test_2 PUBLIC CLI11 link_test_1)
|
||||||
add_gtest(link_test_2)
|
add_catch_test(link_test_2)
|
||||||
if(CLI11_FORCE_LIBCXX)
|
if(CLI11_FORCE_LIBCXX)
|
||||||
set_property(TARGET link_test_1 APPEND_STRING
|
set_property(TARGET link_test_1 APPEND_STRING
|
||||||
PROPERTY LINK_FLAGS -stdlib=libc++)
|
PROPERTY LINK_FLAGS -stdlib=libc++)
|
||||||
|
@ -5,11 +5,11 @@
|
|||||||
// SPDX-License-Identifier: BSD-3-Clause
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
#include "app_helper.hpp"
|
#include "app_helper.hpp"
|
||||||
#include "gmock/gmock.h"
|
|
||||||
#include <complex>
|
#include <complex>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
using ::testing::HasSubstr;
|
using Catch::Matchers::Contains;
|
||||||
|
|
||||||
using cx = std::complex<double>;
|
using cx = std::complex<double>;
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ add_option(CLI::App &app, std::string name, cx &variable, std::string descriptio
|
|||||||
return opt;
|
return opt;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, AddingComplexParser) {
|
TEST_CASE_METHOD(TApp, "AddingComplexParser", "[complex]") {
|
||||||
|
|
||||||
cx comp{0, 0};
|
cx comp{0, 0};
|
||||||
add_option(app, "-c,--complex", comp);
|
add_option(app, "-c,--complex", comp);
|
||||||
@ -41,27 +41,27 @@ TEST_F(TApp, AddingComplexParser) {
|
|||||||
|
|
||||||
run();
|
run();
|
||||||
|
|
||||||
EXPECT_DOUBLE_EQ(1.5, comp.real());
|
CHECK(comp.real() == Approx(1.5));
|
||||||
EXPECT_DOUBLE_EQ(2.5, comp.imag());
|
CHECK(comp.imag() == Approx(2.5));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, DefaultedComplex) {
|
TEST_CASE_METHOD(TApp, "DefaultedComplex", "[complex]") {
|
||||||
|
|
||||||
cx comp{1, 2};
|
cx comp{1, 2};
|
||||||
add_option(app, "-c,--complex", comp, "", true);
|
add_option(app, "-c,--complex", comp, "", true);
|
||||||
args = {"-c", "4", "3"};
|
args = {"-c", "4", "3"};
|
||||||
|
|
||||||
std::string help = app.help();
|
std::string help = app.help();
|
||||||
EXPECT_THAT(help, HasSubstr("1"));
|
CHECK_THAT(help, Contains("1"));
|
||||||
EXPECT_THAT(help, HasSubstr("2"));
|
CHECK_THAT(help, Contains("2"));
|
||||||
|
|
||||||
EXPECT_DOUBLE_EQ(1, comp.real());
|
CHECK(comp.real() == Approx(1));
|
||||||
EXPECT_DOUBLE_EQ(2, comp.imag());
|
CHECK(comp.imag() == Approx(2));
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
|
||||||
EXPECT_DOUBLE_EQ(4, comp.real());
|
CHECK(comp.real() == Approx(4));
|
||||||
EXPECT_DOUBLE_EQ(3, comp.imag());
|
CHECK(comp.imag() == Approx(3));
|
||||||
}
|
}
|
||||||
|
|
||||||
// an example of custom complex number converter that can be used to add new parsing options
|
// an example of custom complex number converter that can be used to add new parsing options
|
||||||
@ -117,7 +117,7 @@ template <> bool lexical_cast<std::complex<double>>(const std::string &input, st
|
|||||||
} // namespace detail
|
} // namespace detail
|
||||||
} // namespace CLI
|
} // namespace CLI
|
||||||
|
|
||||||
TEST_F(TApp, AddingComplexParserDetail) {
|
TEST_CASE_METHOD(TApp, "AddingComplexParserDetail", "[complex]") {
|
||||||
|
|
||||||
bool skip_tests = false;
|
bool skip_tests = false;
|
||||||
try { // check if the library actually supports regex, it is possible to link against a non working regex in the
|
try { // check if the library actually supports regex, it is possible to link against a non working regex in the
|
||||||
@ -131,7 +131,7 @@ TEST_F(TApp, AddingComplexParserDetail) {
|
|||||||
if(!rsearch) {
|
if(!rsearch) {
|
||||||
skip_tests = true;
|
skip_tests = true;
|
||||||
} else {
|
} else {
|
||||||
EXPECT_EQ(m.size(), 9u);
|
CHECK(9u == m.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch(...) {
|
} catch(...) {
|
||||||
@ -146,14 +146,14 @@ TEST_F(TApp, AddingComplexParserDetail) {
|
|||||||
|
|
||||||
run();
|
run();
|
||||||
|
|
||||||
EXPECT_DOUBLE_EQ(1.5, comp.real());
|
CHECK(comp.real() == Approx(1.5));
|
||||||
EXPECT_DOUBLE_EQ(2.5, comp.imag());
|
CHECK(comp.imag() == Approx(2.5));
|
||||||
args = {"-c", "1.5-2.5j"};
|
args = {"-c", "1.5-2.5j"};
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
|
||||||
EXPECT_DOUBLE_EQ(1.5, comp.real());
|
CHECK(comp.real() == Approx(1.5));
|
||||||
EXPECT_DOUBLE_EQ(-2.5, comp.imag());
|
CHECK(comp.imag() == Approx(-2.5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -170,7 +170,7 @@ class complex_new {
|
|||||||
double val2_{0.0};
|
double val2_{0.0};
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(TApp, newComplex) {
|
TEST_CASE_METHOD(TApp, "newComplex", "[complex]") {
|
||||||
complex_new cval;
|
complex_new cval;
|
||||||
static_assert(CLI::detail::is_complex<complex_new>::value, "complex new does not register as a complex type");
|
static_assert(CLI::detail::is_complex<complex_new>::value, "complex new does not register as a complex type");
|
||||||
static_assert(CLI::detail::classify_object<complex_new>::value == CLI::detail::object_category::complex_number,
|
static_assert(CLI::detail::classify_object<complex_new>::value == CLI::detail::object_category::complex_number,
|
||||||
@ -180,12 +180,12 @@ TEST_F(TApp, newComplex) {
|
|||||||
|
|
||||||
run();
|
run();
|
||||||
|
|
||||||
EXPECT_DOUBLE_EQ(1.5, cval.real());
|
CHECK(cval.real() == Approx(1.5));
|
||||||
EXPECT_DOUBLE_EQ(2.5, cval.imag());
|
CHECK(cval.imag() == Approx(2.5));
|
||||||
args = {"-c", "1.5-2.5j"};
|
args = {"-c", "1.5-2.5j"};
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
|
||||||
EXPECT_DOUBLE_EQ(1.5, cval.real());
|
CHECK(cval.real() == Approx(1.5));
|
||||||
EXPECT_DOUBLE_EQ(-2.5, cval.imag());
|
CHECK(cval.imag() == Approx(-2.5));
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -7,224 +7,224 @@
|
|||||||
#include "app_helper.hpp"
|
#include "app_helper.hpp"
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
TEST_F(TApp, AddingExistingShort) {
|
TEST_CASE_METHOD(TApp, "AddingExistingShort", "[creation]") {
|
||||||
CLI::Option *opt = app.add_flag("-c,--count");
|
CLI::Option *opt = app.add_flag("-c,--count");
|
||||||
EXPECT_EQ(opt->get_lnames(), std::vector<std::string>({"count"}));
|
CHECK(std::vector<std::string>({"count"}) == opt->get_lnames());
|
||||||
EXPECT_EQ(opt->get_snames(), std::vector<std::string>({"c"}));
|
CHECK(std::vector<std::string>({"c"}) == opt->get_snames());
|
||||||
|
|
||||||
EXPECT_THROW(app.add_flag("--cat,-c"), CLI::OptionAlreadyAdded);
|
CHECK_THROWS_AS(app.add_flag("--cat,-c"), CLI::OptionAlreadyAdded);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, AddingExistingLong) {
|
TEST_CASE_METHOD(TApp, "AddingExistingLong", "[creation]") {
|
||||||
app.add_flag("-q,--count");
|
app.add_flag("-q,--count");
|
||||||
EXPECT_THROW(app.add_flag("--count,-c"), CLI::OptionAlreadyAdded);
|
CHECK_THROWS_AS(app.add_flag("--count,-c"), CLI::OptionAlreadyAdded);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, AddingExistingShortNoCase) {
|
TEST_CASE_METHOD(TApp, "AddingExistingShortNoCase", "[creation]") {
|
||||||
app.add_flag("-C,--count")->ignore_case();
|
app.add_flag("-C,--count")->ignore_case();
|
||||||
EXPECT_THROW(app.add_flag("--cat,-c"), CLI::OptionAlreadyAdded);
|
CHECK_THROWS_AS(app.add_flag("--cat,-c"), CLI::OptionAlreadyAdded);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, AddingExistingLongNoCase) {
|
TEST_CASE_METHOD(TApp, "AddingExistingLongNoCase", "[creation]") {
|
||||||
app.add_flag("-q,--count")->ignore_case();
|
app.add_flag("-q,--count")->ignore_case();
|
||||||
EXPECT_THROW(app.add_flag("--Count,-c"), CLI::OptionAlreadyAdded);
|
CHECK_THROWS_AS(app.add_flag("--Count,-c"), CLI::OptionAlreadyAdded);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, AddingExistingNoCaseReversed) {
|
TEST_CASE_METHOD(TApp, "AddingExistingNoCaseReversed", "[creation]") {
|
||||||
app.add_flag("-c,--count")->ignore_case();
|
app.add_flag("-c,--count")->ignore_case();
|
||||||
EXPECT_THROW(app.add_flag("--cat,-C"), CLI::OptionAlreadyAdded);
|
CHECK_THROWS_AS(app.add_flag("--cat,-C"), CLI::OptionAlreadyAdded);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, AddingExistingWithCase) {
|
TEST_CASE_METHOD(TApp, "AddingExistingWithCase", "[creation]") {
|
||||||
app.add_flag("-c,--count");
|
app.add_flag("-c,--count");
|
||||||
EXPECT_NO_THROW(app.add_flag("--Cat,-C"));
|
CHECK_NOTHROW(app.add_flag("--Cat,-C"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, AddingExistingWithCaseAfter) {
|
TEST_CASE_METHOD(TApp, "AddingExistingWithCaseAfter", "[creation]") {
|
||||||
auto count = app.add_flag("-c,--count");
|
auto count = app.add_flag("-c,--count");
|
||||||
app.add_flag("--Cat,-C");
|
app.add_flag("--Cat,-C");
|
||||||
|
|
||||||
EXPECT_THROW(count->ignore_case(), CLI::OptionAlreadyAdded);
|
CHECK_THROWS_AS(count->ignore_case(), CLI::OptionAlreadyAdded);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, AddingExistingWithCaseAfter2) {
|
TEST_CASE_METHOD(TApp, "AddingExistingWithCaseAfter2", "[creation]") {
|
||||||
app.add_flag("-c,--count");
|
app.add_flag("-c,--count");
|
||||||
auto cat = app.add_flag("--Cat,-C");
|
auto cat = app.add_flag("--Cat,-C");
|
||||||
|
|
||||||
EXPECT_THROW(cat->ignore_case(), CLI::OptionAlreadyAdded);
|
CHECK_THROWS_AS(cat->ignore_case(), CLI::OptionAlreadyAdded);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, AddingExistingWithUnderscoreAfter) {
|
TEST_CASE_METHOD(TApp, "AddingExistingWithUnderscoreAfter", "[creation]") {
|
||||||
auto count = app.add_flag("--underscore");
|
auto count = app.add_flag("--underscore");
|
||||||
app.add_flag("--under_score");
|
app.add_flag("--under_score");
|
||||||
|
|
||||||
EXPECT_THROW(count->ignore_underscore(), CLI::OptionAlreadyAdded);
|
CHECK_THROWS_AS(count->ignore_underscore(), CLI::OptionAlreadyAdded);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, AddingExistingWithUnderscoreAfter2) {
|
TEST_CASE_METHOD(TApp, "AddingExistingWithUnderscoreAfter2", "[creation]") {
|
||||||
auto count = app.add_flag("--under_score");
|
auto count = app.add_flag("--under_score");
|
||||||
app.add_flag("--underscore");
|
app.add_flag("--underscore");
|
||||||
|
|
||||||
EXPECT_THROW(count->ignore_underscore(), CLI::OptionAlreadyAdded);
|
CHECK_THROWS_AS(count->ignore_underscore(), CLI::OptionAlreadyAdded);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, AddingMultipleInfPositionals) {
|
TEST_CASE_METHOD(TApp, "AddingMultipleInfPositionals", "[creation]") {
|
||||||
std::vector<std::string> one, two;
|
std::vector<std::string> one, two;
|
||||||
app.add_option("one", one);
|
app.add_option("one", one);
|
||||||
app.add_option("two", two);
|
app.add_option("two", two);
|
||||||
|
|
||||||
EXPECT_THROW(run(), CLI::InvalidError);
|
CHECK_THROWS_AS(run(), CLI::InvalidError);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, AddingMultipleInfPositionalsSubcom) {
|
TEST_CASE_METHOD(TApp, "AddingMultipleInfPositionalsSubcom", "[creation]") {
|
||||||
std::vector<std::string> one, two;
|
std::vector<std::string> one, two;
|
||||||
CLI::App *below = app.add_subcommand("below");
|
CLI::App *below = app.add_subcommand("below");
|
||||||
below->add_option("one", one);
|
below->add_option("one", one);
|
||||||
below->add_option("two", two);
|
below->add_option("two", two);
|
||||||
|
|
||||||
EXPECT_THROW(run(), CLI::InvalidError);
|
CHECK_THROWS_AS(run(), CLI::InvalidError);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, MultipleSubcomMatching) {
|
TEST_CASE_METHOD(TApp, "MultipleSubcomMatching", "[creation]") {
|
||||||
app.add_subcommand("first");
|
app.add_subcommand("first");
|
||||||
app.add_subcommand("second");
|
app.add_subcommand("second");
|
||||||
app.add_subcommand("Second");
|
app.add_subcommand("Second");
|
||||||
EXPECT_THROW(app.add_subcommand("first"), CLI::OptionAlreadyAdded);
|
CHECK_THROWS_AS(app.add_subcommand("first"), CLI::OptionAlreadyAdded);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, RecoverSubcommands) {
|
TEST_CASE_METHOD(TApp, "RecoverSubcommands", "[creation]") {
|
||||||
CLI::App *app1 = app.add_subcommand("app1");
|
CLI::App *app1 = app.add_subcommand("app1");
|
||||||
CLI::App *app2 = app.add_subcommand("app2");
|
CLI::App *app2 = app.add_subcommand("app2");
|
||||||
CLI::App *app3 = app.add_subcommand("app3");
|
CLI::App *app3 = app.add_subcommand("app3");
|
||||||
CLI::App *app4 = app.add_subcommand("app4");
|
CLI::App *app4 = app.add_subcommand("app4");
|
||||||
|
|
||||||
EXPECT_EQ(app.get_subcommands({}), std::vector<CLI::App *>({app1, app2, app3, app4}));
|
CHECK(std::vector<CLI::App *>({app1, app2, app3, app4}) == app.get_subcommands({}));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, MultipleSubcomMatchingWithCase) {
|
TEST_CASE_METHOD(TApp, "MultipleSubcomMatchingWithCase", "[creation]") {
|
||||||
app.add_subcommand("first")->ignore_case();
|
app.add_subcommand("first")->ignore_case();
|
||||||
EXPECT_THROW(app.add_subcommand("fIrst"), CLI::OptionAlreadyAdded);
|
CHECK_THROWS_AS(app.add_subcommand("fIrst"), CLI::OptionAlreadyAdded);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, MultipleSubcomMatchingWithCaseFirst) {
|
TEST_CASE_METHOD(TApp, "MultipleSubcomMatchingWithCaseFirst", "[creation]") {
|
||||||
app.ignore_case();
|
app.ignore_case();
|
||||||
app.add_subcommand("first");
|
app.add_subcommand("first");
|
||||||
EXPECT_THROW(app.add_subcommand("fIrst"), CLI::OptionAlreadyAdded);
|
CHECK_THROWS_AS(app.add_subcommand("fIrst"), CLI::OptionAlreadyAdded);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, MultipleSubcomMatchingWithUnderscore) {
|
TEST_CASE_METHOD(TApp, "MultipleSubcomMatchingWithUnderscore", "[creation]") {
|
||||||
app.add_subcommand("first_option")->ignore_underscore();
|
app.add_subcommand("first_option")->ignore_underscore();
|
||||||
EXPECT_THROW(app.add_subcommand("firstoption"), CLI::OptionAlreadyAdded);
|
CHECK_THROWS_AS(app.add_subcommand("firstoption"), CLI::OptionAlreadyAdded);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, MultipleSubcomMatchingWithUnderscoreFirst) {
|
TEST_CASE_METHOD(TApp, "MultipleSubcomMatchingWithUnderscoreFirst", "[creation]") {
|
||||||
app.ignore_underscore();
|
app.ignore_underscore();
|
||||||
app.add_subcommand("first_option");
|
app.add_subcommand("first_option");
|
||||||
EXPECT_THROW(app.add_subcommand("firstoption"), CLI::OptionAlreadyAdded);
|
CHECK_THROWS_AS(app.add_subcommand("firstoption"), CLI::OptionAlreadyAdded);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, MultipleSubcomMatchingWithCaseInplace) {
|
TEST_CASE_METHOD(TApp, "MultipleSubcomMatchingWithCaseInplace", "[creation]") {
|
||||||
app.add_subcommand("first");
|
app.add_subcommand("first");
|
||||||
auto first = app.add_subcommand("fIrst");
|
auto first = app.add_subcommand("fIrst");
|
||||||
|
|
||||||
EXPECT_THROW(first->ignore_case(), CLI::OptionAlreadyAdded);
|
CHECK_THROWS_AS(first->ignore_case(), CLI::OptionAlreadyAdded);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, MultipleSubcomMatchingWithCaseInplace2) {
|
TEST_CASE_METHOD(TApp, "MultipleSubcomMatchingWithCaseInplace2", "[creation]") {
|
||||||
auto first = app.add_subcommand("first");
|
auto first = app.add_subcommand("first");
|
||||||
app.add_subcommand("fIrst");
|
app.add_subcommand("fIrst");
|
||||||
|
|
||||||
EXPECT_THROW(first->ignore_case(), CLI::OptionAlreadyAdded);
|
CHECK_THROWS_AS(first->ignore_case(), CLI::OptionAlreadyAdded);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, MultipleSubcomMatchingWithUnderscoreInplace) {
|
TEST_CASE_METHOD(TApp, "MultipleSubcomMatchingWithUnderscoreInplace", "[creation]") {
|
||||||
app.add_subcommand("first_option");
|
app.add_subcommand("first_option");
|
||||||
auto first = app.add_subcommand("firstoption");
|
auto first = app.add_subcommand("firstoption");
|
||||||
|
|
||||||
EXPECT_THROW(first->ignore_underscore(), CLI::OptionAlreadyAdded);
|
CHECK_THROWS_AS(first->ignore_underscore(), CLI::OptionAlreadyAdded);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, MultipleSubcomMatchingWithUnderscoreInplace2) {
|
TEST_CASE_METHOD(TApp, "MultipleSubcomMatchingWithUnderscoreInplace2", "[creation]") {
|
||||||
auto first = app.add_subcommand("firstoption");
|
auto first = app.add_subcommand("firstoption");
|
||||||
app.add_subcommand("first_option");
|
app.add_subcommand("first_option");
|
||||||
|
|
||||||
EXPECT_THROW(first->ignore_underscore(), CLI::OptionAlreadyAdded);
|
CHECK_THROWS_AS(first->ignore_underscore(), CLI::OptionAlreadyAdded);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, MultipleSubcomNoMatchingInplace2) {
|
TEST_CASE_METHOD(TApp, "MultipleSubcomNoMatchingInplace2", "[creation]") {
|
||||||
auto first = app.add_subcommand("first");
|
auto first = app.add_subcommand("first");
|
||||||
auto second = app.add_subcommand("second");
|
auto second = app.add_subcommand("second");
|
||||||
|
|
||||||
EXPECT_NO_THROW(first->ignore_case());
|
CHECK_NOTHROW(first->ignore_case());
|
||||||
EXPECT_NO_THROW(second->ignore_case());
|
CHECK_NOTHROW(second->ignore_case());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, MultipleSubcomNoMatchingInplaceUnderscore2) {
|
TEST_CASE_METHOD(TApp, "MultipleSubcomNoMatchingInplaceUnderscore2", "[creation]") {
|
||||||
auto first = app.add_subcommand("first_option");
|
auto first = app.add_subcommand("first_option");
|
||||||
auto second = app.add_subcommand("second_option");
|
auto second = app.add_subcommand("second_option");
|
||||||
|
|
||||||
EXPECT_NO_THROW(first->ignore_underscore());
|
CHECK_NOTHROW(first->ignore_underscore());
|
||||||
EXPECT_NO_THROW(second->ignore_underscore());
|
CHECK_NOTHROW(second->ignore_underscore());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, IncorrectConstructionFlagPositional1) {
|
TEST_CASE_METHOD(TApp, "IncorrectConstructionFlagPositional1", "[creation]") {
|
||||||
// This wants to be one line with clang-format
|
// This wants to be one line with clang-format
|
||||||
EXPECT_THROW(app.add_flag("cat"), CLI::IncorrectConstruction);
|
CHECK_THROWS_AS(app.add_flag("cat"), CLI::IncorrectConstruction);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, IncorrectConstructionFlagPositional2) {
|
TEST_CASE_METHOD(TApp, "IncorrectConstructionFlagPositional2", "[creation]") {
|
||||||
int x{0};
|
int x{0};
|
||||||
EXPECT_THROW(app.add_flag("cat", x), CLI::IncorrectConstruction);
|
CHECK_THROWS_AS(app.add_flag("cat", x), CLI::IncorrectConstruction);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, IncorrectConstructionFlagPositional3) {
|
TEST_CASE_METHOD(TApp, "IncorrectConstructionFlagPositional3", "[creation]") {
|
||||||
bool x{false};
|
bool x{false};
|
||||||
EXPECT_THROW(app.add_flag("cat", x), CLI::IncorrectConstruction);
|
CHECK_THROWS_AS(app.add_flag("cat", x), CLI::IncorrectConstruction);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, IncorrectConstructionNeedsCannotFind) {
|
TEST_CASE_METHOD(TApp, "IncorrectConstructionNeedsCannotFind", "[creation]") {
|
||||||
auto cat = app.add_flag("--cat");
|
auto cat = app.add_flag("--cat");
|
||||||
EXPECT_THROW(cat->needs("--nothing"), CLI::IncorrectConstruction);
|
CHECK_THROWS_AS(cat->needs("--nothing"), CLI::IncorrectConstruction);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, IncorrectConstructionExcludesCannotFind) {
|
TEST_CASE_METHOD(TApp, "IncorrectConstructionExcludesCannotFind", "[creation]") {
|
||||||
auto cat = app.add_flag("--cat");
|
auto cat = app.add_flag("--cat");
|
||||||
EXPECT_THROW(cat->excludes("--nothing"), CLI::IncorrectConstruction);
|
CHECK_THROWS_AS(cat->excludes("--nothing"), CLI::IncorrectConstruction);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, IncorrectConstructionDuplicateNeeds) {
|
TEST_CASE_METHOD(TApp, "IncorrectConstructionDuplicateNeeds", "[creation]") {
|
||||||
auto cat = app.add_flag("--cat");
|
auto cat = app.add_flag("--cat");
|
||||||
auto other = app.add_flag("--other");
|
auto other = app.add_flag("--other");
|
||||||
ASSERT_NO_THROW(cat->needs(other));
|
REQUIRE_NOTHROW(cat->needs(other));
|
||||||
// duplicated needs is redundant but not an error
|
// duplicated needs is redundant but not an error
|
||||||
EXPECT_NO_THROW(cat->needs(other));
|
CHECK_NOTHROW(cat->needs(other));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, IncorrectConstructionDuplicateNeedsTxt) {
|
TEST_CASE_METHOD(TApp, "IncorrectConstructionDuplicateNeedsTxt", "[creation]") {
|
||||||
auto cat = app.add_flag("--cat");
|
auto cat = app.add_flag("--cat");
|
||||||
app.add_flag("--other");
|
app.add_flag("--other");
|
||||||
ASSERT_NO_THROW(cat->needs("--other"));
|
REQUIRE_NOTHROW(cat->needs("--other"));
|
||||||
// duplicate needs is redundant but not an error
|
// duplicate needs is redundant but not an error
|
||||||
EXPECT_NO_THROW(cat->needs("--other"));
|
CHECK_NOTHROW(cat->needs("--other"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now allowed
|
// Now allowed
|
||||||
TEST_F(TApp, CorrectConstructionDuplicateExcludes) {
|
TEST_CASE_METHOD(TApp, "CorrectConstructionDuplicateExcludes", "[creation]") {
|
||||||
auto cat = app.add_flag("--cat");
|
auto cat = app.add_flag("--cat");
|
||||||
auto other = app.add_flag("--other");
|
auto other = app.add_flag("--other");
|
||||||
ASSERT_NO_THROW(cat->excludes(other));
|
REQUIRE_NOTHROW(cat->excludes(other));
|
||||||
ASSERT_NO_THROW(other->excludes(cat));
|
REQUIRE_NOTHROW(other->excludes(cat));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now allowed
|
// Now allowed
|
||||||
TEST_F(TApp, CorrectConstructionDuplicateExcludesTxt) {
|
TEST_CASE_METHOD(TApp, "CorrectConstructionDuplicateExcludesTxt", "[creation]") {
|
||||||
auto cat = app.add_flag("--cat");
|
auto cat = app.add_flag("--cat");
|
||||||
auto other = app.add_flag("--other");
|
auto other = app.add_flag("--other");
|
||||||
ASSERT_NO_THROW(cat->excludes("--other"));
|
REQUIRE_NOTHROW(cat->excludes("--other"));
|
||||||
ASSERT_NO_THROW(other->excludes("--cat"));
|
REQUIRE_NOTHROW(other->excludes("--cat"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, CheckName) {
|
TEST_CASE_METHOD(TApp, "CheckName", "[creation]") {
|
||||||
auto long1 = app.add_flag("--long1");
|
auto long1 = app.add_flag("--long1");
|
||||||
auto long2 = app.add_flag("--Long2");
|
auto long2 = app.add_flag("--Long2");
|
||||||
auto short1 = app.add_flag("-a");
|
auto short1 = app.add_flag("-a");
|
||||||
@ -233,26 +233,26 @@ TEST_F(TApp, CheckName) {
|
|||||||
auto pos1 = app.add_option("pos1", x);
|
auto pos1 = app.add_option("pos1", x);
|
||||||
auto pos2 = app.add_option("pOs2", y);
|
auto pos2 = app.add_option("pOs2", y);
|
||||||
|
|
||||||
EXPECT_TRUE(long1->check_name("--long1"));
|
CHECK(long1->check_name("--long1"));
|
||||||
EXPECT_FALSE(long1->check_name("--lonG1"));
|
CHECK(!long1->check_name("--lonG1"));
|
||||||
|
|
||||||
EXPECT_TRUE(long2->check_name("--Long2"));
|
CHECK(long2->check_name("--Long2"));
|
||||||
EXPECT_FALSE(long2->check_name("--long2"));
|
CHECK(!long2->check_name("--long2"));
|
||||||
|
|
||||||
EXPECT_TRUE(short1->check_name("-a"));
|
CHECK(short1->check_name("-a"));
|
||||||
EXPECT_FALSE(short1->check_name("-A"));
|
CHECK(!short1->check_name("-A"));
|
||||||
|
|
||||||
EXPECT_TRUE(short2->check_name("-B"));
|
CHECK(short2->check_name("-B"));
|
||||||
EXPECT_FALSE(short2->check_name("-b"));
|
CHECK(!short2->check_name("-b"));
|
||||||
|
|
||||||
EXPECT_TRUE(pos1->check_name("pos1"));
|
CHECK(pos1->check_name("pos1"));
|
||||||
EXPECT_FALSE(pos1->check_name("poS1"));
|
CHECK(!pos1->check_name("poS1"));
|
||||||
|
|
||||||
EXPECT_TRUE(pos2->check_name("pOs2"));
|
CHECK(pos2->check_name("pOs2"));
|
||||||
EXPECT_FALSE(pos2->check_name("pos2"));
|
CHECK(!pos2->check_name("pos2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, CheckNameNoCase) {
|
TEST_CASE_METHOD(TApp, "CheckNameNoCase", "[creation]") {
|
||||||
auto long1 = app.add_flag("--long1")->ignore_case();
|
auto long1 = app.add_flag("--long1")->ignore_case();
|
||||||
auto long2 = app.add_flag("--Long2")->ignore_case();
|
auto long2 = app.add_flag("--Long2")->ignore_case();
|
||||||
auto short1 = app.add_flag("-a")->ignore_case();
|
auto short1 = app.add_flag("-a")->ignore_case();
|
||||||
@ -261,26 +261,26 @@ TEST_F(TApp, CheckNameNoCase) {
|
|||||||
auto pos1 = app.add_option("pos1", x)->ignore_case();
|
auto pos1 = app.add_option("pos1", x)->ignore_case();
|
||||||
auto pos2 = app.add_option("pOs2", y)->ignore_case();
|
auto pos2 = app.add_option("pOs2", y)->ignore_case();
|
||||||
|
|
||||||
EXPECT_TRUE(long1->check_name("--long1"));
|
CHECK(long1->check_name("--long1"));
|
||||||
EXPECT_TRUE(long1->check_name("--lonG1"));
|
CHECK(long1->check_name("--lonG1"));
|
||||||
|
|
||||||
EXPECT_TRUE(long2->check_name("--Long2"));
|
CHECK(long2->check_name("--Long2"));
|
||||||
EXPECT_TRUE(long2->check_name("--long2"));
|
CHECK(long2->check_name("--long2"));
|
||||||
|
|
||||||
EXPECT_TRUE(short1->check_name("-a"));
|
CHECK(short1->check_name("-a"));
|
||||||
EXPECT_TRUE(short1->check_name("-A"));
|
CHECK(short1->check_name("-A"));
|
||||||
|
|
||||||
EXPECT_TRUE(short2->check_name("-B"));
|
CHECK(short2->check_name("-B"));
|
||||||
EXPECT_TRUE(short2->check_name("-b"));
|
CHECK(short2->check_name("-b"));
|
||||||
|
|
||||||
EXPECT_TRUE(pos1->check_name("pos1"));
|
CHECK(pos1->check_name("pos1"));
|
||||||
EXPECT_TRUE(pos1->check_name("poS1"));
|
CHECK(pos1->check_name("poS1"));
|
||||||
|
|
||||||
EXPECT_TRUE(pos2->check_name("pOs2"));
|
CHECK(pos2->check_name("pOs2"));
|
||||||
EXPECT_TRUE(pos2->check_name("pos2"));
|
CHECK(pos2->check_name("pos2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, CheckNameNoUnderscore) {
|
TEST_CASE_METHOD(TApp, "CheckNameNoUnderscore", "[creation]") {
|
||||||
auto long1 = app.add_flag("--longoption1")->ignore_underscore();
|
auto long1 = app.add_flag("--longoption1")->ignore_underscore();
|
||||||
auto long2 = app.add_flag("--long_option2")->ignore_underscore();
|
auto long2 = app.add_flag("--long_option2")->ignore_underscore();
|
||||||
|
|
||||||
@ -288,30 +288,30 @@ TEST_F(TApp, CheckNameNoUnderscore) {
|
|||||||
auto pos1 = app.add_option("pos_option_1", x)->ignore_underscore();
|
auto pos1 = app.add_option("pos_option_1", x)->ignore_underscore();
|
||||||
auto pos2 = app.add_option("posoption2", y)->ignore_underscore();
|
auto pos2 = app.add_option("posoption2", y)->ignore_underscore();
|
||||||
|
|
||||||
EXPECT_TRUE(long1->check_name("--long_option1"));
|
CHECK(long1->check_name("--long_option1"));
|
||||||
EXPECT_TRUE(long1->check_name("--longoption_1"));
|
CHECK(long1->check_name("--longoption_1"));
|
||||||
EXPECT_TRUE(long1->check_name("--longoption1"));
|
CHECK(long1->check_name("--longoption1"));
|
||||||
EXPECT_TRUE(long1->check_name("--long__opt_ion__1"));
|
CHECK(long1->check_name("--long__opt_ion__1"));
|
||||||
EXPECT_TRUE(long1->check_name("--__l_o_n_g_o_p_t_i_o_n_1"));
|
CHECK(long1->check_name("--__l_o_n_g_o_p_t_i_o_n_1"));
|
||||||
|
|
||||||
EXPECT_TRUE(long2->check_name("--long_option2"));
|
CHECK(long2->check_name("--long_option2"));
|
||||||
EXPECT_TRUE(long2->check_name("--longoption2"));
|
CHECK(long2->check_name("--longoption2"));
|
||||||
EXPECT_TRUE(long2->check_name("--longoption_2"));
|
CHECK(long2->check_name("--longoption_2"));
|
||||||
EXPECT_TRUE(long2->check_name("--long__opt_ion__2"));
|
CHECK(long2->check_name("--long__opt_ion__2"));
|
||||||
EXPECT_TRUE(long2->check_name("--__l_o_n_go_p_t_i_o_n_2__"));
|
CHECK(long2->check_name("--__l_o_n_go_p_t_i_o_n_2__"));
|
||||||
|
|
||||||
EXPECT_TRUE(pos1->check_name("pos_option1"));
|
CHECK(pos1->check_name("pos_option1"));
|
||||||
EXPECT_TRUE(pos1->check_name("pos_option_1"));
|
CHECK(pos1->check_name("pos_option_1"));
|
||||||
EXPECT_TRUE(pos1->check_name("pos_o_p_t_i_on_1"));
|
CHECK(pos1->check_name("pos_o_p_t_i_on_1"));
|
||||||
EXPECT_TRUE(pos1->check_name("posoption1"));
|
CHECK(pos1->check_name("posoption1"));
|
||||||
|
|
||||||
EXPECT_TRUE(pos2->check_name("pos_option2"));
|
CHECK(pos2->check_name("pos_option2"));
|
||||||
EXPECT_TRUE(pos2->check_name("pos_option_2"));
|
CHECK(pos2->check_name("pos_option_2"));
|
||||||
EXPECT_TRUE(pos2->check_name("pos_o_p_t_i_on_2"));
|
CHECK(pos2->check_name("pos_o_p_t_i_on_2"));
|
||||||
EXPECT_TRUE(pos2->check_name("posoption2"));
|
CHECK(pos2->check_name("posoption2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, CheckNameNoCaseNoUnderscore) {
|
TEST_CASE_METHOD(TApp, "CheckNameNoCaseNoUnderscore", "[creation]") {
|
||||||
auto long1 = app.add_flag("--LongoptioN1")->ignore_underscore()->ignore_case();
|
auto long1 = app.add_flag("--LongoptioN1")->ignore_underscore()->ignore_case();
|
||||||
auto long2 = app.add_flag("--long_Option2")->ignore_case()->ignore_underscore();
|
auto long2 = app.add_flag("--long_Option2")->ignore_case()->ignore_underscore();
|
||||||
|
|
||||||
@ -319,85 +319,85 @@ TEST_F(TApp, CheckNameNoCaseNoUnderscore) {
|
|||||||
auto pos1 = app.add_option("pos_Option_1", x)->ignore_underscore()->ignore_case();
|
auto pos1 = app.add_option("pos_Option_1", x)->ignore_underscore()->ignore_case();
|
||||||
auto pos2 = app.add_option("posOption2", y)->ignore_case()->ignore_underscore();
|
auto pos2 = app.add_option("posOption2", y)->ignore_case()->ignore_underscore();
|
||||||
|
|
||||||
EXPECT_TRUE(long1->check_name("--Long_Option1"));
|
CHECK(long1->check_name("--Long_Option1"));
|
||||||
EXPECT_TRUE(long1->check_name("--lONgoption_1"));
|
CHECK(long1->check_name("--lONgoption_1"));
|
||||||
EXPECT_TRUE(long1->check_name("--LongOption1"));
|
CHECK(long1->check_name("--LongOption1"));
|
||||||
EXPECT_TRUE(long1->check_name("--long__Opt_ion__1"));
|
CHECK(long1->check_name("--long__Opt_ion__1"));
|
||||||
EXPECT_TRUE(long1->check_name("--__l_o_N_g_o_P_t_i_O_n_1"));
|
CHECK(long1->check_name("--__l_o_N_g_o_P_t_i_O_n_1"));
|
||||||
|
|
||||||
EXPECT_TRUE(long2->check_name("--long_Option2"));
|
CHECK(long2->check_name("--long_Option2"));
|
||||||
EXPECT_TRUE(long2->check_name("--LongOption2"));
|
CHECK(long2->check_name("--LongOption2"));
|
||||||
EXPECT_TRUE(long2->check_name("--longOPTION_2"));
|
CHECK(long2->check_name("--longOPTION_2"));
|
||||||
EXPECT_TRUE(long2->check_name("--long__OPT_ion__2"));
|
CHECK(long2->check_name("--long__OPT_ion__2"));
|
||||||
EXPECT_TRUE(long2->check_name("--__l_o_n_GO_p_t_i_o_n_2__"));
|
CHECK(long2->check_name("--__l_o_n_GO_p_t_i_o_n_2__"));
|
||||||
|
|
||||||
EXPECT_TRUE(pos1->check_name("POS_Option1"));
|
CHECK(pos1->check_name("POS_Option1"));
|
||||||
EXPECT_TRUE(pos1->check_name("pos_option_1"));
|
CHECK(pos1->check_name("pos_option_1"));
|
||||||
EXPECT_TRUE(pos1->check_name("pos_o_p_t_i_on_1"));
|
CHECK(pos1->check_name("pos_o_p_t_i_on_1"));
|
||||||
EXPECT_TRUE(pos1->check_name("posoption1"));
|
CHECK(pos1->check_name("posoption1"));
|
||||||
|
|
||||||
EXPECT_TRUE(pos2->check_name("pos_option2"));
|
CHECK(pos2->check_name("pos_option2"));
|
||||||
EXPECT_TRUE(pos2->check_name("pos_OPTION_2"));
|
CHECK(pos2->check_name("pos_OPTION_2"));
|
||||||
EXPECT_TRUE(pos2->check_name("poS_o_p_T_I_on_2"));
|
CHECK(pos2->check_name("poS_o_p_T_I_on_2"));
|
||||||
EXPECT_TRUE(pos2->check_name("PosOption2"));
|
CHECK(pos2->check_name("PosOption2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, PreSpaces) {
|
TEST_CASE_METHOD(TApp, "PreSpaces", "[creation]") {
|
||||||
int x{0};
|
int x{0};
|
||||||
auto myapp = app.add_option(" -a, --long, other", x);
|
auto myapp = app.add_option(" -a, --long, other", x);
|
||||||
|
|
||||||
EXPECT_TRUE(myapp->check_lname("long"));
|
CHECK(myapp->check_lname("long"));
|
||||||
EXPECT_TRUE(myapp->check_sname("a"));
|
CHECK(myapp->check_sname("a"));
|
||||||
EXPECT_TRUE(myapp->check_name("other"));
|
CHECK(myapp->check_name("other"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, AllSpaces) {
|
TEST_CASE_METHOD(TApp, "AllSpaces", "[creation]") {
|
||||||
int x{0};
|
int x{0};
|
||||||
auto myapp = app.add_option(" -a , --long , other ", x);
|
auto myapp = app.add_option(" -a , --long , other ", x);
|
||||||
|
|
||||||
EXPECT_TRUE(myapp->check_lname("long"));
|
CHECK(myapp->check_lname("long"));
|
||||||
EXPECT_TRUE(myapp->check_sname("a"));
|
CHECK(myapp->check_sname("a"));
|
||||||
EXPECT_TRUE(myapp->check_name("other"));
|
CHECK(myapp->check_name("other"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, OptionFromDefaults) {
|
TEST_CASE_METHOD(TApp, "OptionFromDefaults", "[creation]") {
|
||||||
app.option_defaults()->required();
|
app.option_defaults()->required();
|
||||||
|
|
||||||
// Options should remember defaults
|
// Options should remember defaults
|
||||||
int x{0};
|
int x{0};
|
||||||
auto opt = app.add_option("--simple", x);
|
auto opt = app.add_option("--simple", x);
|
||||||
EXPECT_TRUE(opt->get_required());
|
CHECK(opt->get_required());
|
||||||
|
|
||||||
// Flags cannot be required
|
// Flags cannot be required
|
||||||
auto flag = app.add_flag("--other");
|
auto flag = app.add_flag("--other");
|
||||||
EXPECT_FALSE(flag->get_required());
|
CHECK(!flag->get_required());
|
||||||
|
|
||||||
app.option_defaults()->required(false);
|
app.option_defaults()->required(false);
|
||||||
auto opt2 = app.add_option("--simple2", x);
|
auto opt2 = app.add_option("--simple2", x);
|
||||||
EXPECT_FALSE(opt2->get_required());
|
CHECK(!opt2->get_required());
|
||||||
|
|
||||||
app.option_defaults()->required()->ignore_case();
|
app.option_defaults()->required()->ignore_case();
|
||||||
|
|
||||||
auto opt3 = app.add_option("--simple3", x);
|
auto opt3 = app.add_option("--simple3", x);
|
||||||
EXPECT_TRUE(opt3->get_required());
|
CHECK(opt3->get_required());
|
||||||
EXPECT_TRUE(opt3->get_ignore_case());
|
CHECK(opt3->get_ignore_case());
|
||||||
|
|
||||||
app.option_defaults()->required()->ignore_underscore();
|
app.option_defaults()->required()->ignore_underscore();
|
||||||
|
|
||||||
auto opt4 = app.add_option("--simple4", x);
|
auto opt4 = app.add_option("--simple4", x);
|
||||||
EXPECT_TRUE(opt4->get_required());
|
CHECK(opt4->get_required());
|
||||||
EXPECT_TRUE(opt4->get_ignore_underscore());
|
CHECK(opt4->get_ignore_underscore());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, OptionFromDefaultsSubcommands) {
|
TEST_CASE_METHOD(TApp, "OptionFromDefaultsSubcommands", "[creation]") {
|
||||||
// Initial defaults
|
// Initial defaults
|
||||||
EXPECT_FALSE(app.option_defaults()->get_required());
|
CHECK(!app.option_defaults()->get_required());
|
||||||
EXPECT_EQ(app.option_defaults()->get_multi_option_policy(), CLI::MultiOptionPolicy::Throw);
|
CHECK(CLI::MultiOptionPolicy::Throw == app.option_defaults()->get_multi_option_policy());
|
||||||
EXPECT_FALSE(app.option_defaults()->get_ignore_case());
|
CHECK(!app.option_defaults()->get_ignore_case());
|
||||||
EXPECT_FALSE(app.option_defaults()->get_ignore_underscore());
|
CHECK(!app.option_defaults()->get_ignore_underscore());
|
||||||
EXPECT_FALSE(app.option_defaults()->get_disable_flag_override());
|
CHECK(!app.option_defaults()->get_disable_flag_override());
|
||||||
EXPECT_TRUE(app.option_defaults()->get_configurable());
|
CHECK(app.option_defaults()->get_configurable());
|
||||||
EXPECT_EQ(app.option_defaults()->get_group(), "Options");
|
CHECK("Options" == app.option_defaults()->get_group());
|
||||||
|
|
||||||
app.option_defaults()
|
app.option_defaults()
|
||||||
->required()
|
->required()
|
||||||
@ -410,55 +410,55 @@ TEST_F(TApp, OptionFromDefaultsSubcommands) {
|
|||||||
|
|
||||||
auto app2 = app.add_subcommand("app2");
|
auto app2 = app.add_subcommand("app2");
|
||||||
|
|
||||||
EXPECT_TRUE(app2->option_defaults()->get_required());
|
CHECK(app2->option_defaults()->get_required());
|
||||||
EXPECT_EQ(app2->option_defaults()->get_multi_option_policy(), CLI::MultiOptionPolicy::TakeLast);
|
CHECK(CLI::MultiOptionPolicy::TakeLast == app2->option_defaults()->get_multi_option_policy());
|
||||||
EXPECT_TRUE(app2->option_defaults()->get_ignore_case());
|
CHECK(app2->option_defaults()->get_ignore_case());
|
||||||
EXPECT_TRUE(app2->option_defaults()->get_ignore_underscore());
|
CHECK(app2->option_defaults()->get_ignore_underscore());
|
||||||
EXPECT_FALSE(app2->option_defaults()->get_configurable());
|
CHECK(!app2->option_defaults()->get_configurable());
|
||||||
EXPECT_TRUE(app.option_defaults()->get_disable_flag_override());
|
CHECK(app.option_defaults()->get_disable_flag_override());
|
||||||
EXPECT_EQ(app2->option_defaults()->get_group(), "Something");
|
CHECK("Something" == app2->option_defaults()->get_group());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, GetNameCheck) {
|
TEST_CASE_METHOD(TApp, "GetNameCheck", "[creation]") {
|
||||||
int x{0};
|
int x{0};
|
||||||
auto a = app.add_flag("--that");
|
auto a = app.add_flag("--that");
|
||||||
auto b = app.add_flag("-x");
|
auto b = app.add_flag("-x");
|
||||||
auto c = app.add_option("pos", x);
|
auto c = app.add_option("pos", x);
|
||||||
auto d = app.add_option("one,-o,--other", x);
|
auto d = app.add_option("one,-o,--other", x);
|
||||||
|
|
||||||
EXPECT_EQ(a->get_name(false, true), "--that");
|
CHECK("--that" == a->get_name(false, true));
|
||||||
EXPECT_EQ(b->get_name(false, true), "-x");
|
CHECK("-x" == b->get_name(false, true));
|
||||||
EXPECT_EQ(c->get_name(false, true), "pos");
|
CHECK("pos" == c->get_name(false, true));
|
||||||
|
|
||||||
EXPECT_EQ(d->get_name(), "--other");
|
CHECK("--other" == d->get_name());
|
||||||
EXPECT_EQ(d->get_name(false, false), "--other");
|
CHECK("--other" == d->get_name(false, false));
|
||||||
EXPECT_EQ(d->get_name(false, true), "-o,--other");
|
CHECK("-o,--other" == d->get_name(false, true));
|
||||||
EXPECT_EQ(d->get_name(true, true), "one,-o,--other");
|
CHECK("one,-o,--other" == d->get_name(true, true));
|
||||||
EXPECT_EQ(d->get_name(true, false), "one");
|
CHECK("one" == d->get_name(true, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, SubcommandDefaults) {
|
TEST_CASE_METHOD(TApp, "SubcommandDefaults", "[creation]") {
|
||||||
// allow_extras, prefix_command, ignore_case, fallthrough, group, min/max subcommand, validate_positionals
|
// allow_extras, prefix_command, ignore_case, fallthrough, group, min/max subcommand, validate_positionals
|
||||||
|
|
||||||
// Initial defaults
|
// Initial defaults
|
||||||
EXPECT_FALSE(app.get_allow_extras());
|
CHECK(!app.get_allow_extras());
|
||||||
EXPECT_FALSE(app.get_prefix_command());
|
CHECK(!app.get_prefix_command());
|
||||||
EXPECT_FALSE(app.get_immediate_callback());
|
CHECK(!app.get_immediate_callback());
|
||||||
EXPECT_FALSE(app.get_ignore_case());
|
CHECK(!app.get_ignore_case());
|
||||||
EXPECT_FALSE(app.get_ignore_underscore());
|
CHECK(!app.get_ignore_underscore());
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
EXPECT_TRUE(app.get_allow_windows_style_options());
|
CHECK(app.get_allow_windows_style_options());
|
||||||
#else
|
#else
|
||||||
EXPECT_FALSE(app.get_allow_windows_style_options());
|
CHECK(!app.get_allow_windows_style_options());
|
||||||
#endif
|
#endif
|
||||||
EXPECT_FALSE(app.get_fallthrough());
|
CHECK(!app.get_fallthrough());
|
||||||
EXPECT_FALSE(app.get_configurable());
|
CHECK(!app.get_configurable());
|
||||||
EXPECT_FALSE(app.get_validate_positionals());
|
CHECK(!app.get_validate_positionals());
|
||||||
|
|
||||||
EXPECT_EQ(app.get_footer(), "");
|
CHECK("" == app.get_footer());
|
||||||
EXPECT_EQ(app.get_group(), "Subcommands");
|
CHECK("Subcommands" == app.get_group());
|
||||||
EXPECT_EQ(app.get_require_subcommand_min(), 0u);
|
CHECK(0u == app.get_require_subcommand_min());
|
||||||
EXPECT_EQ(app.get_require_subcommand_max(), 0u);
|
CHECK(0u == app.get_require_subcommand_max());
|
||||||
|
|
||||||
app.allow_extras();
|
app.allow_extras();
|
||||||
app.prefix_command();
|
app.prefix_command();
|
||||||
@ -481,57 +481,57 @@ TEST_F(TApp, SubcommandDefaults) {
|
|||||||
auto app2 = app.add_subcommand("app2");
|
auto app2 = app.add_subcommand("app2");
|
||||||
|
|
||||||
// Initial defaults
|
// Initial defaults
|
||||||
EXPECT_TRUE(app2->get_allow_extras());
|
CHECK(app2->get_allow_extras());
|
||||||
EXPECT_TRUE(app2->get_prefix_command());
|
CHECK(app2->get_prefix_command());
|
||||||
EXPECT_TRUE(app2->get_immediate_callback());
|
CHECK(app2->get_immediate_callback());
|
||||||
EXPECT_TRUE(app2->get_ignore_case());
|
CHECK(app2->get_ignore_case());
|
||||||
EXPECT_TRUE(app2->get_ignore_underscore());
|
CHECK(app2->get_ignore_underscore());
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
EXPECT_FALSE(app2->get_allow_windows_style_options());
|
CHECK(!app2->get_allow_windows_style_options());
|
||||||
#else
|
#else
|
||||||
EXPECT_TRUE(app2->get_allow_windows_style_options());
|
CHECK(app2->get_allow_windows_style_options());
|
||||||
#endif
|
#endif
|
||||||
EXPECT_TRUE(app2->get_fallthrough());
|
CHECK(app2->get_fallthrough());
|
||||||
EXPECT_TRUE(app2->get_validate_positionals());
|
CHECK(app2->get_validate_positionals());
|
||||||
EXPECT_TRUE(app2->get_configurable());
|
CHECK(app2->get_configurable());
|
||||||
EXPECT_EQ(app2->get_footer(), "footy");
|
CHECK("footy" == app2->get_footer());
|
||||||
EXPECT_EQ(app2->get_group(), "Stuff");
|
CHECK("Stuff" == app2->get_group());
|
||||||
EXPECT_EQ(app2->get_require_subcommand_min(), 0u);
|
CHECK(0u == app2->get_require_subcommand_min());
|
||||||
EXPECT_EQ(app2->get_require_subcommand_max(), 3u);
|
CHECK(3u == app2->get_require_subcommand_max());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, SubcommandMinMax) {
|
TEST_CASE_METHOD(TApp, "SubcommandMinMax", "[creation]") {
|
||||||
|
|
||||||
EXPECT_EQ(app.get_require_subcommand_min(), 0u);
|
CHECK(0u == app.get_require_subcommand_min());
|
||||||
EXPECT_EQ(app.get_require_subcommand_max(), 0u);
|
CHECK(0u == app.get_require_subcommand_max());
|
||||||
|
|
||||||
app.require_subcommand();
|
app.require_subcommand();
|
||||||
|
|
||||||
EXPECT_EQ(app.get_require_subcommand_min(), 1u);
|
CHECK(1u == app.get_require_subcommand_min());
|
||||||
EXPECT_EQ(app.get_require_subcommand_max(), 0u);
|
CHECK(0u == app.get_require_subcommand_max());
|
||||||
|
|
||||||
app.require_subcommand(2);
|
app.require_subcommand(2);
|
||||||
|
|
||||||
EXPECT_EQ(app.get_require_subcommand_min(), 2u);
|
CHECK(2u == app.get_require_subcommand_min());
|
||||||
EXPECT_EQ(app.get_require_subcommand_max(), 2u);
|
CHECK(2u == app.get_require_subcommand_max());
|
||||||
|
|
||||||
app.require_subcommand(0);
|
app.require_subcommand(0);
|
||||||
|
|
||||||
EXPECT_EQ(app.get_require_subcommand_min(), 0u);
|
CHECK(0u == app.get_require_subcommand_min());
|
||||||
EXPECT_EQ(app.get_require_subcommand_max(), 0u);
|
CHECK(0u == app.get_require_subcommand_max());
|
||||||
|
|
||||||
app.require_subcommand(-2);
|
app.require_subcommand(-2);
|
||||||
|
|
||||||
EXPECT_EQ(app.get_require_subcommand_min(), 0u);
|
CHECK(0u == app.get_require_subcommand_min());
|
||||||
EXPECT_EQ(app.get_require_subcommand_max(), 2u);
|
CHECK(2u == app.get_require_subcommand_max());
|
||||||
|
|
||||||
app.require_subcommand(3, 7);
|
app.require_subcommand(3, 7);
|
||||||
|
|
||||||
EXPECT_EQ(app.get_require_subcommand_min(), 3u);
|
CHECK(3u == app.get_require_subcommand_min());
|
||||||
EXPECT_EQ(app.get_require_subcommand_max(), 7u);
|
CHECK(7u == app.get_require_subcommand_max());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, GetOptionList) {
|
TEST_CASE_METHOD(TApp, "GetOptionList", "[creation]") {
|
||||||
int two{0};
|
int two{0};
|
||||||
auto flag = app.add_flag("--one");
|
auto flag = app.add_flag("--one");
|
||||||
auto opt = app.add_option("--two", two);
|
auto opt = app.add_option("--two", two);
|
||||||
@ -539,36 +539,36 @@ TEST_F(TApp, GetOptionList) {
|
|||||||
const CLI::App &const_app = app; // const alias to force use of const-methods
|
const CLI::App &const_app = app; // const alias to force use of const-methods
|
||||||
std::vector<const CLI::Option *> opt_list = const_app.get_options();
|
std::vector<const CLI::Option *> opt_list = const_app.get_options();
|
||||||
|
|
||||||
ASSERT_EQ(opt_list.size(), static_cast<std::size_t>(3));
|
REQUIRE(static_cast<std::size_t>(3) == opt_list.size());
|
||||||
EXPECT_EQ(opt_list.at(1), flag);
|
CHECK(flag == opt_list.at(1));
|
||||||
EXPECT_EQ(opt_list.at(2), opt);
|
CHECK(opt == opt_list.at(2));
|
||||||
|
|
||||||
std::vector<CLI::Option *> nonconst_opt_list = app.get_options();
|
std::vector<CLI::Option *> nonconst_opt_list = app.get_options();
|
||||||
for(std::size_t i = 0; i < opt_list.size(); ++i) {
|
for(std::size_t i = 0; i < opt_list.size(); ++i) {
|
||||||
EXPECT_EQ(nonconst_opt_list.at(i), opt_list.at(i));
|
CHECK(opt_list.at(i) == nonconst_opt_list.at(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(ValidatorTests, TestValidatorCreation) {
|
TEST_CASE("ValidatorTests: TestValidatorCreation", "[creation]") {
|
||||||
std::function<std::string(std::string &)> op1 = [](std::string &val) {
|
std::function<std::string(std::string &)> op1 = [](std::string &val) {
|
||||||
return (val.size() >= 5) ? std::string{} : val;
|
return (val.size() >= 5) ? std::string{} : val;
|
||||||
};
|
};
|
||||||
CLI::Validator V(op1, "", "size");
|
CLI::Validator V(op1, "", "size");
|
||||||
|
|
||||||
EXPECT_EQ(V.get_name(), "size");
|
CHECK("size" == V.get_name());
|
||||||
V.name("harry");
|
V.name("harry");
|
||||||
EXPECT_EQ(V.get_name(), "harry");
|
CHECK("harry" == V.get_name());
|
||||||
EXPECT_TRUE(V.get_active());
|
CHECK(V.get_active());
|
||||||
|
|
||||||
EXPECT_EQ(V("test"), "test");
|
CHECK("test" == V("test"));
|
||||||
EXPECT_EQ(V("test5"), std::string{});
|
CHECK(std::string{} == V("test5"));
|
||||||
|
|
||||||
EXPECT_EQ(V.get_description(), std::string{});
|
CHECK(std::string{} == V.get_description());
|
||||||
V.description("this is a description");
|
V.description("this is a description");
|
||||||
EXPECT_EQ(V.get_description(), "this is a description");
|
CHECK("this is a description" == V.get_description());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(ValidatorTests, TestValidatorOps) {
|
TEST_CASE("ValidatorTests: TestValidatorOps", "[creation]") {
|
||||||
std::function<std::string(std::string &)> op1 = [](std::string &val) {
|
std::function<std::string(std::string &)> op1 = [](std::string &val) {
|
||||||
return (val.size() >= 5) ? std::string{} : val;
|
return (val.size() >= 5) ? std::string{} : val;
|
||||||
};
|
};
|
||||||
@ -593,72 +593,72 @@ TEST(ValidatorTests, TestValidatorOps) {
|
|||||||
std::string eight(8, 'a');
|
std::string eight(8, 'a');
|
||||||
std::string nine(9, 'a');
|
std::string nine(9, 'a');
|
||||||
std::string ten(10, 'a');
|
std::string ten(10, 'a');
|
||||||
EXPECT_TRUE(V1(five).empty());
|
CHECK(V1(five).empty());
|
||||||
EXPECT_FALSE(V1(four).empty());
|
CHECK(!V1(four).empty());
|
||||||
|
|
||||||
EXPECT_TRUE(V2(nine).empty());
|
CHECK(V2(nine).empty());
|
||||||
EXPECT_FALSE(V2(eight).empty());
|
CHECK(!V2(eight).empty());
|
||||||
|
|
||||||
EXPECT_TRUE(V3(two).empty());
|
CHECK(V3(two).empty());
|
||||||
EXPECT_FALSE(V3(four).empty());
|
CHECK(!V3(four).empty());
|
||||||
|
|
||||||
EXPECT_TRUE(V4(eight).empty());
|
CHECK(V4(eight).empty());
|
||||||
EXPECT_FALSE(V4(ten).empty());
|
CHECK(!V4(ten).empty());
|
||||||
|
|
||||||
auto V1a2 = V1 & V2;
|
auto V1a2 = V1 & V2;
|
||||||
EXPECT_EQ(V1a2.get_description(), "(SIZE >= 5) AND (SIZE >= 9)");
|
CHECK("(SIZE >= 5) AND (SIZE >= 9)" == V1a2.get_description());
|
||||||
EXPECT_FALSE(V1a2(five).empty());
|
CHECK(!V1a2(five).empty());
|
||||||
EXPECT_TRUE(V1a2(nine).empty());
|
CHECK(V1a2(nine).empty());
|
||||||
|
|
||||||
auto V1a4 = V1 & V4;
|
auto V1a4 = V1 & V4;
|
||||||
EXPECT_EQ(V1a4.get_description(), "(SIZE >= 5) AND (SIZE <= 9)");
|
CHECK("(SIZE >= 5) AND (SIZE <= 9)" == V1a4.get_description());
|
||||||
EXPECT_TRUE(V1a4(five).empty());
|
CHECK(V1a4(five).empty());
|
||||||
EXPECT_TRUE(V1a4(eight).empty());
|
CHECK(V1a4(eight).empty());
|
||||||
EXPECT_FALSE(V1a4(ten).empty());
|
CHECK(!V1a4(ten).empty());
|
||||||
EXPECT_FALSE(V1a4(four).empty());
|
CHECK(!V1a4(four).empty());
|
||||||
|
|
||||||
auto V1o3 = V1 | V3;
|
auto V1o3 = V1 | V3;
|
||||||
EXPECT_EQ(V1o3.get_description(), "(SIZE >= 5) OR (SIZE < 3)");
|
CHECK("(SIZE >= 5) OR (SIZE < 3)" == V1o3.get_description());
|
||||||
EXPECT_TRUE(V1o3(two).empty());
|
CHECK(V1o3(two).empty());
|
||||||
EXPECT_TRUE(V1o3(eight).empty());
|
CHECK(V1o3(eight).empty());
|
||||||
EXPECT_TRUE(V1o3(ten).empty());
|
CHECK(V1o3(ten).empty());
|
||||||
EXPECT_TRUE(V1o3(two).empty());
|
CHECK(V1o3(two).empty());
|
||||||
EXPECT_FALSE(V1o3(four).empty());
|
CHECK(!V1o3(four).empty());
|
||||||
|
|
||||||
auto m1 = V1o3 & V4;
|
auto m1 = V1o3 & V4;
|
||||||
EXPECT_EQ(m1.get_description(), "((SIZE >= 5) OR (SIZE < 3)) AND (SIZE <= 9)");
|
CHECK("((SIZE >= 5) OR (SIZE < 3)) AND (SIZE <= 9)" == m1.get_description());
|
||||||
EXPECT_TRUE(m1(two).empty());
|
CHECK(m1(two).empty());
|
||||||
EXPECT_TRUE(m1(eight).empty());
|
CHECK(m1(eight).empty());
|
||||||
EXPECT_FALSE(m1(ten).empty());
|
CHECK(!m1(ten).empty());
|
||||||
EXPECT_TRUE(m1(two).empty());
|
CHECK(m1(two).empty());
|
||||||
EXPECT_TRUE(m1(five).empty());
|
CHECK(m1(five).empty());
|
||||||
EXPECT_FALSE(m1(four).empty());
|
CHECK(!m1(four).empty());
|
||||||
|
|
||||||
auto m2 = m1 & V2;
|
auto m2 = m1 & V2;
|
||||||
EXPECT_EQ(m2.get_description(), "(((SIZE >= 5) OR (SIZE < 3)) AND (SIZE <= 9)) AND (SIZE >= 9)");
|
CHECK("(((SIZE >= 5) OR (SIZE < 3)) AND (SIZE <= 9)) AND (SIZE >= 9)" == m2.get_description());
|
||||||
EXPECT_FALSE(m2(two).empty());
|
CHECK(!m2(two).empty());
|
||||||
EXPECT_FALSE(m2(eight).empty());
|
CHECK(!m2(eight).empty());
|
||||||
EXPECT_FALSE(m2(ten).empty());
|
CHECK(!m2(ten).empty());
|
||||||
EXPECT_FALSE(m2(two).empty());
|
CHECK(!m2(two).empty());
|
||||||
EXPECT_TRUE(m2(nine).empty());
|
CHECK(m2(nine).empty());
|
||||||
EXPECT_FALSE(m2(four).empty());
|
CHECK(!m2(four).empty());
|
||||||
|
|
||||||
auto m3 = m2 | V3;
|
auto m3 = m2 | V3;
|
||||||
EXPECT_EQ(m3.get_description(), "((((SIZE >= 5) OR (SIZE < 3)) AND (SIZE <= 9)) AND (SIZE >= 9)) OR (SIZE < 3)");
|
CHECK("((((SIZE >= 5) OR (SIZE < 3)) AND (SIZE <= 9)) AND (SIZE >= 9)) OR (SIZE < 3)" == m3.get_description());
|
||||||
EXPECT_TRUE(m3(two).empty());
|
CHECK(m3(two).empty());
|
||||||
EXPECT_FALSE(m3(eight).empty());
|
CHECK(!m3(eight).empty());
|
||||||
EXPECT_TRUE(m3(nine).empty());
|
CHECK(m3(nine).empty());
|
||||||
EXPECT_FALSE(m3(four).empty());
|
CHECK(!m3(four).empty());
|
||||||
|
|
||||||
auto m4 = V3 | m2;
|
auto m4 = V3 | m2;
|
||||||
EXPECT_EQ(m4.get_description(), "(SIZE < 3) OR ((((SIZE >= 5) OR (SIZE < 3)) AND (SIZE <= 9)) AND (SIZE >= 9))");
|
CHECK("(SIZE < 3) OR ((((SIZE >= 5) OR (SIZE < 3)) AND (SIZE <= 9)) AND (SIZE >= 9))" == m4.get_description());
|
||||||
EXPECT_TRUE(m4(two).empty());
|
CHECK(m4(two).empty());
|
||||||
EXPECT_FALSE(m4(eight).empty());
|
CHECK(!m4(eight).empty());
|
||||||
EXPECT_TRUE(m4(nine).empty());
|
CHECK(m4(nine).empty());
|
||||||
EXPECT_FALSE(m4(four).empty());
|
CHECK(!m4(four).empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(ValidatorTests, TestValidatorNegation) {
|
TEST_CASE("ValidatorTests: TestValidatorNegation", "[creation]") {
|
||||||
|
|
||||||
std::function<std::string(std::string &)> op1 = [](std::string &val) {
|
std::function<std::string(std::string &)> op1 = [](std::string &val) {
|
||||||
return (val.size() >= 5) ? std::string{} : val;
|
return (val.size() >= 5) ? std::string{} : val;
|
||||||
@ -669,21 +669,21 @@ TEST(ValidatorTests, TestValidatorNegation) {
|
|||||||
std::string four(4, 'a');
|
std::string four(4, 'a');
|
||||||
std::string five(5, 'a');
|
std::string five(5, 'a');
|
||||||
|
|
||||||
EXPECT_TRUE(V1(five).empty());
|
CHECK(V1(five).empty());
|
||||||
EXPECT_FALSE(V1(four).empty());
|
CHECK(!V1(four).empty());
|
||||||
|
|
||||||
auto V2 = !V1;
|
auto V2 = !V1;
|
||||||
EXPECT_FALSE(V2(five).empty());
|
CHECK(!V2(five).empty());
|
||||||
EXPECT_TRUE(V2(four).empty());
|
CHECK(V2(four).empty());
|
||||||
EXPECT_EQ(V2.get_description(), "NOT SIZE >= 5");
|
CHECK("NOT SIZE >= 5" == V2.get_description());
|
||||||
|
|
||||||
V2.active(false);
|
V2.active(false);
|
||||||
EXPECT_TRUE(V2(five).empty());
|
CHECK(V2(five).empty());
|
||||||
EXPECT_TRUE(V2(four).empty());
|
CHECK(V2(four).empty());
|
||||||
EXPECT_TRUE(V2.get_description().empty());
|
CHECK(V2.get_description().empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(ValidatorTests, ValidatorDefaults) {
|
TEST_CASE("ValidatorTests: ValidatorDefaults", "[creation]") {
|
||||||
|
|
||||||
CLI::Validator V1{};
|
CLI::Validator V1{};
|
||||||
|
|
||||||
@ -691,23 +691,23 @@ TEST(ValidatorTests, ValidatorDefaults) {
|
|||||||
std::string five(5, 'a');
|
std::string five(5, 'a');
|
||||||
|
|
||||||
// make sure this doesn't generate a seg fault or something
|
// make sure this doesn't generate a seg fault or something
|
||||||
EXPECT_TRUE(V1(five).empty());
|
CHECK(V1(five).empty());
|
||||||
EXPECT_TRUE(V1(four).empty());
|
CHECK(V1(four).empty());
|
||||||
|
|
||||||
EXPECT_TRUE(V1.get_name().empty());
|
CHECK(V1.get_name().empty());
|
||||||
EXPECT_TRUE(V1.get_description().empty());
|
CHECK(V1.get_description().empty());
|
||||||
EXPECT_TRUE(V1.get_active());
|
CHECK(V1.get_active());
|
||||||
EXPECT_TRUE(V1.get_modifying());
|
CHECK(V1.get_modifying());
|
||||||
|
|
||||||
CLI::Validator V2{"check"};
|
CLI::Validator V2{"check"};
|
||||||
// make sure this doesn't generate a seg fault or something
|
// make sure this doesn't generate a seg fault or something
|
||||||
EXPECT_TRUE(V2(five).empty());
|
CHECK(V2(five).empty());
|
||||||
EXPECT_TRUE(V2(four).empty());
|
CHECK(V2(four).empty());
|
||||||
|
|
||||||
EXPECT_TRUE(V2.get_name().empty());
|
CHECK(V2.get_name().empty());
|
||||||
EXPECT_EQ(V2.get_description(), "check");
|
CHECK("check" == V2.get_description());
|
||||||
EXPECT_TRUE(V2.get_active());
|
CHECK(V2.get_active());
|
||||||
EXPECT_TRUE(V2.get_modifying());
|
CHECK(V2.get_modifying());
|
||||||
// This class only support streaming in, not out
|
// This class only support streaming in, not out
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -734,7 +734,7 @@ std::istream &operator>>(std::istream &in, Unstreamable &value) {
|
|||||||
static_assert(CLI::detail::is_istreamable<Unstreamable>::value,
|
static_assert(CLI::detail::is_istreamable<Unstreamable>::value,
|
||||||
"Unstreamable type is still unstreamable and it should be");
|
"Unstreamable type is still unstreamable and it should be");
|
||||||
|
|
||||||
TEST_F(TApp, MakeUnstreamableOptions) {
|
TEST_CASE_METHOD(TApp, "MakeUnstreamableOptions", "[creation]") {
|
||||||
Unstreamable value;
|
Unstreamable value;
|
||||||
app.add_option("--value", value);
|
app.add_option("--value", value);
|
||||||
|
|
||||||
@ -749,10 +749,10 @@ TEST_F(TApp, MakeUnstreamableOptions) {
|
|||||||
|
|
||||||
args = {"--value", "45"};
|
args = {"--value", "45"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(value.get_x(), 45);
|
CHECK(45 == value.get_x());
|
||||||
|
|
||||||
args = {"--values", "45", "27", "34"};
|
args = {"--values", "45", "27", "34"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(values.size(), 3u);
|
CHECK(3u == values.size());
|
||||||
EXPECT_EQ(values[2].get_x(), 34);
|
CHECK(34 == values[2].get_x());
|
||||||
}
|
}
|
||||||
|
@ -6,37 +6,34 @@
|
|||||||
|
|
||||||
#include "app_helper.hpp"
|
#include "app_helper.hpp"
|
||||||
|
|
||||||
#include "gmock/gmock.h"
|
using Catch::Matchers::Contains;
|
||||||
|
|
||||||
using ::testing::HasSubstr;
|
TEST_CASE("Deprecated: Empty", "[deprecated]") {
|
||||||
using ::testing::Not;
|
|
||||||
|
|
||||||
TEST(Deprecated, Empty) {
|
|
||||||
// No deprecated features at this time.
|
// No deprecated features at this time.
|
||||||
EXPECT_TRUE(true);
|
CHECK(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Classic sets
|
// Classic sets
|
||||||
|
|
||||||
TEST_F(TApp, SetWithDefaults) {
|
TEST_CASE_METHOD(TApp, "SetWithDefaults", "[deprecated]") {
|
||||||
int someint = 2;
|
int someint = 2;
|
||||||
app.add_set("-a", someint, {1, 2, 3, 4}, "", true);
|
app.add_set("-a", someint, {1, 2, 3, 4}, "", true);
|
||||||
|
|
||||||
args = {"-a1", "-a2"};
|
args = {"-a1", "-a2"};
|
||||||
|
|
||||||
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
CHECK_THROWS_AS(run(), CLI::ArgumentMismatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, SetWithDefaultsConversion) {
|
TEST_CASE_METHOD(TApp, "SetWithDefaultsConversion", "[deprecated]") {
|
||||||
int someint = 2;
|
int someint = 2;
|
||||||
app.add_set("-a", someint, {1, 2, 3, 4}, "", true);
|
app.add_set("-a", someint, {1, 2, 3, 4}, "", true);
|
||||||
|
|
||||||
args = {"-a", "hi"};
|
args = {"-a", "hi"};
|
||||||
|
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, InSet) {
|
TEST_CASE_METHOD(TApp, "InSet", "[deprecated]") {
|
||||||
|
|
||||||
std::string choice;
|
std::string choice;
|
||||||
app.add_set("-q,--quick", choice, {"one", "two", "three"});
|
app.add_set("-q,--quick", choice, {"one", "two", "three"});
|
||||||
@ -44,30 +41,30 @@ TEST_F(TApp, InSet) {
|
|||||||
args = {"--quick", "two"};
|
args = {"--quick", "two"};
|
||||||
|
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ("two", choice);
|
CHECK(choice == "two");
|
||||||
|
|
||||||
args = {"--quick", "four"};
|
args = {"--quick", "four"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, InSetWithDefault) {
|
TEST_CASE_METHOD(TApp, "InSetWithDefault", "[deprecated]") {
|
||||||
|
|
||||||
std::string choice = "one";
|
std::string choice = "one";
|
||||||
app.add_set("-q,--quick", choice, {"one", "two", "three"}, "", true);
|
app.add_set("-q,--quick", choice, {"one", "two", "three"}, "", true);
|
||||||
|
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ("one", choice);
|
CHECK(choice == "one");
|
||||||
|
|
||||||
args = {"--quick", "two"};
|
args = {"--quick", "two"};
|
||||||
|
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ("two", choice);
|
CHECK(choice == "two");
|
||||||
|
|
||||||
args = {"--quick", "four"};
|
args = {"--quick", "four"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, InIntSet) {
|
TEST_CASE_METHOD(TApp, "InIntSet", "[deprecated]") {
|
||||||
|
|
||||||
int choice;
|
int choice;
|
||||||
app.add_set("-q,--quick", choice, {1, 2, 3});
|
app.add_set("-q,--quick", choice, {1, 2, 3});
|
||||||
@ -75,13 +72,13 @@ TEST_F(TApp, InIntSet) {
|
|||||||
args = {"--quick", "2"};
|
args = {"--quick", "2"};
|
||||||
|
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(2, choice);
|
CHECK(choice == 2);
|
||||||
|
|
||||||
args = {"--quick", "4"};
|
args = {"--quick", "4"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, InIntSetWindows) {
|
TEST_CASE_METHOD(TApp, "InIntSetWindows", "[deprecated]") {
|
||||||
|
|
||||||
int choice;
|
int choice;
|
||||||
app.add_set("-q,--quick", choice, {1, 2, 3});
|
app.add_set("-q,--quick", choice, {1, 2, 3});
|
||||||
@ -89,28 +86,28 @@ TEST_F(TApp, InIntSetWindows) {
|
|||||||
args = {"/q", "2"};
|
args = {"/q", "2"};
|
||||||
|
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(2, choice);
|
CHECK(choice == 2);
|
||||||
|
|
||||||
args = {"/q", "4"};
|
args = {"/q", "4"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||||
|
|
||||||
args = {"/q4"};
|
args = {"/q4"};
|
||||||
EXPECT_THROW(run(), CLI::ExtrasError);
|
CHECK_THROWS_AS(run(), CLI::ExtrasError);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, FailSet) {
|
TEST_CASE_METHOD(TApp, "FailSet", "[deprecated]") {
|
||||||
|
|
||||||
int choice;
|
int choice;
|
||||||
app.add_set("-q,--quick", choice, {1, 2, 3});
|
app.add_set("-q,--quick", choice, {1, 2, 3});
|
||||||
|
|
||||||
args = {"--quick", "3", "--quick=2"};
|
args = {"--quick", "3", "--quick=2"};
|
||||||
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
CHECK_THROWS_AS(run(), CLI::ArgumentMismatch);
|
||||||
|
|
||||||
args = {"--quick=hello"};
|
args = {"--quick=hello"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, FailMutableSet) {
|
TEST_CASE_METHOD(TApp, "FailMutableSet", "[deprecated]") {
|
||||||
|
|
||||||
int choice;
|
int choice;
|
||||||
std::set<int> vals{1, 2, 3};
|
std::set<int> vals{1, 2, 3};
|
||||||
@ -118,14 +115,14 @@ TEST_F(TApp, FailMutableSet) {
|
|||||||
app.add_mutable_set("-s,--slow", choice, vals, "", true);
|
app.add_mutable_set("-s,--slow", choice, vals, "", true);
|
||||||
|
|
||||||
args = {"--quick=hello"};
|
args = {"--quick=hello"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||||
|
|
||||||
args = {"--slow=hello"};
|
args = {"--slow=hello"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #113
|
// #113
|
||||||
TEST_F(TApp, AddRemoveSetItems) {
|
TEST_CASE_METHOD(TApp, "AddRemoveSetItems", "[deprecated]") {
|
||||||
std::set<std::string> items{"TYPE1", "TYPE2", "TYPE3", "TYPE4", "TYPE5"};
|
std::set<std::string> items{"TYPE1", "TYPE2", "TYPE3", "TYPE4", "TYPE5"};
|
||||||
|
|
||||||
std::string type1, type2;
|
std::string type1, type2;
|
||||||
@ -135,8 +132,8 @@ TEST_F(TApp, AddRemoveSetItems) {
|
|||||||
args = {"--type1", "TYPE1", "--type2", "TYPE2"};
|
args = {"--type1", "TYPE1", "--type2", "TYPE2"};
|
||||||
|
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(type1, "TYPE1");
|
CHECK("TYPE1" == type1);
|
||||||
EXPECT_EQ(type2, "TYPE2");
|
CHECK("TYPE2" == type2);
|
||||||
|
|
||||||
items.insert("TYPE6");
|
items.insert("TYPE6");
|
||||||
items.insert("TYPE7");
|
items.insert("TYPE7");
|
||||||
@ -146,17 +143,17 @@ TEST_F(TApp, AddRemoveSetItems) {
|
|||||||
|
|
||||||
args = {"--type1", "TYPE6", "--type2", "TYPE7"};
|
args = {"--type1", "TYPE6", "--type2", "TYPE7"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(type1, "TYPE6");
|
CHECK("TYPE6" == type1);
|
||||||
EXPECT_EQ(type2, "TYPE7");
|
CHECK("TYPE7" == type2);
|
||||||
|
|
||||||
args = {"--type1", "TYPE1"};
|
args = {"--type1", "TYPE1"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||||
|
|
||||||
args = {"--type2", "TYPE2"};
|
args = {"--type2", "TYPE2"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(THelp, Defaults) {
|
TEST_CASE("THelp: Defaults", "[deprecated]") {
|
||||||
CLI::App app{"My prog"};
|
CLI::App app{"My prog"};
|
||||||
|
|
||||||
int one{1}, two{2};
|
int one{1}, two{2};
|
||||||
@ -165,24 +162,24 @@ TEST(THelp, Defaults) {
|
|||||||
|
|
||||||
std::string help = app.help();
|
std::string help = app.help();
|
||||||
|
|
||||||
EXPECT_THAT(help, HasSubstr("--one"));
|
CHECK_THAT(help, Contains("--one"));
|
||||||
EXPECT_THAT(help, HasSubstr("--set"));
|
CHECK_THAT(help, Contains("--set"));
|
||||||
EXPECT_THAT(help, HasSubstr("1"));
|
CHECK_THAT(help, Contains("1"));
|
||||||
EXPECT_THAT(help, HasSubstr("=2"));
|
CHECK_THAT(help, Contains("=2"));
|
||||||
EXPECT_THAT(help, HasSubstr("2,3,4"));
|
CHECK_THAT(help, Contains("2,3,4"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(THelp, VectorOpts) {
|
TEST_CASE("THelp: VectorOpts", "[deprecated]") {
|
||||||
CLI::App app{"My prog"};
|
CLI::App app{"My prog"};
|
||||||
std::vector<int> x = {1, 2};
|
std::vector<int> x = {1, 2};
|
||||||
app.add_option("-q,--quick", x, "", true);
|
app.add_option("-q,--quick", x, "", true);
|
||||||
|
|
||||||
std::string help = app.help();
|
std::string help = app.help();
|
||||||
|
|
||||||
EXPECT_THAT(help, HasSubstr("INT=[1,2] ..."));
|
CHECK_THAT(help, Contains("INT=[1,2] ..."));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(THelp, SetLower) {
|
TEST_CASE("THelp: SetLower", "[deprecated]") {
|
||||||
CLI::App app{"My prog"};
|
CLI::App app{"My prog"};
|
||||||
|
|
||||||
std::string def{"One"};
|
std::string def{"One"};
|
||||||
@ -190,14 +187,14 @@ TEST(THelp, SetLower) {
|
|||||||
|
|
||||||
std::string help = app.help();
|
std::string help = app.help();
|
||||||
|
|
||||||
EXPECT_THAT(help, HasSubstr("--set"));
|
CHECK_THAT(help, Contains("--set"));
|
||||||
EXPECT_THAT(help, HasSubstr("=One"));
|
CHECK_THAT(help, Contains("=One"));
|
||||||
EXPECT_THAT(help, HasSubstr("oNe"));
|
CHECK_THAT(help, Contains("oNe"));
|
||||||
EXPECT_THAT(help, HasSubstr("twO"));
|
CHECK_THAT(help, Contains("twO"));
|
||||||
EXPECT_THAT(help, HasSubstr("THREE"));
|
CHECK_THAT(help, Contains("THREE"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(THelp, ChangingSetDefaulted) {
|
TEST_CASE("THelp: ChangingSetDefaulted", "[deprecated]") {
|
||||||
CLI::App app;
|
CLI::App app;
|
||||||
|
|
||||||
std::set<int> vals{1, 2, 3};
|
std::set<int> vals{1, 2, 3};
|
||||||
@ -206,19 +203,19 @@ TEST(THelp, ChangingSetDefaulted) {
|
|||||||
|
|
||||||
std::string help = app.help();
|
std::string help = app.help();
|
||||||
|
|
||||||
EXPECT_THAT(help, HasSubstr("1"));
|
CHECK_THAT(help, Contains("1"));
|
||||||
EXPECT_THAT(help, Not(HasSubstr("4")));
|
CHECK_THAT(help, !Contains("4"));
|
||||||
|
|
||||||
vals.insert(4);
|
vals.insert(4);
|
||||||
vals.erase(1);
|
vals.erase(1);
|
||||||
|
|
||||||
help = app.help();
|
help = app.help();
|
||||||
|
|
||||||
EXPECT_THAT(help, Not(HasSubstr("1")));
|
CHECK_THAT(help, !Contains("1"));
|
||||||
EXPECT_THAT(help, HasSubstr("4"));
|
CHECK_THAT(help, Contains("4"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(THelp, ChangingCaselessSetDefaulted) {
|
TEST_CASE("THelp: ChangingCaselessSetDefaulted", "[deprecated]") {
|
||||||
CLI::App app;
|
CLI::App app;
|
||||||
|
|
||||||
std::set<std::string> vals{"1", "2", "3"};
|
std::set<std::string> vals{"1", "2", "3"};
|
||||||
@ -227,19 +224,19 @@ TEST(THelp, ChangingCaselessSetDefaulted) {
|
|||||||
|
|
||||||
std::string help = app.help();
|
std::string help = app.help();
|
||||||
|
|
||||||
EXPECT_THAT(help, HasSubstr("1"));
|
CHECK_THAT(help, Contains("1"));
|
||||||
EXPECT_THAT(help, Not(HasSubstr("4")));
|
CHECK_THAT(help, !Contains("4"));
|
||||||
|
|
||||||
vals.insert("4");
|
vals.insert("4");
|
||||||
vals.erase("1");
|
vals.erase("1");
|
||||||
|
|
||||||
help = app.help();
|
help = app.help();
|
||||||
|
|
||||||
EXPECT_THAT(help, Not(HasSubstr("1")));
|
CHECK_THAT(help, !Contains("1"));
|
||||||
EXPECT_THAT(help, HasSubstr("4"));
|
CHECK_THAT(help, Contains("4"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, DefaultOpts) {
|
TEST_CASE_METHOD(TApp, "DefaultOpts", "[deprecated]") {
|
||||||
|
|
||||||
int i = 3;
|
int i = 3;
|
||||||
std::string s = "HI";
|
std::string s = "HI";
|
||||||
@ -251,116 +248,116 @@ TEST_F(TApp, DefaultOpts) {
|
|||||||
|
|
||||||
run();
|
run();
|
||||||
|
|
||||||
EXPECT_EQ(1u, app.count("i"));
|
CHECK(app.count("i") == 1u);
|
||||||
EXPECT_EQ(1u, app.count("-s"));
|
CHECK(app.count("-s") == 1u);
|
||||||
EXPECT_EQ(2, i);
|
CHECK(i == 2);
|
||||||
EXPECT_EQ("9", s);
|
CHECK(s == "9");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, VectorDefaultedFixedString) {
|
TEST_CASE_METHOD(TApp, "VectorDefaultedFixedString", "[deprecated]") {
|
||||||
std::vector<std::string> strvec{"one"};
|
std::vector<std::string> strvec{"one"};
|
||||||
std::vector<std::string> answer{"mystring", "mystring2", "mystring3"};
|
std::vector<std::string> answer{"mystring", "mystring2", "mystring3"};
|
||||||
|
|
||||||
CLI::Option *opt = app.add_option("-s,--string", strvec, "", true)->expected(3);
|
CLI::Option *opt = app.add_option("-s,--string", strvec, "", true)->expected(3);
|
||||||
EXPECT_EQ(3, opt->get_expected());
|
CHECK(opt->get_expected() == 3);
|
||||||
|
|
||||||
args = {"--string", "mystring", "mystring2", "mystring3"};
|
args = {"--string", "mystring", "mystring2", "mystring3"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(3u, app.count("--string"));
|
CHECK(app.count("--string") == 3u);
|
||||||
EXPECT_EQ(answer, strvec);
|
CHECK(strvec == answer);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, DefaultedResult) {
|
TEST_CASE_METHOD(TApp, "DefaultedResult", "[deprecated]") {
|
||||||
std::string sval = "NA";
|
std::string sval = "NA";
|
||||||
int ival;
|
int ival;
|
||||||
auto opts = app.add_option("--string", sval, "", true);
|
auto opts = app.add_option("--string", sval, "", true);
|
||||||
auto optv = app.add_option("--val", ival);
|
auto optv = app.add_option("--val", ival);
|
||||||
args = {};
|
args = {};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(sval, "NA");
|
CHECK("NA" == sval);
|
||||||
std::string nString;
|
std::string nString;
|
||||||
opts->results(nString);
|
opts->results(nString);
|
||||||
EXPECT_EQ(nString, "NA");
|
CHECK("NA" == nString);
|
||||||
int newIval;
|
int newIval;
|
||||||
// EXPECT_THROW(optv->results(newIval), CLI::ConversionError);
|
// CHECK_THROWS_AS (optv->results(newIval), CLI::ConversionError);
|
||||||
optv->default_str("442");
|
optv->default_str("442");
|
||||||
optv->results(newIval);
|
optv->results(newIval);
|
||||||
EXPECT_EQ(newIval, 442);
|
CHECK(442 == newIval);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, OptionWithDefaults) {
|
TEST_CASE_METHOD(TApp, "OptionWithDefaults", "[deprecated]") {
|
||||||
int someint = 2;
|
int someint = 2;
|
||||||
app.add_option("-a", someint, "", true);
|
app.add_option("-a", someint, "", true);
|
||||||
|
|
||||||
args = {"-a1", "-a2"};
|
args = {"-a1", "-a2"};
|
||||||
|
|
||||||
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
CHECK_THROWS_AS(run(), CLI::ArgumentMismatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #209
|
// #209
|
||||||
TEST_F(TApp, CustomUserSepParse) {
|
TEST_CASE_METHOD(TApp, "CustomUserSepParse", "[deprecated]") {
|
||||||
|
|
||||||
std::vector<int> vals = {1, 2, 3};
|
std::vector<int> vals = {1, 2, 3};
|
||||||
args = {"--idx", "1,2,3"};
|
args = {"--idx", "1,2,3"};
|
||||||
auto opt = app.add_option("--idx", vals)->delimiter(',');
|
auto opt = app.add_option("--idx", vals)->delimiter(',');
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(vals, std::vector<int>({1, 2, 3}));
|
CHECK(std::vector<int>({1, 2, 3}) == vals);
|
||||||
std::vector<int> vals2;
|
std::vector<int> vals2;
|
||||||
// check that the results vector gets the results in the same way
|
// check that the results vector gets the results in the same way
|
||||||
opt->results(vals2);
|
opt->results(vals2);
|
||||||
EXPECT_EQ(vals2, vals);
|
CHECK(vals == vals2);
|
||||||
|
|
||||||
app.remove_option(opt);
|
app.remove_option(opt);
|
||||||
|
|
||||||
app.add_option("--idx", vals, "", true)->delimiter(',');
|
app.add_option("--idx", vals, "", true)->delimiter(',');
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(vals, std::vector<int>({1, 2, 3}));
|
CHECK(std::vector<int>({1, 2, 3}) == vals);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #209
|
// #209
|
||||||
TEST_F(TApp, CustomUserSepParse2) {
|
TEST_CASE_METHOD(TApp, "CustomUserSepParse2", "[deprecated]") {
|
||||||
|
|
||||||
std::vector<int> vals = {1, 2, 3};
|
std::vector<int> vals = {1, 2, 3};
|
||||||
args = {"--idx", "1,2,"};
|
args = {"--idx", "1,2,"};
|
||||||
auto opt = app.add_option("--idx", vals)->delimiter(',');
|
auto opt = app.add_option("--idx", vals)->delimiter(',');
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(vals, std::vector<int>({1, 2}));
|
CHECK(std::vector<int>({1, 2}) == vals);
|
||||||
|
|
||||||
app.remove_option(opt);
|
app.remove_option(opt);
|
||||||
|
|
||||||
app.add_option("--idx", vals, "", true)->delimiter(',');
|
app.add_option("--idx", vals, "", true)->delimiter(',');
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(vals, std::vector<int>({1, 2}));
|
CHECK(std::vector<int>({1, 2}) == vals);
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// #209
|
// #209
|
||||||
TEST_F(TApp, CustomUserSepParse4) {
|
TEST_CASE_METHOD(TApp, "CustomUserSepParse4", "[deprecated]") {
|
||||||
|
|
||||||
std::vector<int> vals;
|
std::vector<int> vals;
|
||||||
args = {"--idx", "1, 2"};
|
args = {"--idx", "1, 2"};
|
||||||
auto opt = app.add_option("--idx", vals, "", true)->delimiter(',');
|
auto opt = app.add_option("--idx", vals, "", true)->delimiter(',');
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(vals, std::vector<int>({1, 2}));
|
CHECK(std::vector<int>({1, 2}) == vals);
|
||||||
|
|
||||||
app.remove_option(opt);
|
app.remove_option(opt);
|
||||||
|
|
||||||
app.add_option("--idx", vals)->delimiter(',');
|
app.add_option("--idx", vals)->delimiter(',');
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(vals, std::vector<int>({1, 2}));
|
CHECK(std::vector<int>({1, 2}) == vals);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #218
|
// #218
|
||||||
TEST_F(TApp, CustomUserSepParse5) {
|
TEST_CASE_METHOD(TApp, "CustomUserSepParse5", "[deprecated]") {
|
||||||
|
|
||||||
std::vector<std::string> bar;
|
std::vector<std::string> bar;
|
||||||
args = {"this", "is", "a", "test"};
|
args = {"this", "is", "a", "test"};
|
||||||
auto opt = app.add_option("bar", bar, "bar");
|
auto opt = app.add_option("bar", bar, "bar");
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(bar, std::vector<std::string>({"this", "is", "a", "test"}));
|
CHECK(std::vector<std::string>({"this", "is", "a", "test"}) == bar);
|
||||||
|
|
||||||
app.remove_option(opt);
|
app.remove_option(opt);
|
||||||
args = {"this", "is", "a", "test"};
|
args = {"this", "is", "a", "test"};
|
||||||
app.add_option("bar", bar, "bar", true);
|
app.add_option("bar", bar, "bar", true);
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(bar, std::vector<std::string>({"this", "is", "a", "test"}));
|
CHECK(std::vector<std::string>({"this", "is", "a", "test"}) == bar);
|
||||||
}
|
}
|
||||||
|
@ -10,12 +10,10 @@
|
|||||||
#include "CLI/CLI.hpp"
|
#include "CLI/CLI.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "gmock/gmock.h"
|
#include "catch.hpp"
|
||||||
#include "gtest/gtest.h"
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
using ::testing::HasSubstr;
|
using Catch::Matchers::Contains;
|
||||||
using ::testing::Not;
|
|
||||||
|
|
||||||
class SimpleFormatter : public CLI::FormatterBase {
|
class SimpleFormatter : public CLI::FormatterBase {
|
||||||
public:
|
public:
|
||||||
@ -26,17 +24,17 @@ class SimpleFormatter : public CLI::FormatterBase {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST(Formatter, Nothing) {
|
TEST_CASE("Formatter: Nothing", "[formatter]") {
|
||||||
CLI::App app{"My prog"};
|
CLI::App app{"My prog"};
|
||||||
|
|
||||||
app.formatter(std::make_shared<SimpleFormatter>());
|
app.formatter(std::make_shared<SimpleFormatter>());
|
||||||
|
|
||||||
std::string help = app.help();
|
std::string help = app.help();
|
||||||
|
|
||||||
EXPECT_EQ(help, "This is really simple");
|
CHECK("This is really simple" == help);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Formatter, NothingLambda) {
|
TEST_CASE("Formatter: NothingLambda", "[formatter]") {
|
||||||
CLI::App app{"My prog"};
|
CLI::App app{"My prog"};
|
||||||
|
|
||||||
app.formatter_fn(
|
app.formatter_fn(
|
||||||
@ -44,10 +42,10 @@ TEST(Formatter, NothingLambda) {
|
|||||||
|
|
||||||
std::string help = app.help();
|
std::string help = app.help();
|
||||||
|
|
||||||
EXPECT_EQ(help, "This is really simple");
|
CHECK("This is really simple" == help);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Formatter, OptCustomize) {
|
TEST_CASE("Formatter: OptCustomize", "[formatter]") {
|
||||||
CLI::App app{"My prog"};
|
CLI::App app{"My prog"};
|
||||||
|
|
||||||
auto optfmt = std::make_shared<CLI::Formatter>();
|
auto optfmt = std::make_shared<CLI::Formatter>();
|
||||||
@ -60,16 +58,15 @@ TEST(Formatter, OptCustomize) {
|
|||||||
|
|
||||||
std::string help = app.help();
|
std::string help = app.help();
|
||||||
|
|
||||||
EXPECT_THAT(help, HasSubstr("(MUST HAVE)"));
|
CHECK_THAT(help, Contains("(MUST HAVE)"));
|
||||||
EXPECT_EQ(help,
|
CHECK(help == "My prog\n"
|
||||||
"My prog\n"
|
"Usage: [OPTIONS]\n\n"
|
||||||
"Usage: [OPTIONS]\n\n"
|
"Options:\n"
|
||||||
"Options:\n"
|
" -h,--help Print this help message and exit\n"
|
||||||
" -h,--help Print this help message and exit\n"
|
" --opt INT (MUST HAVE) Something\n\n");
|
||||||
" --opt INT (MUST HAVE) Something\n\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Formatter, OptCustomizeSimple) {
|
TEST_CASE("Formatter: OptCustomizeSimple", "[formatter]") {
|
||||||
CLI::App app{"My prog"};
|
CLI::App app{"My prog"};
|
||||||
|
|
||||||
app.get_formatter()->column_width(25);
|
app.get_formatter()->column_width(25);
|
||||||
@ -80,16 +77,15 @@ TEST(Formatter, OptCustomizeSimple) {
|
|||||||
|
|
||||||
std::string help = app.help();
|
std::string help = app.help();
|
||||||
|
|
||||||
EXPECT_THAT(help, HasSubstr("(MUST HAVE)"));
|
CHECK_THAT(help, Contains("(MUST HAVE)"));
|
||||||
EXPECT_EQ(help,
|
CHECK(help == "My prog\n"
|
||||||
"My prog\n"
|
"Usage: [OPTIONS]\n\n"
|
||||||
"Usage: [OPTIONS]\n\n"
|
"Options:\n"
|
||||||
"Options:\n"
|
" -h,--help Print this help message and exit\n"
|
||||||
" -h,--help Print this help message and exit\n"
|
" --opt INT (MUST HAVE) Something\n\n");
|
||||||
" --opt INT (MUST HAVE) Something\n\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Formatter, OptCustomizeOptionText) {
|
TEST_CASE("Formatter: OptCustomizeOptionText", "[formatter]") {
|
||||||
CLI::App app{"My prog"};
|
CLI::App app{"My prog"};
|
||||||
|
|
||||||
app.get_formatter()->column_width(25);
|
app.get_formatter()->column_width(25);
|
||||||
@ -99,16 +95,15 @@ TEST(Formatter, OptCustomizeOptionText) {
|
|||||||
|
|
||||||
std::string help = app.help();
|
std::string help = app.help();
|
||||||
|
|
||||||
EXPECT_THAT(help, HasSubstr("(ARG)"));
|
CHECK_THAT(help, Contains("(ARG)"));
|
||||||
EXPECT_EQ(help,
|
CHECK(help == "My prog\n"
|
||||||
"My prog\n"
|
"Usage: [OPTIONS]\n\n"
|
||||||
"Usage: [OPTIONS]\n\n"
|
"Options:\n"
|
||||||
"Options:\n"
|
" -h,--help Print this help message and exit\n"
|
||||||
" -h,--help Print this help message and exit\n"
|
" --opt (ARG) Something\n\n");
|
||||||
" --opt (ARG) Something\n\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Formatter, FalseFlagExample) {
|
TEST_CASE("Formatter: FalseFlagExample", "[formatter]") {
|
||||||
CLI::App app{"My prog"};
|
CLI::App app{"My prog"};
|
||||||
|
|
||||||
app.get_formatter()->column_width(25);
|
app.get_formatter()->column_width(25);
|
||||||
@ -122,12 +117,12 @@ TEST(Formatter, FalseFlagExample) {
|
|||||||
|
|
||||||
std::string help = app.help();
|
std::string help = app.help();
|
||||||
|
|
||||||
EXPECT_THAT(help, HasSubstr("--no_opt{false}"));
|
CHECK_THAT(help, Contains("--no_opt{false}"));
|
||||||
EXPECT_THAT(help, HasSubstr("--no_opt2{false}"));
|
CHECK_THAT(help, Contains("--no_opt2{false}"));
|
||||||
EXPECT_THAT(help, HasSubstr("-O{false}"));
|
CHECK_THAT(help, Contains("-O{false}"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Formatter, AppCustomize) {
|
TEST_CASE("Formatter: AppCustomize", "[formatter]") {
|
||||||
CLI::App app{"My prog"};
|
CLI::App app{"My prog"};
|
||||||
app.add_subcommand("subcom1", "This");
|
app.add_subcommand("subcom1", "This");
|
||||||
|
|
||||||
@ -139,17 +134,16 @@ TEST(Formatter, AppCustomize) {
|
|||||||
app.add_subcommand("subcom2", "This");
|
app.add_subcommand("subcom2", "This");
|
||||||
|
|
||||||
std::string help = app.help();
|
std::string help = app.help();
|
||||||
EXPECT_EQ(help,
|
CHECK(help == "My prog\n"
|
||||||
"My prog\n"
|
"Run: [OPTIONS] [SUBCOMMAND]\n\n"
|
||||||
"Run: [OPTIONS] [SUBCOMMAND]\n\n"
|
"Options:\n"
|
||||||
"Options:\n"
|
" -h,--help Print this help message and exit\n\n"
|
||||||
" -h,--help Print this help message and exit\n\n"
|
"Subcommands:\n"
|
||||||
"Subcommands:\n"
|
" subcom1 This\n"
|
||||||
" subcom1 This\n"
|
" subcom2 This\n\n");
|
||||||
" subcom2 This\n\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Formatter, AppCustomizeSimple) {
|
TEST_CASE("Formatter: AppCustomizeSimple", "[formatter]") {
|
||||||
CLI::App app{"My prog"};
|
CLI::App app{"My prog"};
|
||||||
app.add_subcommand("subcom1", "This");
|
app.add_subcommand("subcom1", "This");
|
||||||
|
|
||||||
@ -159,48 +153,47 @@ TEST(Formatter, AppCustomizeSimple) {
|
|||||||
app.add_subcommand("subcom2", "This");
|
app.add_subcommand("subcom2", "This");
|
||||||
|
|
||||||
std::string help = app.help();
|
std::string help = app.help();
|
||||||
EXPECT_EQ(help,
|
CHECK(help == "My prog\n"
|
||||||
"My prog\n"
|
"Run: [OPTIONS] [SUBCOMMAND]\n\n"
|
||||||
"Run: [OPTIONS] [SUBCOMMAND]\n\n"
|
"Options:\n"
|
||||||
"Options:\n"
|
" -h,--help Print this help message and exit\n\n"
|
||||||
" -h,--help Print this help message and exit\n\n"
|
"Subcommands:\n"
|
||||||
"Subcommands:\n"
|
" subcom1 This\n"
|
||||||
" subcom1 This\n"
|
" subcom2 This\n\n");
|
||||||
" subcom2 This\n\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Formatter, AllSub) {
|
TEST_CASE("Formatter: AllSub", "[formatter]") {
|
||||||
CLI::App app{"My prog"};
|
CLI::App app{"My prog"};
|
||||||
CLI::App *sub = app.add_subcommand("subcom", "This");
|
CLI::App *sub = app.add_subcommand("subcom", "This");
|
||||||
sub->add_flag("--insub", "MyFlag");
|
sub->add_flag("--insub", "MyFlag");
|
||||||
|
|
||||||
std::string help = app.help("", CLI::AppFormatMode::All);
|
std::string help = app.help("", CLI::AppFormatMode::All);
|
||||||
EXPECT_THAT(help, HasSubstr("--insub"));
|
CHECK_THAT(help, Contains("--insub"));
|
||||||
EXPECT_THAT(help, HasSubstr("subcom"));
|
CHECK_THAT(help, Contains("subcom"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Formatter, AllSubRequired) {
|
TEST_CASE("Formatter: AllSubRequired", "[formatter]") {
|
||||||
CLI::App app{"My prog"};
|
CLI::App app{"My prog"};
|
||||||
CLI::App *sub = app.add_subcommand("subcom", "This");
|
CLI::App *sub = app.add_subcommand("subcom", "This");
|
||||||
sub->add_flag("--insub", "MyFlag");
|
sub->add_flag("--insub", "MyFlag");
|
||||||
sub->required();
|
sub->required();
|
||||||
std::string help = app.help("", CLI::AppFormatMode::All);
|
std::string help = app.help("", CLI::AppFormatMode::All);
|
||||||
EXPECT_THAT(help, HasSubstr("--insub"));
|
CHECK_THAT(help, Contains("--insub"));
|
||||||
EXPECT_THAT(help, HasSubstr("subcom"));
|
CHECK_THAT(help, Contains("subcom"));
|
||||||
EXPECT_THAT(help, HasSubstr("REQUIRED"));
|
CHECK_THAT(help, Contains("REQUIRED"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Formatter, NamelessSub) {
|
TEST_CASE("Formatter: NamelessSub", "[formatter]") {
|
||||||
CLI::App app{"My prog"};
|
CLI::App app{"My prog"};
|
||||||
CLI::App *sub = app.add_subcommand("", "This subcommand");
|
CLI::App *sub = app.add_subcommand("", "This subcommand");
|
||||||
sub->add_flag("--insub", "MyFlag");
|
sub->add_flag("--insub", "MyFlag");
|
||||||
|
|
||||||
std::string help = app.help("", CLI::AppFormatMode::Normal);
|
std::string help = app.help("", CLI::AppFormatMode::Normal);
|
||||||
EXPECT_THAT(help, HasSubstr("--insub"));
|
CHECK_THAT(help, Contains("--insub"));
|
||||||
EXPECT_THAT(help, HasSubstr("This subcommand"));
|
CHECK_THAT(help, Contains("This subcommand"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Formatter, NamelessSubInGroup) {
|
TEST_CASE("Formatter: NamelessSubInGroup", "[formatter]") {
|
||||||
CLI::App app{"My prog"};
|
CLI::App app{"My prog"};
|
||||||
CLI::App *sub = app.add_subcommand("", "This subcommand");
|
CLI::App *sub = app.add_subcommand("", "This subcommand");
|
||||||
CLI::App *sub2 = app.add_subcommand("sub2", "subcommand2");
|
CLI::App *sub2 = app.add_subcommand("sub2", "subcommand2");
|
||||||
@ -210,9 +203,9 @@ TEST(Formatter, NamelessSubInGroup) {
|
|||||||
sub->group("group1");
|
sub->group("group1");
|
||||||
sub2->group("group1");
|
sub2->group("group1");
|
||||||
std::string help = app.help("", CLI::AppFormatMode::Normal);
|
std::string help = app.help("", CLI::AppFormatMode::Normal);
|
||||||
EXPECT_THAT(help, HasSubstr("--insub"));
|
CHECK_THAT(help, Contains("--insub"));
|
||||||
EXPECT_THAT(help, HasSubstr("This subcommand"));
|
CHECK_THAT(help, Contains("This subcommand"));
|
||||||
EXPECT_THAT(help, HasSubstr("group1"));
|
CHECK_THAT(help, Contains("group1"));
|
||||||
EXPECT_THAT(help, HasSubstr("sub2"));
|
CHECK_THAT(help, Contains("sub2"));
|
||||||
EXPECT_TRUE(help.find("pos") == std::string::npos);
|
CHECK(help.find("pos") == std::string::npos);
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -5,159 +5,159 @@
|
|||||||
// SPDX-License-Identifier: BSD-3-Clause
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
#include "app_helper.hpp"
|
#include "app_helper.hpp"
|
||||||
#include "gmock/gmock.h"
|
|
||||||
#include <complex>
|
#include <complex>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
using ::testing::HasSubstr;
|
using Catch::Matchers::Contains;
|
||||||
|
|
||||||
using cx = std::complex<double>;
|
using cx = std::complex<double>;
|
||||||
|
|
||||||
TEST_F(TApp, Complex) {
|
TEST_CASE_METHOD(TApp, "Complex", "[newparse]") {
|
||||||
cx comp{1, 2};
|
cx comp{1, 2};
|
||||||
app.add_complex("-c,--complex", comp, "", true);
|
app.add_complex("-c,--complex", comp, "", true);
|
||||||
|
|
||||||
args = {"-c", "4", "3"};
|
args = {"-c", "4", "3"};
|
||||||
|
|
||||||
std::string help = app.help();
|
std::string help = app.help();
|
||||||
EXPECT_THAT(help, HasSubstr("1"));
|
CHECK_THAT(help, Contains("1"));
|
||||||
EXPECT_THAT(help, HasSubstr("2"));
|
CHECK_THAT(help, Contains("2"));
|
||||||
EXPECT_THAT(help, HasSubstr("COMPLEX"));
|
CHECK_THAT(help, Contains("COMPLEX"));
|
||||||
|
|
||||||
EXPECT_DOUBLE_EQ(1, comp.real());
|
CHECK(comp.real() == Approx(1));
|
||||||
EXPECT_DOUBLE_EQ(2, comp.imag());
|
CHECK(comp.imag() == Approx(2));
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
|
||||||
EXPECT_DOUBLE_EQ(4, comp.real());
|
CHECK(comp.real() == Approx(4));
|
||||||
EXPECT_DOUBLE_EQ(3, comp.imag());
|
CHECK(comp.imag() == Approx(3));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, ComplexOption) {
|
TEST_CASE_METHOD(TApp, "ComplexOption", "[newparse]") {
|
||||||
cx comp{1, 2};
|
cx comp{1, 2};
|
||||||
app.add_option("-c,--complex", comp, "", true);
|
app.add_option("-c,--complex", comp, "", true);
|
||||||
|
|
||||||
args = {"-c", "4", "3"};
|
args = {"-c", "4", "3"};
|
||||||
|
|
||||||
std::string help = app.help();
|
std::string help = app.help();
|
||||||
EXPECT_THAT(help, HasSubstr("1"));
|
CHECK_THAT(help, Contains("1"));
|
||||||
EXPECT_THAT(help, HasSubstr("2"));
|
CHECK_THAT(help, Contains("2"));
|
||||||
EXPECT_THAT(help, HasSubstr("COMPLEX"));
|
CHECK_THAT(help, Contains("COMPLEX"));
|
||||||
|
|
||||||
EXPECT_DOUBLE_EQ(1, comp.real());
|
CHECK(comp.real() == Approx(1));
|
||||||
EXPECT_DOUBLE_EQ(2, comp.imag());
|
CHECK(comp.imag() == Approx(2));
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
|
||||||
EXPECT_DOUBLE_EQ(4, comp.real());
|
CHECK(comp.real() == Approx(4));
|
||||||
EXPECT_DOUBLE_EQ(3, comp.imag());
|
CHECK(comp.imag() == Approx(3));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, ComplexFloat) {
|
TEST_CASE_METHOD(TApp, "ComplexFloat", "[newparse]") {
|
||||||
std::complex<float> comp{1, 2};
|
std::complex<float> comp{1, 2};
|
||||||
app.add_complex<std::complex<float>, float>("-c,--complex", comp, "", true);
|
app.add_complex<std::complex<float>, float>("-c,--complex", comp, "", true);
|
||||||
|
|
||||||
args = {"-c", "4", "3"};
|
args = {"-c", "4", "3"};
|
||||||
|
|
||||||
std::string help = app.help();
|
std::string help = app.help();
|
||||||
EXPECT_THAT(help, HasSubstr("1"));
|
CHECK_THAT(help, Contains("1"));
|
||||||
EXPECT_THAT(help, HasSubstr("2"));
|
CHECK_THAT(help, Contains("2"));
|
||||||
EXPECT_THAT(help, HasSubstr("COMPLEX"));
|
CHECK_THAT(help, Contains("COMPLEX"));
|
||||||
|
|
||||||
EXPECT_FLOAT_EQ(1, comp.real());
|
CHECK(comp.real() == Approx(1));
|
||||||
EXPECT_FLOAT_EQ(2, comp.imag());
|
CHECK(comp.imag() == Approx(2));
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
|
||||||
EXPECT_FLOAT_EQ(4, comp.real());
|
CHECK(comp.real() == Approx(4));
|
||||||
EXPECT_FLOAT_EQ(3, comp.imag());
|
CHECK(comp.imag() == Approx(3));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, ComplexFloatOption) {
|
TEST_CASE_METHOD(TApp, "ComplexFloatOption", "[newparse]") {
|
||||||
std::complex<float> comp{1, 2};
|
std::complex<float> comp{1, 2};
|
||||||
app.add_option("-c,--complex", comp, "", true);
|
app.add_option("-c,--complex", comp, "", true);
|
||||||
|
|
||||||
args = {"-c", "4", "3"};
|
args = {"-c", "4", "3"};
|
||||||
|
|
||||||
std::string help = app.help();
|
std::string help = app.help();
|
||||||
EXPECT_THAT(help, HasSubstr("1"));
|
CHECK_THAT(help, Contains("1"));
|
||||||
EXPECT_THAT(help, HasSubstr("2"));
|
CHECK_THAT(help, Contains("2"));
|
||||||
EXPECT_THAT(help, HasSubstr("COMPLEX"));
|
CHECK_THAT(help, Contains("COMPLEX"));
|
||||||
|
|
||||||
EXPECT_FLOAT_EQ(1, comp.real());
|
CHECK(comp.real() == Approx(1));
|
||||||
EXPECT_FLOAT_EQ(2, comp.imag());
|
CHECK(comp.imag() == Approx(2));
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
|
||||||
EXPECT_FLOAT_EQ(4, comp.real());
|
CHECK(comp.real() == Approx(4));
|
||||||
EXPECT_FLOAT_EQ(3, comp.imag());
|
CHECK(comp.imag() == Approx(3));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, ComplexWithDelimiter) {
|
TEST_CASE_METHOD(TApp, "ComplexWithDelimiter", "[newparse]") {
|
||||||
cx comp{1, 2};
|
cx comp{1, 2};
|
||||||
app.add_complex("-c,--complex", comp, "", true)->delimiter('+');
|
app.add_complex("-c,--complex", comp, "", true)->delimiter('+');
|
||||||
|
|
||||||
args = {"-c", "4+3i"};
|
args = {"-c", "4+3i"};
|
||||||
|
|
||||||
std::string help = app.help();
|
std::string help = app.help();
|
||||||
EXPECT_THAT(help, HasSubstr("1"));
|
CHECK_THAT(help, Contains("1"));
|
||||||
EXPECT_THAT(help, HasSubstr("2"));
|
CHECK_THAT(help, Contains("2"));
|
||||||
EXPECT_THAT(help, HasSubstr("COMPLEX"));
|
CHECK_THAT(help, Contains("COMPLEX"));
|
||||||
|
|
||||||
EXPECT_DOUBLE_EQ(1, comp.real());
|
CHECK(comp.real() == Approx(1));
|
||||||
EXPECT_DOUBLE_EQ(2, comp.imag());
|
CHECK(comp.imag() == Approx(2));
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
|
||||||
EXPECT_DOUBLE_EQ(4, comp.real());
|
CHECK(comp.real() == Approx(4));
|
||||||
EXPECT_DOUBLE_EQ(3, comp.imag());
|
CHECK(comp.imag() == Approx(3));
|
||||||
|
|
||||||
args = {"-c", "5+-3i"};
|
args = {"-c", "5+-3i"};
|
||||||
run();
|
run();
|
||||||
|
|
||||||
EXPECT_DOUBLE_EQ(5, comp.real());
|
CHECK(comp.real() == Approx(5));
|
||||||
EXPECT_DOUBLE_EQ(-3, comp.imag());
|
CHECK(comp.imag() == Approx(-3));
|
||||||
|
|
||||||
args = {"-c", "6", "-4i"};
|
args = {"-c", "6", "-4i"};
|
||||||
run();
|
run();
|
||||||
|
|
||||||
EXPECT_DOUBLE_EQ(6, comp.real());
|
CHECK(comp.real() == Approx(6));
|
||||||
EXPECT_DOUBLE_EQ(-4, comp.imag());
|
CHECK(comp.imag() == Approx(-4));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, ComplexWithDelimiterOption) {
|
TEST_CASE_METHOD(TApp, "ComplexWithDelimiterOption", "[newparse]") {
|
||||||
cx comp{1, 2};
|
cx comp{1, 2};
|
||||||
app.add_option("-c,--complex", comp, "", true)->delimiter('+');
|
app.add_option("-c,--complex", comp, "", true)->delimiter('+');
|
||||||
|
|
||||||
args = {"-c", "4+3i"};
|
args = {"-c", "4+3i"};
|
||||||
|
|
||||||
std::string help = app.help();
|
std::string help = app.help();
|
||||||
EXPECT_THAT(help, HasSubstr("1"));
|
CHECK_THAT(help, Contains("1"));
|
||||||
EXPECT_THAT(help, HasSubstr("2"));
|
CHECK_THAT(help, Contains("2"));
|
||||||
EXPECT_THAT(help, HasSubstr("COMPLEX"));
|
CHECK_THAT(help, Contains("COMPLEX"));
|
||||||
|
|
||||||
EXPECT_DOUBLE_EQ(1, comp.real());
|
CHECK(comp.real() == Approx(1));
|
||||||
EXPECT_DOUBLE_EQ(2, comp.imag());
|
CHECK(comp.imag() == Approx(2));
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
|
||||||
EXPECT_DOUBLE_EQ(4, comp.real());
|
CHECK(comp.real() == Approx(4));
|
||||||
EXPECT_DOUBLE_EQ(3, comp.imag());
|
CHECK(comp.imag() == Approx(3));
|
||||||
|
|
||||||
args = {"-c", "5+-3i"};
|
args = {"-c", "5+-3i"};
|
||||||
run();
|
run();
|
||||||
|
|
||||||
EXPECT_DOUBLE_EQ(5, comp.real());
|
CHECK(comp.real() == Approx(5));
|
||||||
EXPECT_DOUBLE_EQ(-3, comp.imag());
|
CHECK(comp.imag() == Approx(-3));
|
||||||
|
|
||||||
args = {"-c", "6", "-4i"};
|
args = {"-c", "6", "-4i"};
|
||||||
run();
|
run();
|
||||||
|
|
||||||
EXPECT_DOUBLE_EQ(6, comp.real());
|
CHECK(comp.real() == Approx(6));
|
||||||
EXPECT_DOUBLE_EQ(-4, comp.imag());
|
CHECK(comp.imag() == Approx(-4));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, ComplexIgnoreI) {
|
TEST_CASE_METHOD(TApp, "ComplexIgnoreI", "[newparse]") {
|
||||||
cx comp{1, 2};
|
cx comp{1, 2};
|
||||||
app.add_complex("-c,--complex", comp);
|
app.add_complex("-c,--complex", comp);
|
||||||
|
|
||||||
@ -165,11 +165,11 @@ TEST_F(TApp, ComplexIgnoreI) {
|
|||||||
|
|
||||||
run();
|
run();
|
||||||
|
|
||||||
EXPECT_DOUBLE_EQ(4, comp.real());
|
CHECK(comp.real() == Approx(4));
|
||||||
EXPECT_DOUBLE_EQ(3, comp.imag());
|
CHECK(comp.imag() == Approx(3));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, ComplexIgnoreIOption) {
|
TEST_CASE_METHOD(TApp, "ComplexIgnoreIOption", "[newparse]") {
|
||||||
cx comp{1, 2};
|
cx comp{1, 2};
|
||||||
app.add_option("-c,--complex", comp);
|
app.add_option("-c,--complex", comp);
|
||||||
|
|
||||||
@ -177,122 +177,122 @@ TEST_F(TApp, ComplexIgnoreIOption) {
|
|||||||
|
|
||||||
run();
|
run();
|
||||||
|
|
||||||
EXPECT_DOUBLE_EQ(4, comp.real());
|
CHECK(comp.real() == Approx(4));
|
||||||
EXPECT_DOUBLE_EQ(3, comp.imag());
|
CHECK(comp.imag() == Approx(3));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, ComplexSingleArg) {
|
TEST_CASE_METHOD(TApp, "ComplexSingleArg", "[newparse]") {
|
||||||
cx comp{1, 2};
|
cx comp{1, 2};
|
||||||
app.add_complex("-c,--complex", comp);
|
app.add_complex("-c,--complex", comp);
|
||||||
|
|
||||||
args = {"-c", "4"};
|
args = {"-c", "4"};
|
||||||
run();
|
run();
|
||||||
EXPECT_DOUBLE_EQ(4, comp.real());
|
CHECK(comp.real() == Approx(4));
|
||||||
EXPECT_DOUBLE_EQ(0, comp.imag());
|
CHECK(comp.imag() == Approx(0));
|
||||||
|
|
||||||
args = {"-c", "4-2i"};
|
args = {"-c", "4-2i"};
|
||||||
run();
|
run();
|
||||||
EXPECT_DOUBLE_EQ(4, comp.real());
|
CHECK(comp.real() == Approx(4));
|
||||||
EXPECT_DOUBLE_EQ(-2, comp.imag());
|
CHECK(comp.imag() == Approx(-2));
|
||||||
args = {"-c", "4+2i"};
|
args = {"-c", "4+2i"};
|
||||||
run();
|
run();
|
||||||
EXPECT_DOUBLE_EQ(4, comp.real());
|
CHECK(comp.real() == Approx(4));
|
||||||
EXPECT_DOUBLE_EQ(2, comp.imag());
|
CHECK(comp.imag() == Approx(2));
|
||||||
|
|
||||||
args = {"-c", "-4+2j"};
|
args = {"-c", "-4+2j"};
|
||||||
run();
|
run();
|
||||||
EXPECT_DOUBLE_EQ(-4, comp.real());
|
CHECK(comp.real() == Approx(-4));
|
||||||
EXPECT_DOUBLE_EQ(2, comp.imag());
|
CHECK(comp.imag() == Approx(2));
|
||||||
|
|
||||||
args = {"-c", "-4.2-2j"};
|
args = {"-c", "-4.2-2j"};
|
||||||
run();
|
run();
|
||||||
EXPECT_DOUBLE_EQ(-4.2, comp.real());
|
CHECK(comp.real() == Approx(-4.2));
|
||||||
EXPECT_DOUBLE_EQ(-2, comp.imag());
|
CHECK(comp.imag() == Approx(-2));
|
||||||
|
|
||||||
args = {"-c", "-4.2-2.7i"};
|
args = {"-c", "-4.2-2.7i"};
|
||||||
run();
|
run();
|
||||||
EXPECT_DOUBLE_EQ(-4.2, comp.real());
|
CHECK(comp.real() == Approx(-4.2));
|
||||||
EXPECT_DOUBLE_EQ(-2.7, comp.imag());
|
CHECK(comp.imag() == Approx(-2.7));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, ComplexSingleArgOption) {
|
TEST_CASE_METHOD(TApp, "ComplexSingleArgOption", "[newparse]") {
|
||||||
cx comp{1, 2};
|
cx comp{1, 2};
|
||||||
app.add_option("-c,--complex", comp);
|
app.add_option("-c,--complex", comp);
|
||||||
|
|
||||||
args = {"-c", "4"};
|
args = {"-c", "4"};
|
||||||
run();
|
run();
|
||||||
EXPECT_DOUBLE_EQ(4, comp.real());
|
CHECK(comp.real() == Approx(4));
|
||||||
EXPECT_DOUBLE_EQ(0, comp.imag());
|
CHECK(comp.imag() == Approx(0));
|
||||||
|
|
||||||
args = {"-c", "4-2i"};
|
args = {"-c", "4-2i"};
|
||||||
run();
|
run();
|
||||||
EXPECT_DOUBLE_EQ(4, comp.real());
|
CHECK(comp.real() == Approx(4));
|
||||||
EXPECT_DOUBLE_EQ(-2, comp.imag());
|
CHECK(comp.imag() == Approx(-2));
|
||||||
args = {"-c", "4+2i"};
|
args = {"-c", "4+2i"};
|
||||||
run();
|
run();
|
||||||
EXPECT_DOUBLE_EQ(4, comp.real());
|
CHECK(comp.real() == Approx(4));
|
||||||
EXPECT_DOUBLE_EQ(2, comp.imag());
|
CHECK(comp.imag() == Approx(2));
|
||||||
|
|
||||||
args = {"-c", "-4+2j"};
|
args = {"-c", "-4+2j"};
|
||||||
run();
|
run();
|
||||||
EXPECT_DOUBLE_EQ(-4, comp.real());
|
CHECK(comp.real() == Approx(-4));
|
||||||
EXPECT_DOUBLE_EQ(2, comp.imag());
|
CHECK(comp.imag() == Approx(2));
|
||||||
|
|
||||||
args = {"-c", "-4.2-2j"};
|
args = {"-c", "-4.2-2j"};
|
||||||
run();
|
run();
|
||||||
EXPECT_DOUBLE_EQ(-4.2, comp.real());
|
CHECK(comp.real() == Approx(-4.2));
|
||||||
EXPECT_DOUBLE_EQ(-2, comp.imag());
|
CHECK(comp.imag() == Approx(-2));
|
||||||
|
|
||||||
args = {"-c", "-4.2-2.7i"};
|
args = {"-c", "-4.2-2.7i"};
|
||||||
run();
|
run();
|
||||||
EXPECT_DOUBLE_EQ(-4.2, comp.real());
|
CHECK(comp.real() == Approx(-4.2));
|
||||||
EXPECT_DOUBLE_EQ(-2.7, comp.imag());
|
CHECK(comp.imag() == Approx(-2.7));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, ComplexSingleImag) {
|
TEST_CASE_METHOD(TApp, "ComplexSingleImag", "[newparse]") {
|
||||||
cx comp{1, 2};
|
cx comp{1, 2};
|
||||||
app.add_complex("-c,--complex", comp);
|
app.add_complex("-c,--complex", comp);
|
||||||
|
|
||||||
args = {"-c", "4j"};
|
args = {"-c", "4j"};
|
||||||
run();
|
run();
|
||||||
EXPECT_DOUBLE_EQ(0, comp.real());
|
CHECK(comp.real() == Approx(0));
|
||||||
EXPECT_DOUBLE_EQ(4, comp.imag());
|
CHECK(comp.imag() == Approx(4));
|
||||||
|
|
||||||
args = {"-c", "-4j"};
|
args = {"-c", "-4j"};
|
||||||
run();
|
run();
|
||||||
EXPECT_DOUBLE_EQ(0, comp.real());
|
CHECK(comp.real() == Approx(0));
|
||||||
EXPECT_DOUBLE_EQ(-4, comp.imag());
|
CHECK(comp.imag() == Approx(-4));
|
||||||
args = {"-c", "-4"};
|
args = {"-c", "-4"};
|
||||||
run();
|
run();
|
||||||
EXPECT_DOUBLE_EQ(-4, comp.real());
|
CHECK(comp.real() == Approx(-4));
|
||||||
EXPECT_DOUBLE_EQ(0, comp.imag());
|
CHECK(comp.imag() == Approx(0));
|
||||||
args = {"-c", "+4"};
|
args = {"-c", "+4"};
|
||||||
run();
|
run();
|
||||||
EXPECT_DOUBLE_EQ(4, comp.real());
|
CHECK(comp.real() == Approx(4));
|
||||||
EXPECT_DOUBLE_EQ(0, comp.imag());
|
CHECK(comp.imag() == Approx(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, ComplexSingleImagOption) {
|
TEST_CASE_METHOD(TApp, "ComplexSingleImagOption", "[newparse]") {
|
||||||
cx comp{1, 2};
|
cx comp{1, 2};
|
||||||
app.add_option("-c,--complex", comp);
|
app.add_option("-c,--complex", comp);
|
||||||
|
|
||||||
args = {"-c", "4j"};
|
args = {"-c", "4j"};
|
||||||
run();
|
run();
|
||||||
EXPECT_DOUBLE_EQ(0, comp.real());
|
CHECK(comp.real() == Approx(0));
|
||||||
EXPECT_DOUBLE_EQ(4, comp.imag());
|
CHECK(comp.imag() == Approx(4));
|
||||||
|
|
||||||
args = {"-c", "-4j"};
|
args = {"-c", "-4j"};
|
||||||
run();
|
run();
|
||||||
EXPECT_DOUBLE_EQ(0, comp.real());
|
CHECK(comp.real() == Approx(0));
|
||||||
EXPECT_DOUBLE_EQ(-4, comp.imag());
|
CHECK(comp.imag() == Approx(-4));
|
||||||
args = {"-c", "-4"};
|
args = {"-c", "-4"};
|
||||||
run();
|
run();
|
||||||
EXPECT_DOUBLE_EQ(-4, comp.real());
|
CHECK(comp.real() == Approx(-4));
|
||||||
EXPECT_DOUBLE_EQ(0, comp.imag());
|
CHECK(comp.imag() == Approx(0));
|
||||||
args = {"-c", "+4"};
|
args = {"-c", "+4"};
|
||||||
run();
|
run();
|
||||||
EXPECT_DOUBLE_EQ(4, comp.real());
|
CHECK(comp.real() == Approx(4));
|
||||||
EXPECT_DOUBLE_EQ(0, comp.imag());
|
CHECK(comp.imag() == Approx(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Simple class containing two strings useful for testing lexical cast and conversions
|
/// Simple class containing two strings useful for testing lexical cast and conversions
|
||||||
@ -321,24 +321,24 @@ template <> bool lexical_cast<spair>(const std::string &input, spair &output) {
|
|||||||
} // namespace detail
|
} // namespace detail
|
||||||
} // namespace CLI
|
} // namespace CLI
|
||||||
|
|
||||||
TEST_F(TApp, custom_string_converter) {
|
TEST_CASE_METHOD(TApp, "custom_string_converter", "[newparse]") {
|
||||||
spair val;
|
spair val;
|
||||||
app.add_option("-d,--dual_string", val);
|
app.add_option("-d,--dual_string", val);
|
||||||
|
|
||||||
args = {"-d", "string1:string2"};
|
args = {"-d", "string1:string2"};
|
||||||
|
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(val.first, "string1");
|
CHECK("string1" == val.first);
|
||||||
EXPECT_EQ(val.second, "string2");
|
CHECK("string2" == val.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, custom_string_converterFail) {
|
TEST_CASE_METHOD(TApp, "custom_string_converterFail", "[newparse]") {
|
||||||
spair val;
|
spair val;
|
||||||
app.add_option("-d,--dual_string", val);
|
app.add_option("-d,--dual_string", val);
|
||||||
|
|
||||||
args = {"-d", "string2"};
|
args = {"-d", "string2"};
|
||||||
|
|
||||||
EXPECT_THROW(run(), CLI::ConversionError);
|
CHECK_THROWS_AS(run(), CLI::ConversionError);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// simple class to wrap another with a very specific type constructor and assignment operators to test out some of the
|
/// simple class to wrap another with a very specific type constructor and assignment operators to test out some of the
|
||||||
@ -369,14 +369,14 @@ static_assert(CLI::detail::is_direct_constructible<objWrapper<std::string>, std:
|
|||||||
|
|
||||||
static_assert(!std::is_assignable<objWrapper<std::string>, std::string>::value,
|
static_assert(!std::is_assignable<objWrapper<std::string>, std::string>::value,
|
||||||
"string wrapper is improperly assignable");
|
"string wrapper is improperly assignable");
|
||||||
TEST_F(TApp, stringWrapper) {
|
TEST_CASE_METHOD(TApp, "stringWrapper", "[newparse]") {
|
||||||
objWrapper<std::string> sWrapper;
|
objWrapper<std::string> sWrapper;
|
||||||
app.add_option("-v", sWrapper);
|
app.add_option("-v", sWrapper);
|
||||||
args = {"-v", "string test"};
|
args = {"-v", "string test"};
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
|
||||||
EXPECT_EQ(sWrapper.value(), "string test");
|
CHECK("string test" == sWrapper.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
static_assert(CLI::detail::is_direct_constructible<objWrapper<double>, double>::value,
|
static_assert(CLI::detail::is_direct_constructible<objWrapper<double>, double>::value,
|
||||||
@ -388,18 +388,18 @@ static_assert(!CLI::detail::is_direct_constructible<objWrapper<double>, int>::va
|
|||||||
static_assert(!CLI::detail::is_istreamable<objWrapper<double>>::value,
|
static_assert(!CLI::detail::is_istreamable<objWrapper<double>>::value,
|
||||||
"double wrapper is input streamable and it shouldn't be");
|
"double wrapper is input streamable and it shouldn't be");
|
||||||
|
|
||||||
TEST_F(TApp, doubleWrapper) {
|
TEST_CASE_METHOD(TApp, "doubleWrapper", "[newparse]") {
|
||||||
objWrapper<double> dWrapper;
|
objWrapper<double> dWrapper;
|
||||||
app.add_option("-v", dWrapper);
|
app.add_option("-v", dWrapper);
|
||||||
args = {"-v", "2.36"};
|
args = {"-v", "2.36"};
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
|
||||||
EXPECT_EQ(dWrapper.value(), 2.36);
|
CHECK(2.36 == dWrapper.value());
|
||||||
|
|
||||||
args = {"-v", "thing"};
|
args = {"-v", "thing"};
|
||||||
|
|
||||||
EXPECT_THROW(run(), CLI::ConversionError);
|
CHECK_THROWS_AS(run(), CLI::ConversionError);
|
||||||
}
|
}
|
||||||
|
|
||||||
static_assert(CLI::detail::is_direct_constructible<objWrapper<int>, int>::value,
|
static_assert(CLI::detail::is_direct_constructible<objWrapper<int>, int>::value,
|
||||||
@ -411,17 +411,17 @@ static_assert(!CLI::detail::is_direct_constructible<objWrapper<int>, double>::va
|
|||||||
static_assert(!CLI::detail::is_istreamable<objWrapper<int>>::value,
|
static_assert(!CLI::detail::is_istreamable<objWrapper<int>>::value,
|
||||||
"int wrapper is input streamable and it shouldn't be");
|
"int wrapper is input streamable and it shouldn't be");
|
||||||
|
|
||||||
TEST_F(TApp, intWrapper) {
|
TEST_CASE_METHOD(TApp, "intWrapper", "[newparse]") {
|
||||||
objWrapper<int> iWrapper;
|
objWrapper<int> iWrapper;
|
||||||
app.add_option("-v", iWrapper);
|
app.add_option("-v", iWrapper);
|
||||||
args = {"-v", "45"};
|
args = {"-v", "45"};
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
|
||||||
EXPECT_EQ(iWrapper.value(), 45);
|
CHECK(45 == iWrapper.value());
|
||||||
args = {"-v", "thing"};
|
args = {"-v", "thing"};
|
||||||
|
|
||||||
EXPECT_THROW(run(), CLI::ConversionError);
|
CHECK_THROWS_AS(run(), CLI::ConversionError);
|
||||||
}
|
}
|
||||||
|
|
||||||
static_assert(!CLI::detail::is_direct_constructible<objWrapper<float>, int>::value,
|
static_assert(!CLI::detail::is_direct_constructible<objWrapper<float>, int>::value,
|
||||||
@ -432,17 +432,17 @@ static_assert(!CLI::detail::is_direct_constructible<objWrapper<float>, double>::
|
|||||||
static_assert(!CLI::detail::is_istreamable<objWrapper<float>>::value,
|
static_assert(!CLI::detail::is_istreamable<objWrapper<float>>::value,
|
||||||
"float wrapper is input streamable and it shouldn't be");
|
"float wrapper is input streamable and it shouldn't be");
|
||||||
|
|
||||||
TEST_F(TApp, floatWrapper) {
|
TEST_CASE_METHOD(TApp, "floatWrapper", "[newparse]") {
|
||||||
objWrapper<float> iWrapper;
|
objWrapper<float> iWrapper;
|
||||||
app.add_option<objWrapper<float>, float>("-v", iWrapper);
|
app.add_option<objWrapper<float>, float>("-v", iWrapper);
|
||||||
args = {"-v", "45.3"};
|
args = {"-v", "45.3"};
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
|
||||||
EXPECT_EQ(iWrapper.value(), 45.3f);
|
CHECK(45.3f == iWrapper.value());
|
||||||
args = {"-v", "thing"};
|
args = {"-v", "thing"};
|
||||||
|
|
||||||
EXPECT_THROW(run(), CLI::ConversionError);
|
CHECK_THROWS_AS(run(), CLI::ConversionError);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -461,26 +461,26 @@ class dobjWrapper {
|
|||||||
int ival_{0};
|
int ival_{0};
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(TApp, dobjWrapper) {
|
TEST_CASE_METHOD(TApp, "dobjWrapper", "[newparse]") {
|
||||||
dobjWrapper iWrapper;
|
dobjWrapper iWrapper;
|
||||||
app.add_option("-v", iWrapper);
|
app.add_option("-v", iWrapper);
|
||||||
args = {"-v", "45"};
|
args = {"-v", "45"};
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
|
||||||
EXPECT_EQ(iWrapper.ivalue(), 45);
|
CHECK(45 == iWrapper.ivalue());
|
||||||
EXPECT_EQ(iWrapper.dvalue(), 0.0);
|
CHECK(0.0 == iWrapper.dvalue());
|
||||||
|
|
||||||
args = {"-v", "thing"};
|
args = {"-v", "thing"};
|
||||||
|
|
||||||
EXPECT_THROW(run(), CLI::ConversionError);
|
CHECK_THROWS_AS(run(), CLI::ConversionError);
|
||||||
iWrapper = dobjWrapper{};
|
iWrapper = dobjWrapper{};
|
||||||
|
|
||||||
args = {"-v", "45.1"};
|
args = {"-v", "45.1"};
|
||||||
|
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(iWrapper.ivalue(), 0);
|
CHECK(0 == iWrapper.ivalue());
|
||||||
EXPECT_EQ(iWrapper.dvalue(), 45.1);
|
CHECK(45.1 == iWrapper.dvalue());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// simple class to wrap another with a very specific type constructor and assignment operators to test out some of the
|
/// simple class to wrap another with a very specific type constructor and assignment operators to test out some of the
|
||||||
@ -507,25 +507,25 @@ template <class X> class AobjWrapper {
|
|||||||
static_assert(std::is_assignable<AobjWrapper<std::uint16_t> &, std::uint16_t>::value,
|
static_assert(std::is_assignable<AobjWrapper<std::uint16_t> &, std::uint16_t>::value,
|
||||||
"AobjWrapper not assignable like it should be ");
|
"AobjWrapper not assignable like it should be ");
|
||||||
|
|
||||||
TEST_F(TApp, uint16Wrapper) {
|
TEST_CASE_METHOD(TApp, "uint16Wrapper", "[newparse]") {
|
||||||
AobjWrapper<std::uint16_t> sWrapper;
|
AobjWrapper<std::uint16_t> sWrapper;
|
||||||
app.add_option<AobjWrapper<std::uint16_t>, std::uint16_t>("-v", sWrapper);
|
app.add_option<AobjWrapper<std::uint16_t>, std::uint16_t>("-v", sWrapper);
|
||||||
args = {"-v", "9"};
|
args = {"-v", "9"};
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
|
||||||
EXPECT_EQ(sWrapper.value(), 9u);
|
CHECK(9u == sWrapper.value());
|
||||||
args = {"-v", "thing"};
|
args = {"-v", "thing"};
|
||||||
|
|
||||||
EXPECT_THROW(run(), CLI::ConversionError);
|
CHECK_THROWS_AS(run(), CLI::ConversionError);
|
||||||
|
|
||||||
args = {"-v", "72456245754"};
|
args = {"-v", "72456245754"};
|
||||||
|
|
||||||
EXPECT_THROW(run(), CLI::ConversionError);
|
CHECK_THROWS_AS(run(), CLI::ConversionError);
|
||||||
|
|
||||||
args = {"-v", "-3"};
|
args = {"-v", "-3"};
|
||||||
|
|
||||||
EXPECT_THROW(run(), CLI::ConversionError);
|
CHECK_THROWS_AS(run(), CLI::ConversionError);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> class SimpleWrapper {
|
template <class T> class SimpleWrapper {
|
||||||
@ -539,25 +539,25 @@ template <class T> class SimpleWrapper {
|
|||||||
T val_;
|
T val_;
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(TApp, wrapperInt) {
|
TEST_CASE_METHOD(TApp, "wrapperInt", "[newparse]") {
|
||||||
SimpleWrapper<int> wrap;
|
SimpleWrapper<int> wrap;
|
||||||
app.add_option("--val", wrap);
|
app.add_option("--val", wrap);
|
||||||
args = {"--val", "2"};
|
args = {"--val", "2"};
|
||||||
|
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(wrap.getRef(), 2);
|
CHECK(2 == wrap.getRef());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, wrapperString) {
|
TEST_CASE_METHOD(TApp, "wrapperString", "[newparse]") {
|
||||||
SimpleWrapper<std::string> wrap;
|
SimpleWrapper<std::string> wrap;
|
||||||
app.add_option("--val", wrap);
|
app.add_option("--val", wrap);
|
||||||
args = {"--val", "str"};
|
args = {"--val", "str"};
|
||||||
|
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(wrap.getRef(), "str");
|
CHECK("str" == wrap.getRef());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, wrapperVector) {
|
TEST_CASE_METHOD(TApp, "wrapperVector", "[newparse]") {
|
||||||
SimpleWrapper<std::vector<int>> wrap;
|
SimpleWrapper<std::vector<int>> wrap;
|
||||||
app.add_option("--val", wrap);
|
app.add_option("--val", wrap);
|
||||||
args = {"--val", "1", "2", "3", "4"};
|
args = {"--val", "1", "2", "3", "4"};
|
||||||
@ -565,10 +565,10 @@ TEST_F(TApp, wrapperVector) {
|
|||||||
run();
|
run();
|
||||||
auto v1 = wrap.getRef();
|
auto v1 = wrap.getRef();
|
||||||
auto v2 = std::vector<int>{1, 2, 3, 4};
|
auto v2 = std::vector<int>{1, 2, 3, 4};
|
||||||
EXPECT_EQ(v1, v2);
|
CHECK(v2 == v1);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, wrapperwrapperString) {
|
TEST_CASE_METHOD(TApp, "wrapperwrapperString", "[newparse]") {
|
||||||
SimpleWrapper<SimpleWrapper<std::string>> wrap;
|
SimpleWrapper<SimpleWrapper<std::string>> wrap;
|
||||||
app.add_option("--val", wrap);
|
app.add_option("--val", wrap);
|
||||||
args = {"--val", "arg"};
|
args = {"--val", "arg"};
|
||||||
@ -576,10 +576,10 @@ TEST_F(TApp, wrapperwrapperString) {
|
|||||||
run();
|
run();
|
||||||
auto v1 = wrap.getRef().getRef();
|
auto v1 = wrap.getRef().getRef();
|
||||||
auto v2 = "arg";
|
auto v2 = "arg";
|
||||||
EXPECT_EQ(v1, v2);
|
CHECK(v2 == v1);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, wrapperwrapperVector) {
|
TEST_CASE_METHOD(TApp, "wrapperwrapperVector", "[newparse]") {
|
||||||
SimpleWrapper<SimpleWrapper<std::vector<int>>> wrap;
|
SimpleWrapper<SimpleWrapper<std::vector<int>>> wrap;
|
||||||
auto opt = app.add_option("--val", wrap);
|
auto opt = app.add_option("--val", wrap);
|
||||||
args = {"--val", "1", "2", "3", "4"};
|
args = {"--val", "1", "2", "3", "4"};
|
||||||
@ -587,20 +587,20 @@ TEST_F(TApp, wrapperwrapperVector) {
|
|||||||
run();
|
run();
|
||||||
auto v1 = wrap.getRef().getRef();
|
auto v1 = wrap.getRef().getRef();
|
||||||
auto v2 = std::vector<int>{1, 2, 3, 4};
|
auto v2 = std::vector<int>{1, 2, 3, 4};
|
||||||
EXPECT_EQ(v1, v2);
|
CHECK(v2 == v1);
|
||||||
opt->type_size(0, 5);
|
opt->type_size(0, 5);
|
||||||
|
|
||||||
args = {"--val"};
|
args = {"--val"};
|
||||||
|
|
||||||
run();
|
run();
|
||||||
EXPECT_TRUE(wrap.getRef().getRef().empty());
|
CHECK(wrap.getRef().getRef().empty());
|
||||||
|
|
||||||
args = {"--val", "happy", "sad"};
|
args = {"--val", "happy", "sad"};
|
||||||
|
|
||||||
EXPECT_THROW(run(), CLI::ConversionError);
|
CHECK_THROWS_AS(run(), CLI::ConversionError);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, wrapperComplex) {
|
TEST_CASE_METHOD(TApp, "wrapperComplex", "[newparse]") {
|
||||||
SimpleWrapper<std::complex<double>> wrap;
|
SimpleWrapper<std::complex<double>> wrap;
|
||||||
app.add_option("--val", wrap);
|
app.add_option("--val", wrap);
|
||||||
args = {"--val", "1", "2"};
|
args = {"--val", "1", "2"};
|
||||||
@ -608,26 +608,26 @@ TEST_F(TApp, wrapperComplex) {
|
|||||||
run();
|
run();
|
||||||
auto &v1 = wrap.getRef();
|
auto &v1 = wrap.getRef();
|
||||||
auto v2 = std::complex<double>{1, 2};
|
auto v2 = std::complex<double>{1, 2};
|
||||||
EXPECT_EQ(v1.real(), v2.real());
|
CHECK(v2.real() == v1.real());
|
||||||
EXPECT_EQ(v1.imag(), v2.imag());
|
CHECK(v2.imag() == v1.imag());
|
||||||
args = {"--val", "1.4-4j"};
|
args = {"--val", "1.4-4j"};
|
||||||
|
|
||||||
run();
|
run();
|
||||||
v2 = std::complex<double>{1.4, -4};
|
v2 = std::complex<double>{1.4, -4};
|
||||||
EXPECT_EQ(v1.real(), v2.real());
|
CHECK(v2.real() == v1.real());
|
||||||
EXPECT_EQ(v1.imag(), v2.imag());
|
CHECK(v2.imag() == v1.imag());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, vectorComplex) {
|
TEST_CASE_METHOD(TApp, "vectorComplex", "[newparse]") {
|
||||||
std::vector<std::complex<double>> vcomplex;
|
std::vector<std::complex<double>> vcomplex;
|
||||||
app.add_option("--val", vcomplex);
|
app.add_option("--val", vcomplex);
|
||||||
args = {"--val", "1", "2", "--val", "1.4-4j"};
|
args = {"--val", "1", "2", "--val", "1.4-4j"};
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
|
||||||
ASSERT_EQ(vcomplex.size(), 2U);
|
REQUIRE(2U == vcomplex.size());
|
||||||
EXPECT_EQ(vcomplex[0].real(), 1.0);
|
CHECK(1.0 == vcomplex[0].real());
|
||||||
EXPECT_EQ(vcomplex[0].imag(), 2.0);
|
CHECK(2.0 == vcomplex[0].imag());
|
||||||
EXPECT_EQ(vcomplex[1].real(), 1.4);
|
CHECK(1.4 == vcomplex[1].real());
|
||||||
EXPECT_EQ(vcomplex[1].imag(), -4.0);
|
CHECK(-4.0 == vcomplex[1].imag());
|
||||||
}
|
}
|
||||||
|
@ -6,15 +6,11 @@
|
|||||||
|
|
||||||
#include "app_helper.hpp"
|
#include "app_helper.hpp"
|
||||||
|
|
||||||
#include "gmock/gmock.h"
|
using Catch::Matchers::Contains;
|
||||||
#include "gtest/gtest.h"
|
|
||||||
|
|
||||||
using ::testing::HasSubstr;
|
|
||||||
using ::testing::Not;
|
|
||||||
|
|
||||||
using vs_t = std::vector<std::string>;
|
using vs_t = std::vector<std::string>;
|
||||||
|
|
||||||
TEST_F(TApp, BasicOptionGroup) {
|
TEST_CASE_METHOD(TApp, "BasicOptionGroup", "[optiongroup]") {
|
||||||
auto ogroup = app.add_option_group("clusters");
|
auto ogroup = app.add_option_group("clusters");
|
||||||
int res;
|
int res;
|
||||||
ogroup->add_option("--test1", res);
|
ogroup->add_option("--test1", res);
|
||||||
@ -23,11 +19,11 @@ TEST_F(TApp, BasicOptionGroup) {
|
|||||||
|
|
||||||
args = {"--test1", "5"};
|
args = {"--test1", "5"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(res, 5);
|
CHECK(5 == res);
|
||||||
EXPECT_EQ(app.count_all(), 1u);
|
CHECK(1u == app.count_all());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, BasicOptionGroupExact) {
|
TEST_CASE_METHOD(TApp, "BasicOptionGroupExact", "[optiongroup]") {
|
||||||
auto ogroup = app.add_option_group("clusters");
|
auto ogroup = app.add_option_group("clusters");
|
||||||
int res{0};
|
int res{0};
|
||||||
ogroup->add_option("--test1", res);
|
ogroup->add_option("--test1", res);
|
||||||
@ -38,20 +34,20 @@ TEST_F(TApp, BasicOptionGroupExact) {
|
|||||||
ogroup->require_option(1);
|
ogroup->require_option(1);
|
||||||
args = {"--test1", "5"};
|
args = {"--test1", "5"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(res, 5);
|
CHECK(5 == res);
|
||||||
|
|
||||||
args = {"--test1", "5", "--test2", "4"};
|
args = {"--test1", "5", "--test2", "4"};
|
||||||
EXPECT_THROW(run(), CLI::RequiredError);
|
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||||
|
|
||||||
args = {"--option", "9"};
|
args = {"--option", "9"};
|
||||||
EXPECT_THROW(run(), CLI::RequiredError);
|
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||||
|
|
||||||
std::string help = ogroup->help();
|
std::string help = ogroup->help();
|
||||||
auto exactloc = help.find("[Exactly 1");
|
auto exactloc = help.find("[Exactly 1");
|
||||||
EXPECT_NE(exactloc, std::string::npos);
|
CHECK(std::string::npos != exactloc);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, BasicOptionGroupExactTooMany) {
|
TEST_CASE_METHOD(TApp, "BasicOptionGroupExactTooMany", "[optiongroup]") {
|
||||||
auto ogroup = app.add_option_group("clusters");
|
auto ogroup = app.add_option_group("clusters");
|
||||||
int res{0};
|
int res{0};
|
||||||
ogroup->add_option("--test1", res);
|
ogroup->add_option("--test1", res);
|
||||||
@ -61,10 +57,10 @@ TEST_F(TApp, BasicOptionGroupExactTooMany) {
|
|||||||
app.add_option("--option", val2);
|
app.add_option("--option", val2);
|
||||||
ogroup->require_option(10);
|
ogroup->require_option(10);
|
||||||
args = {"--test1", "5"};
|
args = {"--test1", "5"};
|
||||||
EXPECT_THROW(run(), CLI::InvalidError);
|
CHECK_THROWS_AS(run(), CLI::InvalidError);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, BasicOptionGroupMinMax) {
|
TEST_CASE_METHOD(TApp, "BasicOptionGroupMinMax", "[optiongroup]") {
|
||||||
auto ogroup = app.add_option_group("clusters");
|
auto ogroup = app.add_option_group("clusters");
|
||||||
int res{0};
|
int res{0};
|
||||||
ogroup->add_option("--test1", res);
|
ogroup->add_option("--test1", res);
|
||||||
@ -75,20 +71,20 @@ TEST_F(TApp, BasicOptionGroupMinMax) {
|
|||||||
ogroup->require_option(1, 1);
|
ogroup->require_option(1, 1);
|
||||||
args = {"--test1", "5"};
|
args = {"--test1", "5"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(res, 5);
|
CHECK(5 == res);
|
||||||
|
|
||||||
args = {"--test1", "5", "--test2", "4"};
|
args = {"--test1", "5", "--test2", "4"};
|
||||||
EXPECT_THROW(run(), CLI::RequiredError);
|
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||||
|
|
||||||
args = {"--option", "9"};
|
args = {"--option", "9"};
|
||||||
EXPECT_THROW(run(), CLI::RequiredError);
|
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||||
|
|
||||||
std::string help = ogroup->help();
|
std::string help = ogroup->help();
|
||||||
auto exactloc = help.find("[Exactly 1");
|
auto exactloc = help.find("[Exactly 1");
|
||||||
EXPECT_NE(exactloc, std::string::npos);
|
CHECK(std::string::npos != exactloc);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, BasicOptionGroupMinMaxDifferent) {
|
TEST_CASE_METHOD(TApp, "BasicOptionGroupMinMaxDifferent", "[optiongroup]") {
|
||||||
auto ogroup = app.add_option_group("clusters");
|
auto ogroup = app.add_option_group("clusters");
|
||||||
int res{0};
|
int res{0};
|
||||||
ogroup->add_option("--test1", res);
|
ogroup->add_option("--test1", res);
|
||||||
@ -99,24 +95,24 @@ TEST_F(TApp, BasicOptionGroupMinMaxDifferent) {
|
|||||||
ogroup->require_option(1, 2);
|
ogroup->require_option(1, 2);
|
||||||
args = {"--test1", "5"};
|
args = {"--test1", "5"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(res, 5);
|
CHECK(5 == res);
|
||||||
|
|
||||||
args = {"--test1", "5", "--test2", "4"};
|
args = {"--test1", "5", "--test2", "4"};
|
||||||
EXPECT_NO_THROW(run());
|
CHECK_NOTHROW(run());
|
||||||
EXPECT_EQ(app.count_all(), 2u);
|
CHECK(2u == app.count_all());
|
||||||
|
|
||||||
args = {"--option", "9"};
|
args = {"--option", "9"};
|
||||||
EXPECT_THROW(run(), CLI::RequiredError);
|
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||||
|
|
||||||
args = {"--test1", "5", "--test2", "4", "--test3=5"};
|
args = {"--test1", "5", "--test2", "4", "--test3=5"};
|
||||||
EXPECT_THROW(run(), CLI::RequiredError);
|
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||||
|
|
||||||
std::string help = ogroup->help();
|
std::string help = ogroup->help();
|
||||||
auto exactloc = help.find("[Between 1 and 2");
|
auto exactloc = help.find("[Between 1 and 2");
|
||||||
EXPECT_NE(exactloc, std::string::npos);
|
CHECK(std::string::npos != exactloc);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, BasicOptionGroupMinMaxDifferentReversed) {
|
TEST_CASE_METHOD(TApp, "BasicOptionGroupMinMaxDifferentReversed", "[optiongroup]") {
|
||||||
auto ogroup = app.add_option_group("clusters");
|
auto ogroup = app.add_option_group("clusters");
|
||||||
int res{0};
|
int res{0};
|
||||||
ogroup->add_option("--test1", res);
|
ogroup->add_option("--test1", res);
|
||||||
@ -125,30 +121,30 @@ TEST_F(TApp, BasicOptionGroupMinMaxDifferentReversed) {
|
|||||||
int val2{0};
|
int val2{0};
|
||||||
app.add_option("--option", val2);
|
app.add_option("--option", val2);
|
||||||
ogroup->require_option(2, 1);
|
ogroup->require_option(2, 1);
|
||||||
EXPECT_EQ(ogroup->get_require_option_min(), 2u);
|
CHECK(2u == ogroup->get_require_option_min());
|
||||||
EXPECT_EQ(ogroup->get_require_option_max(), 1u);
|
CHECK(1u == ogroup->get_require_option_max());
|
||||||
args = {"--test1", "5"};
|
args = {"--test1", "5"};
|
||||||
EXPECT_THROW(run(), CLI::InvalidError);
|
CHECK_THROWS_AS(run(), CLI::InvalidError);
|
||||||
ogroup->require_option(1, 2);
|
ogroup->require_option(1, 2);
|
||||||
EXPECT_NO_THROW(run());
|
CHECK_NOTHROW(run());
|
||||||
EXPECT_EQ(res, 5);
|
CHECK(5 == res);
|
||||||
EXPECT_EQ(ogroup->get_require_option_min(), 1u);
|
CHECK(1u == ogroup->get_require_option_min());
|
||||||
EXPECT_EQ(ogroup->get_require_option_max(), 2u);
|
CHECK(2u == ogroup->get_require_option_max());
|
||||||
args = {"--test1", "5", "--test2", "4"};
|
args = {"--test1", "5", "--test2", "4"};
|
||||||
EXPECT_NO_THROW(run());
|
CHECK_NOTHROW(run());
|
||||||
|
|
||||||
args = {"--option", "9"};
|
args = {"--option", "9"};
|
||||||
EXPECT_THROW(run(), CLI::RequiredError);
|
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||||
|
|
||||||
args = {"--test1", "5", "--test2", "4", "--test3=5"};
|
args = {"--test1", "5", "--test2", "4", "--test3=5"};
|
||||||
EXPECT_THROW(run(), CLI::RequiredError);
|
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||||
|
|
||||||
std::string help = ogroup->help();
|
std::string help = ogroup->help();
|
||||||
auto exactloc = help.find("[Between 1 and 2");
|
auto exactloc = help.find("[Between 1 and 2");
|
||||||
EXPECT_NE(exactloc, std::string::npos);
|
CHECK(std::string::npos != exactloc);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, BasicOptionGroupMax) {
|
TEST_CASE_METHOD(TApp, "BasicOptionGroupMax", "[optiongroup]") {
|
||||||
auto ogroup = app.add_option_group("clusters");
|
auto ogroup = app.add_option_group("clusters");
|
||||||
int res{0};
|
int res{0};
|
||||||
ogroup->add_option("--test1", res);
|
ogroup->add_option("--test1", res);
|
||||||
@ -159,20 +155,20 @@ TEST_F(TApp, BasicOptionGroupMax) {
|
|||||||
ogroup->require_option(-2);
|
ogroup->require_option(-2);
|
||||||
args = {"--test1", "5"};
|
args = {"--test1", "5"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(res, 5);
|
CHECK(5 == res);
|
||||||
|
|
||||||
args = {"--option", "9"};
|
args = {"--option", "9"};
|
||||||
EXPECT_NO_THROW(run());
|
CHECK_NOTHROW(run());
|
||||||
|
|
||||||
args = {"--test1", "5", "--test2", "4", "--test3=5"};
|
args = {"--test1", "5", "--test2", "4", "--test3=5"};
|
||||||
EXPECT_THROW(run(), CLI::RequiredError);
|
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||||
|
|
||||||
std::string help = ogroup->help();
|
std::string help = ogroup->help();
|
||||||
auto exactloc = help.find("[At most 2");
|
auto exactloc = help.find("[At most 2");
|
||||||
EXPECT_NE(exactloc, std::string::npos);
|
CHECK(std::string::npos != exactloc);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, BasicOptionGroupMax1) {
|
TEST_CASE_METHOD(TApp, "BasicOptionGroupMax1", "[optiongroup]") {
|
||||||
auto ogroup = app.add_option_group("clusters");
|
auto ogroup = app.add_option_group("clusters");
|
||||||
int res{0};
|
int res{0};
|
||||||
ogroup->add_option("--test1", res);
|
ogroup->add_option("--test1", res);
|
||||||
@ -183,20 +179,20 @@ TEST_F(TApp, BasicOptionGroupMax1) {
|
|||||||
ogroup->require_option(-1);
|
ogroup->require_option(-1);
|
||||||
args = {"--test1", "5"};
|
args = {"--test1", "5"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(res, 5);
|
CHECK(5 == res);
|
||||||
|
|
||||||
args = {"--option", "9"};
|
args = {"--option", "9"};
|
||||||
EXPECT_NO_THROW(run());
|
CHECK_NOTHROW(run());
|
||||||
|
|
||||||
args = {"--test1", "5", "--test2", "4"};
|
args = {"--test1", "5", "--test2", "4"};
|
||||||
EXPECT_THROW(run(), CLI::RequiredError);
|
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||||
|
|
||||||
std::string help = ogroup->help();
|
std::string help = ogroup->help();
|
||||||
auto exactloc = help.find("[At most 1");
|
auto exactloc = help.find("[At most 1");
|
||||||
EXPECT_NE(exactloc, std::string::npos);
|
CHECK(std::string::npos != exactloc);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, BasicOptionGroupMin) {
|
TEST_CASE_METHOD(TApp, "BasicOptionGroupMin", "[optiongroup]") {
|
||||||
auto ogroup = app.add_option_group("clusters");
|
auto ogroup = app.add_option_group("clusters");
|
||||||
int res{0};
|
int res{0};
|
||||||
ogroup->add_option("--test1", res);
|
ogroup->add_option("--test1", res);
|
||||||
@ -207,17 +203,17 @@ TEST_F(TApp, BasicOptionGroupMin) {
|
|||||||
ogroup->require_option();
|
ogroup->require_option();
|
||||||
|
|
||||||
args = {"--option", "9"};
|
args = {"--option", "9"};
|
||||||
EXPECT_THROW(run(), CLI::RequiredError);
|
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||||
|
|
||||||
args = {"--test1", "5", "--test2", "4", "--test3=5"};
|
args = {"--test1", "5", "--test2", "4", "--test3=5"};
|
||||||
EXPECT_NO_THROW(run());
|
CHECK_NOTHROW(run());
|
||||||
|
|
||||||
std::string help = ogroup->help();
|
std::string help = ogroup->help();
|
||||||
auto exactloc = help.find("[At least 1");
|
auto exactloc = help.find("[At least 1");
|
||||||
EXPECT_NE(exactloc, std::string::npos);
|
CHECK(std::string::npos != exactloc);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, BasicOptionGroupExact2) {
|
TEST_CASE_METHOD(TApp, "BasicOptionGroupExact2", "[optiongroup]") {
|
||||||
auto ogroup = app.add_option_group("clusters");
|
auto ogroup = app.add_option_group("clusters");
|
||||||
int res{0};
|
int res{0};
|
||||||
ogroup->add_option("--test1", res);
|
ogroup->add_option("--test1", res);
|
||||||
@ -228,20 +224,20 @@ TEST_F(TApp, BasicOptionGroupExact2) {
|
|||||||
ogroup->require_option(2);
|
ogroup->require_option(2);
|
||||||
|
|
||||||
args = {"--option", "9"};
|
args = {"--option", "9"};
|
||||||
EXPECT_THROW(run(), CLI::RequiredError);
|
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||||
|
|
||||||
args = {"--test1", "5", "--test2", "4", "--test3=5"};
|
args = {"--test1", "5", "--test2", "4", "--test3=5"};
|
||||||
EXPECT_THROW(run(), CLI::RequiredError);
|
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||||
|
|
||||||
args = {"--test1", "5", "--test3=5"};
|
args = {"--test1", "5", "--test3=5"};
|
||||||
EXPECT_NO_THROW(run());
|
CHECK_NOTHROW(run());
|
||||||
|
|
||||||
std::string help = ogroup->help();
|
std::string help = ogroup->help();
|
||||||
auto exactloc = help.find("[Exactly 2");
|
auto exactloc = help.find("[Exactly 2");
|
||||||
EXPECT_NE(exactloc, std::string::npos);
|
CHECK(std::string::npos != exactloc);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, BasicOptionGroupMin2) {
|
TEST_CASE_METHOD(TApp, "BasicOptionGroupMin2", "[optiongroup]") {
|
||||||
auto ogroup = app.add_option_group("clusters");
|
auto ogroup = app.add_option_group("clusters");
|
||||||
int res{0};
|
int res{0};
|
||||||
ogroup->add_option("--test1", res);
|
ogroup->add_option("--test1", res);
|
||||||
@ -252,17 +248,17 @@ TEST_F(TApp, BasicOptionGroupMin2) {
|
|||||||
ogroup->require_option(2, 0);
|
ogroup->require_option(2, 0);
|
||||||
|
|
||||||
args = {"--option", "9"};
|
args = {"--option", "9"};
|
||||||
EXPECT_THROW(run(), CLI::RequiredError);
|
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||||
|
|
||||||
args = {"--test1", "5", "--test2", "4", "--test3=5"};
|
args = {"--test1", "5", "--test2", "4", "--test3=5"};
|
||||||
EXPECT_NO_THROW(run());
|
CHECK_NOTHROW(run());
|
||||||
|
|
||||||
std::string help = ogroup->help();
|
std::string help = ogroup->help();
|
||||||
auto exactloc = help.find("[At least 2");
|
auto exactloc = help.find("[At least 2");
|
||||||
EXPECT_NE(exactloc, std::string::npos);
|
CHECK(std::string::npos != exactloc);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, BasicOptionGroupMinMoved) {
|
TEST_CASE_METHOD(TApp, "BasicOptionGroupMinMoved", "[optiongroup]") {
|
||||||
|
|
||||||
int res{0};
|
int res{0};
|
||||||
auto opt1 = app.add_option("--test1", res);
|
auto opt1 = app.add_option("--test1", res);
|
||||||
@ -278,20 +274,20 @@ TEST_F(TApp, BasicOptionGroupMinMoved) {
|
|||||||
ogroup->add_option(opt3);
|
ogroup->add_option(opt3);
|
||||||
|
|
||||||
args = {"--option", "9"};
|
args = {"--option", "9"};
|
||||||
EXPECT_THROW(run(), CLI::RequiredError);
|
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||||
|
|
||||||
args = {"--test1", "5", "--test2", "4", "--test3=5"};
|
args = {"--test1", "5", "--test2", "4", "--test3=5"};
|
||||||
EXPECT_NO_THROW(run());
|
CHECK_NOTHROW(run());
|
||||||
|
|
||||||
std::string help = app.help();
|
std::string help = app.help();
|
||||||
auto exactloc = help.find("[At least 1");
|
auto exactloc = help.find("[At least 1");
|
||||||
auto oloc = help.find("--test1");
|
auto oloc = help.find("--test1");
|
||||||
EXPECT_NE(exactloc, std::string::npos);
|
CHECK(std::string::npos != exactloc);
|
||||||
EXPECT_NE(oloc, std::string::npos);
|
CHECK(std::string::npos != oloc);
|
||||||
EXPECT_LT(exactloc, oloc);
|
CHECK(oloc > exactloc);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, BasicOptionGroupMinMovedAsGroup) {
|
TEST_CASE_METHOD(TApp, "BasicOptionGroupMinMovedAsGroup", "[optiongroup]") {
|
||||||
|
|
||||||
int res{0};
|
int res{0};
|
||||||
auto opt1 = app.add_option("--test1", res);
|
auto opt1 = app.add_option("--test1", res);
|
||||||
@ -304,22 +300,22 @@ TEST_F(TApp, BasicOptionGroupMinMovedAsGroup) {
|
|||||||
ogroup->require_option();
|
ogroup->require_option();
|
||||||
ogroup->add_options(opt1, opt2, opt3);
|
ogroup->add_options(opt1, opt2, opt3);
|
||||||
|
|
||||||
EXPECT_THROW(ogroup->add_options(opt1), CLI::OptionNotFound);
|
CHECK_THROWS_AS(ogroup->add_options(opt1), CLI::OptionNotFound);
|
||||||
args = {"--option", "9"};
|
args = {"--option", "9"};
|
||||||
EXPECT_THROW(run(), CLI::RequiredError);
|
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||||
|
|
||||||
args = {"--test1", "5", "--test2", "4", "--test3=5"};
|
args = {"--test1", "5", "--test2", "4", "--test3=5"};
|
||||||
EXPECT_NO_THROW(run());
|
CHECK_NOTHROW(run());
|
||||||
|
|
||||||
std::string help = app.help();
|
std::string help = app.help();
|
||||||
auto exactloc = help.find("[At least 1");
|
auto exactloc = help.find("[At least 1");
|
||||||
auto oloc = help.find("--test1");
|
auto oloc = help.find("--test1");
|
||||||
EXPECT_NE(exactloc, std::string::npos);
|
CHECK(std::string::npos != exactloc);
|
||||||
EXPECT_NE(oloc, std::string::npos);
|
CHECK(std::string::npos != oloc);
|
||||||
EXPECT_LT(exactloc, oloc);
|
CHECK(oloc > exactloc);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, BasicOptionGroupAddFailures) {
|
TEST_CASE_METHOD(TApp, "BasicOptionGroupAddFailures", "[optiongroup]") {
|
||||||
|
|
||||||
int res{0};
|
int res{0};
|
||||||
auto opt1 = app.add_option("--test1", res);
|
auto opt1 = app.add_option("--test1", res);
|
||||||
@ -328,24 +324,24 @@ TEST_F(TApp, BasicOptionGroupAddFailures) {
|
|||||||
app.add_option("--option", val2);
|
app.add_option("--option", val2);
|
||||||
|
|
||||||
auto ogroup = app.add_option_group("clusters");
|
auto ogroup = app.add_option_group("clusters");
|
||||||
EXPECT_THROW(ogroup->add_options(app.get_config_ptr()), CLI::OptionAlreadyAdded);
|
CHECK_THROWS_AS(ogroup->add_options(app.get_config_ptr()), CLI::OptionAlreadyAdded);
|
||||||
EXPECT_THROW(ogroup->add_options(app.get_help_ptr()), CLI::OptionAlreadyAdded);
|
CHECK_THROWS_AS(ogroup->add_options(app.get_help_ptr()), CLI::OptionAlreadyAdded);
|
||||||
|
|
||||||
auto sub = app.add_subcommand("sub", "subcommand");
|
auto sub = app.add_subcommand("sub", "subcommand");
|
||||||
auto opt2 = sub->add_option("--option2", val2);
|
auto opt2 = sub->add_option("--option2", val2);
|
||||||
|
|
||||||
EXPECT_THROW(ogroup->add_option(opt2), CLI::OptionNotFound);
|
CHECK_THROWS_AS(ogroup->add_option(opt2), CLI::OptionNotFound);
|
||||||
|
|
||||||
EXPECT_THROW(ogroup->add_options(nullptr), CLI::OptionNotFound);
|
CHECK_THROWS_AS(ogroup->add_options(nullptr), CLI::OptionNotFound);
|
||||||
|
|
||||||
ogroup->add_option(opt1);
|
ogroup->add_option(opt1);
|
||||||
|
|
||||||
auto opt3 = app.add_option("--test1", res);
|
auto opt3 = app.add_option("--test1", res);
|
||||||
|
|
||||||
EXPECT_THROW(ogroup->add_option(opt3), CLI::OptionAlreadyAdded);
|
CHECK_THROWS_AS(ogroup->add_option(opt3), CLI::OptionAlreadyAdded);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, BasicOptionGroupScrewedUpMove) {
|
TEST_CASE_METHOD(TApp, "BasicOptionGroupScrewedUpMove", "[optiongroup]") {
|
||||||
|
|
||||||
int res{0};
|
int res{0};
|
||||||
auto opt1 = app.add_option("--test1", res);
|
auto opt1 = app.add_option("--test1", res);
|
||||||
@ -356,25 +352,25 @@ TEST_F(TApp, BasicOptionGroupScrewedUpMove) {
|
|||||||
auto ogroup = app.add_option_group("clusters");
|
auto ogroup = app.add_option_group("clusters");
|
||||||
ogroup->require_option();
|
ogroup->require_option();
|
||||||
auto ogroup2 = ogroup->add_option_group("clusters2");
|
auto ogroup2 = ogroup->add_option_group("clusters2");
|
||||||
EXPECT_THROW(ogroup2->add_options(opt1, opt2), CLI::OptionNotFound);
|
CHECK_THROWS_AS(ogroup2->add_options(opt1, opt2), CLI::OptionNotFound);
|
||||||
|
|
||||||
CLI::Option_group EmptyGroup("description", "new group", nullptr);
|
CLI::Option_group EmptyGroup("description", "new group", nullptr);
|
||||||
|
|
||||||
EXPECT_THROW(EmptyGroup.add_option(opt2), CLI::OptionNotFound);
|
CHECK_THROWS_AS(EmptyGroup.add_option(opt2), CLI::OptionNotFound);
|
||||||
EXPECT_THROW(app._move_option(opt2, ogroup2), CLI::OptionNotFound);
|
CHECK_THROWS_AS(app._move_option(opt2, ogroup2), CLI::OptionNotFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, InvalidOptions) {
|
TEST_CASE_METHOD(TApp, "InvalidOptions", "[optiongroup]") {
|
||||||
auto ogroup = app.add_option_group("clusters");
|
auto ogroup = app.add_option_group("clusters");
|
||||||
CLI::Option *opt = nullptr;
|
CLI::Option *opt = nullptr;
|
||||||
EXPECT_THROW(ogroup->excludes(opt), CLI::OptionNotFound);
|
CHECK_THROWS_AS(ogroup->excludes(opt), CLI::OptionNotFound);
|
||||||
CLI::App *app_p = nullptr;
|
CLI::App *app_p = nullptr;
|
||||||
EXPECT_THROW(ogroup->excludes(app_p), CLI::OptionNotFound);
|
CHECK_THROWS_AS(ogroup->excludes(app_p), CLI::OptionNotFound);
|
||||||
EXPECT_THROW(ogroup->excludes(ogroup), CLI::OptionNotFound);
|
CHECK_THROWS_AS(ogroup->excludes(ogroup), CLI::OptionNotFound);
|
||||||
EXPECT_THROW(ogroup->add_option(opt), CLI::OptionNotFound);
|
CHECK_THROWS_AS(ogroup->add_option(opt), CLI::OptionNotFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, OptionGroupInheritedOptionDefaults) {
|
TEST_CASE_METHOD(TApp, "OptionGroupInheritedOptionDefaults", "[optiongroup]") {
|
||||||
app.option_defaults()->ignore_case();
|
app.option_defaults()->ignore_case();
|
||||||
auto ogroup = app.add_option_group("clusters");
|
auto ogroup = app.add_option_group("clusters");
|
||||||
int res{0};
|
int res{0};
|
||||||
@ -382,8 +378,8 @@ TEST_F(TApp, OptionGroupInheritedOptionDefaults) {
|
|||||||
|
|
||||||
args = {"--Test1", "5"};
|
args = {"--Test1", "5"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(res, 5);
|
CHECK(5 == res);
|
||||||
EXPECT_EQ(app.count_all(), 1u);
|
CHECK(1u == app.count_all());
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ManyGroups : public TApp {
|
struct ManyGroups : public TApp {
|
||||||
@ -425,48 +421,48 @@ struct ManyGroups : public TApp {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(ManyGroups, SingleGroup) {
|
TEST_CASE_METHOD(ManyGroups, "SingleGroup", "[optiongroup]") {
|
||||||
// only 1 group can be used
|
// only 1 group can be used
|
||||||
main->require_option(1);
|
main->require_option(1);
|
||||||
args = {"--name1", "test"};
|
args = {"--name1", "test"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(name1, "test");
|
CHECK("test" == name1);
|
||||||
|
|
||||||
args = {"--name2", "test", "--val2", "tval"};
|
args = {"--name2", "test", "--val2", "tval"};
|
||||||
|
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(val2, "tval");
|
CHECK("tval" == val2);
|
||||||
|
|
||||||
args = {"--name1", "test", "--val2", "tval"};
|
args = {"--name1", "test", "--val2", "tval"};
|
||||||
|
|
||||||
EXPECT_THROW(run(), CLI::RequiredError);
|
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ManyGroups, ExcludesGroup) {
|
TEST_CASE_METHOD(ManyGroups, "ExcludesGroup", "[optiongroup]") {
|
||||||
// only 1 group can be used
|
// only 1 group can be used
|
||||||
g1->excludes(g2);
|
g1->excludes(g2);
|
||||||
g1->excludes(g3);
|
g1->excludes(g3);
|
||||||
args = {"--name1", "test"};
|
args = {"--name1", "test"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(name1, "test");
|
CHECK("test" == name1);
|
||||||
|
|
||||||
args = {"--name1", "test", "--name2", "test2"};
|
args = {"--name1", "test", "--name2", "test2"};
|
||||||
|
|
||||||
EXPECT_THROW(run(), CLI::ExcludesError);
|
CHECK_THROWS_AS(run(), CLI::ExcludesError);
|
||||||
|
|
||||||
EXPECT_TRUE(g1->remove_excludes(g2));
|
CHECK(g1->remove_excludes(g2));
|
||||||
EXPECT_NO_THROW(run());
|
CHECK_NOTHROW(run());
|
||||||
EXPECT_FALSE(g1->remove_excludes(g1));
|
CHECK(!g1->remove_excludes(g1));
|
||||||
EXPECT_FALSE(g1->remove_excludes(g2));
|
CHECK(!g1->remove_excludes(g2));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ManyGroups, NeedsGroup) {
|
TEST_CASE_METHOD(ManyGroups, "NeedsGroup", "[optiongroup]") {
|
||||||
remove_required();
|
remove_required();
|
||||||
// all groups needed if g1 is used
|
// all groups needed if g1 is used
|
||||||
g1->needs(g2);
|
g1->needs(g2);
|
||||||
g1->needs(g3);
|
g1->needs(g3);
|
||||||
args = {"--name1", "test"};
|
args = {"--name1", "test"};
|
||||||
EXPECT_THROW(run(), CLI::RequiresError);
|
CHECK_THROWS_AS(run(), CLI::RequiresError);
|
||||||
// other groups should run fine
|
// other groups should run fine
|
||||||
args = {"--name2", "test2"};
|
args = {"--name2", "test2"};
|
||||||
|
|
||||||
@ -474,11 +470,11 @@ TEST_F(ManyGroups, NeedsGroup) {
|
|||||||
// all three groups should be fine
|
// all three groups should be fine
|
||||||
args = {"--name1", "test", "--name2", "test2", "--name3", "test3"};
|
args = {"--name1", "test", "--name2", "test2", "--name3", "test3"};
|
||||||
|
|
||||||
EXPECT_NO_THROW(run());
|
CHECK_NOTHROW(run());
|
||||||
}
|
}
|
||||||
|
|
||||||
// test adding an option group with existing subcommands to an app
|
// test adding an option group with existing subcommands to an app
|
||||||
TEST_F(TApp, ExistingSubcommandMatch) {
|
TEST_CASE_METHOD(TApp, "ExistingSubcommandMatch", "[optiongroup]") {
|
||||||
auto sshared = std::make_shared<CLI::Option_group>("documenting the subcommand", "sub1g", nullptr);
|
auto sshared = std::make_shared<CLI::Option_group>("documenting the subcommand", "sub1g", nullptr);
|
||||||
auto s1 = sshared->add_subcommand("sub1");
|
auto s1 = sshared->add_subcommand("sub1");
|
||||||
auto o1 = sshared->add_option_group("opt1");
|
auto o1 = sshared->add_option_group("opt1");
|
||||||
@ -489,9 +485,9 @@ TEST_F(TApp, ExistingSubcommandMatch) {
|
|||||||
try {
|
try {
|
||||||
app.add_subcommand(sshared);
|
app.add_subcommand(sshared);
|
||||||
// this should throw the next line should never be reached
|
// this should throw the next line should never be reached
|
||||||
EXPECT_FALSE(true);
|
CHECK(!true);
|
||||||
} catch(const CLI::OptionAlreadyAdded &oaa) {
|
} catch(const CLI::OptionAlreadyAdded &oaa) {
|
||||||
EXPECT_THAT(oaa.what(), HasSubstr("sub1"));
|
CHECK_THAT(oaa.what(), Contains("sub1"));
|
||||||
}
|
}
|
||||||
sshared->remove_subcommand(s1);
|
sshared->remove_subcommand(s1);
|
||||||
|
|
||||||
@ -500,40 +496,40 @@ TEST_F(TApp, ExistingSubcommandMatch) {
|
|||||||
try {
|
try {
|
||||||
app.add_subcommand(sshared);
|
app.add_subcommand(sshared);
|
||||||
// this should throw the next line should never be reached
|
// this should throw the next line should never be reached
|
||||||
EXPECT_FALSE(true);
|
CHECK(!true);
|
||||||
} catch(const CLI::OptionAlreadyAdded &oaa) {
|
} catch(const CLI::OptionAlreadyAdded &oaa) {
|
||||||
EXPECT_THAT(oaa.what(), HasSubstr("sub3"));
|
CHECK_THAT(oaa.what(), Contains("sub3"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ManyGroups, SingleGroupError) {
|
TEST_CASE_METHOD(ManyGroups, "SingleGroupError", "[optiongroup]") {
|
||||||
// only 1 group can be used
|
// only 1 group can be used
|
||||||
main->require_option(1);
|
main->require_option(1);
|
||||||
args = {"--name1", "test", "--name2", "test3"};
|
args = {"--name1", "test", "--name2", "test3"};
|
||||||
EXPECT_THROW(run(), CLI::RequiredError);
|
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ManyGroups, AtMostOneGroup) {
|
TEST_CASE_METHOD(ManyGroups, "AtMostOneGroup", "[optiongroup]") {
|
||||||
// only 1 group can be used
|
// only 1 group can be used
|
||||||
main->require_option(0, 1);
|
main->require_option(0, 1);
|
||||||
args = {"--name1", "test", "--name2", "test3"};
|
args = {"--name1", "test", "--name2", "test3"};
|
||||||
EXPECT_THROW(run(), CLI::RequiredError);
|
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||||
|
|
||||||
args = {};
|
args = {};
|
||||||
EXPECT_NO_THROW(run());
|
CHECK_NOTHROW(run());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ManyGroups, AtLeastTwoGroups) {
|
TEST_CASE_METHOD(ManyGroups, "AtLeastTwoGroups", "[optiongroup]") {
|
||||||
// only 1 group can be used
|
// only 1 group can be used
|
||||||
main->require_option(2, 0);
|
main->require_option(2, 0);
|
||||||
args = {"--name1", "test", "--name2", "test3"};
|
args = {"--name1", "test", "--name2", "test3"};
|
||||||
run();
|
run();
|
||||||
|
|
||||||
args = {"--name1", "test"};
|
args = {"--name1", "test"};
|
||||||
EXPECT_THROW(run(), CLI::RequiredError);
|
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ManyGroups, BetweenOneAndTwoGroups) {
|
TEST_CASE_METHOD(ManyGroups, "BetweenOneAndTwoGroups", "[optiongroup]") {
|
||||||
// only 1 group can be used
|
// only 1 group can be used
|
||||||
main->require_option(1, 2);
|
main->require_option(1, 2);
|
||||||
args = {"--name1", "test", "--name2", "test3"};
|
args = {"--name1", "test", "--name2", "test3"};
|
||||||
@ -543,19 +539,19 @@ TEST_F(ManyGroups, BetweenOneAndTwoGroups) {
|
|||||||
run();
|
run();
|
||||||
|
|
||||||
args = {};
|
args = {};
|
||||||
EXPECT_THROW(run(), CLI::RequiredError);
|
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||||
|
|
||||||
args = {"--name1", "test", "--name2", "test3", "--name3=test3"};
|
args = {"--name1", "test", "--name2", "test3", "--name3=test3"};
|
||||||
EXPECT_THROW(run(), CLI::RequiredError);
|
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ManyGroups, RequiredFirst) {
|
TEST_CASE_METHOD(ManyGroups, "RequiredFirst", "[optiongroup]") {
|
||||||
// only 1 group can be used
|
// only 1 group can be used
|
||||||
remove_required();
|
remove_required();
|
||||||
g1->required();
|
g1->required();
|
||||||
|
|
||||||
EXPECT_TRUE(g1->get_required());
|
CHECK(g1->get_required());
|
||||||
EXPECT_FALSE(g2->get_required());
|
CHECK(!g2->get_required());
|
||||||
args = {"--name1", "test", "--name2", "test3"};
|
args = {"--name1", "test", "--name2", "test3"};
|
||||||
run();
|
run();
|
||||||
|
|
||||||
@ -563,32 +559,32 @@ TEST_F(ManyGroups, RequiredFirst) {
|
|||||||
try {
|
try {
|
||||||
run();
|
run();
|
||||||
} catch(const CLI::RequiredError &re) {
|
} catch(const CLI::RequiredError &re) {
|
||||||
EXPECT_THAT(re.what(), HasSubstr("g1"));
|
CHECK_THAT(re.what(), Contains("g1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
args = {"--name1", "test", "--name2", "test3", "--name3=test3"};
|
args = {"--name1", "test", "--name2", "test3", "--name3=test3"};
|
||||||
EXPECT_NO_THROW(run());
|
CHECK_NOTHROW(run());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ManyGroups, DisableFirst) {
|
TEST_CASE_METHOD(ManyGroups, "DisableFirst", "[optiongroup]") {
|
||||||
// only 1 group can be used if remove_required not used
|
// only 1 group can be used if remove_required not used
|
||||||
remove_required();
|
remove_required();
|
||||||
g1->disabled();
|
g1->disabled();
|
||||||
|
|
||||||
EXPECT_TRUE(g1->get_disabled());
|
CHECK(g1->get_disabled());
|
||||||
EXPECT_FALSE(g2->get_disabled());
|
CHECK(!g2->get_disabled());
|
||||||
args = {"--name2", "test"};
|
args = {"--name2", "test"};
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
|
||||||
args = {"--name1", "test", "--name2", "test3"};
|
args = {"--name1", "test", "--name2", "test3"};
|
||||||
EXPECT_THROW(run(), CLI::ExtrasError);
|
CHECK_THROWS_AS(run(), CLI::ExtrasError);
|
||||||
g1->disabled(false);
|
g1->disabled(false);
|
||||||
args = {"--name1", "test", "--name2", "test3", "--name3=test3"};
|
args = {"--name1", "test", "--name2", "test3", "--name3=test3"};
|
||||||
EXPECT_NO_THROW(run());
|
CHECK_NOTHROW(run());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ManyGroups, SameSubcommand) {
|
TEST_CASE_METHOD(ManyGroups, "SameSubcommand", "[optiongroup]") {
|
||||||
// only 1 group can be used if remove_required not used
|
// only 1 group can be used if remove_required not used
|
||||||
remove_required();
|
remove_required();
|
||||||
auto sub1 = g1->add_subcommand("sub1")->disabled();
|
auto sub1 = g1->add_subcommand("sub1")->disabled();
|
||||||
@ -602,30 +598,30 @@ TEST_F(ManyGroups, SameSubcommand) {
|
|||||||
|
|
||||||
run();
|
run();
|
||||||
|
|
||||||
EXPECT_TRUE(*sub1);
|
CHECK(*sub1);
|
||||||
EXPECT_TRUE(*sub2);
|
CHECK(*sub2);
|
||||||
EXPECT_TRUE(*sub3);
|
CHECK(*sub3);
|
||||||
auto subs = app.get_subcommands();
|
auto subs = app.get_subcommands();
|
||||||
EXPECT_EQ(subs.size(), 3u);
|
CHECK(3u == subs.size());
|
||||||
EXPECT_EQ(subs[0], sub1);
|
CHECK(sub1 == subs[0]);
|
||||||
EXPECT_EQ(subs[1], sub2);
|
CHECK(sub2 == subs[1]);
|
||||||
EXPECT_EQ(subs[2], sub3);
|
CHECK(sub3 == subs[2]);
|
||||||
|
|
||||||
args = {"sub1", "sub1", "sub1", "sub1"};
|
args = {"sub1", "sub1", "sub1", "sub1"};
|
||||||
// for the 4th and future ones they will route to the first one
|
// for the 4th and future ones they will route to the first one
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(sub1->count(), 2u);
|
CHECK(2u == sub1->count());
|
||||||
EXPECT_EQ(sub2->count(), 1u);
|
CHECK(1u == sub2->count());
|
||||||
EXPECT_EQ(sub3->count(), 1u);
|
CHECK(1u == sub3->count());
|
||||||
|
|
||||||
// subs should remain the same since the duplicate would not be registered there
|
// subs should remain the same since the duplicate would not be registered there
|
||||||
subs = app.get_subcommands();
|
subs = app.get_subcommands();
|
||||||
EXPECT_EQ(subs.size(), 3u);
|
CHECK(3u == subs.size());
|
||||||
EXPECT_EQ(subs[0], sub1);
|
CHECK(sub1 == subs[0]);
|
||||||
EXPECT_EQ(subs[1], sub2);
|
CHECK(sub2 == subs[1]);
|
||||||
EXPECT_EQ(subs[2], sub3);
|
CHECK(sub3 == subs[2]);
|
||||||
}
|
}
|
||||||
TEST_F(ManyGroups, CallbackOrder) {
|
TEST_CASE_METHOD(ManyGroups, "CallbackOrder", "[optiongroup]") {
|
||||||
// only 1 group can be used if remove_required not used
|
// only 1 group can be used if remove_required not used
|
||||||
remove_required();
|
remove_required();
|
||||||
std::vector<int> callback_order;
|
std::vector<int> callback_order;
|
||||||
@ -635,61 +631,61 @@ TEST_F(ManyGroups, CallbackOrder) {
|
|||||||
|
|
||||||
args = {"--name2", "test"};
|
args = {"--name2", "test"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(callback_order, std::vector<int>({2, 3}));
|
CHECK(std::vector<int>({2, 3}) == callback_order);
|
||||||
|
|
||||||
callback_order.clear();
|
callback_order.clear();
|
||||||
args = {"--name1", "t2", "--name2", "test"};
|
args = {"--name1", "t2", "--name2", "test"};
|
||||||
g2->immediate_callback();
|
g2->immediate_callback();
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(callback_order, std::vector<int>({2, 1, 3}));
|
CHECK(std::vector<int>({2, 1, 3}) == callback_order);
|
||||||
callback_order.clear();
|
callback_order.clear();
|
||||||
|
|
||||||
args = {"--name2", "test", "--name1", "t2"};
|
args = {"--name2", "test", "--name1", "t2"};
|
||||||
g2->immediate_callback(false);
|
g2->immediate_callback(false);
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(callback_order, std::vector<int>({1, 2, 3}));
|
CHECK(std::vector<int>({1, 2, 3}) == callback_order);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test the fallthrough for extra arguments
|
// Test the fallthrough for extra arguments
|
||||||
TEST_F(ManyGroups, ExtrasFallDown) {
|
TEST_CASE_METHOD(ManyGroups, "ExtrasFallDown", "[optiongroup]") {
|
||||||
// only 1 group can be used if remove_required not used
|
// only 1 group can be used if remove_required not used
|
||||||
remove_required();
|
remove_required();
|
||||||
|
|
||||||
args = {"--test1", "--flag", "extra"};
|
args = {"--test1", "--flag", "extra"};
|
||||||
EXPECT_THROW(run(), CLI::ExtrasError);
|
CHECK_THROWS_AS(run(), CLI::ExtrasError);
|
||||||
main->allow_extras();
|
main->allow_extras();
|
||||||
EXPECT_NO_THROW(run());
|
CHECK_NOTHROW(run());
|
||||||
|
|
||||||
EXPECT_EQ(app.remaining_size(true), 3u);
|
CHECK(3u == app.remaining_size(true));
|
||||||
EXPECT_EQ(main->remaining_size(), 3u);
|
CHECK(3u == main->remaining_size());
|
||||||
|
|
||||||
std::vector<std::string> extras{"--test1", "--flag", "extra"};
|
std::vector<std::string> extras{"--test1", "--flag", "extra"};
|
||||||
EXPECT_EQ(app.remaining(true), extras);
|
CHECK(extras == app.remaining(true));
|
||||||
EXPECT_EQ(main->remaining(), extras);
|
CHECK(extras == main->remaining());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test the option Inheritance
|
// Test the option Inheritance
|
||||||
TEST_F(ManyGroups, Inheritance) {
|
TEST_CASE_METHOD(ManyGroups, "Inheritance", "[optiongroup]") {
|
||||||
remove_required();
|
remove_required();
|
||||||
g1->ignore_case();
|
g1->ignore_case();
|
||||||
g1->ignore_underscore();
|
g1->ignore_underscore();
|
||||||
auto t2 = g1->add_subcommand("t2");
|
auto t2 = g1->add_subcommand("t2");
|
||||||
args = {"T2", "t_2"};
|
args = {"T2", "t_2"};
|
||||||
EXPECT_TRUE(t2->get_ignore_underscore());
|
CHECK(t2->get_ignore_underscore());
|
||||||
EXPECT_TRUE(t2->get_ignore_case());
|
CHECK(t2->get_ignore_case());
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(t2->count(), 2u);
|
CHECK(2u == t2->count());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ManyGroups, Moving) {
|
TEST_CASE_METHOD(ManyGroups, "Moving", "[optiongroup]") {
|
||||||
remove_required();
|
remove_required();
|
||||||
auto mg = app.add_option_group("maing");
|
auto mg = app.add_option_group("maing");
|
||||||
mg->add_subcommand(g1);
|
mg->add_subcommand(g1);
|
||||||
mg->add_subcommand(g2);
|
mg->add_subcommand(g2);
|
||||||
|
|
||||||
EXPECT_EQ(g1->get_parent(), mg);
|
CHECK(mg == g1->get_parent());
|
||||||
EXPECT_EQ(g2->get_parent(), mg);
|
CHECK(mg == g2->get_parent());
|
||||||
EXPECT_EQ(g3->get_parent(), main);
|
CHECK(main == g3->get_parent());
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ManyGroupsPreTrigger : public ManyGroups {
|
struct ManyGroupsPreTrigger : public ManyGroups {
|
||||||
@ -704,35 +700,35 @@ struct ManyGroupsPreTrigger : public ManyGroups {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(ManyGroupsPreTrigger, PreTriggerTestsOptions) {
|
TEST_CASE_METHOD(ManyGroupsPreTrigger, "PreTriggerTestsOptions", "[optiongroup]") {
|
||||||
|
|
||||||
args = {"--name1", "test", "--name2", "test3"};
|
args = {"--name1", "test", "--name2", "test3"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(triggerMain, 4u);
|
CHECK(4u == triggerMain);
|
||||||
EXPECT_EQ(trigger1, 2u);
|
CHECK(2u == trigger1);
|
||||||
EXPECT_EQ(trigger2, 0u);
|
CHECK(0u == trigger2);
|
||||||
EXPECT_EQ(trigger3, 27u);
|
CHECK(27u == trigger3);
|
||||||
|
|
||||||
args = {"--name1", "test"};
|
args = {"--name1", "test"};
|
||||||
trigger2 = 34u;
|
trigger2 = 34u;
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(triggerMain, 2u);
|
CHECK(2u == triggerMain);
|
||||||
EXPECT_EQ(trigger1, 0u);
|
CHECK(0u == trigger1);
|
||||||
EXPECT_EQ(trigger2, 34u);
|
CHECK(34u == trigger2);
|
||||||
|
|
||||||
args = {};
|
args = {};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(triggerMain, 0u);
|
CHECK(0u == triggerMain);
|
||||||
|
|
||||||
args = {"--name1", "test", "--val1", "45", "--name2", "test3", "--name3=test3", "--val2=37"};
|
args = {"--name1", "test", "--val1", "45", "--name2", "test3", "--name3=test3", "--val2=37"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(triggerMain, 8u);
|
CHECK(8u == triggerMain);
|
||||||
EXPECT_EQ(trigger1, 6u);
|
CHECK(6u == trigger1);
|
||||||
EXPECT_EQ(trigger2, 2u);
|
CHECK(2u == trigger2);
|
||||||
EXPECT_EQ(trigger3, 1u);
|
CHECK(1u == trigger3);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ManyGroupsPreTrigger, PreTriggerTestsPositionals) {
|
TEST_CASE_METHOD(ManyGroupsPreTrigger, "PreTriggerTestsPositionals", "[optiongroup]") {
|
||||||
// only 1 group can be used
|
// only 1 group can be used
|
||||||
g1->add_option("pos1");
|
g1->add_option("pos1");
|
||||||
g2->add_option("pos2");
|
g2->add_option("pos2");
|
||||||
@ -740,26 +736,26 @@ TEST_F(ManyGroupsPreTrigger, PreTriggerTestsPositionals) {
|
|||||||
|
|
||||||
args = {"pos1"};
|
args = {"pos1"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(triggerMain, 1u);
|
CHECK(1u == triggerMain);
|
||||||
EXPECT_EQ(trigger1, 0u);
|
CHECK(0u == trigger1);
|
||||||
EXPECT_EQ(trigger2, 34u);
|
CHECK(34u == trigger2);
|
||||||
EXPECT_EQ(trigger3, 27u);
|
CHECK(27u == trigger3);
|
||||||
|
|
||||||
args = {"pos1", "pos2"};
|
args = {"pos1", "pos2"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(triggerMain, 2u);
|
CHECK(2u == triggerMain);
|
||||||
EXPECT_EQ(trigger1, 1u);
|
CHECK(1u == trigger1);
|
||||||
EXPECT_EQ(trigger2, 0u);
|
CHECK(0u == trigger2);
|
||||||
|
|
||||||
args = {"pos1", "pos2", "pos3"};
|
args = {"pos1", "pos2", "pos3"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(triggerMain, 3u);
|
CHECK(3u == triggerMain);
|
||||||
EXPECT_EQ(trigger1, 2u);
|
CHECK(2u == trigger1);
|
||||||
EXPECT_EQ(trigger2, 1u);
|
CHECK(1u == trigger2);
|
||||||
EXPECT_EQ(trigger3, 0u);
|
CHECK(0u == trigger3);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ManyGroupsPreTrigger, PreTriggerTestsSubcommand) {
|
TEST_CASE_METHOD(ManyGroupsPreTrigger, "PreTriggerTestsSubcommand", "[optiongroup]") {
|
||||||
|
|
||||||
auto sub1 = g1->add_subcommand("sub1")->fallthrough();
|
auto sub1 = g1->add_subcommand("sub1")->fallthrough();
|
||||||
g2->add_subcommand("sub2")->fallthrough();
|
g2->add_subcommand("sub2")->fallthrough();
|
||||||
@ -769,23 +765,23 @@ TEST_F(ManyGroupsPreTrigger, PreTriggerTestsSubcommand) {
|
|||||||
sub1->preparse_callback([&subtrigger](std::size_t count) { subtrigger = count; });
|
sub1->preparse_callback([&subtrigger](std::size_t count) { subtrigger = count; });
|
||||||
args = {"sub1"};
|
args = {"sub1"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(triggerMain, 1u);
|
CHECK(1u == triggerMain);
|
||||||
EXPECT_EQ(trigger1, 0u);
|
CHECK(0u == trigger1);
|
||||||
EXPECT_EQ(trigger2, 34u);
|
CHECK(34u == trigger2);
|
||||||
EXPECT_EQ(trigger3, 27u);
|
CHECK(27u == trigger3);
|
||||||
|
|
||||||
args = {"sub1", "sub2"};
|
args = {"sub1", "sub2"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(triggerMain, 2u);
|
CHECK(2u == triggerMain);
|
||||||
EXPECT_EQ(subtrigger, 1u);
|
CHECK(1u == subtrigger);
|
||||||
EXPECT_EQ(trigger1, 1u);
|
CHECK(1u == trigger1);
|
||||||
EXPECT_EQ(trigger2, 0u);
|
CHECK(0u == trigger2);
|
||||||
|
|
||||||
args = {"sub2", "sub3", "--name1=test", "sub1"};
|
args = {"sub2", "sub3", "--name1=test", "sub1"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(triggerMain, 4u);
|
CHECK(4u == triggerMain);
|
||||||
EXPECT_EQ(trigger1, 1u);
|
CHECK(1u == trigger1);
|
||||||
EXPECT_EQ(trigger2, 3u);
|
CHECK(3u == trigger2);
|
||||||
EXPECT_EQ(trigger3, 1u); // processes the first argument in group3 which includes the entire subcommand, which will
|
CHECK(1u == trigger3);
|
||||||
// go until the sub1 command is given
|
// go until the sub1 command is given
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -62,70 +62,70 @@
|
|||||||
#pragma warning(disable : 4244)
|
#pragma warning(disable : 4244)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TEST_F(TApp, StdOptionalTest) {
|
TEST_CASE_METHOD(TApp, "StdOptionalTest", "[optional]") {
|
||||||
std::optional<int> opt;
|
std::optional<int> opt;
|
||||||
app.add_option("-c,--count", opt);
|
app.add_option("-c,--count", opt);
|
||||||
run();
|
run();
|
||||||
EXPECT_FALSE(opt);
|
CHECK(!opt);
|
||||||
|
|
||||||
args = {"-c", "1"};
|
args = {"-c", "1"};
|
||||||
run();
|
run();
|
||||||
EXPECT_TRUE(opt);
|
CHECK(opt);
|
||||||
EXPECT_EQ(*opt, 1);
|
CHECK(1 == *opt);
|
||||||
|
|
||||||
args = {"--count", "3"};
|
args = {"--count", "3"};
|
||||||
run();
|
run();
|
||||||
EXPECT_TRUE(opt);
|
CHECK(opt);
|
||||||
EXPECT_EQ(*opt, 3);
|
CHECK(3 == *opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, StdOptionalVectorEmptyDirect) {
|
TEST_CASE_METHOD(TApp, "StdOptionalVectorEmptyDirect", "[optional]") {
|
||||||
std::optional<std::vector<int>> opt;
|
std::optional<std::vector<int>> opt;
|
||||||
app.add_option("-v,--vec", opt)->expected(0, 3)->allow_extra_args();
|
app.add_option("-v,--vec", opt)->expected(0, 3)->allow_extra_args();
|
||||||
// app.add_option("-v,--vec", opt)->expected(0, 3)->allow_extra_args();
|
// app.add_option("-v,--vec", opt)->expected(0, 3)->allow_extra_args();
|
||||||
run();
|
run();
|
||||||
EXPECT_FALSE(opt);
|
CHECK(!opt);
|
||||||
args = {"-v"};
|
args = {"-v"};
|
||||||
opt = std::vector<int>{4, 3};
|
opt = std::vector<int>{4, 3};
|
||||||
run();
|
run();
|
||||||
EXPECT_FALSE(opt);
|
CHECK(!opt);
|
||||||
args = {"-v", "1", "4", "5"};
|
args = {"-v", "1", "4", "5"};
|
||||||
run();
|
run();
|
||||||
EXPECT_TRUE(opt);
|
CHECK(opt);
|
||||||
std::vector<int> expV{1, 4, 5};
|
std::vector<int> expV{1, 4, 5};
|
||||||
EXPECT_EQ(*opt, expV);
|
CHECK(expV == *opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, StdOptionalComplexDirect) {
|
TEST_CASE_METHOD(TApp, "StdOptionalComplexDirect", "[optional]") {
|
||||||
std::optional<std::complex<double>> opt;
|
std::optional<std::complex<double>> opt;
|
||||||
app.add_option("-c,--complex", opt)->type_size(0, 2);
|
app.add_option("-c,--complex", opt)->type_size(0, 2);
|
||||||
run();
|
run();
|
||||||
EXPECT_FALSE(opt);
|
CHECK(!opt);
|
||||||
args = {"-c"};
|
args = {"-c"};
|
||||||
opt = std::complex<double>{4.0, 3.0};
|
opt = std::complex<double>{4.0, 3.0};
|
||||||
run();
|
run();
|
||||||
EXPECT_FALSE(opt);
|
CHECK(!opt);
|
||||||
args = {"-c", "1+2j"};
|
args = {"-c", "1+2j"};
|
||||||
run();
|
run();
|
||||||
EXPECT_TRUE(opt);
|
CHECK(opt);
|
||||||
std::complex<double> val{1, 2};
|
std::complex<double> val{1, 2};
|
||||||
EXPECT_EQ(*opt, val);
|
CHECK(val == *opt);
|
||||||
args = {"-c", "3", "-4"};
|
args = {"-c", "3", "-4"};
|
||||||
run();
|
run();
|
||||||
EXPECT_TRUE(opt);
|
CHECK(opt);
|
||||||
std::complex<double> val2{3, -4};
|
std::complex<double> val2{3, -4};
|
||||||
EXPECT_EQ(*opt, val2);
|
CHECK(val2 == *opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, StdOptionalUint) {
|
TEST_CASE_METHOD(TApp, "StdOptionalUint", "[optional]") {
|
||||||
std::optional<std::uint64_t> opt;
|
std::optional<std::uint64_t> opt;
|
||||||
app.add_option("-i,--int", opt);
|
app.add_option("-i,--int", opt);
|
||||||
run();
|
run();
|
||||||
EXPECT_FALSE(opt);
|
CHECK(!opt);
|
||||||
|
|
||||||
args = {"-i", "15"};
|
args = {"-i", "15"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(*opt, 15U);
|
CHECK(15U == *opt);
|
||||||
static_assert(CLI::detail::classify_object<std::optional<std::uint64_t>>::value ==
|
static_assert(CLI::detail::classify_object<std::optional<std::uint64_t>>::value ==
|
||||||
CLI::detail::object_category::wrapper_value);
|
CLI::detail::object_category::wrapper_value);
|
||||||
}
|
}
|
||||||
@ -137,97 +137,97 @@ TEST_F(TApp, StdOptionalUint) {
|
|||||||
#endif
|
#endif
|
||||||
#if CLI11_EXPERIMENTAL_OPTIONAL
|
#if CLI11_EXPERIMENTAL_OPTIONAL
|
||||||
|
|
||||||
TEST_F(TApp, ExperimentalOptionalTest) {
|
TEST_CASE_METHOD(TApp, "ExperimentalOptionalTest", "[optional]") {
|
||||||
std::experimental::optional<int> opt;
|
std::experimental::optional<int> opt;
|
||||||
app.add_option("-c,--count", opt);
|
app.add_option("-c,--count", opt);
|
||||||
run();
|
run();
|
||||||
EXPECT_FALSE(opt);
|
CHECK(!opt);
|
||||||
|
|
||||||
args = {"-c", "1"};
|
args = {"-c", "1"};
|
||||||
run();
|
run();
|
||||||
EXPECT_TRUE(opt);
|
CHECK(opt);
|
||||||
EXPECT_EQ(*opt, 1);
|
CHECK(1 == *opt);
|
||||||
|
|
||||||
args = {"--count", "3"};
|
args = {"--count", "3"};
|
||||||
run();
|
run();
|
||||||
EXPECT_TRUE(opt);
|
CHECK(opt);
|
||||||
EXPECT_EQ(*opt, 3);
|
CHECK(3 == *opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#if CLI11_BOOST_OPTIONAL
|
#if CLI11_BOOST_OPTIONAL
|
||||||
|
|
||||||
TEST_F(TApp, BoostOptionalTest) {
|
TEST_CASE_METHOD(TApp, "BoostOptionalTest", "[optional]") {
|
||||||
boost::optional<int> opt;
|
boost::optional<int> opt;
|
||||||
app.add_option("-c,--count", opt);
|
app.add_option("-c,--count", opt);
|
||||||
run();
|
run();
|
||||||
EXPECT_FALSE(opt);
|
CHECK(!opt);
|
||||||
|
|
||||||
args = {"-c", "1"};
|
args = {"-c", "1"};
|
||||||
run();
|
run();
|
||||||
EXPECT_TRUE(opt);
|
CHECK(opt);
|
||||||
EXPECT_EQ(*opt, 1);
|
CHECK(1 == *opt);
|
||||||
opt = {};
|
opt = {};
|
||||||
args = {"--count", "3"};
|
args = {"--count", "3"};
|
||||||
run();
|
run();
|
||||||
EXPECT_TRUE(opt);
|
CHECK(opt);
|
||||||
EXPECT_EQ(*opt, 3);
|
CHECK(3 == *opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, BoostOptionalTestZarg) {
|
TEST_CASE_METHOD(TApp, "BoostOptionalTestZarg", "[optional]") {
|
||||||
boost::optional<int> opt;
|
boost::optional<int> opt;
|
||||||
app.add_option("-c,--count", opt)->expected(0, 1);
|
app.add_option("-c,--count", opt)->expected(0, 1);
|
||||||
run();
|
run();
|
||||||
EXPECT_FALSE(opt);
|
CHECK(!opt);
|
||||||
|
|
||||||
args = {"-c", "1"};
|
args = {"-c", "1"};
|
||||||
run();
|
run();
|
||||||
EXPECT_TRUE(opt);
|
CHECK(opt);
|
||||||
EXPECT_EQ(*opt, 1);
|
CHECK(1 == *opt);
|
||||||
opt = {};
|
opt = {};
|
||||||
args = {"--count"};
|
args = {"--count"};
|
||||||
run();
|
run();
|
||||||
EXPECT_FALSE(opt);
|
CHECK(!opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, BoostOptionalint64Test) {
|
TEST_CASE_METHOD(TApp, "BoostOptionalint64Test", "[optional]") {
|
||||||
boost::optional<std::int64_t> opt;
|
boost::optional<std::int64_t> opt;
|
||||||
app.add_option("-c,--count", opt);
|
app.add_option("-c,--count", opt);
|
||||||
run();
|
run();
|
||||||
EXPECT_FALSE(opt);
|
CHECK(!opt);
|
||||||
|
|
||||||
args = {"-c", "1"};
|
args = {"-c", "1"};
|
||||||
run();
|
run();
|
||||||
EXPECT_TRUE(opt);
|
CHECK(opt);
|
||||||
EXPECT_EQ(*opt, 1);
|
CHECK(1 == *opt);
|
||||||
opt = {};
|
opt = {};
|
||||||
args = {"--count", "3"};
|
args = {"--count", "3"};
|
||||||
run();
|
run();
|
||||||
EXPECT_TRUE(opt);
|
CHECK(opt);
|
||||||
EXPECT_EQ(*opt, 3);
|
CHECK(3 == *opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, BoostOptionalStringTest) {
|
TEST_CASE_METHOD(TApp, "BoostOptionalStringTest", "[optional]") {
|
||||||
boost::optional<std::string> opt;
|
boost::optional<std::string> opt;
|
||||||
app.add_option("-s,--string", opt);
|
app.add_option("-s,--string", opt);
|
||||||
run();
|
run();
|
||||||
EXPECT_FALSE(opt);
|
CHECK(!opt);
|
||||||
|
|
||||||
args = {"-s", "strval"};
|
args = {"-s", "strval"};
|
||||||
run();
|
run();
|
||||||
EXPECT_TRUE(opt);
|
CHECK(opt);
|
||||||
EXPECT_EQ(*opt, "strval");
|
CHECK("strval" == *opt);
|
||||||
opt = {};
|
opt = {};
|
||||||
args = {"--string", "strv"};
|
args = {"--string", "strv"};
|
||||||
run();
|
run();
|
||||||
EXPECT_TRUE(opt);
|
CHECK(opt);
|
||||||
EXPECT_EQ(*opt, "strv");
|
CHECK("strv" == *opt);
|
||||||
}
|
}
|
||||||
namespace boost {
|
namespace boost {
|
||||||
using CLI::enums::operator<<;
|
using CLI::enums::operator<<;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, BoostOptionalEnumTest) {
|
TEST_CASE_METHOD(TApp, "BoostOptionalEnumTest", "[optional]") {
|
||||||
|
|
||||||
enum class eval : char { val0 = 0, val1 = 1, val2 = 2, val3 = 3, val4 = 4 };
|
enum class eval : char { val0 = 0, val1 = 1, val2 = 2, val3 = 3, val4 = 4 };
|
||||||
boost::optional<eval> opt, opt2;
|
boost::optional<eval> opt, opt2;
|
||||||
@ -237,93 +237,89 @@ TEST_F(TApp, BoostOptionalEnumTest) {
|
|||||||
optptr->capture_default_str();
|
optptr->capture_default_str();
|
||||||
|
|
||||||
auto dstring = optptr->get_default_str();
|
auto dstring = optptr->get_default_str();
|
||||||
EXPECT_TRUE(dstring.empty());
|
CHECK(dstring.empty());
|
||||||
run();
|
run();
|
||||||
EXPECT_FALSE(opt);
|
CHECK(!opt);
|
||||||
|
|
||||||
args = {"-v", "3"};
|
args = {"-v", "3"};
|
||||||
run();
|
run();
|
||||||
EXPECT_TRUE(opt);
|
CHECK(opt);
|
||||||
EXPECT_TRUE(*opt == eval::val3);
|
CHECK(*opt == eval::val3);
|
||||||
opt = {};
|
opt = {};
|
||||||
args = {"--val", "1"};
|
args = {"--val", "1"};
|
||||||
run();
|
run();
|
||||||
EXPECT_TRUE(opt);
|
CHECK(opt);
|
||||||
EXPECT_TRUE(*opt == eval::val1);
|
CHECK(*opt == eval::val1);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, BoostOptionalVector) {
|
TEST_CASE_METHOD(TApp, "BoostOptionalVector", "[optional]") {
|
||||||
boost::optional<std::vector<int>> opt;
|
boost::optional<std::vector<int>> opt;
|
||||||
app.add_option_function<std::vector<int>>(
|
app.add_option_function<std::vector<int>>(
|
||||||
"-v,--vec", [&opt](const std::vector<int> &v) { opt = v; }, "some vector")
|
"-v,--vec", [&opt](const std::vector<int> &v) { opt = v; }, "some vector")
|
||||||
->expected(3);
|
->expected(3);
|
||||||
run();
|
run();
|
||||||
EXPECT_FALSE(opt);
|
CHECK(!opt);
|
||||||
|
|
||||||
args = {"-v", "1", "4", "5"};
|
args = {"-v", "1", "4", "5"};
|
||||||
run();
|
run();
|
||||||
EXPECT_TRUE(opt);
|
CHECK(opt);
|
||||||
std::vector<int> expV{1, 4, 5};
|
std::vector<int> expV{1, 4, 5};
|
||||||
EXPECT_EQ(*opt, expV);
|
CHECK(expV == *opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, BoostOptionalVectorEmpty) {
|
TEST_CASE_METHOD(TApp, "BoostOptionalVectorEmpty", "[optional]") {
|
||||||
boost::optional<std::vector<int>> opt;
|
boost::optional<std::vector<int>> opt;
|
||||||
app.add_option<decltype(opt), std::vector<int>>("-v,--vec", opt)->expected(0, 3)->allow_extra_args();
|
app.add_option<decltype(opt), std::vector<int>>("-v,--vec", opt)->expected(0, 3)->allow_extra_args();
|
||||||
// app.add_option("-v,--vec", opt)->expected(0, 3)->allow_extra_args();
|
// app.add_option("-v,--vec", opt)->expected(0, 3)->allow_extra_args();
|
||||||
run();
|
run();
|
||||||
EXPECT_FALSE(opt);
|
CHECK(!opt);
|
||||||
args = {"-v"};
|
args = {"-v"};
|
||||||
opt = std::vector<int>{4, 3};
|
opt = std::vector<int>{4, 3};
|
||||||
run();
|
run();
|
||||||
EXPECT_FALSE(opt);
|
CHECK(!opt);
|
||||||
args = {"-v", "1", "4", "5"};
|
args = {"-v", "1", "4", "5"};
|
||||||
run();
|
run();
|
||||||
EXPECT_TRUE(opt);
|
CHECK(opt);
|
||||||
std::vector<int> expV{1, 4, 5};
|
std::vector<int> expV{1, 4, 5};
|
||||||
EXPECT_EQ(*opt, expV);
|
CHECK(expV == *opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, BoostOptionalVectorEmptyDirect) {
|
TEST_CASE_METHOD(TApp, "BoostOptionalVectorEmptyDirect", "[optional]") {
|
||||||
boost::optional<std::vector<int>> opt;
|
boost::optional<std::vector<int>> opt;
|
||||||
app.add_option_no_stream("-v,--vec", opt)->expected(0, 3)->allow_extra_args();
|
app.add_option_no_stream("-v,--vec", opt)->expected(0, 3)->allow_extra_args();
|
||||||
// app.add_option("-v,--vec", opt)->expected(0, 3)->allow_extra_args();
|
// app.add_option("-v,--vec", opt)->expected(0, 3)->allow_extra_args();
|
||||||
run();
|
run();
|
||||||
EXPECT_FALSE(opt);
|
CHECK(!opt);
|
||||||
args = {"-v"};
|
args = {"-v"};
|
||||||
opt = std::vector<int>{4, 3};
|
opt = std::vector<int>{4, 3};
|
||||||
run();
|
run();
|
||||||
EXPECT_FALSE(opt);
|
CHECK(!opt);
|
||||||
args = {"-v", "1", "4", "5"};
|
args = {"-v", "1", "4", "5"};
|
||||||
run();
|
run();
|
||||||
EXPECT_TRUE(opt);
|
CHECK(opt);
|
||||||
std::vector<int> expV{1, 4, 5};
|
std::vector<int> expV{1, 4, 5};
|
||||||
EXPECT_EQ(*opt, expV);
|
CHECK(expV == *opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, BoostOptionalComplexDirect) {
|
TEST_CASE_METHOD(TApp, "BoostOptionalComplexDirect", "[optional]") {
|
||||||
boost::optional<std::complex<double>> opt;
|
boost::optional<std::complex<double>> opt;
|
||||||
app.add_option("-c,--complex", opt)->type_size(0, 2);
|
app.add_option("-c,--complex", opt)->type_size(0, 2);
|
||||||
run();
|
run();
|
||||||
EXPECT_FALSE(opt);
|
CHECK(!opt);
|
||||||
args = {"-c"};
|
args = {"-c"};
|
||||||
opt = std::complex<double>{4.0, 3.0};
|
opt = std::complex<double>{4.0, 3.0};
|
||||||
run();
|
run();
|
||||||
EXPECT_FALSE(opt);
|
CHECK(!opt);
|
||||||
args = {"-c", "1+2j"};
|
args = {"-c", "1+2j"};
|
||||||
run();
|
run();
|
||||||
EXPECT_TRUE(opt);
|
CHECK(opt);
|
||||||
std::complex<double> val{1, 2};
|
std::complex<double> val{1, 2};
|
||||||
EXPECT_EQ(*opt, val);
|
CHECK(val == *opt);
|
||||||
args = {"-c", "3", "-4"};
|
args = {"-c", "3", "-4"};
|
||||||
run();
|
run();
|
||||||
EXPECT_TRUE(opt);
|
CHECK(opt);
|
||||||
std::complex<double> val2{3, -4};
|
std::complex<double> val2{3, -4};
|
||||||
EXPECT_EQ(*opt, val2);
|
CHECK(val2 == *opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !CLI11_OPTIONAL
|
|
||||||
TEST_F(TApp, DISABLED_OptionalTest) {}
|
|
||||||
#endif
|
|
||||||
|
@ -31,79 +31,79 @@ static_assert(CLI::detail::pair_adaptor<std::vector<std::string>>::value == fals
|
|||||||
static_assert(CLI::detail::pair_adaptor<std::map<int, int>>::value == true, "Should have pairs");
|
static_assert(CLI::detail::pair_adaptor<std::map<int, int>>::value == true, "Should have pairs");
|
||||||
static_assert(CLI::detail::pair_adaptor<std::vector<std::pair<int, int>>>::value == true, "Should have pairs");
|
static_assert(CLI::detail::pair_adaptor<std::vector<std::pair<int, int>>>::value == true, "Should have pairs");
|
||||||
|
|
||||||
TEST_F(TApp, SimpleMaps) {
|
TEST_CASE_METHOD(TApp, "SimpleMaps", "[set]") {
|
||||||
int value{0};
|
int value{0};
|
||||||
std::map<std::string, int> map = {{"one", 1}, {"two", 2}};
|
std::map<std::string, int> map = {{"one", 1}, {"two", 2}};
|
||||||
auto opt = app.add_option("-s,--set", value)->transform(CLI::Transformer(map));
|
auto opt = app.add_option("-s,--set", value)->transform(CLI::Transformer(map));
|
||||||
args = {"-s", "one"};
|
args = {"-s", "one"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(1u, app.count("-s"));
|
CHECK(app.count("-s") == 1u);
|
||||||
EXPECT_EQ(1u, app.count("--set"));
|
CHECK(app.count("--set") == 1u);
|
||||||
EXPECT_EQ(1u, opt->count());
|
CHECK(opt->count() == 1u);
|
||||||
EXPECT_EQ(value, 1);
|
CHECK(1 == value);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, StringStringMap) {
|
TEST_CASE_METHOD(TApp, "StringStringMap", "[set]") {
|
||||||
std::string value;
|
std::string value;
|
||||||
std::map<std::string, std::string> map = {{"a", "b"}, {"b", "c"}};
|
std::map<std::string, std::string> map = {{"a", "b"}, {"b", "c"}};
|
||||||
app.add_option("-s,--set", value)->transform(CLI::CheckedTransformer(map));
|
app.add_option("-s,--set", value)->transform(CLI::CheckedTransformer(map));
|
||||||
args = {"-s", "a"};
|
args = {"-s", "a"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(value, "b");
|
CHECK("b" == value);
|
||||||
|
|
||||||
args = {"-s", "b"};
|
args = {"-s", "b"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(value, "c");
|
CHECK("c" == value);
|
||||||
|
|
||||||
args = {"-s", "c"};
|
args = {"-s", "c"};
|
||||||
EXPECT_EQ(value, "c");
|
CHECK("c" == value);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, StringStringMapNoModify) {
|
TEST_CASE_METHOD(TApp, "StringStringMapNoModify", "[set]") {
|
||||||
std::string value;
|
std::string value;
|
||||||
std::map<std::string, std::string> map = {{"a", "b"}, {"b", "c"}};
|
std::map<std::string, std::string> map = {{"a", "b"}, {"b", "c"}};
|
||||||
app.add_option("-s,--set", value)->check(CLI::IsMember(map));
|
app.add_option("-s,--set", value)->check(CLI::IsMember(map));
|
||||||
args = {"-s", "a"};
|
args = {"-s", "a"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(value, "a");
|
CHECK("a" == value);
|
||||||
|
|
||||||
args = {"-s", "b"};
|
args = {"-s", "b"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(value, "b");
|
CHECK("b" == value);
|
||||||
|
|
||||||
args = {"-s", "c"};
|
args = {"-s", "c"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum SimpleEnum { SE_one = 1, SE_two = 2 };
|
enum SimpleEnum { SE_one = 1, SE_two = 2 };
|
||||||
|
|
||||||
TEST_F(TApp, EnumMap) {
|
TEST_CASE_METHOD(TApp, "EnumMap", "[set]") {
|
||||||
SimpleEnum value;
|
SimpleEnum value;
|
||||||
std::map<std::string, SimpleEnum> map = {{"one", SE_one}, {"two", SE_two}};
|
std::map<std::string, SimpleEnum> map = {{"one", SE_one}, {"two", SE_two}};
|
||||||
auto opt = app.add_option("-s,--set", value)->transform(CLI::Transformer(map));
|
auto opt = app.add_option("-s,--set", value)->transform(CLI::Transformer(map));
|
||||||
args = {"-s", "one"};
|
args = {"-s", "one"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(1u, app.count("-s"));
|
CHECK(app.count("-s") == 1u);
|
||||||
EXPECT_EQ(1u, app.count("--set"));
|
CHECK(app.count("--set") == 1u);
|
||||||
EXPECT_EQ(1u, opt->count());
|
CHECK(opt->count() == 1u);
|
||||||
EXPECT_EQ(value, SE_one);
|
CHECK(SE_one == value);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class SimpleEnumC { one = 1, two = 2 };
|
enum class SimpleEnumC { one = 1, two = 2 };
|
||||||
|
|
||||||
TEST_F(TApp, EnumCMap) {
|
TEST_CASE_METHOD(TApp, "EnumCMap", "[set]") {
|
||||||
SimpleEnumC value;
|
SimpleEnumC value;
|
||||||
std::map<std::string, SimpleEnumC> map = {{"one", SimpleEnumC::one}, {"two", SimpleEnumC::two}};
|
std::map<std::string, SimpleEnumC> map = {{"one", SimpleEnumC::one}, {"two", SimpleEnumC::two}};
|
||||||
auto opt = app.add_option("-s,--set", value)->transform(CLI::Transformer(map));
|
auto opt = app.add_option("-s,--set", value)->transform(CLI::Transformer(map));
|
||||||
args = {"-s", "one"};
|
args = {"-s", "one"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(1u, app.count("-s"));
|
CHECK(app.count("-s") == 1u);
|
||||||
EXPECT_EQ(1u, app.count("--set"));
|
CHECK(app.count("--set") == 1u);
|
||||||
EXPECT_EQ(1u, opt->count());
|
CHECK(opt->count() == 1u);
|
||||||
EXPECT_EQ(value, SimpleEnumC::one);
|
CHECK(SimpleEnumC::one == value);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, structMap) {
|
TEST_CASE_METHOD(TApp, "structMap", "[set]") {
|
||||||
struct tstruct {
|
struct tstruct {
|
||||||
int val2;
|
int val2;
|
||||||
double val3;
|
double val3;
|
||||||
@ -114,16 +114,16 @@ TEST_F(TApp, structMap) {
|
|||||||
auto opt = app.add_option("-s,--set", struct_name)->check(CLI::IsMember(map));
|
auto opt = app.add_option("-s,--set", struct_name)->check(CLI::IsMember(map));
|
||||||
args = {"-s", "sone"};
|
args = {"-s", "sone"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(1u, app.count("-s"));
|
CHECK(app.count("-s") == 1u);
|
||||||
EXPECT_EQ(1u, app.count("--set"));
|
CHECK(app.count("--set") == 1u);
|
||||||
EXPECT_EQ(1u, opt->count());
|
CHECK(opt->count() == 1u);
|
||||||
EXPECT_EQ(struct_name, "sone");
|
CHECK("sone" == struct_name);
|
||||||
|
|
||||||
args = {"-s", "sthree"};
|
args = {"-s", "sthree"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, structMapChange) {
|
TEST_CASE_METHOD(TApp, "structMapChange", "[set]") {
|
||||||
struct tstruct {
|
struct tstruct {
|
||||||
int val2;
|
int val2;
|
||||||
double val3;
|
double val3;
|
||||||
@ -135,23 +135,23 @@ TEST_F(TApp, structMapChange) {
|
|||||||
->transform(CLI::IsMember(map, CLI::ignore_case, CLI::ignore_underscore, CLI::ignore_space));
|
->transform(CLI::IsMember(map, CLI::ignore_case, CLI::ignore_underscore, CLI::ignore_space));
|
||||||
args = {"-s", "s one"};
|
args = {"-s", "s one"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(1u, app.count("-s"));
|
CHECK(app.count("-s") == 1u);
|
||||||
EXPECT_EQ(1u, app.count("--set"));
|
CHECK(app.count("--set") == 1u);
|
||||||
EXPECT_EQ(1u, opt->count());
|
CHECK(opt->count() == 1u);
|
||||||
EXPECT_EQ(struct_name, "sone");
|
CHECK("sone" == struct_name);
|
||||||
|
|
||||||
args = {"-s", "sthree"};
|
args = {"-s", "sthree"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||||
|
|
||||||
args = {"-s", "S_t_w_o"};
|
args = {"-s", "S_t_w_o"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(struct_name, "stwo");
|
CHECK("stwo" == struct_name);
|
||||||
args = {"-s", "S two"};
|
args = {"-s", "S two"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(struct_name, "stwo");
|
CHECK("stwo" == struct_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, structMapNoChange) {
|
TEST_CASE_METHOD(TApp, "structMapNoChange", "[set]") {
|
||||||
struct tstruct {
|
struct tstruct {
|
||||||
int val2;
|
int val2;
|
||||||
double val3;
|
double val3;
|
||||||
@ -163,24 +163,24 @@ TEST_F(TApp, structMapNoChange) {
|
|||||||
->check(CLI::IsMember(map, CLI::ignore_case, CLI::ignore_underscore, CLI::ignore_space));
|
->check(CLI::IsMember(map, CLI::ignore_case, CLI::ignore_underscore, CLI::ignore_space));
|
||||||
args = {"-s", "SONE"};
|
args = {"-s", "SONE"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(1u, app.count("-s"));
|
CHECK(app.count("-s") == 1u);
|
||||||
EXPECT_EQ(1u, app.count("--set"));
|
CHECK(app.count("--set") == 1u);
|
||||||
EXPECT_EQ(1u, opt->count());
|
CHECK(opt->count() == 1u);
|
||||||
EXPECT_EQ(struct_name, "SONE");
|
CHECK("SONE" == struct_name);
|
||||||
|
|
||||||
args = {"-s", "sthree"};
|
args = {"-s", "sthree"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||||
|
|
||||||
args = {"-s", "S_t_w_o"};
|
args = {"-s", "S_t_w_o"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(struct_name, "S_t_w_o");
|
CHECK("S_t_w_o" == struct_name);
|
||||||
|
|
||||||
args = {"-s", "S two"};
|
args = {"-s", "S two"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(struct_name, "S two");
|
CHECK("S two" == struct_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, NonCopyableMap) {
|
TEST_CASE_METHOD(TApp, "NonCopyableMap", "[set]") {
|
||||||
|
|
||||||
std::string map_name;
|
std::string map_name;
|
||||||
std::map<std::string, std::unique_ptr<double>> map;
|
std::map<std::string, std::unique_ptr<double>> map;
|
||||||
@ -189,16 +189,16 @@ TEST_F(TApp, NonCopyableMap) {
|
|||||||
auto opt = app.add_option("-s,--set", map_name)->check(CLI::IsMember(&map));
|
auto opt = app.add_option("-s,--set", map_name)->check(CLI::IsMember(&map));
|
||||||
args = {"-s", "e1"};
|
args = {"-s", "e1"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(1u, app.count("-s"));
|
CHECK(app.count("-s") == 1u);
|
||||||
EXPECT_EQ(1u, app.count("--set"));
|
CHECK(app.count("--set") == 1u);
|
||||||
EXPECT_EQ(1u, opt->count());
|
CHECK(opt->count() == 1u);
|
||||||
EXPECT_EQ(map_name, "e1");
|
CHECK("e1" == map_name);
|
||||||
|
|
||||||
args = {"-s", "e45"};
|
args = {"-s", "e45"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, NonCopyableMapWithFunction) {
|
TEST_CASE_METHOD(TApp, "NonCopyableMapWithFunction", "[set]") {
|
||||||
|
|
||||||
std::string map_name;
|
std::string map_name;
|
||||||
std::map<std::string, std::unique_ptr<double>> map;
|
std::map<std::string, std::unique_ptr<double>> map;
|
||||||
@ -207,16 +207,16 @@ TEST_F(TApp, NonCopyableMapWithFunction) {
|
|||||||
auto opt = app.add_option("-s,--set", map_name)->transform(CLI::IsMember(&map, CLI::ignore_underscore));
|
auto opt = app.add_option("-s,--set", map_name)->transform(CLI::IsMember(&map, CLI::ignore_underscore));
|
||||||
args = {"-s", "e_1"};
|
args = {"-s", "e_1"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(1u, app.count("-s"));
|
CHECK(app.count("-s") == 1u);
|
||||||
EXPECT_EQ(1u, app.count("--set"));
|
CHECK(app.count("--set") == 1u);
|
||||||
EXPECT_EQ(1u, opt->count());
|
CHECK(opt->count() == 1u);
|
||||||
EXPECT_EQ(map_name, "e1");
|
CHECK("e1" == map_name);
|
||||||
|
|
||||||
args = {"-s", "e45"};
|
args = {"-s", "e45"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, NonCopyableMapNonStringMap) {
|
TEST_CASE_METHOD(TApp, "NonCopyableMapNonStringMap", "[set]") {
|
||||||
|
|
||||||
std::string map_name;
|
std::string map_name;
|
||||||
std::map<int, std::unique_ptr<double>> map;
|
std::map<int, std::unique_ptr<double>> map;
|
||||||
@ -225,16 +225,16 @@ TEST_F(TApp, NonCopyableMapNonStringMap) {
|
|||||||
auto opt = app.add_option("-s,--set", map_name)->check(CLI::IsMember(&map));
|
auto opt = app.add_option("-s,--set", map_name)->check(CLI::IsMember(&map));
|
||||||
args = {"-s", "4"};
|
args = {"-s", "4"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(1u, app.count("-s"));
|
CHECK(app.count("-s") == 1u);
|
||||||
EXPECT_EQ(1u, app.count("--set"));
|
CHECK(app.count("--set") == 1u);
|
||||||
EXPECT_EQ(1u, opt->count());
|
CHECK(opt->count() == 1u);
|
||||||
EXPECT_EQ(map_name, "4");
|
CHECK("4" == map_name);
|
||||||
|
|
||||||
args = {"-s", "e45"};
|
args = {"-s", "e45"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, CopyableMapMove) {
|
TEST_CASE_METHOD(TApp, "CopyableMapMove", "[set]") {
|
||||||
|
|
||||||
std::string map_name;
|
std::string map_name;
|
||||||
std::map<int, double> map;
|
std::map<int, double> map;
|
||||||
@ -243,162 +243,162 @@ TEST_F(TApp, CopyableMapMove) {
|
|||||||
auto opt = app.add_option("-s,--set", map_name)->check(CLI::IsMember(std::move(map)));
|
auto opt = app.add_option("-s,--set", map_name)->check(CLI::IsMember(std::move(map)));
|
||||||
args = {"-s", "4"};
|
args = {"-s", "4"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(1u, app.count("-s"));
|
CHECK(app.count("-s") == 1u);
|
||||||
EXPECT_EQ(1u, app.count("--set"));
|
CHECK(app.count("--set") == 1u);
|
||||||
EXPECT_EQ(1u, opt->count());
|
CHECK(opt->count() == 1u);
|
||||||
EXPECT_EQ(map_name, "4");
|
CHECK("4" == map_name);
|
||||||
|
|
||||||
args = {"-s", "e45"};
|
args = {"-s", "e45"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, SimpleSets) {
|
TEST_CASE_METHOD(TApp, "SimpleSets", "[set]") {
|
||||||
std::string value;
|
std::string value;
|
||||||
auto opt = app.add_option("-s,--set", value)->check(CLI::IsMember{std::set<std::string>({"one", "two", "three"})});
|
auto opt = app.add_option("-s,--set", value)->check(CLI::IsMember{std::set<std::string>({"one", "two", "three"})});
|
||||||
args = {"-s", "one"};
|
args = {"-s", "one"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(1u, app.count("-s"));
|
CHECK(app.count("-s") == 1u);
|
||||||
EXPECT_EQ(1u, app.count("--set"));
|
CHECK(app.count("--set") == 1u);
|
||||||
EXPECT_EQ(1u, opt->count());
|
CHECK(opt->count() == 1u);
|
||||||
EXPECT_EQ(value, "one");
|
CHECK("one" == value);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, SimpleSetsPtrs) {
|
TEST_CASE_METHOD(TApp, "SimpleSetsPtrs", "[set]") {
|
||||||
auto set = std::shared_ptr<std::set<std::string>>(new std::set<std::string>{"one", "two", "three"});
|
auto set = std::shared_ptr<std::set<std::string>>(new std::set<std::string>{"one", "two", "three"});
|
||||||
std::string value;
|
std::string value;
|
||||||
auto opt = app.add_option("-s,--set", value)->check(CLI::IsMember{set});
|
auto opt = app.add_option("-s,--set", value)->check(CLI::IsMember{set});
|
||||||
args = {"-s", "one"};
|
args = {"-s", "one"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(1u, app.count("-s"));
|
CHECK(app.count("-s") == 1u);
|
||||||
EXPECT_EQ(1u, app.count("--set"));
|
CHECK(app.count("--set") == 1u);
|
||||||
EXPECT_EQ(1u, opt->count());
|
CHECK(opt->count() == 1u);
|
||||||
EXPECT_EQ(value, "one");
|
CHECK("one" == value);
|
||||||
|
|
||||||
set->insert("four");
|
set->insert("four");
|
||||||
|
|
||||||
args = {"-s", "four"};
|
args = {"-s", "four"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(1u, app.count("-s"));
|
CHECK(app.count("-s") == 1u);
|
||||||
EXPECT_EQ(1u, app.count("--set"));
|
CHECK(app.count("--set") == 1u);
|
||||||
EXPECT_EQ(1u, opt->count());
|
CHECK(opt->count() == 1u);
|
||||||
EXPECT_EQ(value, "four");
|
CHECK("four" == value);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, SimiShortcutSets) {
|
TEST_CASE_METHOD(TApp, "SimiShortcutSets", "[set]") {
|
||||||
std::string value;
|
std::string value;
|
||||||
auto opt = app.add_option("--set", value)->check(CLI::IsMember({"one", "two", "three"}));
|
auto opt = app.add_option("--set", value)->check(CLI::IsMember({"one", "two", "three"}));
|
||||||
args = {"--set", "one"};
|
args = {"--set", "one"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(1u, app.count("--set"));
|
CHECK(app.count("--set") == 1u);
|
||||||
EXPECT_EQ(1u, opt->count());
|
CHECK(opt->count() == 1u);
|
||||||
EXPECT_EQ(value, "one");
|
CHECK("one" == value);
|
||||||
|
|
||||||
std::string value2;
|
std::string value2;
|
||||||
auto opt2 = app.add_option("--set2", value2)->transform(CLI::IsMember({"One", "two", "three"}, CLI::ignore_case));
|
auto opt2 = app.add_option("--set2", value2)->transform(CLI::IsMember({"One", "two", "three"}, CLI::ignore_case));
|
||||||
args = {"--set2", "onE"};
|
args = {"--set2", "onE"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(1u, app.count("--set2"));
|
CHECK(app.count("--set2") == 1u);
|
||||||
EXPECT_EQ(1u, opt2->count());
|
CHECK(opt2->count() == 1u);
|
||||||
EXPECT_EQ(value2, "One");
|
CHECK("One" == value2);
|
||||||
|
|
||||||
std::string value3;
|
std::string value3;
|
||||||
auto opt3 = app.add_option("--set3", value3)
|
auto opt3 = app.add_option("--set3", value3)
|
||||||
->transform(CLI::IsMember({"O_ne", "two", "three"}, CLI::ignore_case, CLI::ignore_underscore));
|
->transform(CLI::IsMember({"O_ne", "two", "three"}, CLI::ignore_case, CLI::ignore_underscore));
|
||||||
args = {"--set3", "onE"};
|
args = {"--set3", "onE"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(1u, app.count("--set3"));
|
CHECK(app.count("--set3") == 1u);
|
||||||
EXPECT_EQ(1u, opt3->count());
|
CHECK(opt3->count() == 1u);
|
||||||
EXPECT_EQ(value3, "O_ne");
|
CHECK("O_ne" == value3);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, SetFromCharStarArrayVector) {
|
TEST_CASE_METHOD(TApp, "SetFromCharStarArrayVector", "[set]") {
|
||||||
constexpr const char *names[3]{"one", "two", "three"};
|
constexpr const char *names[3]{"one", "two", "three"};
|
||||||
std::string value;
|
std::string value;
|
||||||
auto opt = app.add_option("-s,--set", value)
|
auto opt = app.add_option("-s,--set", value)
|
||||||
->check(CLI::IsMember{std::vector<std::string>(std::begin(names), std::end(names))});
|
->check(CLI::IsMember{std::vector<std::string>(std::begin(names), std::end(names))});
|
||||||
args = {"-s", "one"};
|
args = {"-s", "one"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(1u, app.count("-s"));
|
CHECK(app.count("-s") == 1u);
|
||||||
EXPECT_EQ(1u, app.count("--set"));
|
CHECK(app.count("--set") == 1u);
|
||||||
EXPECT_EQ(1u, opt->count());
|
CHECK(opt->count() == 1u);
|
||||||
EXPECT_EQ(value, "one");
|
CHECK("one" == value);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, OtherTypeSets) {
|
TEST_CASE_METHOD(TApp, "OtherTypeSets", "[set]") {
|
||||||
int value{0};
|
int value{0};
|
||||||
std::vector<int> set = {2, 3, 4};
|
std::vector<int> set = {2, 3, 4};
|
||||||
auto opt = app.add_option("--set", value)->check(CLI::IsMember(set));
|
auto opt = app.add_option("--set", value)->check(CLI::IsMember(set));
|
||||||
args = {"--set", "3"};
|
args = {"--set", "3"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(1u, app.count("--set"));
|
CHECK(app.count("--set") == 1u);
|
||||||
EXPECT_EQ(1u, opt->count());
|
CHECK(opt->count() == 1u);
|
||||||
EXPECT_EQ(value, 3);
|
CHECK(3 == value);
|
||||||
|
|
||||||
args = {"--set", "5"};
|
args = {"--set", "5"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||||
|
|
||||||
std::vector<int> set2 = {-2, 3, 4};
|
std::vector<int> set2 = {-2, 3, 4};
|
||||||
auto opt2 = app.add_option("--set2", value)->transform(CLI::IsMember(set2, [](int x) { return std::abs(x); }));
|
auto opt2 = app.add_option("--set2", value)->transform(CLI::IsMember(set2, [](int x) { return std::abs(x); }));
|
||||||
args = {"--set2", "-3"};
|
args = {"--set2", "-3"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(1u, app.count("--set2"));
|
CHECK(app.count("--set2") == 1u);
|
||||||
EXPECT_EQ(1u, opt2->count());
|
CHECK(opt2->count() == 1u);
|
||||||
EXPECT_EQ(value, 3);
|
CHECK(3 == value);
|
||||||
|
|
||||||
args = {"--set2", "-3"};
|
args = {"--set2", "-3"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(1u, app.count("--set2"));
|
CHECK(app.count("--set2") == 1u);
|
||||||
EXPECT_EQ(1u, opt2->count());
|
CHECK(opt2->count() == 1u);
|
||||||
EXPECT_EQ(value, 3);
|
CHECK(3 == value);
|
||||||
|
|
||||||
args = {"--set2", "2"};
|
args = {"--set2", "2"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(1u, app.count("--set2"));
|
CHECK(app.count("--set2") == 1u);
|
||||||
EXPECT_EQ(1u, opt2->count());
|
CHECK(opt2->count() == 1u);
|
||||||
EXPECT_EQ(value, -2);
|
CHECK(-2 == value);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, NumericalSets) {
|
TEST_CASE_METHOD(TApp, "NumericalSets", "[set]") {
|
||||||
int value{0};
|
int value{0};
|
||||||
auto opt = app.add_option("-s,--set", value)->check(CLI::IsMember{std::set<int>({1, 2, 3})});
|
auto opt = app.add_option("-s,--set", value)->check(CLI::IsMember{std::set<int>({1, 2, 3})});
|
||||||
args = {"-s", "1"};
|
args = {"-s", "1"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(1u, app.count("-s"));
|
CHECK(app.count("-s") == 1u);
|
||||||
EXPECT_EQ(1u, app.count("--set"));
|
CHECK(app.count("--set") == 1u);
|
||||||
EXPECT_EQ(1u, opt->count());
|
CHECK(opt->count() == 1u);
|
||||||
EXPECT_EQ(value, 1);
|
CHECK(1 == value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Converted original set tests
|
// Converted original set tests
|
||||||
|
|
||||||
TEST_F(TApp, SetWithDefaults) {
|
TEST_CASE_METHOD(TApp, "SetWithDefaults", "[set]") {
|
||||||
int someint{2};
|
int someint{2};
|
||||||
app.add_option("-a", someint, "", true)->check(CLI::IsMember({1, 2, 3, 4}));
|
app.add_option("-a", someint, "", true)->check(CLI::IsMember({1, 2, 3, 4}));
|
||||||
|
|
||||||
args = {"-a1", "-a2"};
|
args = {"-a1", "-a2"};
|
||||||
|
|
||||||
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
CHECK_THROWS_AS(run(), CLI::ArgumentMismatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, SetWithDefaultsConversion) {
|
TEST_CASE_METHOD(TApp, "SetWithDefaultsConversion", "[set]") {
|
||||||
int someint{2};
|
int someint{2};
|
||||||
app.add_option("-a", someint, "", true)->check(CLI::IsMember({1, 2, 3, 4}));
|
app.add_option("-a", someint, "", true)->check(CLI::IsMember({1, 2, 3, 4}));
|
||||||
|
|
||||||
args = {"-a", "hi"};
|
args = {"-a", "hi"};
|
||||||
|
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, SetWithDefaultsIC) {
|
TEST_CASE_METHOD(TApp, "SetWithDefaultsIC", "[set]") {
|
||||||
std::string someint = "ho";
|
std::string someint = "ho";
|
||||||
app.add_option("-a", someint, "", true)->check(CLI::IsMember({"Hi", "Ho"}));
|
app.add_option("-a", someint, "", true)->check(CLI::IsMember({"Hi", "Ho"}));
|
||||||
|
|
||||||
args = {"-aHi", "-aHo"};
|
args = {"-aHi", "-aHo"};
|
||||||
|
|
||||||
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
CHECK_THROWS_AS(run(), CLI::ArgumentMismatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, InSet) {
|
TEST_CASE_METHOD(TApp, "InSet", "[set]") {
|
||||||
|
|
||||||
std::string choice;
|
std::string choice;
|
||||||
app.add_option("-q,--quick", choice)->check(CLI::IsMember({"one", "two", "three"}));
|
app.add_option("-q,--quick", choice)->check(CLI::IsMember({"one", "two", "three"}));
|
||||||
@ -406,47 +406,47 @@ TEST_F(TApp, InSet) {
|
|||||||
args = {"--quick", "two"};
|
args = {"--quick", "two"};
|
||||||
|
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ("two", choice);
|
CHECK(choice == "two");
|
||||||
|
|
||||||
args = {"--quick", "four"};
|
args = {"--quick", "four"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, InSetWithDefault) {
|
TEST_CASE_METHOD(TApp, "InSetWithDefault", "[set]") {
|
||||||
|
|
||||||
std::string choice = "one";
|
std::string choice = "one";
|
||||||
app.add_option("-q,--quick", choice, "", true)->check(CLI::IsMember({"one", "two", "three"}));
|
app.add_option("-q,--quick", choice, "", true)->check(CLI::IsMember({"one", "two", "three"}));
|
||||||
|
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ("one", choice);
|
CHECK(choice == "one");
|
||||||
|
|
||||||
args = {"--quick", "two"};
|
args = {"--quick", "two"};
|
||||||
|
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ("two", choice);
|
CHECK(choice == "two");
|
||||||
|
|
||||||
args = {"--quick", "four"};
|
args = {"--quick", "four"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, InCaselessSetWithDefault) {
|
TEST_CASE_METHOD(TApp, "InCaselessSetWithDefault", "[set]") {
|
||||||
|
|
||||||
std::string choice = "one";
|
std::string choice = "one";
|
||||||
app.add_option("-q,--quick", choice, "", true)->transform(CLI::IsMember({"one", "two", "three"}, CLI::ignore_case));
|
app.add_option("-q,--quick", choice, "", true)->transform(CLI::IsMember({"one", "two", "three"}, CLI::ignore_case));
|
||||||
|
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ("one", choice);
|
CHECK(choice == "one");
|
||||||
|
|
||||||
args = {"--quick", "tWo"};
|
args = {"--quick", "tWo"};
|
||||||
|
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ("two", choice);
|
CHECK(choice == "two");
|
||||||
|
|
||||||
args = {"--quick", "four"};
|
args = {"--quick", "four"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, InIntSet) {
|
TEST_CASE_METHOD(TApp, "InIntSet", "[set]") {
|
||||||
|
|
||||||
int choice{0};
|
int choice{0};
|
||||||
app.add_option("-q,--quick", choice)->check(CLI::IsMember({1, 2, 3}));
|
app.add_option("-q,--quick", choice)->check(CLI::IsMember({1, 2, 3}));
|
||||||
@ -454,13 +454,13 @@ TEST_F(TApp, InIntSet) {
|
|||||||
args = {"--quick", "2"};
|
args = {"--quick", "2"};
|
||||||
|
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(2, choice);
|
CHECK(choice == 2);
|
||||||
|
|
||||||
args = {"--quick", "4"};
|
args = {"--quick", "4"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, InIntSetWindows) {
|
TEST_CASE_METHOD(TApp, "InIntSetWindows", "[set]") {
|
||||||
|
|
||||||
int choice{0};
|
int choice{0};
|
||||||
app.add_option("-q,--quick", choice)->check(CLI::IsMember({1, 2, 3}));
|
app.add_option("-q,--quick", choice)->check(CLI::IsMember({1, 2, 3}));
|
||||||
@ -468,28 +468,28 @@ TEST_F(TApp, InIntSetWindows) {
|
|||||||
args = {"/q", "2"};
|
args = {"/q", "2"};
|
||||||
|
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(2, choice);
|
CHECK(choice == 2);
|
||||||
|
|
||||||
args = {"/q", "4"};
|
args = {"/q", "4"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||||
|
|
||||||
args = {"/q4"};
|
args = {"/q4"};
|
||||||
EXPECT_THROW(run(), CLI::ExtrasError);
|
CHECK_THROWS_AS(run(), CLI::ExtrasError);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, FailSet) {
|
TEST_CASE_METHOD(TApp, "FailSet", "[set]") {
|
||||||
|
|
||||||
int choice{0};
|
int choice{0};
|
||||||
app.add_option("-q,--quick", choice)->check(CLI::IsMember({1, 2, 3}));
|
app.add_option("-q,--quick", choice)->check(CLI::IsMember({1, 2, 3}));
|
||||||
|
|
||||||
args = {"--quick", "3", "--quick=2"};
|
args = {"--quick", "3", "--quick=2"};
|
||||||
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
CHECK_THROWS_AS(run(), CLI::ArgumentMismatch);
|
||||||
|
|
||||||
args = {"--quick=hello"};
|
args = {"--quick=hello"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, FailMutableSet) {
|
TEST_CASE_METHOD(TApp, "FailMutableSet", "[set]") {
|
||||||
|
|
||||||
int choice{0};
|
int choice{0};
|
||||||
auto vals = std::shared_ptr<std::set<int>>(new std::set<int>({1, 2, 3}));
|
auto vals = std::shared_ptr<std::set<int>>(new std::set<int>({1, 2, 3}));
|
||||||
@ -497,37 +497,37 @@ TEST_F(TApp, FailMutableSet) {
|
|||||||
app.add_option("-s,--slow", choice, "", true)->check(CLI::IsMember(vals));
|
app.add_option("-s,--slow", choice, "", true)->check(CLI::IsMember(vals));
|
||||||
|
|
||||||
args = {"--quick=hello"};
|
args = {"--quick=hello"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||||
|
|
||||||
args = {"--slow=hello"};
|
args = {"--slow=hello"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, InSetIgnoreCase) {
|
TEST_CASE_METHOD(TApp, "InSetIgnoreCase", "[set]") {
|
||||||
|
|
||||||
std::string choice;
|
std::string choice;
|
||||||
app.add_option("-q,--quick", choice)->transform(CLI::IsMember({"one", "Two", "THREE"}, CLI::ignore_case));
|
app.add_option("-q,--quick", choice)->transform(CLI::IsMember({"one", "Two", "THREE"}, CLI::ignore_case));
|
||||||
|
|
||||||
args = {"--quick", "One"};
|
args = {"--quick", "One"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ("one", choice);
|
CHECK(choice == "one");
|
||||||
|
|
||||||
args = {"--quick", "two"};
|
args = {"--quick", "two"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ("Two", choice); // Keeps caps from set
|
CHECK(choice == "Two");
|
||||||
|
|
||||||
args = {"--quick", "ThrEE"};
|
args = {"--quick", "ThrEE"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ("THREE", choice); // Keeps caps from set
|
CHECK(choice == "THREE");
|
||||||
|
|
||||||
args = {"--quick", "four"};
|
args = {"--quick", "four"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||||
|
|
||||||
args = {"--quick=one", "--quick=two"};
|
args = {"--quick=one", "--quick=two"};
|
||||||
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
CHECK_THROWS_AS(run(), CLI::ArgumentMismatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, InSetIgnoreCaseMutableValue) {
|
TEST_CASE_METHOD(TApp, "InSetIgnoreCaseMutableValue", "[set]") {
|
||||||
|
|
||||||
std::set<std::string> options{"one", "Two", "THREE"};
|
std::set<std::string> options{"one", "Two", "THREE"};
|
||||||
std::string choice;
|
std::string choice;
|
||||||
@ -535,22 +535,22 @@ TEST_F(TApp, InSetIgnoreCaseMutableValue) {
|
|||||||
|
|
||||||
args = {"--quick", "One"};
|
args = {"--quick", "One"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ("one", choice);
|
CHECK(choice == "one");
|
||||||
|
|
||||||
args = {"--quick", "two"};
|
args = {"--quick", "two"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ("Two", choice); // Keeps caps from set
|
CHECK(choice == "Two");
|
||||||
|
|
||||||
args = {"--quick", "ThrEE"};
|
args = {"--quick", "ThrEE"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ("THREE", choice); // Keeps caps from set
|
CHECK(choice == "THREE");
|
||||||
|
|
||||||
options.clear();
|
options.clear();
|
||||||
args = {"--quick", "ThrEE"};
|
args = {"--quick", "ThrEE"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, InSetIgnoreCasePointer) {
|
TEST_CASE_METHOD(TApp, "InSetIgnoreCasePointer", "[set]") {
|
||||||
|
|
||||||
std::set<std::string> *options = new std::set<std::string>{"one", "Two", "THREE"};
|
std::set<std::string> *options = new std::set<std::string>{"one", "Two", "THREE"};
|
||||||
std::string choice;
|
std::string choice;
|
||||||
@ -558,43 +558,43 @@ TEST_F(TApp, InSetIgnoreCasePointer) {
|
|||||||
|
|
||||||
args = {"--quick", "One"};
|
args = {"--quick", "One"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ("one", choice);
|
CHECK(choice == "one");
|
||||||
|
|
||||||
args = {"--quick", "two"};
|
args = {"--quick", "two"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ("Two", choice); // Keeps caps from set
|
CHECK(choice == "Two");
|
||||||
|
|
||||||
args = {"--quick", "ThrEE"};
|
args = {"--quick", "ThrEE"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ("THREE", choice); // Keeps caps from set
|
CHECK(choice == "THREE");
|
||||||
|
|
||||||
delete options;
|
delete options;
|
||||||
args = {"--quick", "ThrEE"};
|
args = {"--quick", "ThrEE"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ("THREE", choice); // this does not throw a segfault
|
CHECK(choice == "THREE");
|
||||||
|
|
||||||
args = {"--quick", "four"};
|
args = {"--quick", "four"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||||
|
|
||||||
args = {"--quick=one", "--quick=two"};
|
args = {"--quick=one", "--quick=two"};
|
||||||
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
CHECK_THROWS_AS(run(), CLI::ArgumentMismatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, NotInSetIgnoreCasePointer) {
|
TEST_CASE_METHOD(TApp, "NotInSetIgnoreCasePointer", "[set]") {
|
||||||
|
|
||||||
std::set<std::string> *options = new std::set<std::string>{"one", "Two", "THREE"};
|
std::set<std::string> *options = new std::set<std::string>{"one", "Two", "THREE"};
|
||||||
std::string choice;
|
std::string choice;
|
||||||
app.add_option("-q,--quick", choice)->check(!CLI::IsMember(*options, CLI::ignore_case));
|
app.add_option("-q,--quick", choice)->check(!CLI::IsMember(*options, CLI::ignore_case));
|
||||||
|
|
||||||
args = {"--quick", "One"};
|
args = {"--quick", "One"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||||
|
|
||||||
args = {"--quick", "four"};
|
args = {"--quick", "four"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(choice, "four");
|
CHECK("four" == choice);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, InSetIgnoreUnderscore) {
|
TEST_CASE_METHOD(TApp, "InSetIgnoreUnderscore", "[set]") {
|
||||||
|
|
||||||
std::string choice;
|
std::string choice;
|
||||||
app.add_option("-q,--quick", choice)
|
app.add_option("-q,--quick", choice)
|
||||||
@ -602,24 +602,24 @@ TEST_F(TApp, InSetIgnoreUnderscore) {
|
|||||||
|
|
||||||
args = {"--quick", "option_one"};
|
args = {"--quick", "option_one"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ("option_one", choice);
|
CHECK(choice == "option_one");
|
||||||
|
|
||||||
args = {"--quick", "optiontwo"};
|
args = {"--quick", "optiontwo"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ("option_two", choice); // Keeps underscore from set
|
CHECK(choice == "option_two");
|
||||||
|
|
||||||
args = {"--quick", "_option_thr_ee"};
|
args = {"--quick", "_option_thr_ee"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ("optionthree", choice); // no underscore
|
CHECK(choice == "optionthree");
|
||||||
|
|
||||||
args = {"--quick", "Option4"};
|
args = {"--quick", "Option4"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||||
|
|
||||||
args = {"--quick=option_one", "--quick=option_two"};
|
args = {"--quick=option_one", "--quick=option_two"};
|
||||||
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
CHECK_THROWS_AS(run(), CLI::ArgumentMismatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, InSetIgnoreCaseUnderscore) {
|
TEST_CASE_METHOD(TApp, "InSetIgnoreCaseUnderscore", "[set]") {
|
||||||
|
|
||||||
std::string choice;
|
std::string choice;
|
||||||
app.add_option("-q,--quick", choice)
|
app.add_option("-q,--quick", choice)
|
||||||
@ -628,25 +628,25 @@ TEST_F(TApp, InSetIgnoreCaseUnderscore) {
|
|||||||
|
|
||||||
args = {"--quick", "option_one"};
|
args = {"--quick", "option_one"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ("Option_One", choice);
|
CHECK(choice == "Option_One");
|
||||||
|
|
||||||
args = {"--quick", "OptionTwo"};
|
args = {"--quick", "OptionTwo"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ("option_two", choice); // Keeps underscore and case from set
|
CHECK(choice == "option_two");
|
||||||
|
|
||||||
args = {"--quick", "_OPTION_thr_ee"};
|
args = {"--quick", "_OPTION_thr_ee"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ("OptionThree", choice); // no underscore
|
CHECK(choice == "OptionThree");
|
||||||
|
|
||||||
args = {"--quick", "Option4"};
|
args = {"--quick", "Option4"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||||
|
|
||||||
args = {"--quick=option_one", "--quick=option_two"};
|
args = {"--quick=option_one", "--quick=option_two"};
|
||||||
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
CHECK_THROWS_AS(run(), CLI::ArgumentMismatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #113
|
// #113
|
||||||
TEST_F(TApp, AddRemoveSetItems) {
|
TEST_CASE_METHOD(TApp, "AddRemoveSetItems", "[set]") {
|
||||||
std::set<std::string> items{"TYPE1", "TYPE2", "TYPE3", "TYPE4", "TYPE5"};
|
std::set<std::string> items{"TYPE1", "TYPE2", "TYPE3", "TYPE4", "TYPE5"};
|
||||||
|
|
||||||
std::string type1, type2;
|
std::string type1, type2;
|
||||||
@ -656,8 +656,8 @@ TEST_F(TApp, AddRemoveSetItems) {
|
|||||||
args = {"--type1", "TYPE1", "--type2", "TYPE2"};
|
args = {"--type1", "TYPE1", "--type2", "TYPE2"};
|
||||||
|
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(type1, "TYPE1");
|
CHECK("TYPE1" == type1);
|
||||||
EXPECT_EQ(type2, "TYPE2");
|
CHECK("TYPE2" == type2);
|
||||||
|
|
||||||
items.insert("TYPE6");
|
items.insert("TYPE6");
|
||||||
items.insert("TYPE7");
|
items.insert("TYPE7");
|
||||||
@ -667,17 +667,17 @@ TEST_F(TApp, AddRemoveSetItems) {
|
|||||||
|
|
||||||
args = {"--type1", "TYPE6", "--type2", "TYPE7"};
|
args = {"--type1", "TYPE6", "--type2", "TYPE7"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(type1, "TYPE6");
|
CHECK("TYPE6" == type1);
|
||||||
EXPECT_EQ(type2, "TYPE7");
|
CHECK("TYPE7" == type2);
|
||||||
|
|
||||||
args = {"--type1", "TYPE1"};
|
args = {"--type1", "TYPE1"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||||
|
|
||||||
args = {"--type2", "TYPE2"};
|
args = {"--type2", "TYPE2"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, AddRemoveSetItemsNoCase) {
|
TEST_CASE_METHOD(TApp, "AddRemoveSetItemsNoCase", "[set]") {
|
||||||
std::set<std::string> items{"TYPE1", "TYPE2", "TYPE3", "TYPE4", "TYPE5"};
|
std::set<std::string> items{"TYPE1", "TYPE2", "TYPE3", "TYPE4", "TYPE5"};
|
||||||
|
|
||||||
std::string type1, type2;
|
std::string type1, type2;
|
||||||
@ -687,8 +687,8 @@ TEST_F(TApp, AddRemoveSetItemsNoCase) {
|
|||||||
args = {"--type1", "TYPe1", "--type2", "TyPE2"};
|
args = {"--type1", "TYPe1", "--type2", "TyPE2"};
|
||||||
|
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(type1, "TYPE1");
|
CHECK("TYPE1" == type1);
|
||||||
EXPECT_EQ(type2, "TYPE2");
|
CHECK("TYPE2" == type2);
|
||||||
|
|
||||||
items.insert("TYPE6");
|
items.insert("TYPE6");
|
||||||
items.insert("TYPE7");
|
items.insert("TYPE7");
|
||||||
@ -698,12 +698,12 @@ TEST_F(TApp, AddRemoveSetItemsNoCase) {
|
|||||||
|
|
||||||
args = {"--type1", "TyPE6", "--type2", "tYPE7"};
|
args = {"--type1", "TyPE6", "--type2", "tYPE7"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(type1, "TYPE6");
|
CHECK("TYPE6" == type1);
|
||||||
EXPECT_EQ(type2, "TYPE7");
|
CHECK("TYPE7" == type2);
|
||||||
|
|
||||||
args = {"--type1", "TYPe1"};
|
args = {"--type1", "TYPe1"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||||
|
|
||||||
args = {"--type2", "TYpE2"};
|
args = {"--type2", "TYpE2"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||||
}
|
}
|
||||||
|
@ -10,11 +10,11 @@
|
|||||||
#include "CLI/CLI.hpp"
|
#include "CLI/CLI.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "catch.hpp"
|
||||||
|
|
||||||
using input_t = std::vector<std::string>;
|
using input_t = std::vector<std::string>;
|
||||||
|
|
||||||
TEST(Basic, Empty) {
|
TEST_CASE("Basic: Empty", "[simple]") {
|
||||||
|
|
||||||
{
|
{
|
||||||
CLI::App app;
|
CLI::App app;
|
||||||
@ -24,7 +24,7 @@ TEST(Basic, Empty) {
|
|||||||
{
|
{
|
||||||
CLI::App app;
|
CLI::App app;
|
||||||
input_t spare = {"spare"};
|
input_t spare = {"spare"};
|
||||||
EXPECT_THROW(app.parse(spare), CLI::ExtrasError);
|
CHECK_THROWS_AS(app.parse(spare), CLI::ExtrasError);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
CLI::App app;
|
CLI::App app;
|
||||||
|
@ -6,11 +6,10 @@
|
|||||||
|
|
||||||
#include "app_helper.hpp"
|
#include "app_helper.hpp"
|
||||||
|
|
||||||
#include "gmock/gmock.h"
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
TEST_F(TApp, ExistingExeCheck) {
|
TEST_CASE_METHOD(TApp, "ExistingExeCheck", "[stringparse]") {
|
||||||
|
|
||||||
TempFile tmpexe{"existingExe.out"};
|
TempFile tmpexe{"existingExe.out"};
|
||||||
|
|
||||||
@ -27,12 +26,12 @@ TEST_F(TApp, ExistingExeCheck) {
|
|||||||
app.parse(std::string("./") + std::string(tmpexe) +
|
app.parse(std::string("./") + std::string(tmpexe) +
|
||||||
" --string=\"this is my quoted string\" -t 'qstring 2' -m=`\"quoted string\"`",
|
" --string=\"this is my quoted string\" -t 'qstring 2' -m=`\"quoted string\"`",
|
||||||
true);
|
true);
|
||||||
EXPECT_EQ(str, "this is my quoted string");
|
CHECK("this is my quoted string" == str);
|
||||||
EXPECT_EQ(str2, "qstring 2");
|
CHECK("qstring 2" == str2);
|
||||||
EXPECT_EQ(str3, "\"quoted string\"");
|
CHECK("\"quoted string\"" == str3);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, ExistingExeCheckWithSpace) {
|
TEST_CASE_METHOD(TApp, "ExistingExeCheckWithSpace", "[stringparse]") {
|
||||||
|
|
||||||
TempFile tmpexe{"Space File.out"};
|
TempFile tmpexe{"Space File.out"};
|
||||||
|
|
||||||
@ -49,14 +48,14 @@ TEST_F(TApp, ExistingExeCheckWithSpace) {
|
|||||||
app.parse(std::string("./") + std::string(tmpexe) +
|
app.parse(std::string("./") + std::string(tmpexe) +
|
||||||
" --string=\"this is my quoted string\" -t 'qstring 2' -m=`\"quoted string\"`",
|
" --string=\"this is my quoted string\" -t 'qstring 2' -m=`\"quoted string\"`",
|
||||||
true);
|
true);
|
||||||
EXPECT_EQ(str, "this is my quoted string");
|
CHECK("this is my quoted string" == str);
|
||||||
EXPECT_EQ(str2, "qstring 2");
|
CHECK("qstring 2" == str2);
|
||||||
EXPECT_EQ(str3, "\"quoted string\"");
|
CHECK("\"quoted string\"" == str3);
|
||||||
|
|
||||||
EXPECT_EQ(app.get_name(), std::string("./") + std::string(tmpexe));
|
CHECK(std::string("./") + std::string(tmpexe) == app.get_name());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TApp, ExistingExeCheckWithLotsOfSpace) {
|
TEST_CASE_METHOD(TApp, "ExistingExeCheckWithLotsOfSpace", "[stringparse]") {
|
||||||
|
|
||||||
TempFile tmpexe{"this is a weird file.exe"};
|
TempFile tmpexe{"this is a weird file.exe"};
|
||||||
|
|
||||||
@ -73,9 +72,9 @@ TEST_F(TApp, ExistingExeCheckWithLotsOfSpace) {
|
|||||||
app.parse(std::string("./") + std::string(tmpexe) +
|
app.parse(std::string("./") + std::string(tmpexe) +
|
||||||
" --string=\"this is my quoted string\" -t 'qstring 2' -m=`\"quoted string\"`",
|
" --string=\"this is my quoted string\" -t 'qstring 2' -m=`\"quoted string\"`",
|
||||||
true);
|
true);
|
||||||
EXPECT_EQ(str, "this is my quoted string");
|
CHECK("this is my quoted string" == str);
|
||||||
EXPECT_EQ(str2, "qstring 2");
|
CHECK("qstring 2" == str2);
|
||||||
EXPECT_EQ(str3, "\"quoted string\"");
|
CHECK("\"quoted string\"" == str3);
|
||||||
|
|
||||||
EXPECT_EQ(app.get_name(), std::string("./") + std::string(tmpexe));
|
CHECK(std::string("./") + std::string(tmpexe) == app.get_name());
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -5,66 +5,66 @@
|
|||||||
// SPDX-License-Identifier: BSD-3-Clause
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
#include "CLI/Timer.hpp"
|
#include "CLI/Timer.hpp"
|
||||||
#include "gmock/gmock.h"
|
|
||||||
#include "gtest/gtest.h"
|
#include "catch.hpp"
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
using ::testing::HasSubstr;
|
using Catch::Matchers::Contains;
|
||||||
|
|
||||||
TEST(Timer, MSTimes) {
|
TEST_CASE("Timer: MSTimes", "[timer]") {
|
||||||
CLI::Timer timer{"My Timer"};
|
CLI::Timer timer{"My Timer"};
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(123));
|
std::this_thread::sleep_for(std::chrono::milliseconds(123));
|
||||||
std::string output = timer.to_string();
|
std::string output = timer.to_string();
|
||||||
std::string new_output = (timer / 1000000).to_string();
|
std::string new_output = (timer / 1000000).to_string();
|
||||||
EXPECT_THAT(output, HasSubstr("My Timer"));
|
CHECK_THAT(output, Contains("My Timer"));
|
||||||
EXPECT_THAT(output, HasSubstr(" ms"));
|
CHECK_THAT(output, Contains(" ms"));
|
||||||
EXPECT_THAT(new_output, HasSubstr(" ns"));
|
CHECK_THAT(new_output, Contains(" ns"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Takes too long
|
/* Takes too long
|
||||||
TEST(Timer, STimes) {
|
TEST_CASE("Timer: STimes", "[timer]") {
|
||||||
CLI::Timer timer;
|
CLI::Timer timer;
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
std::string output = timer.to_string();
|
std::string output = timer.to_string();
|
||||||
EXPECT_THAT(output, HasSubstr(" s"));
|
CHECK_THAT (output, Contains(" s"));
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Fails on Windows
|
// Fails on Windows
|
||||||
// TEST(Timer, UStimes) {
|
// TEST_CASE("Timer: UStimes", "[timer]") {
|
||||||
// CLI::Timer timer;
|
// CLI::Timer timer;
|
||||||
// std::this_thread::sleep_for(std::chrono::microseconds(2));
|
// std::this_thread::sleep_for(std::chrono::microseconds(2));
|
||||||
// std::string output = timer.to_string();
|
// std::string output = timer.to_string();
|
||||||
// EXPECT_THAT(output, HasSubstr(" ms"));
|
// CHECK_THAT (output, Contains(" ms"));
|
||||||
//}
|
//}
|
||||||
|
|
||||||
TEST(Timer, BigTimer) {
|
TEST_CASE("Timer: BigTimer", "[timer]") {
|
||||||
CLI::Timer timer{"My Timer", CLI::Timer::Big};
|
CLI::Timer timer{"My Timer", CLI::Timer::Big};
|
||||||
std::string output = timer.to_string();
|
std::string output = timer.to_string();
|
||||||
EXPECT_THAT(output, HasSubstr("Time ="));
|
CHECK_THAT(output, Contains("Time ="));
|
||||||
EXPECT_THAT(output, HasSubstr("-----------"));
|
CHECK_THAT(output, Contains("-----------"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Timer, AutoTimer) {
|
TEST_CASE("Timer: AutoTimer", "[timer]") {
|
||||||
CLI::AutoTimer timer;
|
CLI::AutoTimer timer;
|
||||||
std::string output = timer.to_string();
|
std::string output = timer.to_string();
|
||||||
EXPECT_THAT(output, HasSubstr("Timer"));
|
CHECK_THAT(output, Contains("Timer"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Timer, PrintTimer) {
|
TEST_CASE("Timer: PrintTimer", "[timer]") {
|
||||||
std::stringstream out;
|
std::stringstream out;
|
||||||
CLI::AutoTimer timer;
|
CLI::AutoTimer timer;
|
||||||
out << timer;
|
out << timer;
|
||||||
std::string output = out.str();
|
std::string output = out.str();
|
||||||
EXPECT_THAT(output, HasSubstr("Timer"));
|
CHECK_THAT(output, Contains("Timer"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Timer, TimeItTimer) {
|
TEST_CASE("Timer: TimeItTimer", "[timer]") {
|
||||||
CLI::Timer timer;
|
CLI::Timer timer;
|
||||||
std::string output = timer.time_it([]() { std::this_thread::sleep_for(std::chrono::milliseconds(10)); }, .1);
|
std::string output = timer.time_it([]() { std::this_thread::sleep_for(std::chrono::milliseconds(10)); }, .1);
|
||||||
std::cout << output << std::endl;
|
std::cout << output << std::endl;
|
||||||
EXPECT_THAT(output, HasSubstr("ms"));
|
CHECK_THAT(output, Contains("ms"));
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -6,31 +6,24 @@
|
|||||||
|
|
||||||
#include "app_helper.hpp"
|
#include "app_helper.hpp"
|
||||||
|
|
||||||
/// This allows a set of strings to be run over by a test
|
TEST_CASE_METHOD(TApp, "True Bool Option", "[bool][flag]") {
|
||||||
struct TApp_TBO : public TApp_base, testing::TestWithParam<const char *> {};
|
// Strings needed here due to MSVC 2015.
|
||||||
|
auto param = GENERATE(as<std::string>{}, "true", "on", "True", "ON");
|
||||||
TEST_P(TApp_TBO, TrueBoolOption) {
|
|
||||||
bool value{false}; // Not used, but set just in case
|
bool value{false}; // Not used, but set just in case
|
||||||
app.add_option("-b,--bool", value);
|
app.add_option("-b,--bool", value);
|
||||||
args = {"--bool", GetParam()};
|
args = {"--bool", param};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(1u, app.count("--bool"));
|
CHECK(app.count("--bool") == 1u);
|
||||||
EXPECT_TRUE(value);
|
CHECK(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change to INSTANTIATE_TEST_SUITE_P in GTest master
|
TEST_CASE_METHOD(TApp, "False Bool Option", "[bool][flag]") {
|
||||||
INSTANTIATE_TEST_SUITE_P(TrueBoolOptions_test, TApp_TBO, testing::Values("true", "on", "True", "ON"));
|
auto param = GENERATE(as<std::string>{}, "false", "off", "False", "OFF");
|
||||||
|
|
||||||
/// This allows a set of strings to be run over by a test
|
|
||||||
struct TApp_FBO : public TApp_base, public ::testing::TestWithParam<const char *> {};
|
|
||||||
|
|
||||||
TEST_P(TApp_FBO, FalseBoolOptions) {
|
|
||||||
bool value{true}; // Not used, but set just in case
|
bool value{true}; // Not used, but set just in case
|
||||||
app.add_option("-b,--bool", value);
|
app.add_option("-b,--bool", value);
|
||||||
args = {"--bool", GetParam()};
|
args = {"--bool", param};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(1u, app.count("--bool"));
|
CHECK(app.count("--bool") == 1u);
|
||||||
EXPECT_FALSE(value);
|
CHECK_FALSE(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
INSTANTIATE_TEST_SUITE_P(FalseBoolOptions_test, TApp_FBO, ::testing::Values("false", "off", "False", "OFF"));
|
|
||||||
|
@ -10,10 +10,10 @@
|
|||||||
// This test verifies that CLI11 still works if
|
// This test verifies that CLI11 still works if
|
||||||
// Windows.h is included. #145
|
// Windows.h is included. #145
|
||||||
|
|
||||||
TEST_F(TApp, WindowsTestSimple) {
|
TEST_CASE_METHOD(TApp, "WindowsTestSimple", "[windows]") {
|
||||||
app.add_flag("-c,--count");
|
app.add_flag("-c,--count");
|
||||||
args = {"-c"};
|
args = {"-c"};
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(1u, app.count("-c"));
|
CHECK(app.count("-c") == 1u);
|
||||||
EXPECT_EQ(1u, app.count("--count"));
|
CHECK(app.count("--count") == 1u);
|
||||||
}
|
}
|
||||||
|
@ -6,12 +6,12 @@
|
|||||||
|
|
||||||
#include "CLI/CLI.hpp"
|
#include "CLI/CLI.hpp"
|
||||||
#include "CLI/Timer.hpp"
|
#include "CLI/Timer.hpp"
|
||||||
#include <gtest/gtest.h>
|
#include "catch.hpp"
|
||||||
|
|
||||||
int do_nothing();
|
int do_nothing();
|
||||||
|
|
||||||
// Verifies there are no unguarded inlines
|
// Verifies there are no unguarded inlines
|
||||||
TEST(Link, DoNothing) {
|
TEST_CASE("Link: DoNothing", "[link]") {
|
||||||
int a = do_nothing();
|
int a = do_nothing();
|
||||||
EXPECT_EQ(7, a);
|
CHECK(a == 7);
|
||||||
}
|
}
|
||||||
|
2
tests/main.cpp
Normal file
2
tests/main.cpp
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#define CATCH_CONFIG_MAIN
|
||||||
|
#include "catch.hpp"
|
Loading…
x
Reference in New Issue
Block a user