From 17c11e9601941afacc5f8c0e598a573519899775 Mon Sep 17 00:00:00 2001 From: Nandan V Date: Wed, 5 Oct 2022 03:50:40 +0000 Subject: [PATCH] Just some documentation. --- docs/assertions.md | 24 +++++++++++++++++++++++- docs/benchmarks.md | 3 +++ docs/generators.md | 13 +++++++++++++ docs/matchers.md | 3 +++ 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/docs/assertions.md b/docs/assertions.md index 682eb6e7..8626b98b 100644 --- a/docs/assertions.md +++ b/docs/assertions.md @@ -15,6 +15,9 @@ Catch is different. Because it decomposes natural C-style conditional expression Most of these macros come in two forms: ## Natural Expressions +```cpp +#include +``` The ```REQUIRE``` family of macros tests an expression and aborts the test case if it fails. The ```CHECK``` family are equivalent but execution continues in the same test case even if the assertion fails. This is useful if you have a series of essentially orthogonal assertions and it is useful to see all the results rather than stopping at the first failure. @@ -52,6 +55,9 @@ This expression is too complex because of the `||` operator. If you want to chec ### Floating point comparisons +```cpp +#include +``` When comparing floating point numbers - especially if at least one of them has been computed - great care must be taken to allow for rounding errors and inexact representations. @@ -124,7 +130,9 @@ Expects that an exception of the _specified type_ is thrown during evaluation of * **REQUIRE_THROWS_WITH(** _expression_, _string or string matcher_ **)** and * **CHECK_THROWS_WITH(** _expression_, _string or string matcher_ **)** - +```cpp +#include +``` Expects that an exception is thrown that, when converted to a string, matches the _string_ or _string matcher_ provided (see next section for Matchers). e.g. @@ -196,6 +204,20 @@ TEST_CASE_METHOD((Fixture), "foo", "[bar]") { This solution is not always applicable, because it might require extra changes on the Catch's side to work. +## Lambdas +Lambdas are a C++ language feature and can be freely used inside a `TEST_CASE` or a `SECTION`. + +```cpp +#include + +TEST_CASE("Dumb") { + auto fnTest = [](const bool bPass) { CHECK(bPass); }; + + fnTest(true); +} +``` +[godbolt](https://catch2.godbolt.org/z/ebdr9vKcj) + --- [Home](Readme.md#top) diff --git a/docs/benchmarks.md b/docs/benchmarks.md index 548913c7..6f57564e 100644 --- a/docs/benchmarks.md +++ b/docs/benchmarks.md @@ -45,6 +45,9 @@ User code that cannot be executed repeatedly will lead to bogus results or crashes. ## Benchmark specification +```cpp +#include +``` Benchmarks can be specified anywhere inside a Catch test case. There is a simple and a slightly more advanced version of the `BENCHMARK` macro. diff --git a/docs/generators.md b/docs/generators.md index 7a865d43..c0a9415b 100644 --- a/docs/generators.md +++ b/docs/generators.md @@ -2,6 +2,9 @@ # Data Generators > Introduced in Catch2 2.6.0. +```cpp +#include +``` Data generators (also known as _data driven/parametrized test cases_) let you reuse the same set of assertions across different input values. @@ -145,6 +148,16 @@ type, making their usage much nicer. These are > `range()` for floating point numbers has been introduced in Catch2 2.11.0 +### Random generators +```cpp +#include +``` + +### Range generators +```cpp +#include +``` + And can be used as shown in the example below to create a generator that returns 100 odd random number: diff --git a/docs/matchers.md b/docs/matchers.md index f71f18a3..03995460 100644 --- a/docs/matchers.md +++ b/docs/matchers.md @@ -15,6 +15,9 @@ own and combine them with the Catch2-provided matchers seamlessly. ## Using Matchers +```cpp +#include +``` Matchers are most commonly used in tandem with the `REQUIRE_THAT` or `CHECK_THAT` macros. The `REQUIRE_THAT` macro takes two arguments,