From f3d65bdc26d1245a1483a7f71bc5b777485c19f8 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Thu, 24 Jun 2021 12:06:36 -0400 Subject: [PATCH] chore: bump catch to 2.13.6 --- chapters/projects/fetch.md | 2 +- chapters/testing/catch.md | 33 +++++++++++++++++-- chapters/testing/googletest.md | 2 ++ .../extended-project/tests/CMakeLists.txt | 2 +- examples/fetch/CMakeLists.txt | 2 +- 5 files changed, 36 insertions(+), 5 deletions(-) diff --git a/chapters/projects/fetch.md b/chapters/projects/fetch.md index e23bbc3..77e6628 100644 --- a/chapters/projects/fetch.md +++ b/chapters/projects/fetch.md @@ -14,7 +14,7 @@ For example, to download Catch2: FetchContent_Declare( catch GIT_REPOSITORY https://github.com/catchorg/Catch2.git - GIT_TAG v2.13.0 + GIT_TAG v2.13.6 ) # CMake 3.14+ diff --git a/chapters/testing/catch.md b/chapters/testing/catch.md index 9a04188..b9902c0 100644 --- a/chapters/testing/catch.md +++ b/chapters/testing/catch.md @@ -1,13 +1,42 @@ # Catch -Catch and [Catch2] (C++11 only version) are powerful, idomatic testing solutions similar in philosophy to PyTest for Python. To use Catch in a CMake project, there are several options. +[Catch2] (C++11 only version) is a powerful, idomatic testing solutions similar in philosophy to PyTest for Python. It supports a wider range of compilers than GTest, and is quick to support new things, like M1 builds on macOS. It also has a smaller but faster twin, [doctest](https://github.com/onqtam/doctest), which is quick to compile but misses features like matchers. To use Catch in a CMake project, there are several options. + +## Configure methods + +Catch has nice CMake support, though to use it, you need the full repo. This could be with submodules or FetchContent. Both the [`extended-project`](https://gitlab.com/CLIUtils/modern-cmake/-/tree/master/examples/extended-project) and [`fetch`](https://gitlab.com/CLIUtils/modern-cmake/-/tree/master/examples/fetch) examples use FetchContent. See [the docs](https://github.com/catchorg/Catch2/blob/v2.x/docs/cmake-integration.md#top). + +## Quick download + +This is likely the simplest method and supports older versions of CMake. You can download the all-in-one header file in one step: + +```cmake +add_library(catch_main main.cpp) +target_include_directories(catch_main PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") +set(url https://github.com/philsquared/Catch/releases/download/v2.13.6/catch.hpp) +file( + DOWNLOAD ${url} "${CMAKE_CURRENT_BINARY_DIR}/catch.hpp" + STATUS status + EXPECTED_HASH SHA256=681e7505a50887c9085539e5135794fc8f66d8e5de28eadf13a30978627b0f47) +list(GET status 0 error) +if(error) + message(FATAL_ERROR "Could not download ${url}") +endif() +target_include_directories(catch_main PUBLIC "${CMAKE_CURRENT_BINARY_DIR}") +``` + +This will two downloads when Catch 3 is released, as that now requires two files (but you no longer have to write a main.cpp). The `main.cpp` looks like this: + +```cpp +#define CATCH_CONFIG_MAIN +#include "catch.hpp" +``` ## Vendoring If you simply drop in the single include release of Catch into your project, this is what you would need to add Catch: - ```cmake # Prepare "Catch" library for other executables set(CATCH_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/extern/catch) diff --git a/chapters/testing/googletest.md b/chapters/testing/googletest.md index ff75680..730366e 100644 --- a/chapters/testing/googletest.md +++ b/chapters/testing/googletest.md @@ -1,5 +1,7 @@ # GoogleTest +GoogleTest and GoogleMock are classic options; personally, I personally would recommend Catch2 instead, as GoogleTest heavily follows the Google development philosophy; it drops old compilers very quickly, it assumes users want to live at HEAD, etc. Adding GoogleMock is also often painful - and you need GoogleMock to get matchers, which are a default feature in Catch2 (but not doctest). + ## Submodule method (preferred) To use this method, just checkout GoogleTest as a submodule:[^1] diff --git a/examples/extended-project/tests/CMakeLists.txt b/examples/extended-project/tests/CMakeLists.txt index 96c9129..917e23d 100644 --- a/examples/extended-project/tests/CMakeLists.txt +++ b/examples/extended-project/tests/CMakeLists.txt @@ -2,7 +2,7 @@ FetchContent_Declare( catch GIT_REPOSITORY https://github.com/catchorg/Catch2.git - GIT_TAG v2.9.1) + GIT_TAG v2.13.6) FetchContent_MakeAvailable(catch) # Adds Catch2::Catch2 diff --git a/examples/fetch/CMakeLists.txt b/examples/fetch/CMakeLists.txt index 0046d01..3f2310f 100644 --- a/examples/fetch/CMakeLists.txt +++ b/examples/fetch/CMakeLists.txt @@ -8,7 +8,7 @@ include(CTest) FetchContent_Declare( catch GIT_REPOSITORY https://github.com/catchorg/Catch2.git - GIT_TAG v2.13.0) + GIT_TAG v2.13.6) # CMake 3.14+ FetchContent_MakeAvailable(catch)