From 3e89f5ae83184ec66255d1cc96530f9d85b35539 Mon Sep 17 00:00:00 2001 From: Sebastian Sura Date: Tue, 3 Mar 2026 16:18:23 +0000 Subject: [PATCH] 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 --- Source/CTest/cmCTestTestHandler.cxx | 4 ++-- .../CustomPrePost-show-only-stdout.txt | 5 +++++ .../CTestCommandLine/CustomPrePost-stdout.txt | 10 ++++++++++ .../RunCMake/CTestCommandLine/RunCMakeTest.cmake | 16 ++++++++++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 Tests/RunCMake/CTestCommandLine/CustomPrePost-show-only-stdout.txt create mode 100644 Tests/RunCMake/CTestCommandLine/CustomPrePost-stdout.txt diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index 806ddf5961..98094dda46 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -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; } diff --git a/Tests/RunCMake/CTestCommandLine/CustomPrePost-show-only-stdout.txt b/Tests/RunCMake/CTestCommandLine/CustomPrePost-show-only-stdout.txt new file mode 100644 index 0000000000..971bc9a573 --- /dev/null +++ b/Tests/RunCMake/CTestCommandLine/CustomPrePost-show-only-stdout.txt @@ -0,0 +1,5 @@ +^Test project [^ +]+/Tests/RunCMake/CTestCommandLine/CustomPrePost + Test #1: Echo + +Total Tests: 1$ diff --git a/Tests/RunCMake/CTestCommandLine/CustomPrePost-stdout.txt b/Tests/RunCMake/CTestCommandLine/CustomPrePost-stdout.txt new file mode 100644 index 0000000000..d06f476a78 --- /dev/null +++ b/Tests/RunCMake/CTestCommandLine/CustomPrePost-stdout.txt @@ -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$ diff --git a/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake index bb29635229..e3df1cc84b 100644 --- a/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake +++ b/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake @@ -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)