Computer Assisted Medical Intervention Tool Kit  version 5.2
CamiTKAddTest.h
Go to the documentation of this file.
1 #
52  set(options "")
53  set(oneValueArgs EXECUTABLE_ARGS PASS_FILE PASS_REGULAR_EXPRESSION FAIL_REGULAR_EXPRESSION PASS_FILE_OUTPUT TEST_SUFFIX PROJECT_NAME)
54  set(multiValueArgs "")
55  cmake_parse_arguments(CAMITK_ADD_TEST "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
56 
57  math(EXPR CAMITK_TEST_ID "${CAMITK_TEST_ID} + 1")
58  set(CAMITK_TEST_NAME "${CAMITK_ADD_TEST_PROJECT_NAME}${CAMITK_ADD_TEST_TEST_SUFFIX}${CAMITK_TEST_ID}")
59  set(CAMITK_TEST_LIST ${CAMITK_TEST_LIST} ${CAMITK_TEST_NAME})
60 
61  # determine cmake macro path
62  if (NOT EXISTS ${SDK_TOP_LEVEL_SOURCE_DIR})
63  # this macro is called outside the sdk
64  set(CAMITK_CMAKE_MACRO_PATH ${CAMITK_CMAKE_DIR}/macros/camitk/test)
65  if(NOT IS_DIRECTORY ${CAMITK_CMAKE_MACRO_PATH})
66  # inside communityedition but not in sdk (modeling or imaging)
67  set(CAMITK_CMAKE_MACRO_PATH ${CMAKE_SOURCE_DIR}/sdk/cmake/modules/macros/camitk/test)
68  endif()
69  else()
70  # directly use the macro source dir
71  set(CAMITK_CMAKE_MACRO_PATH ${SDK_TOP_LEVEL_SOURCE_DIR}/cmake/modules/macros/camitk/test)
72  endif()
73 
74  # create test output directory
75  set(CAMITK_TEST_OUTPUT_DIR "${CMAKE_BINARY_DIR}/Testing/Temporary/${CAMITK_TEST_NAME}")
76  execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${CAMITK_TEST_OUTPUT_DIR})
77 
78  # check which test is to be done
79  if(CAMITK_ADD_TEST_PASS_FILE)
80  add_test(NAME ${CAMITK_TEST_NAME}
81  COMMAND ${CMAKE_COMMAND}
82  -DCAMITK_TEST_COMMAND=${CAMITK_INIT_TEST_EXECUTABLE}
83  -DCAMITK_TEST_COMMAND_ARG=${CAMITK_ADD_TEST_EXECUTABLE_ARGS}
84  -DCAMITK_TEST_PASS_FILE=${CAMITK_ADD_TEST_PASS_FILE}
85  -DCAMITK_TEST_OUTPUT_DIR=${CAMITK_TEST_OUTPUT_DIR}
86  -DCAMITK_TEST_NAME=${CAMITK_TEST_NAME}
87  -P ${CAMITK_CMAKE_MACRO_PATH}/CamiTKTestPassFile.cmake
88  WORKING_DIRECTORY ${CMAKE_BINARY_DIR} # needs to be at the top of the CamiTK module repository
89  )
90  elseif(CAMITK_ADD_TEST_PASS_FILE_OUTPUT)
91  add_test(NAME ${CAMITK_TEST_NAME}
92  COMMAND ${CMAKE_COMMAND}
93  -DCAMITK_TEST_COMMAND=${CAMITK_INIT_TEST_EXECUTABLE}
94  -DCAMITK_TEST_COMMAND_ARG=${CAMITK_ADD_TEST_EXECUTABLE_ARGS}
95  -DCAMITK_TEST_PASS_FILE=${CAMITK_ADD_TEST_PASS_FILE_OUTPUT}
96  -DCAMITK_TEST_OUTPUT_DIR=${CAMITK_TEST_OUTPUT_DIR}
97  -DCAMITK_TEST_NAME=${CAMITK_TEST_NAME}
98  -P ${CAMITK_CMAKE_MACRO_PATH}/CamiTKTestCompareFile.cmake
99  WORKING_DIRECTORY ${CMAKE_BINARY_DIR} # needs to be at the top of the CamiTK module repository
100  )
101  else()
102  # set output files for more advanced checking/debugging
103  set(CAMITK_TEST_COMMAND_FILE ${CAMITK_TEST_OUTPUT_DIR}/command) # which command is run to test the exectable
104  # cleanup
105  execute_process(COMMAND ${CMAKE_COMMAND} -E remove -f ${CAMITK_TEST_COMMAND_FILE} )
106  file(WRITE ${CAMITK_TEST_COMMAND_FILE} "Test command: ${CAMITK_INIT_TEST_EXECUTABLE} ${CAMITK_ADD_TEST_EXECUTABLE_ARGS}\nPASS_REGULAR_EXPRESSION: '${CAMITK_ADD_TEST_PASS_REGULAR_EXPRESSION}'\n")
107 
108  if(CAMITK_ADD_TEST_EXECUTABLE_ARGS)
109  # expands all arguments
110  string(REPLACE " " "" CAMITK_TEST_COMMAND_ARG_LIST ${CAMITK_ADD_TEST_EXECUTABLE_ARGS})
111  else()
112  set(CAMITK_TEST_COMMAND_ARG_LIST)
113  endif()
114 
115  # add the simple test command
116  add_test(NAME ${CAMITK_TEST_NAME}
117  COMMAND ${CAMITK_INIT_TEST_EXECUTABLE} ${CAMITK_TEST_COMMAND_ARG_LIST}
118  WORKING_DIRECTORY ${CMAKE_BINARY_DIR} # needs to be at the top of the CamiTK module repository
119  )
120 
121  # add properties if needed
122  if(CAMITK_ADD_TEST_PASS_REGULAR_EXPRESSION)
123  set_tests_properties(${CAMITK_TEST_NAME} PROPERTIES PASS_REGULAR_EXPRESSION ${CAMITK_ADD_TEST_PASS_REGULAR_EXPRESSION})
124  else()
125  if(CAMITK_ADD_TEST_FAIL_REGULAR_EXPRESSION)
126  set_tests_properties(${CAMITK_TEST_NAME} PROPERTIES FAIL_REGULAR_EXPRESSION ${CAMITK_ADD_TEST_FAIL_REGULAR_EXPRESSION})
127  endif()
128  endif()
129  endif()
130 
131  # set the label for tests
132  if( CAMITK_ADD_TEST_PROJECT_NAME )
133  set_tests_properties( ${CAMITK_TEST_NAME} PROPERTIES LABELS ${CAMITK_ADD_TEST_PROJECT_NAME} )#associate tests to a project name in CDash
134  else()
135  set_tests_properties( ${CAMITK_TEST_NAME} PROPERTIES LABELS ${CAMITK_TEST_BASENAME} )
136  endif()
137 
138 end(){)
cmake modules macros camitk test endif() add_custom_target(camitk-ce-iwyu COMMAND $
Definition: CamiTKIncludeWhatYouUse.h:37
#define a
iwyu out CACHE PATH Output filename for include what you use set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${IWYU_EXECUTABLE}) if(NOT EXISTS $
Definition: CamiTKIncludeWhatYouUse.h:22
test result execute_process(COMMAND ${CMAKE_COMMAND} -E remove -f ${CAMITK_TEST_COMMAND_FILE} ${CAMITK_TEST_COMMAND_RESULT_FILE} ${CAMITK_TEST_COMMAND_OUTPUT_FILE} ${CAMITK_TEST_PASS_FILE_COMMAND_FILE} ${CAMITK_TEST_PASS_FILE_OUTPUT_FILE} ${CAMITK_TEST_PASS_FILE_RESULT_FILE}) file(WRITE $
Definition: CamiTKTestPassFile.h:21
camitk_add_test()
camitk_add_test is a macro to add a new test to the CTest infrastructure It encapsulates CMake add_te...
Definition: CamiTKAddTest.h:51
Definition: Action.cpp:36