catchorg / catchorg/Catch2

add option to catch_discover_tests to build target as part of cmake test include script

Open
#2,352 1 comment 1 reaction 0 assignees View on GitHub
Extras
Dominant language
C++
Stars
21.5k
Forks
3.5k
Avg merge
3d 16h
Merged PRs (30d)
2

Description

**Description**

I want to be able to integrate catch2 and ctest such that I can run

```
cmake ..
ctest
```
instead of having to run

```
cmake ..
cmake --build .
ctest
```
This could be accomplished by adding an option to the catch_discover_tests function in extras/Catch.cmake that, when this option is used, alters the contents of the generated ctest_include_file by adding an execute_process function call that builds the target that the test uses.

Adding an option to a cmake function is backwards compatible, so this change shouldn't impact anyone who doesn't want to use this feature.

**Additional context**

If I was just using ctest without catch2, I could run ctest without running the build step by setting DEPENDS test property on an added test to another test that has the command for building the target. There is also a test fixtures property that can be used in a similar way to build an executable used in a test before running that test.

But, I can't do that with catch_discover_tests because catch_discover_tests generates ctest_tests_file at build time, and the ctest_tests_file needs to be generated before or during when the TEST_INCLUDE_FILES are run. If the target isn't built before ctest starts, generating the ctest_tests_file as part of a test doesn't help because the ctest_tests_file has to be generated before the ctest_include_file is run.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.