Debian Codegraph @

3rdparty/catch2/README.md

raw symbols SCIP
1 <a id="top"></a>
2 ![Catch2 logo](data/artwork/catch2-logo-small-with-background.png)
3
4 [![Github Releases](https://img.shields.io/github/release/catchorg/catch2.svg)](https://github.com/catchorg/catch2/releases)
5 [![Linux build status](https://github.com/catchorg/Catch2/actions/workflows/linux-simple-builds.yml/badge.svg)](https://github.com/catchorg/Catch2/actions/workflows/linux-simple-builds.yml)
6 [![Linux build status](https://github.com/catchorg/Catch2/actions/workflows/linux-other-builds.yml/badge.svg)](https://github.com/catchorg/Catch2/actions/workflows/linux-other-builds.yml)
7 [![MacOS build status](https://github.com/catchorg/Catch2/actions/workflows/mac-builds.yml/badge.svg)](https://github.com/catchorg/Catch2/actions/workflows/mac-builds.yml)
8 [![Build Status](https://ci.appveyor.com/api/projects/status/github/catchorg/Catch2?svg=true&branch=devel)](https://ci.appveyor.com/project/catchorg/catch2)
9 [![Code Coverage](https://codecov.io/gh/catchorg/Catch2/branch/devel/graph/badge.svg)](https://codecov.io/gh/catchorg/Catch2)
10 [![Try online](https://img.shields.io/badge/try-online-blue.svg)](https://godbolt.org/z/EdoY15q9G)
11 [![Join the chat in Discord: https://discord.gg/4CWS9zD](https://img.shields.io/badge/Discord-Chat!-brightgreen.svg)](https://discord.gg/4CWS9zD)
12
13
14 ## What is Catch2?
15
16 Catch2 is mainly a unit testing framework for C++, but it also
17 provides basic micro-benchmarking features, and simple BDD macros.
18
19 Catch2's main advantage is that using it is both simple and natural.
20 Test names do not have to be valid identifiers, assertions look like
21 normal C++ boolean expressions, and sections provide a nice and local way
22 to share set-up and tear-down code in tests.
23
24 **Example unit test**
25 ```cpp
26 #include <catch2/catch_test_macros.hpp>
27
28 #include <cstdint>
29
30 uint32_t factorial( uint32_t number ) {
31 return number <= 1 ? number : factorial(number-1) * number;
32 }
33
34 TEST_CASE( "Factorials are computed", "[factorial]" ) {
35 REQUIRE( factorial( 1) == 1 );
36 REQUIRE( factorial( 2) == 2 );
37 REQUIRE( factorial( 3) == 6 );
38 REQUIRE( factorial(10) == 3'628'800 );
39 }
40 ```
41
42 **Example microbenchmark**
43 ```cpp
44 #include <catch2/catch_test_macros.hpp>
45 #include <catch2/benchmark/catch_benchmark.hpp>
46
47 #include <cstdint>
48
49 uint64_t fibonacci(uint64_t number) {
50 return number < 2 ? number : fibonacci(number - 1) + fibonacci(number - 2);
51 }
52
53 TEST_CASE("Benchmark Fibonacci", "[!benchmark]") {
54 REQUIRE(fibonacci(5) == 5);
55
56 REQUIRE(fibonacci(20) == 6'765);
57 BENCHMARK("fibonacci 20") {
58 return fibonacci(20);
59 };
60
61 REQUIRE(fibonacci(25) == 75'025);
62 BENCHMARK("fibonacci 25") {
63 return fibonacci(25);
64 };
65 }
66 ```
67
68 _Note that benchmarks are not run by default, so you need to run it explicitly
69 with the `[!benchmark]` tag._
70
71
72 ## Catch2 v3 has been released!
73
74 You are on the `devel` branch, where the v3 version is being developed.
75 v3 brings a bunch of significant changes, the big one being that Catch2
76 is no longer a single-header library. Catch2 now behaves as a normal
77 library, with multiple headers and separately compiled implementation.
78
79 The documentation is slowly being updated to take these changes into
80 account, but this work is currently still ongoing.
81
82 For migrating from the v2 releases to v3, you should look at [our
83 documentation](docs/migrate-v2-to-v3.md#top). It provides a simple
84 guidelines on getting started, and collects most common migration
85 problems.
86
87 For the previous major version of Catch2 [look into the `v2.x` branch
88 here on GitHub](https://github.com/catchorg/Catch2/tree/v2.x).
89
90
91 ## How to use it
92 This documentation comprises these three parts:
93
94 * [Why do we need yet another C++ Test Framework?](docs/why-catch.md#top)
95 * [Tutorial](docs/tutorial.md#top) - getting started
96 * [Reference section](docs/Readme.md#top) - all the details
97
98
99 ## More
100 * Issues and bugs can be raised on the [Issue tracker on GitHub](https://github.com/catchorg/Catch2/issues)
101 * For discussion or questions please use [our Discord](https://discord.gg/4CWS9zD)
102 * See who else is using Catch2 in [Open Source Software](docs/opensource-users.md#top)
103 or [commercially](docs/commercial-users.md#top).