Add support for testing using CMake

This commit is contained in:
Peter Dimov
2018-09-20 00:55:16 +03:00
parent d6c3159261
commit b41f6c14b9
2 changed files with 58 additions and 0 deletions

View File

@@ -1,4 +1,12 @@
# Copyright 2018 Peter Dimov
#
# Distributed under the Boost Software License, Version 1.0.
#
# See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt
cmake_minimum_required(VERSION 3.5)
project(BoostAssert LANGUAGES CXX)
add_library(boost_assert INTERFACE)
@@ -10,3 +18,30 @@ target_link_libraries(boost_assert
INTERFACE
Boost::config
)
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
add_subdirectory(../config bin/config)
add_subdirectory(../core bin/core)
enable_testing()
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C ${CMAKE_CFG_INTDIR})
function(boost_test)
cmake_parse_arguments(PARSE "" "NAME" "SOURCES;LIBRARIES" ${ARGN})
add_executable(${PARSE_NAME} EXCLUDE_FROM_ALL ${PARSE_SOURCES})
target_link_libraries(${PARSE_NAME} ${PARSE_LIBRARIES})
add_test(NAME compile-${PARSE_NAME} COMMAND "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target ${PARSE_NAME})
add_test(NAME run-${PARSE_NAME} COMMAND ${PARSE_NAME})
set_tests_properties(run-${PARSE_NAME} PROPERTIES DEPENDS compile-${PARSE_NAME})
endfunction(boost_test)
add_subdirectory(test)
endif()

23
test/CMakeLists.txt Normal file
View File

@@ -0,0 +1,23 @@
# Copyright 2018 Peter Dimov
#
# Distributed under the Boost Software License, Version 1.0.
#
# See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt
boost_test(NAME assert_test SOURCES assert_test.cpp LIBRARIES Boost::assert Boost::core)
boost_test(NAME current_function_test SOURCES current_function_test.cpp LIBRARIES Boost::assert Boost::core)
boost_test(NAME verify_test SOURCES verify_test.cpp LIBRARIES Boost::assert Boost::core)
boost_test(NAME assert_is_void_test SOURCES assert_is_void_test.cpp LIBRARIES Boost::assert Boost::core)
# expansion tests are in exp/ so that there is a backslash in the path on Windows
boost_test(NAME assert_exp_test SOURCES exp/assert_exp_test.cpp LIBRARIES Boost::assert Boost::core)
boost_test(NAME assert_msg_exp_test SOURCES exp/assert_msg_exp_test.cpp LIBRARIES Boost::assert Boost::core)
boost_test(NAME verify_exp_test SOURCES exp/verify_exp_test.cpp LIBRARIES Boost::assert Boost::core)
boost_test(NAME verify_msg_exp_test SOURCES exp/verify_msg_exp_test.cpp LIBRARIES Boost::assert Boost::core)
boost_test(NAME assert_test2 SOURCES assert_test2.cpp LIBRARIES Boost::assert Boost::core)
boost_test(NAME assert_msg_test2 SOURCES assert_msg_test2.cpp LIBRARIES Boost::assert Boost::core)
boost_test(NAME quick SOURCES quick.cpp LIBRARIES Boost::assert Boost::core)