A modern, C++-native, test framework for unit-tests, TDD and BDD - using C++14, C++17 and later (C++11 support is in v2.x branch, and C++03 on the Catch1.x branch)
Go to file
Reinhold Gschweicher 031a57e7b7
Fix Catch.cmake helper by setting variable globally
Set `_CATCH_DISCOVER_TESTS_SCRIPT` helper variable globally. Otherwise in a
scoped call (like `add_subdirectory()`) the variable gets lost. This lost
variable results in a post build error with not much information to lead to the
root of the problem.

This enables the usage of the helper script with the following example structure

- CMakeLists.txt (project root with `add_subdirectory(external/catch2)`
- external/catch2
  - CMakeLists.txt (contents listed below)
  - contrib/Catch.cmake
  - contrib/CatchAddTests.cmake
  - catch2/catch.hpp
- tests
  - CMakeLists.txt (add tests with `catch_discover_tests(${PROJECT_NAME})`)

contents of project specific helper `external/catch2/CMakeLists.txt`
```cmake
cmake_minimum_required (VERSION 3.1...${CMAKE_VERSION})
project(Catch2 LANGUAGES CXX VERSION 2.13.3)
add_library(Catch2 INTERFACE)
target_include_directories(Catch2
  INTERFACE
    $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>
)
 # provide a namespaced alias for clients to 'link' against if catch is included as a sub-project
add_library(Catch2::Catch2 ALIAS Catch2)
include(contrib/Catch.cmake)
```
2021-05-09 18:05:18 +02:00
.conan Add support for Components 2020-11-02 15:37:35 +01:00
.github Fix and improve GitHub Actions CI 2021-04-30 23:26:28 +02:00
CMake Fix Wold-style-cast error (#2125) 2020-12-28 14:00:19 +01:00
data/artwork Move artwork/ to data/artwork/ 2019-12-06 11:36:12 +01:00
docs Fix typos in the code base (#2206) 2021-04-07 20:43:50 +02:00
examples Fix typos in the code base (#2206) 2021-04-07 20:43:50 +02:00
extras Fix Catch.cmake helper by setting variable globally 2021-05-09 18:05:18 +02:00
fuzzing add fuzzer for columns 2020-10-07 17:38:27 +02:00
src Modified hash to make it more independent of the choice of test names. 2021-05-09 18:05:14 +02:00
tests Remove StringRef::isNullTerminated and StringRef::c_str 2021-03-26 21:11:44 +01:00
third_party fixing UB 2020-07-22 17:17:33 +02:00
tools Fix introduced in version placeholders 2021-03-13 10:26:12 +01:00
.clang-format Clang-format configuration added. 2020-07-22 21:43:30 +02:00
.gitattributes Update gitattributes 2018-07-23 10:15:52 +02:00
.gitignore Add a script - buildAndTest.sh 2020-10-28 11:38:06 +01:00
.travis.yml Remove conan to bintray packaging task from travis 2021-05-09 17:45:29 +02:00
appveyor.yml Add Linux and Windows CI builds with surrogate TUs 2021-02-19 23:23:00 +01:00
BUILD.bazel Add Bazel support for the v3 branch 2020-05-26 14:49:49 +02:00
CMakeLists.txt Prepare to prevent Catch2 v3's tests from being run, and CTest targets from being added, if Catch2 is configured as a sub-project. (#2205) 2021-04-16 21:19:58 +02:00
CODE_OF_CONDUCT.md Create CODE_OF_CONDUCT.md 2017-08-17 07:45:12 +01:00
codecov.yml Sweep out two leftover references to master 2020-10-23 23:02:44 +02:00
conanfile.py Add support for Components 2020-11-02 15:37:35 +01:00
Doxyfile Simple Doxygen file 2020-11-26 18:43:31 +01:00
LICENSE.txt Renamed licence file, license should now be detected by github 2017-03-20 08:59:25 +01:00
mdsnippets.json Add infrastructure for embedding code samples in docs. 2020-10-28 11:38:06 +01:00
README.md Link to the migration docs from main readme and docs/readme 2020-10-31 09:08:58 +01:00
WORKSPACE Add Bazel support for the v3 branch 2020-05-26 14:49:49 +02:00

Catch2 logo

Github Releases Build Status Build Status Code Coverage Try online Join the chat in Discord: https://discord.gg/4CWS9zD

Catch2 v3 is being developed!

You are on the devel branch, where the next major version, v3, of Catch2 is being developed. As it is a significant rework, you will find that parts of this documentation are likely still stuck on v2.

For stable (and documentation-matching) version of Catch2, go to the v2.x branch.

For migrating from the v2 releases to v3, you should look at our documentation. It provides a simple guidelines on getting started, and collects most common migration problems.

What's the Catch2?

Catch2 is mainly a unit testing framework for C++, but it also provides basic micro-benchmarking features, and simple BDD macros.

Catch2's main advantage is that using it is both simple and natural. Tests autoregister themselves and do not have to be named with valid identifiers, assertions look like normal C++ code, and sections provide a nice way to share set-up and tear-down code in tests.

How to use it

This documentation comprises these three parts:

More