From 2bc2f3b638637c79c67b46ce007c0e9727d60d10 Mon Sep 17 00:00:00 2001 From: "Sung, Po Han" Date: Mon, 2 Mar 2026 17:28:14 +0800 Subject: [PATCH] Fix catch_discover_tests PRE_TEST failure with zero discoverable tests When using catch_discover_tests() with DISCOVERY_MODE PRE_TEST and a multi-config generator (e.g. Ninja Multi-Config), if a test target has zero discoverable tests (e.g. all tests tagged with [.]), ctest fails: CMake Error: include could not find requested file: .../test-hidden-b12d07c_tests-Release.cmake The early return added in #2962 (76f70b14) correctly prevented a JSON parsing crash for zero tests, but skipped writing the ctest file. The PRE_TEST include script unconditionally includes this file, so the missing file causes a hard error that aborts all test discovery. Write an empty file before returning early so the include always succeeds. --- extras/CatchAddTests.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/extras/CatchAddTests.cmake b/extras/CatchAddTests.cmake index 90fbd5e313..4c27f479ec 100644 --- a/extras/CatchAddTests.cmake +++ b/extras/CatchAddTests.cmake @@ -146,6 +146,7 @@ function(catch_discover_tests_impl) # Exit early if no tests are detected if(num_tests STREQUAL "0") + file(WRITE "${_CTEST_FILE}" "") return() endif()