Commit d421c706 authored by Dennis Gläser's avatar Dennis Gläser
Browse files

rename test function

parent ea14915c
# The code in this file has been inspired or copied from the dune-common
# The code in this file has been inspired by the dune-common
# module of the dune project (https://gitlab.dune-project.org/core/dune-common),
# in particular from the following file:
# https://gitlab.dune-project.org/core/dune-common/-/blob/master/cmake/modules/DuneTestMacros.cmake
......@@ -30,36 +30,28 @@ function(frackit_register_test_labels)
endforeach()
endfunction(frackit_register_test_labels)
function(frackit_declare_test_label)
if(NOT DEFINED FRACKIT_TEST_LABEL_DEPR_WARNING)
message(WARNING "This function is deprecated. Use frackit_register_test_labels instead!")
set(FRACKIT_TEST_LABEL_DEPR_WARNING)
endif()
frackit_register_test_labels(${ARGV})
endfunction(frackit_declare_test_label)
# function to add a test
function(frackit_add_test)
# function to register a test
function(frackit_register_test)
include(CMakeParseArguments)
set(SINGLEARGS NAME TARGET TIMEOUT)
set(MULTIARGS SOURCES COMPILE_DEFINITIONS COMPILE_FLAGS CMD_ARGS COMMAND CMAKE_GUARD LABELS)
cmake_parse_arguments(ADDTEST "${OPTIONS}" "${SINGLEARGS}" "${MULTIARGS}" ${ARGN})
set(MULTIARGS SOURCES COMPILE_DEFINITIONS CMD_ARGS COMMAND LABELS)
cmake_parse_arguments(ADDTEST "" "${SINGLEARGS}" "${MULTIARGS}" ${ARGN})
# Check whether the parser produced any errors
if(ADDTEST_UNPARSED_ARGUMENTS)
message(WARNING "Unrecognized arguments ('${ADDTEST_UNPARSED_ARGUMENTS}') for frackit_add_test!")
message(WARNING "Unparsed arguments ('${ADDTEST_UNPARSED_ARGUMENTS}') for frackit_register_test!")
endif()
# Check input for validity and apply defaults
# catch erroneous argument combos
if(NOT ADDTEST_SOURCES AND NOT ADDTEST_TARGET)
message(FATAL_ERROR "You need to specify either the SOURCES or the TARGET option for frackit_add_test!")
message(FATAL_ERROR "Neither SOURCES nor TARGET was set for frackit_register_test!")
endif()
if(ADDTEST_SOURCES AND ADDTEST_TARGET)
message(FATAL_ERROR "You cannot specify both SOURCES and TARGET for frackit_add_test")
message(FATAL_ERROR "You cannot set both SOURCES and TARGET for frackit_register_test")
endif()
if(NOT ADDTEST_NAME)
message(FATAL_ERROR "You have to define a name for the test!")
endif()
if(NOT ADDTEST_COMMAND)
set(ADDTEST_COMMAND ${ADDTEST_NAME})
endif()
......@@ -78,23 +70,41 @@ function(frackit_add_test)
set(ADDTEST_TARGET ${ADDTEST_NAME})
endif()
# Now add the actual test
# Add the actual test
add_test(NAME ${ADDTEST_NAME} COMMAND "${ADDTEST_COMMAND}" ${ADDTEST_CMD_ARGS})
# Make sure to exclude the target from all
# Exclude the target from all
set_property(TARGET ${ADDTEST_TARGET} PROPERTY EXCLUDE_FROM_ALL 1)
# make sure each label exists and its name is acceptable
frackit_declare_test_label(LABELS ${ADDTEST_LABELS})
frackit_register_test_labels(LABELS ${ADDTEST_LABELS})
# Set the labels on this new test
set_tests_properties(${ADDTEST_NAME} PROPERTIES LABELS "${ADDTEST_LABELS}")
# Have build_tests and build_${label}_tests depend on the given target in
# order to trigger the build correctly
# register test within the custom targets
add_dependencies(build_tests ${ADDTEST_TARGET})
foreach(label IN LISTS ADDTEST_LABELS)
add_dependencies(build_${label}_tests ${ADDTEST_TARGET})
endforeach()
# Set the labels on the test
set_tests_properties(${ADDTEST_NAME} PROPERTIES LABELS "${ADDTEST_LABELS}")
endfunction(frackit_register_test)
#######################
# deprecated functions
function(frackit_declare_test_label)
if(NOT DEFINED FRACKIT_TEST_LABEL_DEPR_WARNING)
message(WARNING "This function is deprecated. Use frackit_register_test_labels instead!")
set(FRACKIT_TEST_LABEL_DEPR_WARNING)
endif()
frackit_register_test_labels(${ARGV})
endfunction(frackit_declare_test_label)
function(frackit_add_test)
if(NOT DEFINED FRACKIT_TEST_DEPR_WARNING)
message(WARNING "This function is deprecated. Use frackit_register_test instead!")
set(FRACKIT_TEST_DEPR_WARNING)
endif()
frackit_register_test(${ARGV})
endfunction(frackit_add_test)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment