Fix catch_discover_tests PRE_TEST failure with zero discoverable tests#3075
Open
solarispika wants to merge 1 commit intocatchorg:develfrom
Open
Fix catch_discover_tests PRE_TEST failure with zero discoverable tests#3075solarispika wants to merge 1 commit intocatchorg:develfrom
solarispika wants to merge 1 commit intocatchorg:develfrom
Conversation
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 catchorg#2962 (76f70b1) 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.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## devel #3075 +/- ##
==========================================
- Coverage 91.38% 91.37% -0.01%
==========================================
Files 204 204
Lines 8899 8899
==========================================
- Hits 8132 8131 -1
- Misses 767 768 +1 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When using
catch_discover_tests()withDISCOVERY_MODE PRE_TESTand a multi-config generator (e.g., Ninja Multi-Config), if a test target has zero discoverable tests (e.g., all tests tagged with[.]),ctestfails with:This error aborts all test discovery, preventing any tests from running — even from other targets that have tests.
Root Cause
The early return added in #2962 (76f70b1) correctly prevented a JSON parsing crash for zero tests, but skipped
file(WRITE "${_CTEST_FILE}" ...). ThePRE_TESTcode path inCatch.cmakeunconditionallyinclude()s this file (line 282), so the missing file causes a hard error.The
POST_BUILDcode path is unaffected because it wraps the include inif(EXISTS ...).Fix
Write an empty file before the early return so the
include()always succeeds.Reproduction
Minimal project with two test targets — one normal, one with only hidden (
[.]) tests:CMakeLists.txt
test-normal.cpp
test-hidden.cpp
CMakePresets.json
{ "version": 6, "configurePresets": [ { "name": "default", "generator": "Ninja Multi-Config", "binaryDir": "${sourceDir}/build" } ], "buildPresets": [ { "name": "release", "configurePreset": "default", "configuration": "Release" } ] }After this fix,
test-normalruns and passes;test-hiddenis gracefully skipped.