diff options
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/TryCompile/CMakeLists.txt | 29 | ||||
-rw-r--r-- | Tests/TryCompile/exit_success.c | 3 | ||||
-rw-r--r-- | Tests/TryCompile/exit_with_error.c | 3 |
3 files changed, 33 insertions, 2 deletions
diff --git a/Tests/TryCompile/CMakeLists.txt b/Tests/TryCompile/CMakeLists.txt index 02359fe..a39f7c9 100644 --- a/Tests/TryCompile/CMakeLists.txt +++ b/Tests/TryCompile/CMakeLists.txt @@ -87,6 +87,8 @@ ADD_EXECUTABLE(TryCompile pass.c) # now two tests for TRY_RUN # try to run a file that should compile and run without error +# also check that OUTPUT_VARIABLE contains both the compile output +# and the run output TRY_RUN(SHOULD_RUN SHOULD_COMPILE ${TryCompile_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp ${TryCompile_SOURCE_DIR}/exit_success.c @@ -97,16 +99,39 @@ ENDIF(NOT SHOULD_COMPILE) IF(NOT "${SHOULD_RUN}" STREQUAL "0") MESSAGE(SEND_ERROR "exit_success failed running with exit code ${SHOULD_RUN}") ENDIF(NOT "${SHOULD_RUN}" STREQUAL "0") +# check the compile output for the filename +IF(NOT "${TRY_OUT}" MATCHES "exit_success") + MESSAGE(SEND_ERROR " TRY_OUT didn't contain \"exit_success\": \"${TRY_OUT}\"") +ENDIF(NOT "${TRY_OUT}" MATCHES "exit_success") +# check the run output +IF(NOT "${TRY_OUT}" MATCHES "hello world") + MESSAGE(SEND_ERROR " TRY_OUT didn't contain \"hello world\": \"${TRY_OUT}\"") +ENDIF(NOT "${TRY_OUT}" MATCHES "hello world") + # try to run a file that should compile and run, but return an error TRY_RUN(SHOULD_EXIT_WITH_ERROR SHOULD_COMPILE ${TryCompile_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp ${TryCompile_SOURCE_DIR}/exit_with_error.c - OUTPUT_VARIABLE TRY_OUT) + COMPILE_OUTPUT_VARIABLE COMPILE_OUTPUT + RUN_OUTPUT_VARIABLE RUN_OUTPUT) + IF(NOT SHOULD_COMPILE) - MESSAGE(STATUS " exit_with_error failed compiling: ${TRY_OUT}") + MESSAGE(STATUS " exit_with_error failed compiling: ${COMPILE_OUTPUT}") ENDIF(NOT SHOULD_COMPILE) IF("${SHOULD_EXIT_WITH_ERROR}" STREQUAL "0") MESSAGE(SEND_ERROR " exit_with_error passed with exit code ${SHOULD_EXIT_WITH_ERROR}") ENDIF("${SHOULD_EXIT_WITH_ERROR}" STREQUAL "0") +# check the compile output, it should contain the filename +IF(NOT "${COMPILE_OUTPUT}" MATCHES "exit_with_error") + MESSAGE(SEND_ERROR " COMPILE_OUT didn't contain \"exit_with_error\": \"${COMPILE_OUTPUT}\"") +ENDIF(NOT "${COMPILE_OUTPUT}" MATCHES "exit_with_error") +#... but not the run time output +IF("${COMPILE_OUTPUT}" MATCHES "hello world") + MESSAGE(SEND_ERROR " COMPILE_OUT contains the run output: \"${COMPILE_OUTPUT}\"") +ENDIF("${COMPILE_OUTPUT}" MATCHES "hello world") +# check the run output, it should stdout +IF(NOT "${RUN_OUTPUT}" MATCHES "hello world") + MESSAGE(SEND_ERROR " RUN_OUTPUT didn't contain \"hello world\": \"${RUN_OUTPUT}\"") +ENDIF(NOT "${RUN_OUTPUT}" MATCHES "hello world") diff --git a/Tests/TryCompile/exit_success.c b/Tests/TryCompile/exit_success.c index f8b643a..82f5b5f 100644 --- a/Tests/TryCompile/exit_success.c +++ b/Tests/TryCompile/exit_success.c @@ -1,4 +1,7 @@ +#include <stdio.h> + int main() { + printf("hello world\n"); return 0; } diff --git a/Tests/TryCompile/exit_with_error.c b/Tests/TryCompile/exit_with_error.c index a9a283d..f3c523d 100644 --- a/Tests/TryCompile/exit_with_error.c +++ b/Tests/TryCompile/exit_with_error.c @@ -1,4 +1,7 @@ +#include <stdio.h> + int main() { + printf("hello world\n"); return -1; } |