mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-05-03 05:53:52 +00:00
Adding FetchContent on CMake 3.11
This commit is contained in:
parent
f059528559
commit
0c3df9150c
@ -4,8 +4,10 @@
|
||||
# gives output on failed tests without having to set an environment variable.
|
||||
#
|
||||
#
|
||||
set(UPDATE_DISCONNECTED_IF_AVAILABLE "UPDATE_DISCONNECTED 1")
|
||||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||
|
||||
if(CMAKE_VERSION VERSION_LESS 3.11)
|
||||
set(UPDATE_DISCONNECTED_IF_AVAILABLE "UPDATE_DISCONNECTED 1")
|
||||
include(DownloadProject)
|
||||
download_project(PROJ googletest
|
||||
GIT_REPOSITORY https://github.com/google/googletest.git
|
||||
@ -14,12 +16,25 @@ download_project(PROJ googletest
|
||||
QUIET
|
||||
)
|
||||
|
||||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||
|
||||
# CMake warning suppression will not be needed in version 1.9
|
||||
set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS 1 CACHE BOOL "")
|
||||
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_SOURCE_DIR} EXCLUDE_FROM_ALL)
|
||||
unset(CMAKE_SUPPRESS_DEVELOPER_WARNINGS)
|
||||
else()
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(googletest
|
||||
GIT_REPOSITORY https://github.com/google/googletest.git
|
||||
GIT_TAG release-1.8.0)
|
||||
FetchContent_GetProperties(googletest)
|
||||
if(NOT googletest_POPULATED)
|
||||
FetchContent_Populate(googletest)
|
||||
set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS 1 CACHE BOOL "")
|
||||
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} EXCLUDE_FROM_ALL)
|
||||
unset(CMAKE_SUPPRESS_DEVELOPER_WARNINGS)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
if(CMAKE_CONFIGURATION_TYPES)
|
||||
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
|
||||
@ -54,16 +69,17 @@ macro(add_gtest TESTNAME)
|
||||
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})
|
||||
endif()
|
||||
set_target_properties(${TESTNAME} PROPERTIES FOLDER "Tests")
|
||||
endif()
|
||||
|
||||
endmacro()
|
||||
|
||||
|
@ -353,6 +353,23 @@ TEST_F(TApp, MissingValueMoreThan) {
|
||||
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
||||
}
|
||||
|
||||
TEST_F(TApp, NoMissingValueMoreThan) {
|
||||
std::vector<int> vals1;
|
||||
std::vector<int> vals2;
|
||||
app.add_option("-v", vals1)->expected(-2);
|
||||
app.add_option("--vals", vals2)->expected(-2);
|
||||
|
||||
args = {"-v", "2", "3", "4"};
|
||||
run();
|
||||
EXPECT_EQ(vals1, std::vector<int>({2,3,4}));
|
||||
|
||||
app.reset();
|
||||
|
||||
args = {"--vals", "2", "3", "4"};
|
||||
run();
|
||||
EXPECT_EQ(vals2, std::vector<int>({2,3,4}));
|
||||
}
|
||||
|
||||
TEST_F(TApp, NotRequiredOptsSingle) {
|
||||
|
||||
std::string str;
|
||||
|
Loading…
x
Reference in New Issue
Block a user