Skip to content

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

@hjstn

Description

@hjstn

Describe the bug
When compiling in a project with no tests, but a (empty) tests file exists, the compile fails with the following error:

[ 50%] Linking CXX executable test
CMake Error at /usr/lib/cmake/Catch2/CatchAddTests.cmake:150 (string):
  string sub-command JSON expected an index less than 0 got '0'.
Call Stack (most recent call first):
  /usr/lib/cmake/Catch2/CatchAddTests.cmake:228 (catch_discover_tests_impl)

Expected behavior
The project should compile correctly.

Reproduction steps
Steps to reproduce the bug.

  1. Create base project directory (base_dir)
  2. Add CMakeLists.txt (CMakeLists.txt)
  3. Create tests directory inside base (base_dir/tests)
  4. Create an empty test file inside base (base_dir/tests/tests.cpp)
  5. Create build directory inside base (base_dir/build)
  6. cd into build directory
  7. Run cmake ..
  8. Run make -> an error occurs

Platform information:

  • OS: Ubuntu 24.04.1 LTS arm64
  • Compiler+version: clang 18.1.3 (1ubuntu1)
  • Catch version: v3.8.0

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions