2018-12-03 20:28:04 +05:00
|
|
|
|
|
|
|
if(ENABLE_UNIT_TESTS)
|
|
|
|
add_custom_target(unit_tests)
|
|
|
|
|
|
|
|
# Build catch_main test object
|
2018-12-28 17:43:15 +05:00
|
|
|
include_directories(${CATCH_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../../libsrc/include ${SPDLOG_INCLUDE_DIR})
|
2018-12-03 20:28:04 +05:00
|
|
|
add_library(catch_main STATIC main.cpp)
|
|
|
|
set_target_properties(catch_main PROPERTIES CXX_STANDARD 17)
|
|
|
|
add_dependencies(unit_tests catch_main)
|
|
|
|
add_dependencies(catch_main project_catch)
|
|
|
|
|
|
|
|
# ensure the test targets are built before testing
|
|
|
|
add_test(NAME unit_tests_built COMMAND ${CMAKE_COMMAND} --build . --target unit_tests --config ${CMAKE_BUILD_TYPE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../.. )
|
|
|
|
|
|
|
|
macro(add_unit_test name sources)
|
|
|
|
add_executable(test_${name} ${sources} )
|
2018-12-28 17:43:15 +05:00
|
|
|
target_link_libraries(test_${name} ngcore catch_main)
|
2018-12-03 20:28:04 +05:00
|
|
|
|
|
|
|
add_dependencies(unit_tests test_${name})
|
|
|
|
add_test(NAME unit_${name} COMMAND test_${name})
|
|
|
|
set_tests_properties(unit_${name} PROPERTIES DEPENDS unit_tests_built)
|
2019-01-02 22:21:52 +05:00
|
|
|
|
|
|
|
if(ENABLE_CPP_CORE_GUIDELINES_CHECK)
|
|
|
|
set_target_properties(test_${name} PROPERTIES CXX_CLANG_TIDY "${DO_CLANG_TIDY}")
|
|
|
|
endif(ENABLE_CPP_CORE_GUIDELINES_CHECK)
|
2018-12-03 20:28:04 +05:00
|
|
|
endmacro()
|
|
|
|
|
|
|
|
add_unit_test(archive archive.cpp)
|
2019-01-02 22:21:52 +05:00
|
|
|
add_unit_test(symboltable symboltable.cpp)
|
2018-12-05 18:20:24 +05:00
|
|
|
add_unit_test(version version.cpp)
|
2018-12-08 20:10:29 +05:00
|
|
|
|
2018-12-03 20:28:04 +05:00
|
|
|
endif(ENABLE_UNIT_TESTS)
|