hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 1 | # Arguments:
|
| 2 | # - COMMAND: the command to run with all it's arguments
|
| 3 | # - TEST_MODE: NORMAL/VALGRIND/COLLECT/COMPARE
|
| 4 | # - TEST_OUTPUT_FILE: the file to/from which to write/read the output of the test
|
| 5 | # - TEST_TEMP_FILE: the temp file for the current test output used in COMPARE mode
|
| 6 | # To run something through this script use cmake like this:
|
| 7 | # cmake -DCOMMAND=path/to/my.exe -arg1 -arg2 -DTEST_MODE=VALGRIND -P path/to/exec_test.cmake
|
| 8 |
|
| 9 | #message("COMMAND: ${COMMAND}")
|
| 10 | #message("TEST_MODE: ${TEST_MODE}")
|
| 11 | #message("TEST_OUTPUT_FILE: ${TEST_OUTPUT_FILE}")
|
| 12 | #message("TEST_TEMP_FILE: ${TEST_TEMP_FILE}")
|
| 13 |
|
| 14 | string(REPLACE " " ";" COMMAND_LIST ${COMMAND})
|
| 15 | set(cmd COMMAND ${COMMAND_LIST} RESULT_VARIABLE CMD_RESULT)
|
| 16 | if("${TEST_MODE}" STREQUAL "COLLECT")
|
| 17 | list(APPEND cmd OUTPUT_FILE ${TEST_OUTPUT_FILE} ERROR_FILE ${TEST_OUTPUT_FILE})
|
| 18 | elseif("${TEST_MODE}" STREQUAL "COMPARE")
|
| 19 | list(APPEND cmd OUTPUT_FILE ${TEST_TEMP_FILE} ERROR_FILE ${TEST_TEMP_FILE})
|
| 20 | endif()
|
| 21 |
|
| 22 | execute_process(${cmd})
|
| 23 |
|
| 24 | # fix line endings
|
| 25 | if("${TEST_MODE}" STREQUAL "COLLECT" AND NOT CMAKE_HOST_UNIX)
|
| 26 | execute_process(COMMAND dos2unix ${TEST_OUTPUT_FILE})
|
| 27 | endif()
|
| 28 |
|
| 29 | if("${TEST_MODE}" STREQUAL "COMPARE")
|
| 30 | if(NOT CMAKE_HOST_UNIX)
|
| 31 | execute_process(COMMAND dos2unix ${TEST_TEMP_FILE})
|
| 32 | endif()
|
| 33 |
|
| 34 | execute_process(COMMAND ${CMAKE_COMMAND} -E compare_files ${TEST_OUTPUT_FILE} ${TEST_TEMP_FILE} RESULT_VARIABLE cmp_result)
|
| 35 |
|
| 36 | if(cmp_result)
|
| 37 | file(READ ${TEST_OUTPUT_FILE} orig)
|
| 38 | file(READ ${TEST_TEMP_FILE} temp)
|
| 39 |
|
onqtam | fe80dc9 | 2016-05-22 13:32:20 +0300 | [diff] [blame] | 40 | message("==========================================================================")
|
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 41 | message("== CONTENTS OF ${TEST_OUTPUT_FILE}")
|
onqtam | fe80dc9 | 2016-05-22 13:32:20 +0300 | [diff] [blame] | 42 | message("==========================================================================")
|
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 43 | message("${orig}")
|
onqtam | fe80dc9 | 2016-05-22 13:32:20 +0300 | [diff] [blame] | 44 | message("==========================================================================")
|
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 45 | message("== CONTENTS OF ${TEST_TEMP_FILE}")
|
onqtam | fe80dc9 | 2016-05-22 13:32:20 +0300 | [diff] [blame] | 46 | message("==========================================================================")
|
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 47 | message("${temp}")
|
| 48 | set(CMD_RESULT "Output is different from reference file!")
|
| 49 | endif()
|
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 50 | endif()
|
| 51 |
|
| 52 | if(CMD_RESULT)
|
| 53 | message(FATAL_ERROR "Running '${COMMAND}' ended with code '${CMD_RESULT}'")
|
| 54 | endif()
|