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,24 +4,39 @@
|
|||||||
# gives output on failed tests without having to set an environment variable.
|
# gives output on failed tests without having to set an environment variable.
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
set(UPDATE_DISCONNECTED_IF_AVAILABLE "UPDATE_DISCONNECTED 1")
|
|
||||||
|
|
||||||
include(DownloadProject)
|
|
||||||
download_project(PROJ googletest
|
|
||||||
GIT_REPOSITORY https://github.com/google/googletest.git
|
|
||||||
GIT_TAG release-1.8.0
|
|
||||||
UPDATE_DISCONNECTED 1
|
|
||||||
QUIET
|
|
||||||
)
|
|
||||||
|
|
||||||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||||
|
|
||||||
# CMake warning suppression will not be needed in version 1.9
|
if(CMAKE_VERSION VERSION_LESS 3.11)
|
||||||
set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS 1 CACHE BOOL "")
|
set(UPDATE_DISCONNECTED_IF_AVAILABLE "UPDATE_DISCONNECTED 1")
|
||||||
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_SOURCE_DIR} EXCLUDE_FROM_ALL)
|
include(DownloadProject)
|
||||||
unset(CMAKE_SUPPRESS_DEVELOPER_WARNINGS)
|
download_project(PROJ googletest
|
||||||
|
GIT_REPOSITORY https://github.com/google/googletest.git
|
||||||
|
GIT_TAG release-1.8.0
|
||||||
|
UPDATE_DISCONNECTED 1
|
||||||
|
QUIET
|
||||||
|
)
|
||||||
|
|
||||||
|
# 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)
|
|
||||||
|
|
||||||
|
if(CMAKE_CONFIGURATION_TYPES)
|
||||||
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
|
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
|
||||||
--force-new-ctest-process --output-on-failure
|
--force-new-ctest-process --output-on-failure
|
||||||
--build-config "$<CONFIGURATION>")
|
--build-config "$<CONFIGURATION>")
|
||||||
@ -54,16 +69,17 @@ macro(add_gtest TESTNAME)
|
|||||||
gtest_add_tests(TARGET ${TESTNAME}
|
gtest_add_tests(TARGET ${TESTNAME}
|
||||||
TEST_PREFIX "${TESTNAME}."
|
TEST_PREFIX "${TESTNAME}."
|
||||||
TEST_LIST TmpTestList)
|
TEST_LIST TmpTestList)
|
||||||
|
set_tests_properties(${TmpTestList} PROPERTIES FOLDER "Tests")
|
||||||
else()
|
else()
|
||||||
gtest_discover_tests(${TESTNAME}
|
gtest_discover_tests(${TESTNAME}
|
||||||
TEST_PREFIX "${TESTNAME}."
|
TEST_PREFIX "${TESTNAME}."
|
||||||
)
|
PROPERTIES FOLDER "Tests")
|
||||||
|
|
||||||
endif()
|
endif()
|
||||||
else()
|
else()
|
||||||
add_test(${TESTNAME} ${TESTNAME})
|
add_test(${TESTNAME} ${TESTNAME})
|
||||||
|
set_target_properties(${TESTNAME} PROPERTIES FOLDER "Tests")
|
||||||
endif()
|
endif()
|
||||||
set_target_properties(${TESTNAME} PROPERTIES FOLDER "Tests")
|
|
||||||
|
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
|
@ -353,6 +353,23 @@ TEST_F(TApp, MissingValueMoreThan) {
|
|||||||
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
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) {
|
TEST_F(TApp, NotRequiredOptsSingle) {
|
||||||
|
|
||||||
std::string str;
|
std::string str;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user