Computer Assisted Medical Intervention Tool Kit  version 5.2
CamiTKTestPassFile.h
Go to the documentation of this file.
1 
12 # declare outputfiles
13 set(CAMITK_TEST_COMMAND_FILE ${CAMITK_TEST_OUTPUT_DIR}/command) # which command is run to test the exectable
14 set(CAMITK_TEST_COMMAND_RESULT_FILE ${CAMITK_TEST_OUTPUT_DIR}/command-result) # the exit result (0=success, 1=failure) of the tested command goes in this file
15 set(CAMITK_TEST_COMMAND_OUTPUT_FILE ${CAMITK_TEST_OUTPUT_DIR}/command-output) # the output of the tested command goes in this files
16 set(CAMITK_TEST_PASS_FILE_COMMAND_FILE ${CAMITK_TEST_OUTPUT_DIR}/test) # which command is run to diff the files
17 set(CAMITK_TEST_PASS_FILE_OUTPUT_FILE ${CAMITK_TEST_OUTPUT_DIR}/test-output) # output of the diff cmake command
18 set(CAMITK_TEST_PASS_FILE_RESULT_FILE ${CAMITK_TEST_OUTPUT_DIR}/test-result) # exit result (0=success, 1=failure)
19 
20 # remove all
21 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})
22 # First run the executable
23 file(WRITE ${CAMITK_TEST_COMMAND_FILE} "${CAMITK_TEST_COMMAND} ${CAMITK_TEST_COMMAND_ARG}")
24 
25 # expands all arguments
26 string(REPLACE " " "" CAMITK_TEST_COMMAND_ARG_LIST ${CAMITK_TEST_COMMAND_ARG})
27 
28 # Run test and get output
30  COMMAND ${CAMITK_TEST_COMMAND} ${CAMITK_TEST_COMMAND_ARG_LIST}
31  RESULT_VARIABLE CAMITK_TEST_COMMAND_RESULT
32  OUTPUT_VARIABLE CAMITK_TEST_COMMAND_OUTPUT
33 )
34 file(WRITE ${CAMITK_TEST_COMMAND_RESULT_FILE} ${CAMITK_TEST_COMMAND_RESULT})
35 file(WRITE ${CAMITK_TEST_COMMAND_OUTPUT_FILE} ${CAMITK_TEST_COMMAND_OUTPUT})
36 
37 # Then compare output with input
38 file(WRITE ${CAMITK_TEST_PASS_FILE_COMMAND_FILE} "${CMAKE_COMMAND} -E compare_files ${CAMITK_TEST_PASS_FILE} ${CAMITK_TEST_COMMAND_OUTPUT_FILE}")
39 
40 
41 # check file exists
42 if (NOT EXISTS ${CAMITK_TEST_PASS_FILE})
43  message(STATUS "[FAIL]")
44  message(FATAL_ERROR "${CAMITK_TEST_NAME}: input file ${CAMITK_TEST_PASS_FILE} not found." )
45 endif()
46 
47 if (NOT EXISTS ${CAMITK_TEST_COMMAND_OUTPUT_FILE})
48  message(STATUS "[FAIL]")
49  message(FATAL_ERROR "${CAMITK_TEST_NAME}: output file ${CAMITK_TEST_COMMAND_OUTPUT_FILE} not found." )
50 endif()
51 
52 
53 message(STATUS "Comparing file \"${CAMITK_TEST_PASS_FILE}\" to \"${CAMITK_TEST_COMMAND_OUTPUT_FILE}\"...")
55  COMMAND ${CMAKE_COMMAND} -E compare_files ${CAMITK_TEST_PASS_FILE} ${CAMITK_TEST_COMMAND_OUTPUT_FILE}
56  RESULT_VARIABLE CAMITK_TEST_PASS_FILE_RESULT
57  OUTPUT_VARIABLE CAMITK_TEST_PASS_FILE_OUTPUT
58  OUTPUT_QUIET
59  ERROR_QUIET
60 )
61 file(WRITE ${CAMITK_TEST_PASS_FILE_OUTPUT_FILE} ${CAMITK_TEST_PASS_FILE_OUTPUT})
62 file(WRITE ${CAMITK_TEST_PASS_FILE_RESULT_FILE} ${CAMITK_TEST_PASS_FILE_RESULT})
63 
64 # check result
65 if( CAMITK_TEST_PASS_FILE_RESULT )
66  message(STATUS "[FAIL]")
67  message(FATAL_ERROR "${CAMITK_TEST_NAME}: ${CAMITK_TEST_COMMAND_OUTPUT_FILE} does not match ${CAMITK_TEST_PASS_FILE}" )
68 else()
69  message(STATUS "[OK]")
70 endif()
if(${CMAKE_VERSION} VERSION_GREATER "3.3" OR ${CMAKE_VERSION} VERSION_EQUAL "3.3") option(CAMITK_INCLUDE_WHAT_YOU_USE "Enable the header analysis on you code
cmake modules macros camitk test endif() add_custom_target(camitk-ce-iwyu COMMAND $
Definition: CamiTKIncludeWhatYouUse.h:37
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
set(CAMITK_TEST_COMMAND_FILE ${CAMITK_TEST_OUTPUT_DIR}/command) set(CAMITK_TEST_COMMAND_RESULT_FILE $
This CMake file run a command, put the command output in a given file and check if the command output...
Definition: CamiTKTestPassFile.h:13