summaryrefslogtreecommitdiff
path: root/Tests
diff options
context:
space:
mode:
authorAsit Dhal <dhal.asitk@gmail.com>2020-12-08 09:51:00 +0100
committerBrad King <brad.king@kitware.com>2020-12-10 06:09:59 -0500
commite5a4ffaad166de7a8b907919ca2d805a3ec72c39 (patch)
treedc88ffe172348ecb4a33cd3a206ba18964942c4e /Tests
parent8a3ecb484fb04aa9fb8b9f6d198b3a6942c26115 (diff)
downloadcmake-e5a4ffaad166de7a8b907919ca2d805a3ec72c39.tar.gz
execute_process: Improve COMMAND_ERROR_IS_FATAL error capture scenarios
1. COMMAND_ERROR_IS_FATAL ANY will capture errors if the exit code is non zero, there is a timeout or an abnormal exit. 2. COMMAND_ERROR_IS_FATAL LAST will capture if only the last process has an exit code non zero, there is a timeout or an abnormal exit. Fixes: #21562
Diffstat (limited to 'Tests')
-rw-r--r--Tests/RunCMake/CMakeLists.txt5
-rw-r--r--Tests/RunCMake/execute_process/AnyCommandAbnormalExit-result.txt1
-rw-r--r--Tests/RunCMake/execute_process/AnyCommandAbnormalExit-stderr.txt4
-rw-r--r--Tests/RunCMake/execute_process/AnyCommandAbnormalExit.cmake5
-rw-r--r--Tests/RunCMake/execute_process/AnyCommandError-stderr.txt5
-rw-r--r--Tests/RunCMake/execute_process/AnyCommandError.cmake10
-rw-r--r--Tests/RunCMake/execute_process/AnyCommandGood.cmake4
-rw-r--r--Tests/RunCMake/execute_process/AnyCommandTimeout-result.txt1
-rw-r--r--Tests/RunCMake/execute_process/AnyCommandTimeout-stderr.txt2
-rw-r--r--Tests/RunCMake/execute_process/AnyCommandTimeout.cmake15
-rw-r--r--Tests/RunCMake/execute_process/LastCommandAbnormalExit-1.cmake13
-rw-r--r--Tests/RunCMake/execute_process/LastCommandAbnormalExit-2-result.txt1
-rw-r--r--Tests/RunCMake/execute_process/LastCommandAbnormalExit-2-stderr.txt2
-rw-r--r--Tests/RunCMake/execute_process/LastCommandAbnormalExit-2.cmake13
-rw-r--r--Tests/RunCMake/execute_process/LastCommandError-stderr.txt2
-rw-r--r--Tests/RunCMake/execute_process/LastCommandError.cmake13
-rw-r--r--Tests/RunCMake/execute_process/LastCommandGood.cmake15
-rw-r--r--Tests/RunCMake/execute_process/LastCommandTimeout-result.txt1
-rw-r--r--Tests/RunCMake/execute_process/LastCommandTimeout-stderr.txt2
-rw-r--r--Tests/RunCMake/execute_process/LastCommandTimeout.cmake15
-rw-r--r--Tests/RunCMake/execute_process/RunCMakeTest.cmake12
21 files changed, 130 insertions, 11 deletions
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt
index 615bf20cda..98d5d01c4f 100644
--- a/Tests/RunCMake/CMakeLists.txt
+++ b/Tests/RunCMake/CMakeLists.txt
@@ -299,7 +299,10 @@ add_RunCMake_test(add_subdirectory)
add_RunCMake_test(add_test)
add_RunCMake_test(build_command)
add_executable(exit_code exit_code.c)
-set(execute_process_ARGS -DEXIT_CODE_EXE=$<TARGET_FILE:exit_code>)
+set(execute_process_ARGS
+ -DEXIT_CODE_EXE=$<TARGET_FILE:exit_code>
+ -DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}
+ )
if(NOT CMake_TEST_EXTERNAL_CMAKE)
list(APPEND execute_process_ARGS -DTEST_ENCODING_EXE=$<TARGET_FILE:testEncoding>)
endif()
diff --git a/Tests/RunCMake/execute_process/AnyCommandAbnormalExit-result.txt b/Tests/RunCMake/execute_process/AnyCommandAbnormalExit-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/execute_process/AnyCommandAbnormalExit-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/execute_process/AnyCommandAbnormalExit-stderr.txt b/Tests/RunCMake/execute_process/AnyCommandAbnormalExit-stderr.txt
new file mode 100644
index 0000000000..9627872fe4
--- /dev/null
+++ b/Tests/RunCMake/execute_process/AnyCommandAbnormalExit-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at .*AnyCommandAbnormalExit.cmake:[0-9]+ \(execute_process\):
+ execute_process failed command indexes:
+
+ 1: "Abnormal exit with child return code: Segmentation fault
diff --git a/Tests/RunCMake/execute_process/AnyCommandAbnormalExit.cmake b/Tests/RunCMake/execute_process/AnyCommandAbnormalExit.cmake
new file mode 100644
index 0000000000..5ac0c21d09
--- /dev/null
+++ b/Tests/RunCMake/execute_process/AnyCommandAbnormalExit.cmake
@@ -0,0 +1,5 @@
+execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c
+ "import os; os.kill(os.getpid(),11)"
+ COMMAND ${CMAKE_COMMAND} -E true
+ COMMAND_ERROR_IS_FATAL ANY
+ )
diff --git a/Tests/RunCMake/execute_process/AnyCommandError-stderr.txt b/Tests/RunCMake/execute_process/AnyCommandError-stderr.txt
index 038056231b..bf36391f82 100644
--- a/Tests/RunCMake/execute_process/AnyCommandError-stderr.txt
+++ b/Tests/RunCMake/execute_process/AnyCommandError-stderr.txt
@@ -1,2 +1,5 @@
CMake Error at .*AnyCommandError.cmake:1 \(execute_process\):
- execute_process failed command indexes: 2, 3, 4
+ execute_process failed command indexes:
+
+ 2: "Child return code: 1"
+ 3: "Child return code: 1"
diff --git a/Tests/RunCMake/execute_process/AnyCommandError.cmake b/Tests/RunCMake/execute_process/AnyCommandError.cmake
index f8ec38513e..c9348cdbce 100644
--- a/Tests/RunCMake/execute_process/AnyCommandError.cmake
+++ b/Tests/RunCMake/execute_process/AnyCommandError.cmake
@@ -1,8 +1,6 @@
execute_process(COMMAND ${CMAKE_COMMAND} -E true
- COMMAND ${CMAKE_COMMAND} -E false
- COMMAND ${CMAKE_COMMAND} -E false
- COMMAND ${CMAKE_COMMAND} -E false
- COMMAND ${CMAKE_COMMAND} -E true
- COMMAND ${CMAKE_COMMAND} -E true
- COMMAND_ERROR_IS_FATAL ANY
+ COMMAND ${CMAKE_COMMAND} -E false
+ COMMAND ${CMAKE_COMMAND} -E false
+ COMMAND ${CMAKE_COMMAND} -E true
+ COMMAND_ERROR_IS_FATAL ANY
)
diff --git a/Tests/RunCMake/execute_process/AnyCommandGood.cmake b/Tests/RunCMake/execute_process/AnyCommandGood.cmake
new file mode 100644
index 0000000000..27f0996914
--- /dev/null
+++ b/Tests/RunCMake/execute_process/AnyCommandGood.cmake
@@ -0,0 +1,4 @@
+execute_process(COMMAND ${CMAKE_COMMAND} -E true
+ COMMAND ${CMAKE_COMMAND} -E true
+ COMMAND_ERROR_IS_FATAL ANY
+ )
diff --git a/Tests/RunCMake/execute_process/AnyCommandTimeout-result.txt b/Tests/RunCMake/execute_process/AnyCommandTimeout-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/execute_process/AnyCommandTimeout-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/execute_process/AnyCommandTimeout-stderr.txt b/Tests/RunCMake/execute_process/AnyCommandTimeout-stderr.txt
new file mode 100644
index 0000000000..10cc5f49c0
--- /dev/null
+++ b/Tests/RunCMake/execute_process/AnyCommandTimeout-stderr.txt
@@ -0,0 +1,2 @@
+CMake Error at .*AnyCommandTimeout.cmake:9 \(execute_process\):
+ execute_process Process terminated due to timeout
diff --git a/Tests/RunCMake/execute_process/AnyCommandTimeout.cmake b/Tests/RunCMake/execute_process/AnyCommandTimeout.cmake
new file mode 100644
index 0000000000..a5a53fdd9a
--- /dev/null
+++ b/Tests/RunCMake/execute_process/AnyCommandTimeout.cmake
@@ -0,0 +1,15 @@
+execute_process(COMMAND ${CMAKE_COMMAND} -E true
+ COMMAND ${CMAKE_COMMAND} -E sleep 10
+ COMMAND ${CMAKE_COMMAND} -E true
+ TIMEOUT 1
+ RESULT_VARIABLE result
+)
+
+if(NOT result EQUAL "0")
+ execute_process(COMMAND ${CMAKE_COMMAND} -E true
+ COMMAND ${CMAKE_COMMAND} -E sleep 10
+ COMMAND ${CMAKE_COMMAND} -E true
+ TIMEOUT 1
+ COMMAND_ERROR_IS_FATAL ANY
+ )
+endif()
diff --git a/Tests/RunCMake/execute_process/LastCommandAbnormalExit-1.cmake b/Tests/RunCMake/execute_process/LastCommandAbnormalExit-1.cmake
new file mode 100644
index 0000000000..5a4574c378
--- /dev/null
+++ b/Tests/RunCMake/execute_process/LastCommandAbnormalExit-1.cmake
@@ -0,0 +1,13 @@
+execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c
+ "import os; os.kill(os.getpid(),11)"
+ COMMAND ${CMAKE_COMMAND} -E true
+ RESULT_VARIABLE result
+ )
+
+if(result EQUAL "0")
+ execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c
+ "import os; os.kill(os.getpid(),11)"
+ COMMAND ${CMAKE_COMMAND} -E true
+ COMMAND_ERROR_IS_FATAL LAST
+ )
+endif()
diff --git a/Tests/RunCMake/execute_process/LastCommandAbnormalExit-2-result.txt b/Tests/RunCMake/execute_process/LastCommandAbnormalExit-2-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/execute_process/LastCommandAbnormalExit-2-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/execute_process/LastCommandAbnormalExit-2-stderr.txt b/Tests/RunCMake/execute_process/LastCommandAbnormalExit-2-stderr.txt
new file mode 100644
index 0000000000..c915e58fad
--- /dev/null
+++ b/Tests/RunCMake/execute_process/LastCommandAbnormalExit-2-stderr.txt
@@ -0,0 +1,2 @@
+CMake Error at .*LastCommandAbnormalExit-2.cmake:[0-9]+ \(execute_process\):
+ execute_process Abnormal exit: Segmentation fault
diff --git a/Tests/RunCMake/execute_process/LastCommandAbnormalExit-2.cmake b/Tests/RunCMake/execute_process/LastCommandAbnormalExit-2.cmake
new file mode 100644
index 0000000000..b87e0f7ba2
--- /dev/null
+++ b/Tests/RunCMake/execute_process/LastCommandAbnormalExit-2.cmake
@@ -0,0 +1,13 @@
+execute_process(COMMAND ${CMAKE_COMMAND} -E true
+ COMMAND "${PYTHON_EXECUTABLE}" -c
+ "import os; os.kill(os.getpid(),11)"
+ RESULT_VARIABLE result
+ )
+
+if(NOT result EQUAL "0")
+ execute_process(COMMAND ${CMAKE_COMMAND} -E true
+ COMMAND "${PYTHON_EXECUTABLE}" -c
+ "import os; os.kill(os.getpid(),11)"
+ COMMAND_ERROR_IS_FATAL LAST
+ )
+endif()
diff --git a/Tests/RunCMake/execute_process/LastCommandError-stderr.txt b/Tests/RunCMake/execute_process/LastCommandError-stderr.txt
index ff191b3cd7..335a771edc 100644
--- a/Tests/RunCMake/execute_process/LastCommandError-stderr.txt
+++ b/Tests/RunCMake/execute_process/LastCommandError-stderr.txt
@@ -1,2 +1,2 @@
-CMake Error at .*LastCommandError.cmake:1 \(execute_process\):
+CMake Error at .*LastCommandError.cmake:11 \(execute_process\):
execute_process last command failed
diff --git a/Tests/RunCMake/execute_process/LastCommandError.cmake b/Tests/RunCMake/execute_process/LastCommandError.cmake
index 6116a5c23d..9a925fef8e 100644
--- a/Tests/RunCMake/execute_process/LastCommandError.cmake
+++ b/Tests/RunCMake/execute_process/LastCommandError.cmake
@@ -1,8 +1,19 @@
execute_process(COMMAND ${CMAKE_COMMAND} -E true
+ COMMAND ${CMAKE_COMMAND} -E false
+ COMMAND ${CMAKE_COMMAND} -E false
+ COMMAND ${CMAKE_COMMAND} -E false
+ COMMAND ${CMAKE_COMMAND} -E true
+ COMMAND ${CMAKE_COMMAND} -E false
+ RESULT_VARIABLE result
+)
+
+if(NOT result EQUAL "0")
+ execute_process(COMMAND ${CMAKE_COMMAND} -E true
COMMAND ${CMAKE_COMMAND} -E false
COMMAND ${CMAKE_COMMAND} -E false
COMMAND ${CMAKE_COMMAND} -E false
COMMAND ${CMAKE_COMMAND} -E true
COMMAND ${CMAKE_COMMAND} -E false
COMMAND_ERROR_IS_FATAL LAST
-)
+ )
+endif()
diff --git a/Tests/RunCMake/execute_process/LastCommandGood.cmake b/Tests/RunCMake/execute_process/LastCommandGood.cmake
new file mode 100644
index 0000000000..c22b49d96b
--- /dev/null
+++ b/Tests/RunCMake/execute_process/LastCommandGood.cmake
@@ -0,0 +1,15 @@
+execute_process(COMMAND ${CMAKE_COMMAND} -E true
+ COMMAND ${CMAKE_COMMAND} -E false
+ COMMAND ${CMAKE_COMMAND} -E false
+ COMMAND ${CMAKE_COMMAND} -E true
+ RESULT_VARIABLE result
+ )
+
+if(result EQUAL "0")
+ execute_process(COMMAND ${CMAKE_COMMAND} -E true
+ COMMAND ${CMAKE_COMMAND} -E false
+ COMMAND ${CMAKE_COMMAND} -E false
+ COMMAND ${CMAKE_COMMAND} -E true
+ COMMAND_ERROR_IS_FATAL LAST
+ )
+endif()
diff --git a/Tests/RunCMake/execute_process/LastCommandTimeout-result.txt b/Tests/RunCMake/execute_process/LastCommandTimeout-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/execute_process/LastCommandTimeout-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/execute_process/LastCommandTimeout-stderr.txt b/Tests/RunCMake/execute_process/LastCommandTimeout-stderr.txt
new file mode 100644
index 0000000000..1cd1546bfc
--- /dev/null
+++ b/Tests/RunCMake/execute_process/LastCommandTimeout-stderr.txt
@@ -0,0 +1,2 @@
+CMake Error at .*LastCommandTimeout.cmake:9 \(execute_process\):
+ execute_process Process terminated due to timeout
diff --git a/Tests/RunCMake/execute_process/LastCommandTimeout.cmake b/Tests/RunCMake/execute_process/LastCommandTimeout.cmake
new file mode 100644
index 0000000000..9c1f444ff1
--- /dev/null
+++ b/Tests/RunCMake/execute_process/LastCommandTimeout.cmake
@@ -0,0 +1,15 @@
+execute_process(COMMAND ${CMAKE_COMMAND} -E true
+ COMMAND ${CMAKE_COMMAND} -E sleep 10
+ COMMAND ${CMAKE_COMMAND} -E true
+ TIMEOUT 1
+ RESULT_VARIABLE result
+)
+
+if(NOT result EQUAL "0")
+ execute_process(COMMAND ${CMAKE_COMMAND} -E true
+ COMMAND ${CMAKE_COMMAND} -E sleep 10
+ COMMAND ${CMAKE_COMMAND} -E true
+ TIMEOUT 1
+ COMMAND_ERROR_IS_FATAL LAST
+ )
+endif()
diff --git a/Tests/RunCMake/execute_process/RunCMakeTest.cmake b/Tests/RunCMake/execute_process/RunCMakeTest.cmake
index f4c3d1919b..35712f6a28 100644
--- a/Tests/RunCMake/execute_process/RunCMakeTest.cmake
+++ b/Tests/RunCMake/execute_process/RunCMakeTest.cmake
@@ -27,6 +27,16 @@ run_cmake_command(EchoCommand3 ${CMAKE_COMMAND}
run_cmake_command(EchoVariable ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/EchoVariable.cmake)
+run_cmake_command(CommandError ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/CommandError.cmake)
run_cmake_command(AnyCommandError ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/AnyCommandError.cmake)
+run_cmake_command(AnyCommandTimeout ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/AnyCommandTimeout.cmake)
+run_cmake_command(AnyCommandGood ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/AnyCommandGood.cmake)
run_cmake_command(LastCommandError ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/LastCommandError.cmake)
-run_cmake_command(CommandError ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/CommandError.cmake)
+run_cmake_command(LastCommandTimeout ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/LastCommandTimeout.cmake)
+run_cmake_command(LastCommandGood ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/LastCommandGood.cmake)
+
+if(UNIX AND PYTHON_EXECUTABLE)
+ run_cmake_command(AnyCommandAbnormalExit ${CMAKE_COMMAND} -DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE} -P ${RunCMake_SOURCE_DIR}/AnyCommandAbnormalExit.cmake)
+ run_cmake_command(LastCommandAbnormalExit-1 ${CMAKE_COMMAND} -DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE} -P ${RunCMake_SOURCE_DIR}/LastCommandAbnormalExit-1.cmake)
+ run_cmake_command(LastCommandAbnormalExit-2 ${CMAKE_COMMAND} -DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE} -P ${RunCMake_SOURCE_DIR}/LastCommandAbnormalExit-2.cmake)
+endif()