1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-05-05 22:53:52 +00:00
CLI11/tests/CMakeLists.txt
Philip Top c67ab9dd43 Config file handling refactor. (#362)
Refactor some of the configuration file handling code.  Make it easier to get the actual file that was processed, and allow extras in the config file to be ignored (default now), captured or errored.

fix std::error reference and formatting

add test for required but no default and fix a shadow warning on 'required' from gcc 4.8

Test correctness of config write-read loop

fix config generation for flag definitions

make the config output conform with toml

continue work on the config file interpretation and construction

get all the ini tests working again with the cleaned up features.

update formatting

rename IniTest to ConfigFileTest to better reflect actual tests and add a few more test of the configTOML
disambiguate enable/disable by default to an enumeration, and to make room for a configurable option to allow subcommands to be triggered by a config file.
add a ConfigBase class to generally reflect a broader class of configuration files formats of similar nature to INI files

add configurable to app and allow it to trigger subcommands

add test of ini formatting

add section support to the config files so sections can be opened and closed and the callbacks triggered as appropriate.

add handling of option groups to the config file output

add subcommand and option group configuration to config file output

subsubcom test on config files

fix a few sign comparison warnings and formatting

start working on the book edits for configuration and a few more tests

more test to check for subcommand close in config files

more tests for coverage

generalize section opening and closing

add more tests and some fixes for different configurations

yet more tests of different situations related to configuration files

test more paths for configuration file sections

remove some unused code and fix some codacy warnings

update readme with updates from configuration files

more book edits and README formatting

remove extra space

Apply suggestions from code review

Co-Authored-By: Henry Schreiner <HenrySchreinerIII@gmail.com>

fix some comments and documentation

fix spacing

Rename size_t -> std::size_t

Fix compiler warnings with -Wsign-conversion

Fix new warnings with -Wsign-conversion in PR
2019-12-31 11:28:25 -05:00

154 lines
4.5 KiB
CMake

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")
# If submodule is available, add sanitizers
# Set SANITIZE_ADDRESS, SANITIZE_MEMORY, SANITIZE_THREAD or SANITIZE_UNDEFINED
if(EXISTS "${CLI11_SOURCE_DIR}/extern/sanitizers/cmake/FindSanitizers.cmake")
list(APPEND CMAKE_MODULE_PATH "${CLI11_SOURCE_DIR}/extern/sanitizers/cmake")
find_package(Sanitizers)
if(SANITIZE_ADDRESS)
message(STATUS "You might want to use \"${ASan_WRAPPER}\" to run your program")
endif()
else()
macro(add_sanitizers)
endmacro()
endif()
set(GOOGLE_TEST_INDIVIDUAL OFF)
include(AddGoogletest)
set(CLI11_TESTS
HelpersTest
ConfigFileTest
SimpleTest
AppTest
SetTest
TransformTest
CreationTest
SubcommandTest
HelpTest
FormatterTest
NewParseTest
OptionalTest
DeprecatedTest
StringParseTest
TrueFalseTest
OptionGroupTest
)
if(WIN32)
list(APPEND CLI11_TESTS WindowsTest)
endif()
set(CLI11_MULTIONLY_TESTS
TimerTest
)
# Only affects current directory, so safe
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
foreach(T ${CLI11_TESTS})
if(CLI11_CUDA_TESTS)
set_property(
SOURCE ${T}.cpp
PROPERTY
LANGUAGE CUDA
)
endif()
add_executable(${T} ${T}.cpp ${CLI11_headers})
add_sanitizers(${T})
target_link_libraries(${T} PUBLIC CLI11)
if(NOT CLI11_CUDA_TESTS)
target_link_libraries(${T} PUBLIC CLI11_warnings)
endif()
add_gtest(${T})
if(CLI11_SINGLE_FILE AND CLI11_SINGLE_FILE_TESTS)
add_executable(${T}_Single ${T}.cpp)
target_link_libraries(${T}_Single PUBLIC CLI11_SINGLE)
add_gtest(${T}_Single)
set_target_properties(${T}_Single
PROPERTIES
FOLDER "Tests Single File")
endif()
endforeach()
foreach(T ${CLI11_MULTIONLY_TESTS})
add_executable(${T} ${T}.cpp ${CLI11_headers})
add_sanitizers(${T})
target_link_libraries(${T} PUBLIC CLI11)
add_gtest(${T})
endforeach()
# Add -Wno-deprecated-declarations to DeprecatedTest
if(NOT MSVC)
target_compile_options(DeprecatedTest PRIVATE -Wno-deprecated-declarations)
if(TARGET DeprecatedTest_Single)
target_compile_options(DeprecatedTest_Single PRIVATE -Wno-deprecated-declarations)
endif()
else()
target_compile_options(DeprecatedTest PRIVATE "/wd4996")
if(TARGET DeprecatedTest_Single)
target_compile_options(DeprecatedTest_Single PRIVATE "/wd4996")
endif()
endif()
# Link test (build error if inlines missing)
add_library(link_test_1 link_test_1.cpp)
target_link_libraries(link_test_1 PUBLIC CLI11)
set_target_properties(link_test_1 PROPERTIES FOLDER "Tests")
add_executable(link_test_2 link_test_2.cpp)
target_link_libraries(link_test_2 PUBLIC CLI11 link_test_1)
add_gtest(link_test_2)
# Add informational printout
# Force this to be in a standard location so CTest can find it
add_executable(informational informational.cpp)
target_link_libraries(informational PUBLIC CLI11)
set_target_properties(informational PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}"
RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}"
RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_BINARY_DIR}"
RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL "${CMAKE_BINARY_DIR}"
)
# Adding this printout to CTest
file(WRITE "${PROJECT_BINARY_DIR}/CTestCustom.cmake"
"set(CTEST_CUSTOM_PRE_TEST \"${CMAKE_BINARY_DIR}/informational\")"
)
# Add boost to test boost::optional if available
find_package(Boost 1.61)
if(Boost_FOUND)
if(TARGET Boost::boost)
target_link_libraries(informational PRIVATE Boost::boost)
target_link_libraries(OptionalTest PRIVATE Boost::boost)
else()
target_include_directories(informational PRIVATE ${Boost_INCLUDE_DIRS})
target_include_directories(OptionalTest PRIVATE ${Boost_INCLUDE_DIRS})
endif()
target_compile_definitions(informational PRIVATE CLI11_BOOST_OPTIONAL)
target_compile_definitions(OptionalTest PRIVATE CLI11_BOOST_OPTIONAL)
endif()
if(CMAKE_BUILD_TYPE STREQUAL Coverage)
include(CodeCoverage)
setup_target_for_coverage(
NAME CLI11_coverage
EXECUTABLE ctest
DEPENDENCIES
${CLI11_TESTS}
${CLI11_MULTIONLY_TESTS})
endif()