summaryrefslogtreecommitdiff
path: root/Tests
diff options
context:
space:
mode:
authorPatrick Northon <northon_patrick3@yahoo.ca>2022-07-08 15:49:02 -0400
committerPatrick Northon <northon_patrick3@yahoo.ca>2022-07-08 15:49:02 -0400
commita2cd0687db1afec58d5f42a94bb85b2e2ce301fe (patch)
tree8297ac568aeab79b1b1e7148881dc38aa75d2ad5 /Tests
parentfc30196e76dcbc47f045b451adbab643a2387700 (diff)
downloadcmake-a2cd0687db1afec58d5f42a94bb85b2e2ce301fe.tar.gz
try_run: Add RUN_OUTPUT_STDOUT_VARIABLE and RUN_OUTPUT_STDERR_VARIABLE.
Diffstat (limited to 'Tests')
-rw-r--r--Tests/RunCMake/try_run/BadStdErrVariable-result.txt1
-rw-r--r--Tests/RunCMake/try_run/BadStdErrVariable-stderr.txt5
-rw-r--r--Tests/RunCMake/try_run/BadStdErrVariable.cmake5
-rw-r--r--Tests/RunCMake/try_run/BadStdOutVariable-result.txt1
-rw-r--r--Tests/RunCMake/try_run/BadStdOutVariable-stderr.txt5
-rw-r--r--Tests/RunCMake/try_run/BadStdOutVariable.cmake5
-rw-r--r--Tests/RunCMake/try_run/RunCMakeTest.cmake3
-rw-r--r--Tests/TryCompile/CMakeLists.txt23
-rw-r--r--Tests/TryCompile/stdout_and_stderr.c8
9 files changed, 55 insertions, 1 deletions
diff --git a/Tests/RunCMake/try_run/BadStdErrVariable-result.txt b/Tests/RunCMake/try_run/BadStdErrVariable-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/try_run/BadStdErrVariable-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/try_run/BadStdErrVariable-stderr.txt b/Tests/RunCMake/try_run/BadStdErrVariable-stderr.txt
new file mode 100644
index 0000000000..5d7e5e9127
--- /dev/null
+++ b/Tests/RunCMake/try_run/BadStdErrVariable-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error: RUN_OUTPUT_STDERR_VARIABLE specified but there is no variable
+CMake Error at BadStdErrVariable.cmake:1 \(try_run\):
+ try_run unknown error.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/try_run/BadStdErrVariable.cmake b/Tests/RunCMake/try_run/BadStdErrVariable.cmake
new file mode 100644
index 0000000000..88c2a72641
--- /dev/null
+++ b/Tests/RunCMake/try_run/BadStdErrVariable.cmake
@@ -0,0 +1,5 @@
+try_run(RUN_RESULT COMPILE_RESULT
+ ${CMAKE_CURRENT_BINARY_DIR}/CMakeTmp ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/CMakeTmp/workdir
+ RUN_OUTPUT_STDERR_VARIABLE
+ )
diff --git a/Tests/RunCMake/try_run/BadStdOutVariable-result.txt b/Tests/RunCMake/try_run/BadStdOutVariable-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/try_run/BadStdOutVariable-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/try_run/BadStdOutVariable-stderr.txt b/Tests/RunCMake/try_run/BadStdOutVariable-stderr.txt
new file mode 100644
index 0000000000..df606582a9
--- /dev/null
+++ b/Tests/RunCMake/try_run/BadStdOutVariable-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error: RUN_OUTPUT_STDOUT_VARIABLE specified but there is no variable
+CMake Error at BadStdOutVariable.cmake:1 \(try_run\):
+ try_run unknown error.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/try_run/BadStdOutVariable.cmake b/Tests/RunCMake/try_run/BadStdOutVariable.cmake
new file mode 100644
index 0000000000..691e8813e5
--- /dev/null
+++ b/Tests/RunCMake/try_run/BadStdOutVariable.cmake
@@ -0,0 +1,5 @@
+try_run(RUN_RESULT COMPILE_RESULT
+ ${CMAKE_CURRENT_BINARY_DIR}/CMakeTmp ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/CMakeTmp/workdir
+ RUN_OUTPUT_STDOUT_VARIABLE
+ )
diff --git a/Tests/RunCMake/try_run/RunCMakeTest.cmake b/Tests/RunCMake/try_run/RunCMakeTest.cmake
index d74add05ca..5fa5b2fef0 100644
--- a/Tests/RunCMake/try_run/RunCMakeTest.cmake
+++ b/Tests/RunCMake/try_run/RunCMakeTest.cmake
@@ -10,3 +10,6 @@ if (CMAKE_SYSTEM_NAME MATCHES "^(Linux|Darwin|Windows)$" AND
endif()
run_cmake(WorkingDirArg)
+
+run_cmake(BadStdOutVariable)
+run_cmake(BadStdErrVariable)
diff --git a/Tests/TryCompile/CMakeLists.txt b/Tests/TryCompile/CMakeLists.txt
index 000fd2cbc9..7c6f970e52 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 0000000000..84ded1f799
--- /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;
+}