From b41f6c14b99cc162dbf222eb8fa1680a49056b3c Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Thu, 20 Sep 2018 00:55:16 +0300 Subject: [PATCH] Add support for testing using CMake --- CMakeLists.txt | 35 +++++++++++++++++++++++++++++++++++ test/CMakeLists.txt | 23 +++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 test/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 947a4b5..0f0fd6c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..ee0316b --- /dev/null +++ b/test/CMakeLists.txt @@ -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)