ctest: Exit nonzero when write to output JUnit or XML fails

`ProcessHandler` can return -1, 0, or 1, and the latter is used in this
particular case.

Fixes: #27949
This commit is contained in:
Tyler Yankee
2026-07-15 15:56:03 -04:00
parent 1f3b0f6c0a
commit 0d320cb496
5 changed files with 33 additions and 1 deletions
+1 -1
View File
@@ -2763,7 +2763,7 @@ int cmCTest::ExecuteTests(std::vector<std::string> const& args)
cmInstrumentation instrumentation(this->GetBinaryDir());
auto processHandler = [&handler]() -> int {
return handler.ProcessHandler() < 0 ? cmCTest::TEST_ERRORS : 0;
return handler.ProcessHandler() != 0 ? cmCTest::TEST_ERRORS : 0;
};
std::map<std::string, std::string> data;
data["showOnly"] = this->GetShowOnly() ? "1" : "0";
@@ -861,6 +861,21 @@ set_tests_properties(test5 PROPERTIES SKIP_REGULAR_EXPRESSION \"please skip\")
endfunction()
run_output_junit()
function(run_output_junit_invalid)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/output-junit-invalid)
set(RunCMake_TEST_NO_CLEAN 1)
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
file(WRITE "${RunCMake_TEST_BINARY_DIR}/CTestTestfile.cmake" "
add_test(test1 \"${CMAKE_COMMAND}\" -E true)
")
set(output_dir "${RunCMake_TEST_BINARY_DIR}/not-a-dir")
file(WRITE "${output_dir}" "")
set(output_file "${output_dir}/junit.xml")
run_cmake_command(output-junit-invalid ${CMAKE_CTEST_COMMAND} --output-junit "${output_file}")
endfunction()
run_output_junit_invalid()
run_cmake_command(invalid-ctest-argument ${CMAKE_CTEST_COMMAND} --not-a-valid-ctest-argument)
block()
@@ -0,0 +1,6 @@
# Verify that CTest did not create our badly formed output file.
if(EXISTS "${RunCMake_TEST_BINARY_DIR}/not-a-dir/junit.xml" OR IS_DIRECTORY "${RunCMake_TEST_BINARY_DIR}/not-a-dir")
set(RunCMake_TEST_FAILED
"Found output junit ${RunCMake_TEST_BINARY_DIR}/not-a-dir/junit.xml"
)
endif()
@@ -0,0 +1 @@
8
@@ -0,0 +1,10 @@
^CMake Error: Cannot open file for write: [^
]*/Tests/RunCMake/CTestCommandLine/output-junit-invalid/not-a-dir/junit\.xml\.tmp[^
]*
CMake Error: : System Error: (Not a directory|No such file or directory)
Problem opening file: [^
]*/Tests/RunCMake/CTestCommandLine/output-junit-invalid/not-a-dir/junit\.xml
Errors while running CTest
Output from these tests are in: [^
]*/Tests/RunCMake/CTestCommandLine/output-junit-invalid/Testing/Temporary/LastTest\.log
Use "--rerun-failed --output-on-failure" to re-run the failed cases verbosely\.$