Catch2's tests should never be run, if it is loaded as a sub-project
- Dominant language
- C++
- Stars
- 21.5k
- Forks
- 3.5k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 2
Description
_Please note: I will submit PRs to fix this on the v2 and v3 branches... the fix is trivial_
**Describe the bug**
Catch2's top-level `CMakeLists.txt` file has code to prevent self-tests being run if the project is being bundled e.g. via `add_subdirectory()` or `FetchContent`.
```cmake
# detect if Catch is being bundled,
# disable testsuite in that case
if(NOT DEFINED PROJECT_NAME)
set(NOT_SUBPROJECT ON)
endif()
```
However, if `NOT_SUBPROJECT` was already set to `ON` in a parent scope, the self-tests are still run anyway (and also the 20-30 CTest targets are added)
**Expected behavior**
Turn off `NOT_SUBPROJECT` if Catch2 is running as a sub-project
**Reproduction steps**
Steps to reproduce the bug.
```bash
git clone https://github.com/claremacrae/demo-cmake-subproject-error.git
mkdir build
cd build
cmake ..
cmake --build . --target help
```
Expected output:
```
The following are some of the valid targets for this Makefile:
... all (the default if no target is provided)
... clean
... depend
... rebuild_cache
... edit_cache
... package_source
... package
... Catch2WithMain
... tests
```
Actual output - note the include of `SelfTest`, as well as all the targets generated by including CTest:
```
The following are some of the valid targets for this Makefile:
... all (the default if no target is provided)
... clean
... depend
... install/local
... install/strip
... install
... package_source
... rebuild_cache
... edit_cache
... list_install_components
... package
... Catch2WithMain
... ContinuousCoverage
... ContinuousTest
... ContinuousBuild
... ContinuousStart
... ExperimentalBuild
... ExperimentalCoverage
... ExperimentalSubmit
... ContinuousUpdate
... ExperimentalUpdate
... ExperimentalStart
... ContinuousSubmit
... ExperimentalTest
... NightlySubmit
... NightlyMemCheck
... ExperimentalConfigure
... NightlyCoverage
... NightlyTest
... ContinuousMemCheck
... NightlyBuild
... NightlyConfigure
... NightlyUpdate
... NightlyMemoryCheck
... ContinuousConfigure
... Nightly
... NightlyStart
... ExperimentalMemCheck
... Continuous
... Experimental
... SelfTest
... tests
```
**Platform information:**
- OS: **Windows NT**
- Compiler+version: **GCC v2.9.5**
- Catch version: **v1.2.3**
**Additional context**
Add any other context about the problem here.
Contributor guide
Assessment
This issue has not been assessed yet.