2017-08-25 18:19:58 +00:00
|
|
|
option(JSON_Sanitizer "Build test suite with Clang sanitizer" OFF)
|
|
|
|
option(JSON_Valgrind "Execute test suite with Valgrind" OFF)
|
2017-08-25 19:29:27 +00:00
|
|
|
option(JSON_NoExceptions "Build test suite without exceptions" OFF)
|
2017-08-25 18:12:21 +00:00
|
|
|
|
|
|
|
if(JSON_Sanitizer)
|
2017-08-25 18:19:58 +00:00
|
|
|
message(STATUS "Building test suite with Clang sanitizer")
|
2017-08-25 18:12:21 +00:00
|
|
|
if(NOT MSVC)
|
2017-08-26 06:20:37 +00:00
|
|
|
set(CMAKE_CXX_FLAGS "-std=c++11 -g -O2 -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer")
|
2017-08-25 18:12:21 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(JSON_Valgrind)
|
|
|
|
find_program(CMAKE_MEMORYCHECK_COMMAND valgrind)
|
2017-08-25 18:19:58 +00:00
|
|
|
message(STATUS "Executing test suite with Valgrind (${CMAKE_MEMORYCHECK_COMMAND})")
|
2017-08-25 18:12:21 +00:00
|
|
|
set(MEMORYCHECK_COMMAND_OPTIONS "--error-exitcode=1 --leak-check=full")
|
|
|
|
set(memcheck_command "${CMAKE_MEMORYCHECK_COMMAND} ${CMAKE_MEMORYCHECK_COMMAND_OPTIONS}")
|
|
|
|
separate_arguments(memcheck_command)
|
|
|
|
endif()
|
|
|
|
|
2017-08-25 19:29:27 +00:00
|
|
|
if(JSON_NoExceptions)
|
|
|
|
message(STATUS "Building test suite without exceptions")
|
|
|
|
if(NOT MSVC)
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DJSON_NOEXCEPTION")
|
|
|
|
endif()
|
|
|
|
set(CATCH_TEST_FILTER -e)
|
|
|
|
endif()
|
|
|
|
|
2017-08-25 16:06:22 +00:00
|
|
|
#############################################################################
|
|
|
|
# Catch library with the main function to speed up build
|
|
|
|
#############################################################################
|
|
|
|
|
2017-02-12 11:46:54 +00:00
|
|
|
add_library(catch_main OBJECT
|
|
|
|
"src/unit.cpp"
|
|
|
|
)
|
|
|
|
set_target_properties(catch_main PROPERTIES
|
|
|
|
CXX_STANDARD 11
|
|
|
|
CXX_STANDARD_REQUIRED ON
|
2017-08-25 16:06:22 +00:00
|
|
|
COMPILE_DEFINITIONS "$<$<CXX_COMPILER_ID:MSVC>:_SCL_SECURE_NO_WARNINGS>"
|
|
|
|
COMPILE_OPTIONS "$<$<CXX_COMPILER_ID:MSVC>:/EHsc;$<$<CONFIG:Release>:/Od>>"
|
2017-02-12 11:46:54 +00:00
|
|
|
)
|
|
|
|
target_include_directories(catch_main PRIVATE "thirdparty/catch")
|
|
|
|
|
2017-08-25 16:06:22 +00:00
|
|
|
#############################################################################
|
|
|
|
# one executable for each unit test file
|
|
|
|
#############################################################################
|
2016-05-11 00:25:54 +00:00
|
|
|
|
2017-08-25 16:06:22 +00:00
|
|
|
file(GLOB files "src/unit-*.cpp")
|
|
|
|
foreach(file ${files})
|
|
|
|
get_filename_component(file_basename ${file} NAME_WE)
|
|
|
|
string(REGEX REPLACE "unit-([^$]+)" "test-\\1" testcase ${file_basename})
|
2016-05-11 00:25:54 +00:00
|
|
|
|
2017-08-25 16:06:22 +00:00
|
|
|
add_executable(${testcase} $<TARGET_OBJECTS:catch_main> ${file})
|
|
|
|
set_target_properties(${testcase} PROPERTIES
|
|
|
|
CXX_STANDARD 11
|
|
|
|
CXX_STANDARD_REQUIRED ON
|
|
|
|
COMPILE_DEFINITIONS "$<$<CXX_COMPILER_ID:MSVC>:_SCL_SECURE_NO_WARNINGS>"
|
|
|
|
COMPILE_OPTIONS "$<$<CXX_COMPILER_ID:MSVC>:/EHsc;$<$<CONFIG:Release>:/Od>>"
|
2017-02-12 11:46:54 +00:00
|
|
|
)
|
|
|
|
|
2017-08-25 16:06:22 +00:00
|
|
|
target_compile_definitions(${testcase} PRIVATE CATCH_CONFIG_FAST_COMPILE)
|
|
|
|
target_include_directories(${testcase} PRIVATE "thirdparty/catch")
|
|
|
|
target_link_libraries(${testcase} ${JSON_TARGET_NAME})
|
|
|
|
|
|
|
|
if(NOT MSVC)
|
2017-08-25 18:12:21 +00:00
|
|
|
set_target_properties(${testcase} PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated -Wno-float-equal")
|
2017-08-25 16:06:22 +00:00
|
|
|
endif()
|
2016-05-11 00:38:52 +00:00
|
|
|
|
2017-08-25 16:06:22 +00:00
|
|
|
include(cotire OPTIONAL)
|
|
|
|
if(COMMAND cotire)
|
|
|
|
cotire(${testcase})
|
|
|
|
endif()
|
2017-02-12 11:46:54 +00:00
|
|
|
|
2017-08-25 16:06:22 +00:00
|
|
|
add_test(NAME "${testcase}_default"
|
2017-08-25 19:29:27 +00:00
|
|
|
COMMAND ${testcase} ${CATCH_TEST_FILTER}
|
2017-08-25 16:06:22 +00:00
|
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
2017-02-12 11:46:54 +00:00
|
|
|
)
|
2017-08-25 16:06:22 +00:00
|
|
|
set_tests_properties("${testcase}_default" PROPERTIES LABELS "default")
|
2017-02-12 11:46:54 +00:00
|
|
|
|
2017-08-25 16:06:22 +00:00
|
|
|
add_test(NAME "${testcase}_all"
|
2017-08-25 19:29:27 +00:00
|
|
|
COMMAND ${testcase} ${CATCH_TEST_FILTER} "*"
|
2017-08-25 16:06:22 +00:00
|
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
|
|
|
)
|
|
|
|
set_tests_properties("${testcase}_all" PROPERTIES LABELS "all")
|
2017-08-25 18:12:21 +00:00
|
|
|
|
|
|
|
if(JSON_Valgrind)
|
|
|
|
add_test(NAME "${testcase}_valgrind"
|
2017-08-25 19:29:27 +00:00
|
|
|
COMMAND ${memcheck_command} ${CMAKE_CURRENT_BINARY_DIR}/${testcase} ${CATCH_TEST_FILTER}
|
2017-08-25 18:12:21 +00:00
|
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
|
|
|
)
|
|
|
|
set_tests_properties("${testcase}_valgrind" PROPERTIES LABELS "valgrind")
|
|
|
|
endif()
|
|
|
|
|
2017-08-25 16:06:22 +00:00
|
|
|
endforeach()
|