diff options
author | Patrick Northon <northon_patrick3@yahoo.ca> | 2022-07-08 19:49:02 (GMT) |
---|---|---|
committer | Patrick Northon <northon_patrick3@yahoo.ca> | 2022-07-08 19:49:02 (GMT) |
commit | a2cd0687db1afec58d5f42a94bb85b2e2ce301fe (patch) | |
tree | 8297ac568aeab79b1b1e7148881dc38aa75d2ad5 /Tests/TryCompile | |
parent | fc30196e76dcbc47f045b451adbab643a2387700 (diff) | |
download | CMake-a2cd0687db1afec58d5f42a94bb85b2e2ce301fe.zip CMake-a2cd0687db1afec58d5f42a94bb85b2e2ce301fe.tar.gz CMake-a2cd0687db1afec58d5f42a94bb85b2e2ce301fe.tar.bz2 |
try_run: Add RUN_OUTPUT_STDOUT_VARIABLE and RUN_OUTPUT_STDERR_VARIABLE.
Diffstat (limited to 'Tests/TryCompile')
-rw-r--r-- | Tests/TryCompile/CMakeLists.txt | 23 | ||||
-rw-r--r-- | Tests/TryCompile/stdout_and_stderr.c | 8 |
2 files changed, 30 insertions, 1 deletions
diff --git a/Tests/TryCompile/CMakeLists.txt b/Tests/TryCompile/CMakeLists.txt index 000fd2c..7c6f970 100644 --- a/Tests/TryCompile/CMakeLists.txt +++ b/Tests/TryCompile/CMakeLists.txt @@ -259,11 +259,32 @@ endif() if("${COMPILE_OUTPUT}" MATCHES "hello world") message(SEND_ERROR " COMPILE_OUT contains the run output: \"${COMPILE_OUTPUT}\"") endif() -# check the run output, it should stdout +# check the run output, it should contain stdout if(NOT "${RUN_OUTPUT}" MATCHES "hello world") message(SEND_ERROR " RUN_OUTPUT didn't contain \"hello world\": \"${RUN_OUTPUT}\"") endif() +# try to run a file and parse stdout and stderr separately +try_run(SHOULD_EXIT_WITH_ERROR SHOULD_COMPILE + ${TryCompile_BINARY_DIR} + ${TryCompile_SOURCE_DIR}/stdout_and_stderr.c + COMPILE_OUTPUT_VARIABLE COMPILE_OUTPUT + RUN_OUTPUT_STDOUT_VARIABLE RUN_OUTPUT_STDOUT + RUN_OUTPUT_STDERR_VARIABLE RUN_OUTPUT_STDERR) + +if(NOT SHOULD_COMPILE) + message(STATUS " exit_with_error failed compiling: ${COMPILE_OUTPUT}") +endif() + +# check the run stdout output +if(NOT "${RUN_OUTPUT_STDOUT}" MATCHES "hello world") + message(SEND_ERROR " RUN_OUTPUT_STDOUT didn't contain \"hello world\": \"${RUN_OUTPUT_STDOUT}\"") +endif() +# check the run stderr output +if(NOT "${RUN_OUTPUT_STDERR}" MATCHES "error") + message(SEND_ERROR " RUN_OUTPUT_STDERR didn't contain \"error\": \"${RUN_OUTPUT_STDERR}\"") +endif() + ####################################################################### # # also test that the CHECK_C_SOURCE_COMPILES, CHECK_CXX_SOURCE_COMPILES diff --git a/Tests/TryCompile/stdout_and_stderr.c b/Tests/TryCompile/stdout_and_stderr.c new file mode 100644 index 0000000..84ded1f --- /dev/null +++ b/Tests/TryCompile/stdout_and_stderr.c @@ -0,0 +1,8 @@ +#include <stdio.h> + +int main() +{ + fputs("error\n", stderr); + puts("hello world\n"); + return 0; +} |