Enable testing in CMakeLists.txt

* Per instructions by @SlavSlavov in https://github.com/HowardHinnant/date/pull/278
This commit is contained in:
Howard Hinnant
2018-01-28 18:40:46 -05:00
parent 040eed838b
commit 4ada98d247

View File

@@ -4,11 +4,10 @@ project( date_prj )
find_package( Threads REQUIRED )
enable_testing( )
option( USE_SYSTEM_TZ_DB "Use the operating system's timezone database" OFF )
option( USE_TZ_DB_IN_DOT "Save the timezone database in the current folder" OFF )
option( BUILD_TZ_STATIC "Build a static version of library" ON )
option( ENABLE_DATE_TESTING "Enable unit tests" ON )
function( print_option OPT )
if ( NOT DEFINED PRINT_OPTION_CURR_${OPT} OR ( NOT PRINT_OPTION_CURR_${OPT} STREQUAL ${OPT} ) )
@@ -21,6 +20,7 @@ endfunction( )
print_option( USE_SYSTEM_TZ_DB )
print_option( USE_TZ_DB_IN_DOT )
print_option( BUILD_TZ_STATIC )
print_option( ENABLE_DATE_TESTING )
set( HEADER_FOLDER "include" )
set( SOURCE_FOLDER "src" )
@@ -100,10 +100,14 @@ install( EXPORT DateConfig DESTINATION ${DEF_INSTALL_CMAKE_DIR} )
install( TARGETS tz DESTINATION lib )
install( DIRECTORY ${HEADER_FOLDER}/ DESTINATION include/ )
add_custom_target( testit COMMAND ${CMAKE_CTEST_COMMAND} )
if ( ENABLE_DATE_TESTING )
add_dependencies( testit tz )
function( add_pass_tests TEST_GLOB TEST_PREFIX )
enable_testing( )
add_custom_target( testit COMMAND ${CMAKE_CTEST_COMMAND} )
add_dependencies( testit tz )
function( add_pass_tests TEST_GLOB TEST_PREFIX )
file( GLOB_RECURSE FILENAMES ${TEST_GLOB} )
include_directories( "${HEADER_FOLDER}/date" )
@@ -121,9 +125,9 @@ function( add_pass_tests TEST_GLOB TEST_PREFIX )
add_dependencies( testit ${BIN_NAME} )
endif( )
endforeach( )
endfunction( )
endfunction( )
function( add_fail_tests TEST_GLOB TEST_PREFIX )
function( add_fail_tests TEST_GLOB TEST_PREFIX )
file( GLOB_RECURSE FILENAMES ${TEST_GLOB} )
foreach( TEST_FILE ${FILENAMES} )
@@ -147,10 +151,10 @@ function( add_fail_tests TEST_GLOB TEST_PREFIX )
#set_tests_properties( ${TST_NAME} PROPERTIES WILL_FAIL TRUE)
add_dependencies( testit ${BIN_NAME} )
endforeach( )
endfunction( )
endfunction( )
file( GLOB children RELATIVE "${PROJECT_SOURCE_DIR}/${TEST_FOLDER}" "${PROJECT_SOURCE_DIR}/${TEST_FOLDER}/*" )
foreach( child ${children} )
file( GLOB children RELATIVE "${PROJECT_SOURCE_DIR}/${TEST_FOLDER}" "${PROJECT_SOURCE_DIR}/${TEST_FOLDER}/*" )
foreach( child ${children} )
if( IS_DIRECTORY "${PROJECT_SOURCE_DIR}/${TEST_FOLDER}/${child}" )
set( CUR_FOLDER "${PROJECT_SOURCE_DIR}/${TEST_FOLDER}/${child}" )
add_pass_tests( "${CUR_FOLDER}/*.cpp" ${child} )
@@ -158,5 +162,5 @@ foreach( child ${children} )
add_fail_tests( "${CUR_FOLDER}/*.fail.cpp" ${child} )
endif( )
endif( )
endforeach( )
endforeach( )
endif( )