Skip to content

Fix bug where catch_discover_tests fails when no TEST_CASEs are present#2962

Merged
ChrisThrasher merged 1 commit intodevelfrom
zero_test_case_crash
Mar 12, 2025
Merged

Fix bug where catch_discover_tests fails when no TEST_CASEs are present#2962
ChrisThrasher merged 1 commit intodevelfrom
zero_test_case_crash

Conversation

@ChrisThrasher
Copy link
Copy Markdown
Collaborator

@ChrisThrasher ChrisThrasher commented Mar 12, 2025

Description

Closes #2961

This bug was introduced in 7d7b2f8

@ChrisThrasher ChrisThrasher requested a review from horenmar March 12, 2025 02:39
@ChrisThrasher ChrisThrasher changed the title Fix bug where catch_discover_tests fails when no TEST_CASEs are preset Fix bug where catch_discover_tests fails when no TEST_CASEs are present Mar 12, 2025
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.01%. Comparing base (914aeec) to head (30b7f74).
Report is 1 commits behind head on devel.

Additional details and impacted files
@@           Coverage Diff           @@
##            devel    #2962   +/-   ##
=======================================
  Coverage   91.01%   91.01%           
=======================================
  Files         198      198           
  Lines        8599     8599           
=======================================
  Hits         7826     7826           
  Misses        773      773           
🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ChrisThrasher ChrisThrasher merged commit 76f70b1 into devel Mar 12, 2025
152 checks passed
@ChrisThrasher ChrisThrasher deleted the zero_test_case_crash branch March 18, 2025 05:03
solarispika added a commit to solarispika/Catch2 that referenced this pull request Mar 2, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Catch2 (with CMake) does not compile when only test file discovered is empty

1 participant