Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch2's tests should never be run, if it is loaded as a sub-project #2202

Open
claremacrae opened this issue Apr 5, 2021 · 2 comments
Open

Comments

@claremacrae
Copy link
Contributor

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.

# 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.

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.

@claremacrae
Copy link
Contributor Author

The fix is trivial:

# detect if Catch is being bundled,
# disable testsuite in that case
if(NOT DEFINED PROJECT_NAME)
    set(NOT_SUBPROJECT ON)
+else()
+    set(NOT_SUBPROJECT OFF)
endif()

claremacrae added a commit to claremacrae/Catch2 that referenced this issue Apr 5, 2021
@claremacrae
Copy link
Contributor Author

claremacrae commented Apr 5, 2021

The with-catch2-v3 branch of claremacrae/demo-cmake-subproject-error allows the behaviour to be tested against Catch2's v3 code, i.e. the devel branch.

claremacrae added a commit to claremacrae/Catch2 that referenced this issue Apr 5, 2021
horenmar pushed a commit that referenced this issue Apr 16, 2021
…s from being added, if Catch2 is configured as a sub-project. (#2205)

This commit fixes issue that happens if the project above us uses the same variable name, thus confusing our script which see the variable scoped from the project including Catch2, rather than ours

See #2202
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

No branches or pull requests

1 participant