Commit 5cbb651f authored by Emmanuel Promayon's avatar Emmanuel Promayon
Browse files

FIXED now test can be ran multiple times in the same build dir

parent 9565451c
......@@ -10,6 +10,6 @@ camitk_extension(ACTION_EXTENSION
set(SHIBOKEN_CAMITK_SDK_PATH ${SHIBOKEN_CAMITK_SDK_PATH}:${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "")
# add a specific test to run the action, save the output and compare it to expected
camitk_add_test_actionstatemachine(NAME "action-reconstruction-regression-test"
CAMITK_SCXML "action-reconstruction-regression-test.xml"
EXPECTED_OUTPUT_FILES "action-reconstruction-output-test.vtk")
\ No newline at end of file
camitk_add_test_actionstatemachine(NAME action-reconstruction-regression-test
CAMITK_SCXML action-reconstruction-regression-test.xml
EXPECTED_OUTPUT_FILES action-reconstruction-output-test.vtk)
......@@ -11,7 +11,7 @@
#! \code
#! camitk_add_test_actionstatemachine(NAME "testName"
#! CAMITK_SCXML "file.xml"
#! EXPECTED_OUTPUT_FILES "file1;file2;file3;..."
#! EXPECTED_OUTPUT_FILES file1 file2 file3...
#! )
#! \endcode
#!
......@@ -34,8 +34,8 @@
macro(camitk_add_test_actionstatemachine)
set(options "")
set(oneValueArgs NAME CAMITK_SCXML EXPECTED_OUTPUT_FILES)
set(multiValueArgs "")
set(oneValueArgs NAME CAMITK_SCXML)
set(multiValueArgs EXPECTED_OUTPUT_FILES)
cmake_parse_arguments(CAMITK_ADD_TEST_ASM "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
# determine cmake macro path
......@@ -74,7 +74,7 @@ macro(camitk_add_test_actionstatemachine)
# copy the corresponding file to the temp directory
# message("===== Input File = ${INPUT_FILE_NAME}")
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/testdata/${INPUT_FILE_NAME}
DESTINATION ${CAMITK_TEST_OUTPUT_DIR})
DESTINATION ${CAMITK_TEST_OUTPUT_DIR})
endforeach()
# Finally write the file in the temp directory
......@@ -86,7 +86,7 @@ macro(camitk_add_test_actionstatemachine)
# And copy the expected output files
foreach(EXPECTED_OUTPUT_FILE ${CAMITK_ADD_TEST_ASM_EXPECTED_OUTPUT_FILES})
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/testdata/${EXPECTED_OUTPUT_FILE}
DESTINATION ${CAMITK_TEST_OUTPUT_DIR})
DESTINATION ${CAMITK_TEST_OUTPUT_DIR})
endforeach()
#-- run actionstatemachine
......
......@@ -39,8 +39,16 @@ set(CAMITK_TEST_EXPECTED_FILE_COMMAND_FILE ${CAMITK_TEST_OUTPUT_DIR}/test) # whi
set(CAMITK_TEST_EXPECTED_FILE_OUTPUT_FILE ${CAMITK_TEST_OUTPUT_DIR}/test-output) # output of the diff cmake command
set(CAMITK_TEST_EXPECTED_FILE_RESULT_FILE ${CAMITK_TEST_OUTPUT_DIR}/test-result) # exit result (0=success, 1=failure)
# clean/remove all output files
file(REMOVE_RECURSE ${CAMITK_TEST_COMMAND_FILE} ${CAMITK_TEST_COMMAND_RESULT_FILE} ${CAMITK_TEST_COMMAND_OUTPUT_FILE} ${CAMITK_TEST_EXPECTED_FILE_COMMAND_FILE} ${CAMITK_TEST_EXPECTED_FILE_OUTPUT_FILE} ${CAMITK_TEST_EXPECTED_FILE_RESULT_FILE})
# clean/remove all output files and previous test attempt
unset(PREVIOUS_ATTEMPTS)
file(GLOB ALL_OUTPUT_FILES ${CAMITK_TEST_OUTPUT_DIR}/*)
foreach(POTENTIAL_DIR ${ALL_OUTPUT_FILES})
# only remove subdirectories (as they are previous attempts of running the test and should be asm output directory)
if(IS_DIRECTORY ${POTENTIAL_DIR})
list(APPEND PREVIOUS_ATTEMPTS ${POTENTIAL_DIR})
endif()
endforeach()
file(REMOVE_RECURSE ${CAMITK_TEST_COMMAND_FILE} ${CAMITK_TEST_COMMAND_RESULT_FILE} ${CAMITK_TEST_COMMAND_OUTPUT_FILE} ${CAMITK_TEST_EXPECTED_FILE_COMMAND_FILE} ${CAMITK_TEST_EXPECTED_FILE_OUTPUT_FILE} ${CAMITK_TEST_EXPECTED_FILE_RESULT_FILE} ${PREVIOUS_ATTEMPTS})
#-- First run the executable
# Build the command file (so the user can retrieve/review it later)
......@@ -58,7 +66,7 @@ execute_process(
file(WRITE ${CAMITK_TEST_COMMAND_RESULT_FILE} ${CAMITK_TEST_COMMAND_RESULT})
file(WRITE ${CAMITK_TEST_COMMAND_OUTPUT_FILE} ${CAMITK_TEST_COMMAND_OUTPUT})
set(CAMITK_TEST_EXPECTED_FILE_OUTPUT)
set(CAMITK_TEST_EXPECTED_FILE_OUTPUT "Action state machine regression test called with:\n - CAMITK_TEST_NAME=${CAMITK_TEST_NAME}\n - CAMITK_TEST_COMMAND=${CMAKE_BINARY_DIR}/bin/camitk-actionstatemachine\n - CAMITK_TEST_COMMAND_ARG=${CAMITK_TEST_COMMAND_ARG}\n - CAMITK_TEST_EXPECTED_FILES=${CAMITK_TEST_EXPECTED_FILES}\n - CAMITK_TEST_OUTPUT_DIR=${CAMITK_TEST_OUTPUT_DIR}\n")
set(CAMITK_TEST_EXPECTED_FILE_RESULT 0)
set(CAMITK_TEST_EXPECTED_FILE_COMMAND)
set(CAMITK_TEST_FAILED_FILE)
......@@ -67,6 +75,7 @@ set(CAMITK_TEST_FAILED_FILE)
foreach(EXPECTED_OUTPUT_FILE ${CAMITK_TEST_EXPECTED_FILES})
# find the same file in the asm output directory (*T*)
file(GLOB_RECURSE OUTPUT_FILE "${CAMITK_TEST_OUTPUT_DIR}/*T*/${EXPECTED_OUTPUT_FILE}")
# compare the files
execute_process(
COMMAND ${CMAKE_COMMAND} -E compare_files ${OUTPUT_FILE} ${CAMITK_TEST_OUTPUT_DIR}/${EXPECTED_OUTPUT_FILE}
......@@ -75,9 +84,10 @@ foreach(EXPECTED_OUTPUT_FILE ${CAMITK_TEST_EXPECTED_FILES})
OUTPUT_QUIET
ERROR_QUIET
)
# update the output variables
# update the output variables (command, output and result)
set(CAMITK_TEST_EXPECTED_FILE_OUTPUT
"${CAMITK_TEST_EXPECTED_FILE_OUTPUT}=================================================\ncompare ${OUTPUT_FILE} with ${CAMITK_TEST_OUTPUT_DIR}/${EXPECTED_OUTPUT_FILE}\nOutput:\n${CAMITK_TEST_EXPECTED_FILE_OUTPUT_SINGLE}\n")
"${CAMITK_TEST_EXPECTED_FILE_OUTPUT}=================================================\nComparing ${OUTPUT_FILE} with ${CAMITK_TEST_OUTPUT_DIR}/${EXPECTED_OUTPUT_FILE}\nOutput:\n${CAMITK_TEST_EXPECTED_FILE_OUTPUT_SINGLE}\n")
set(CAMITK_TEST_EXPECTED_FILE_COMMAND
"${CAMITK_TEST_EXPECTED_FILE_COMMAND}${CMAKE_COMMAND} -E compare_files ${OUTPUT_FILE} ${CAMITK_TEST_OUTPUT_DIR}/${EXPECTED_OUTPUT_FILE}\n")
if(CAMITK_TEST_EXPECTED_FILE_RESULT_SINGLE)
......@@ -89,12 +99,16 @@ foreach(EXPECTED_OUTPUT_FILE ${CAMITK_TEST_EXPECTED_FILES})
endif()
endforeach()
# write everything to the test-command, test-output and test-result files
#-- write everything to the test-command, test-output and test-result files
# These information detail the results for an easier diagnostic by a human
file(WRITE ${CAMITK_TEST_EXPECTED_FILE_COMMAND_FILE} ${CAMITK_TEST_EXPECTED_FILE_COMMAND})
file(WRITE ${CAMITK_TEST_EXPECTED_FILE_OUTPUT_FILE} ${CAMITK_TEST_EXPECTED_FILE_OUTPUT})
file(WRITE ${CAMITK_TEST_EXPECTED_FILE_RESULT_FILE} ${CAMITK_TEST_EXPECTED_FILE_RESULT})
#-- check result
if( CAMITK_TEST_EXPECTED_FILE_RESULT )
message(SEND_ERROR "${CAMITK_TEST_NAME}: output file(s) do not match:\n${CAMITK_TEST_FAILED_FILE}See ${CAMITK_TEST_EXPECTED_FILE_OUTPUT_FILE} for more information" )
message("[FAIL]")
message(FATAL_ERROR "${CAMITK_TEST_NAME}: (one or more) output file do(es) not match the corresponding expected file\nSee ${CAMITK_TEST_EXPECTED_FILE_OUTPUT_FILE} for more information" )
else()
message("[OK]")
endif()
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