Prefix tests with project name; generate test names if not given

This commit is contained in:
Peter Dimov
2018-09-20 01:30:54 +03:00
parent b41f6c14b9
commit 726ee688d6
2 changed files with 32 additions and 17 deletions

View File

@@ -30,18 +30,33 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
function(boost_test) function(boost_test)
cmake_parse_arguments(PARSE "" "NAME" "SOURCES;LIBRARIES" ${ARGN}) cmake_parse_arguments(_ "" "PREFIX;NAME" "SOURCES;LIBRARIES" ${ARGN})
add_executable(${PARSE_NAME} EXCLUDE_FROM_ALL ${PARSE_SOURCES}) if(NOT __PREFIX)
target_link_libraries(${PARSE_NAME} ${PARSE_LIBRARIES}) set(__PREFIX ${PROJECT_NAME})
endif()
add_test(NAME compile-${PARSE_NAME} COMMAND "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target ${PARSE_NAME}) if(NOT __NAME)
list(GET __SOURCES 0 __NAME)
string(MAKE_C_IDENTIFIER ${__NAME} __NAME)
endif()
add_test(NAME run-${PARSE_NAME} COMMAND ${PARSE_NAME}) set(__NAME ${__PREFIX}-${__NAME})
set_tests_properties(run-${PARSE_NAME} PROPERTIES DEPENDS compile-${PARSE_NAME})
add_executable(${__NAME} EXCLUDE_FROM_ALL ${__SOURCES})
target_link_libraries(${__NAME} ${__LIBRARIES})
add_test(NAME compile-${__NAME} COMMAND "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target ${__NAME})
add_test(NAME run-${__NAME} COMMAND ${__NAME})
set_tests_properties(run-${__NAME} PROPERTIES DEPENDS compile-${__NAME})
endfunction(boost_test) endfunction(boost_test)
endif()
if(COMMAND boost_test)
add_subdirectory(test) add_subdirectory(test)
endif() endif()

View File

@@ -5,19 +5,19 @@
# See accompanying file LICENSE_1_0.txt or copy at # See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt # http://www.boost.org/LICENSE_1_0.txt
boost_test(NAME assert_test SOURCES assert_test.cpp LIBRARIES Boost::assert Boost::core) boost_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(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(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) boost_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 # 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(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(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(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(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(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(SOURCES assert_msg_test2.cpp LIBRARIES Boost::assert Boost::core)
boost_test(NAME quick SOURCES quick.cpp LIBRARIES Boost::assert Boost::core) boost_test(SOURCES quick.cpp LIBRARIES Boost::assert Boost::core)