Debian Codegraph @

3rdparty/catch2/docs/migrate-v2-to-v3.md

raw symbols SCIP
1 <a id="top"></a>
2 # Migrating from v2 to v3
3
4 v3 is the next major version of Catch2 and brings three significant changes:
5 * Catch2 is now split into multiple headers
6 * Catch2 is now compiled as a static library
7 * C++14 is the minimum required C++ version
8
9 There are many reasons why we decided to go from the old single-header
10 distribution model to a more standard library distribution model. The
11 big one is compile-time performance, but moving over to a split header
12 distribution model also improves the future maintainability and
13 extendability of the codebase. For example v3 adds a new kind of matchers
14 without impacting the compilation times of users that do not use matchers
15 in their tests. The new model is also more friendly towards package
16 managers, such as vcpkg and Conan.
17
18 The result of this move is a significant improvement in compilation
19 times, e.g. the inclusion overhead of Catch2 in the common case has been
20 reduced by roughly 80%. The improved ease of maintenance also led to
21 various runtime performance improvements and the introduction of new features.
22 For details, look at [the release notes of 3.0.1](release-notes.md#301).
23
24 _Note that we still provide one header + one translation unit (TU)
25 distribution but do not consider it the primarily supported option. You
26 should also expect that the compilation times will be worse if you use
27 this option._
28
29
30 ## How to migrate projects from v2 to v3
31
32 To migrate to v3, there are two basic approaches to do so.
33
34 1. Use `catch_amalgamated.hpp` and `catch_amalgamated.cpp`.
35 2. Build Catch2 as a proper (static) library, and move to piecewise headers
36
37 Doing 1 means downloading the [amalgamated header](/extras/catch_amalgamated.hpp)
38 and the [amalgamated sources](/extras/catch_amalgamated.cpp) from `extras`,
39 dropping them into your test project, and rewriting your includes from
40 `<catch2/catch.hpp>` to `"catch_amalgamated.hpp"` (or something similar,
41 based on how you set up your paths).
42
43 The disadvantage of using this approach are increased compilation times,
44 at least compared to the second approach, but it does let you avoid
45 dealing with consuming libraries in your build system of choice.
46
47
48 However, we recommend doing 2, and taking extra time to migrate to v3
49 properly. This lets you reap the benefits of significantly improved
50 compilation times in the v3 version. The basic steps to do so are:
51
52 1. Change your CMakeLists.txt to link against `Catch2WithMain` target if
53 you use Catch2's default main. (If you do not, keep linking against
54 the `Catch2` target.). If you use pkg-config, change `pkg-config catch2` to
55 `pkg-config catch2-with-main`.
56 2. Delete TU with `CATCH_CONFIG_RUNNER` or `CATCH_CONFIG_MAIN` defined,
57 as it is no longer needed.
58 3. Change `#include <catch2/catch.hpp>` to `#include <catch2/catch_all.hpp>`
59 4. Check that everything compiles. You might have to modify namespaces,
60 or perform some other changes (see the
61 [Things that can break during porting](#things-that-can-break-during-porting)
62 section for the most common things).
63 5. Start migrating your test TUs from including `<catch2/catch_all.hpp>`
64 to piecemeal includes. You will likely want to start by including
65 `<catch2/catch_test_macros.hpp>`, and then go from there. (see
66 [other notes](#other-notes) for further ideas)
67
68 ## Other notes
69
70 * The main test include is now `<catch2/catch_test_macros.hpp>`
71
72 * Big "subparts" like Matchers, or Generators, have their own folder, and
73 also their own "big header", so if you just want to include all matchers,
74 you can include `<catch2/matchers/catch_matchers_all.hpp>`,
75 or `<catch2/generators/catch_generators_all.hpp>`
76
77
78 ## Things that can break during porting
79
80 * The namespaces of Matchers were flattened and cleaned up.
81
82 Matchers are no longer declared deep within an internal namespace and
83 then brought up into `Catch` namespace. All Matchers now live in the
84 `Catch::Matchers` namespace.
85
86 * The `Contains` string matcher was renamed to `ContainsSubstring`.
87
88 * The reporter interfaces changed in a breaking manner.
89
90 If you are using a custom reporter or listener, you will likely need to
91 modify them to conform to the new interfaces. Unlike before in v2,
92 the [interfaces](reporters.md#top) and the [events](reporter-events.md#top)
93 are now documented.
94
95
96 ---
97
98 [Home](Readme.md#top)