ctest: Disable pre- and post-processing during --show-only

Do not run the custom pre-/post- test tasks when instructed to only show
the tests that would be executed.  Otherwise it's impossible to reliably
parse the output of this as is will be contaminated by all output
produced by the pre-/post-scripts!

Fixes: #23254
This commit is contained in:
Sebastian Sura
2026-03-03 16:57:05 -05:00
committed by Brad King
parent aef87a3378
commit 3e89f5ae83
4 changed files with 33 additions and 2 deletions
+2 -2
View File
@@ -359,7 +359,7 @@ int cmCTestTestHandler::ProcessHandler()
<< cmSystemTools::GetLogicalWorkingDirectory()
<< std::endl,
this->Quiet);
if (!this->PreProcessHandler()) {
if (!this->CTest->GetShowOnly() && !this->PreProcessHandler()) {
return -1;
}
@@ -428,7 +428,7 @@ int cmCTestTestHandler::ProcessHandler()
return 1;
}
if (!this->PostProcessHandler()) {
if (!this->CTest->GetShowOnly() && !this->PostProcessHandler()) {
this->LogFile = nullptr;
return -1;
}
@@ -0,0 +1,5 @@
^Test project [^
]+/Tests/RunCMake/CTestCommandLine/CustomPrePost
Test #1: Echo
Total Tests: 1$
@@ -0,0 +1,10 @@
^Test project [^
]+/Tests/RunCMake/CTestCommandLine/CustomPrePost
Custom Pre-Test
Start 1: Echo
1/1 Test #1: Echo \.+ Passed +[0-9\.]+ sec
100% tests passed, 0 tests failed out of 1
Total Test time \(real\) = +[0-9\.]+ sec
Custom Post-Test$
@@ -492,6 +492,22 @@ function(show_only_json_check_python v)
return(PROPAGATE RunCMake_TEST_FAILED)
endfunction()
block()
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/CustomPrePost)
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}/CTestCustom.cmake" "
set(CTEST_CUSTOM_PRE_TEST \"\\\"${CMAKE_COMMAND}\\\" -E echo \\\"Custom Pre-Test\\\"\")
set(CTEST_CUSTOM_POST_TEST \"\\\"${CMAKE_COMMAND}\\\" -E echo \\\"Custom Post-Test\\\"\")
")
file(WRITE "${RunCMake_TEST_BINARY_DIR}/CTestTestfile.cmake" "
add_test(Echo \"${CMAKE_COMMAND}\" -E echo)
")
run_cmake_command(CustomPrePost ${CMAKE_CTEST_COMMAND})
run_cmake_command(CustomPrePost-show-only ${CMAKE_CTEST_COMMAND} --show-only=human)
endblock()
function(run_ShowOnly)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/ShowOnly)
set(RunCMake_TEST_NO_CLEAN 1)