### Install Catch2 using vcpkg
Source: https://github.com/catchorg/catch2/blob/devel/docs/cmake-integration.md
Steps to install Catch2 using the vcpkg dependency manager. This includes cloning vcpkg, bootstrapping, integrating, and installing catch2.
```bash
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh
./vcpkg integrate install
./vcpkg install catch2
```
--------------------------------
### Basic CMake Setup for Catch2 Tests
Source: https://github.com/catchorg/catch2/blob/devel/docs/cmake-integration.md
This example shows the minimal CMake configuration required to find the Catch2 package, build an executable with tests, and link it against the Catch2 library.
```cmake
cmake_minimum_required(VERSION 3.16)
project(baz LANGUAGES CXX VERSION 0.0.1)
find_package(Catch2 REQUIRED)
add_executable(tests test.cpp)
target_link_libraries(tests PRIVATE Catch2::Catch2)
include(CTest)
include(ParseAndAddCatchTests)
ParseAndAddCatchTests(tests)
```
--------------------------------
### Install Catch2 from Git Repository using CMake
Source: https://github.com/catchorg/catch2/blob/devel/docs/cmake-integration.md
Instructions for cloning the Catch2 repository, configuring the build with CMake, and installing it. Use BUILD_TESTING=OFF to skip building tests.
```bash
$ git clone https://github.com/catchorg/Catch2.git
$ cd Catch2
$ cmake -B build -S . -DBUILD_TESTING=OFF
$ sudo cmake --build build/ --target install
```
--------------------------------
### Benchmark Model Started Check
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.multi.approved.txt
Verifies the 'model.started' state in benchmark tests. This check is used when the benchmark is expected to have started.
```xml
model.started == 1
1 == 1
```
```xml
model.started == 0
0 == 0
```
--------------------------------
### Verify Default Output Filename
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.multi.approved.txt
This example checks if the `defaultOutputFilename` configuration is correctly set to the provided filename after parsing.
```cpp
config.defaultOutputFilename == "filename.ext"
```
--------------------------------
### StartsWith String Matcher Examples
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/console.sw.multi.approved.txt
Illustrates the usage and output of the StartsWith string matcher in Catch2, including case-sensitive and case-insensitive comparisons.
```cpp
CHECK_THAT( testStringForMatching(), StartsWith( "This String" ) )
with expansion:
"this string contains 'abc' as a substring" starts with: "This String"
```
```cpp
CHECK_THAT( testStringForMatching(), StartsWith( "string", Catch::CaseSensitive::No ) )
with expansion:
"this string contains 'abc' as a substring" starts with: "string" (case
insensitive)
```
--------------------------------
### Catch2 License Header
Source: https://github.com/catchorg/catch2/blob/devel/docs/contributing.md
All source files must start with this license header.
```cpp
// Copyright Catch2 Authors
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.txt or copy at
// https://www.boost.org/LICENSE_1_0.txt)
// SPDX-License-Identifier: BSL-1.0
```
--------------------------------
### Basic Assertion Example
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/console.sw.approved.txt
Demonstrates a simple assertion using REQUIRE_FALSE. This is typically used to verify that a condition is not met.
```cpp
REQUIRE_FALSE( 1 == 2 )
```
--------------------------------
### MatchAllOfGeneric Nesting Example
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.multi.approved.txt
Demonstrates the evaluation of nested MatchAllOfGeneric expressions. This is useful for complex AND conditions.
```cpp
1, ( MatcherA() && MatcherB() ) && MatcherC()
```
```cpp
1, MatcherA() && ( MatcherB() && MatcherC() )
```
```cpp
1, ( MatcherA() && MatcherB() ) && ( MatcherC() && MatcherD() )
```
--------------------------------
### Create a Custom Streaming Reporter in C++
Source: https://github.com/catchorg/catch2/blob/devel/docs/reporters.md
Example of a custom reporter inheriting from StreamingReporterBase. It responds to test case partial start and end events and registers itself with the name 'partial'.
```cpp
#include
#include
#include
#include
class PartialReporter : public Catch::StreamingReporterBase {
public:
using StreamingReporterBase::StreamingReporterBase;
static std::string getDescription() {
return "Reporter for testing TestCasePartialStarting/Ended events";
}
void testCasePartialStarting(Catch::TestCaseInfo const& testInfo,
uint64_t partNumber) override {
std::cout << "TestCaseStartingPartial: " << testInfo.name << '#' << partNumber << '\n';
}
void testCasePartialEnded(Catch::TestCaseStats const& testCaseStats,
uint64_t partNumber) override {
std::cout << "TestCasePartialEnded: " << testCaseStats.testInfo->name << '#' << partNumber << '\n';
}
};
CATCH_REGISTER_REPORTER("partial", PartialReporter)
```
--------------------------------
### UnorderedEquals Matcher Examples
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.approved.txt
Showcases the UnorderedEquals matcher for comparing vectors where element order does not matter. Includes examples with custom allocators and permuted vectors.
```cpp
v, UnorderedEquals( v )
```
```cpp
v, UnorderedEquals( { 3, 2, 1 } )
```
```cpp
empty, UnorderedEquals( empty )
```
```cpp
permuted, UnorderedEquals( v )
```
```cpp
permuted, UnorderedEquals( v )
```
```cpp
v5, ( UnorderedEquals, CustomAllocator>( permuted ) )
```
```cpp
v5_permuted, UnorderedEquals( v5 )
```
--------------------------------
### Catch2 Equals Matcher Examples
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.approved.txt
Illustrates the Equals matcher for exact sequence comparison. Covers cases with empty and non-empty sequences.
```cpp
v, Equals( v2 )
```
```cpp
{ 1, 2, 3 } Equals: { 1, 2 }
```
```cpp
v2, Equals( v )
```
```cpp
{ 1, 2 } Equals: { 1, 2, 3 }
```
```cpp
empty, Equals( v )
```
```cpp
{ } Equals: { 1, 2, 3 }
```
```cpp
v, Equals( empty )
```
```cpp
{ 1, 2, 3 } Equals: { }
```
--------------------------------
### Equals Matcher Examples
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.approved.txt
Demonstrates the usage of the Equals matcher for various scenarios, including empty containers, vectors with specific elements, and custom allocators.
```cpp
empty, Equals( empty )
```
```cpp
v, Equals( { 1, 2, 3 } )
```
```cpp
v, Equals( v2 )
```
```cpp
v5, ( Equals, CustomAllocator>( v2 ) )
```
```cpp
v5, Equals( v6 )
```
--------------------------------
### XML Reporter Configuration
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/console.sw.multi.approved.txt
Verifies the command-line setup for the XML reporter, ensuring that the reporter specification matches the expected 'xml' type.
```cpp
CHECK( result )
with message:
result.errorMessage() := ""
```
```cpp
REQUIRE( config.reporterSpecifications == vec_Specs{ { "xml", {}, {}, {} } } )
with expansion:
{ {?} } == { {?} }
with message:
result.errorMessage() := ""
```
--------------------------------
### Combining Templated Matchers Example
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.multi.approved.txt
Demonstrates combining templated matchers using the OR operator. This is for scenarios where any of the conditions should pass.
```cpp
1, MatcherA() || MatcherB()
```
--------------------------------
### Combine Concrete Matchers
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/console.sw.approved.txt
Demonstrates combining concrete matchers (e.g., StartsWith, EndsWith) with logical operators. This example shows a mix of OR and AND operations.
```cpp
std::is_same>::value
```
--------------------------------
### Nested generators example
Source: https://github.com/catchorg/catch2/blob/devel/docs/filtering-execution-path.md
Demonstrates filtering with nested generators. The behavior depends on the indices provided for each generator.
```cpp
TEST_CASE( "waldo" ) {
auto i = GENERATE( 1, 10, 100 );
auto j = GENERATE( 2, 20, 200 );
CAPTURE( i, j );
REQUIRE( true );
}
```
--------------------------------
### Basic Generator Usage
Source: https://github.com/catchorg/catch2/blob/devel/docs/generators.md
A simple example demonstrating how `GENERATE` reuses a test case for each provided value. Requires `#include `.
```cpp
TEST_CASE("Generators") {
auto i = GENERATE(1, 3, 5);
REQUIRE(is_odd(i));
}
```
--------------------------------
### Basic Test Case Definitions
Source: https://github.com/catchorg/catch2/blob/devel/docs/command-line.md
These are example test cases used to demonstrate filtering. They include different names and tags.
```cpp
TEST_CASE("Test 1") {}
TEST_CASE("Test 2", "[.foo]") {}
TEST_CASE("Test 3", "[.bar]") {}
TEST_CASE("Test 4", "[.][foo][bar]") {}
```
--------------------------------
### String StartsWith matcher (case-sensitive)
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.approved.txt
Tests the StartsWith string matcher for case-sensitive prefix checking. The original string does not start with the specified prefix.
```cpp
testStringForMatching(), StartsWith( "This String" )
```
```cpp
"this string contains 'abc' as a substring" starts with: "This String"
```
--------------------------------
### Benchmark measure check
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.approved.txt
These examples demonstrate checks performed during a benchmark measurement. They verify specific values of `x`, elapsed time, result, and iterations.
```cpp
x == 17
```
```cpp
x == 23
```
```cpp
r.elapsed.count() == 42
```
```cpp
r.result == 23
```
```cpp
r.iterations == 1
```
```cpp
s.elapsed.count() == 69
```
--------------------------------
### Variable Assignment Example
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.multi.approved.txt
A simple variable assignment, likely for setup or context within a test.
```text
a := 1
```
--------------------------------
### String Size Check
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/console.std.approved.txt
Verifies the size of a string. This failing example checks if the string size is not equal to 5.
```cpp
CHECK( data.str_hello.size() != 5 )
```
--------------------------------
### SizeIs Matcher - Negated Exact Size
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/console.sw.multi.approved.txt
This example demonstrates negating the SizeIs matcher to assert that a container does not have a specific size.
```cpp
REQUIRE_THAT( empty_vec, !SizeIs(2) )
```
--------------------------------
### Generator Get Value Check (Further Negative)
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.approved.txt
Asserts the current value obtained from a generator using `gen.get()`. This example demonstrates checking for a further negative value after subsequent generation steps.
```cpp
gen.get() == -4
```
```cpp
-4 == -4
```
--------------------------------
### String Matcher: StartsWith
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/console.std.approved.txt
Demonstrates the StartsWith string matcher for exact and case-insensitive prefix checks.
```cpp
CHECK_THAT( testStringForMatching(), StartsWith( "This String" ) )
```
```cpp
CHECK_THAT( testStringForMatching(), StartsWith( "string", Catch::CaseSensitive::No ) )
```
--------------------------------
### Check Starts With Character
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.approved.txt
Demonstrates the startsWith function for checking if a string begins with a specific character. Includes checks for empty strings and different string types.
```cpp
!(startsWith("", 'c'))
```
```cpp
startsWith(std::string("abc"), 'a')
```
```cpp
startsWith("def"_catch_sr, 'd')
```
--------------------------------
### Handle Substring Starting After End
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.approved.txt
Tests if a substring operation starting at an index far beyond the string's length correctly returns an empty string. This ensures robustness when dealing with invalid start positions.
```cpp
s.substr(1'000'000, 1).empty()
true
```
--------------------------------
### Print Help Message
Source: https://github.com/catchorg/catch2/blob/devel/docs/command-line.md
Displays a list of available command-line arguments and their descriptions.
```bash
-h, -?, --help
```
--------------------------------
### Stream Handling for Unknown %-Starting Streams
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/console.sw.approved.txt
Verifies that attempting to create a stream with an unknown %-starting identifier throws an exception.
```cpp
REQUIRE_THROWS( Catch::makeStream( "%somestream" ) )
```
--------------------------------
### String Equality Check
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/console.std.approved.txt
A basic check for string equality. This example demonstrates a failing assertion where the string content does not match.
```cpp
CHECK( data.str_hello != "hello" )
```
--------------------------------
### StringRef Substring Start After End
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/console.sw.approved.txt
Tests creating a substring that starts significantly after the end of the original string. The resulting substring should be empty.
```cpp
REQUIRE( s.substr(1'000'000, 1).empty() )
```
--------------------------------
### Execute Build and Test Script
Source: https://github.com/catchorg/catch2/blob/devel/docs/contributing.md
Run the convenience script for building and testing Catch2. Ensure you are in the Catch2 directory before execution.
```bash
cd Catch2
./tools/scripts/buildAndTest.sh
```
--------------------------------
### Get Single Value from Generator
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.approved.txt
Verifies retrieving the current value from a generator. Ensure the generator is properly initialized before calling get().
```cpp
gen.get() == 123
```
--------------------------------
### Benchmark Catch2 SelfTest build time (debug)
Source: https://github.com/catchorg/catch2/blob/devel/benchmarks/readme.md
Compares the build time of Catch2's `SelfTest` suite in a debug configuration. The `--prepare` command ensures all source files are touched before building.
```bash
hyperfine --warmup 2 --parameter-list version old,vas --prepare 'find ~/benches/Catch2-{version}/tests/SelfTest -type f -name "*.cpp" -exec touch {} +' 'ninja -j 1 -C ~/benches/Catch2-{version}/build-debug'
```
--------------------------------
### Generator next() and get() calls
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.approved.txt
Demonstrates the sequence of calling gen.next() and gen.get() to advance a generator and retrieve its value. This pattern is used to test generator behavior.
```cpp
gen.next()
```
```cpp
gen.get() == 2
```
```cpp
gen.next()
```
```cpp
gen.get() == -1
```
```cpp
gen.next()
```
```cpp
gen.get() == -4
```
```cpp
gen.next()
```
```cpp
gen.get() == -7
```
```cpp
!(gen.next())
```
--------------------------------
### Equals String Matcher (Case Insensitive)
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.multi.approved.txt
Demonstrates the Equals matcher with case-insensitive comparison. This example shows a successful match regardless of case.
```cpp
testStringForMatching(), Equals( "this string contains 'ABC' as a substring", Catch::CaseSensitive::No )
```
```cpp
"this string contains 'abc' as a substring" equals: "this string contains 'abc' as a substring" (case insensitive)
```
--------------------------------
### Identify Framework and Version
Source: https://github.com/catchorg/catch2/blob/devel/docs/command-line.md
Outputs framework and version information according to the libIdentify standard.
```bash
--libidentify
```
--------------------------------
### Composed Matcher Examples (C++)
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.multi.approved.txt
Shows how to combine different matchers using logical OR (||) for more complex assertions. Useful when a value must satisfy one of several conditions.
```cpp
1.f, WithinAbs( 1.f, 0.5 ) || WithinULP( 1.f, 1 )
```
```cpp
1.f, WithinAbs( 2.f, 0.5 ) || WithinULP( 1.f, 0 )
```
```cpp
0.0001f, WithinAbs( 0.f, 0.001f ) || WithinRel( 0.f, 0.1f )
```
--------------------------------
### JSON String Escaping Examples
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.approved.txt
Demonstrates how various special characters within JSON strings are escaped and asserted in Catch2. These examples show the original and expanded forms of the assertions.
```cpp
sstream.str() == "\"\\b\""
```
```cpp
"\b" == "\b"
```
```cpp
sstream.str() == "\"\\f\""
```
```cpp
"\f" == "\f"
```
```cpp
sstream.str() == "\"\\n\""
```
```cpp
"\n" == "\n"
```
```cpp
sstream.str() == "\"\\r\""
```
```cpp
"\r" == "\r"
```
```cpp
sstream.str() == "\"\\t\""
```
```cpp
"\t" == "\t"
```
```cpp
sstream.str() == "\"\\\\/\t\r\n\""
```
```cpp
"\\/\t\r\n" == "\\/\t\r\n"
```
--------------------------------
### More Varied Assertions
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/console.sw.multi.approved.txt
Further examples of assertions with varying values and successful checks.
```cpp
CHECK( x < y )
with expansion:
3 < 6
```
```cpp
CHECK( y < z )
with expansion:
6 < 8
```
```cpp
REQUIRE( x < z )
with expansion:
3 < 8
```
--------------------------------
### Build and Run All Catch2 Tests
Source: https://github.com/catchorg/catch2/blob/devel/docs/contributing.md
This sequence of commands regenerates amalgamated files, configures a full test build in Debug mode using the 'all-tests' preset, and then builds the project. This is recommended for running all test types.
```sh
# 1. Regenerate the amalgamated distribution (some tests are built against it)
./tools/scripts/generateAmalgamatedFiles.py
# 2. Configure the full test build
cmake -B debug-build -S . -DCMAKE_BUILD_TYPE=Debug --preset all-tests
# 3. Run the actual build
cmake --build debug-build
```
--------------------------------
### Basic Generator Usage with REQUIRE
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/console.sw.approved.txt
Demonstrates basic generator usage with REQUIRE assertions. Shows comparisons between generated values and fixed values.
```cpp
REQUIRE( j < i )
with expansion:
-3 < 3
```
```cpp
REQUIRE( j < i )
with expansion:
-2 < 3
```
```cpp
REQUIRE( j < i )
with expansion:
-1 < 3
```
```cpp
REQUIRE( 4u * i > str.size() )
with expansion:
12 > 1
```
```cpp
REQUIRE( 4u * i > str.size() )
with expansion:
12 > 2
```
```cpp
REQUIRE( 4u * i > str.size() )
with expansion:
12 > 3
```
--------------------------------
### Capturing standard output messages
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.approved.txt
This example shows how standard output messages from test sections are captured and reported, particularly useful for debugging.
```cpp
Message from section one
Message from section two
```
--------------------------------
### Command Line Process Configuration (Default)
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/console.sw.approved.txt
Tests the default command-line process configuration when no arguments are explicitly given. Verifies default settings like process name, debug break, and reporter specifications.
```cpp
CHECK( result )
```
```cpp
CHECK( config.processName == "test" )
```
```cpp
CHECK( config.shouldDebugBreak == false )
```
```cpp
CHECK( config.abortAfter == -1 )
```
```cpp
CHECK( config.noThrow == false )
```
```cpp
CHECK( config.reporterSpecifications.empty() )
```
```cpp
CHECK_FALSE( cfg.hasTestFilters() )
```
```cpp
CHECK( cfg.getReporterSpecs().size() == 1 )
```
```cpp
CHECK( cfg.getReporterSpecs()[0] == Catch::ReporterSpec{ expectedReporter, {}, {}, {} } )
```
```cpp
CHECK( cfg.getProcessedReporterSpecs().size() == 1 )
```
--------------------------------
### Skipped test example
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/console.sw.approved.txt
Demonstrates a test case that is marked as PASSED but also SKIPPED.
```cpp
// No code provided for this example, only test status.
```
--------------------------------
### Multiple Reporters with Output Files
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/console.sw.approved.txt
Tests the ability to configure multiple reporters, each with its own specified output file. This is useful for complex reporting setups.
```cpp
CHECK( cli.parse({ "test", "-r", "xml::out=output.xml", "-r", "junit::out=output-junit.xml" }) )
with expansion:
{?}
```
```cpp
REQUIRE( config.reporterSpecifications == vec_Specs{ { "xml", "output.xml"s, {}, {} }, { "junit", "output-junit.xml"s, {}, {} } } )
with expansion:
{ {?}, {?} } == { {?}, {?} }
```
--------------------------------
### Scoped Message Survival
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/console.std.approved.txt
Example of messages that are expected to survive the end of a test section.
```cpp
Message.tests.cpp:: FAILED:
REQUIRE( false )
with message:
Should survive a section end
A string sent directly to stdout
A string sent directly to stderr
A string sent to stderr via clog
Message from section one
Message from section two
```
--------------------------------
### Benchmark REQUIRE with stringification (release build)
Source: https://github.com/catchorg/catch2/blob/devel/benchmarks/readme.md
Compares the performance of `REQUIRE` with stringification enabled in a release build. Redirecting output to /dev/null helps isolate the impact of stringification.
```bash
hyperfine --warmup 2 --shell none --parameter-list version old,new '/home/xarn/benches/Catch2-{version}/build-release/benchmarks/AssertionsFastPath -s -o /dev/null "REQUIRE"'
```
--------------------------------
### Integrate Catch2 using FetchContent
Source: https://github.com/catchorg/catch2/blob/devel/docs/cmake-integration.md
Use FetchContent to download and integrate Catch2 directly from its Git repository into your CMake project. This is an alternative to system-wide installation or subdirectory inclusion.
```cmake
Include(FetchContent)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.8.1 # or a later release
)
FetchContent_MakeAvailable(Catch2)
add_executable(tests test.cpp)
target_link_libraries(tests PRIVATE Catch2::Catch2WithMain)
```
--------------------------------
### Crosslink to Contributing Page
Source: https://github.com/catchorg/catch2/blob/devel/docs/contributing.md
Example of creating a crosslink to the top anchor of the contributing page.
```markdown
[link to contributing](contributing.md#top)
```
--------------------------------
### AllMatch Basic Usage
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.approved.txt
Demonstrates the basic usage of the AllMatch matcher with a simple range and predicate.
```cpp
mocked, allMatch
```
```cpp
{ 1, 2, 3, 4, 5 } all match matches undescribed predicate
```
```cpp
mocked.m_derefed[0]
```
```cpp
true
```
```cpp
mocked.m_derefed[1]
```
```cpp
true
```
```cpp
mocked.m_derefed[2]
```
```cpp
true
```
```cpp
mocked.m_derefed[3]
```
```cpp
true
```
```cpp
mocked.m_derefed[4]
```
```cpp
true
```
--------------------------------
### Catch2 UnorderedEquals Matcher Examples
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.approved.txt
Shows the UnorderedEquals matcher for comparing sequences irrespective of element order. Includes checks with empty and permuted sequences.
```cpp
v, UnorderedEquals( empty )
```
```cpp
{ 1, 2, 3 } UnorderedEquals: { }
```
```cpp
empty, UnorderedEquals( v )
```
```cpp
{ } UnorderedEquals: { 1, 2, 3 }
```
```cpp
permuted, UnorderedEquals( v )
```
```cpp
{ 1, 3 } UnorderedEquals: { 1, 2, 3 }
```
```cpp
permuted, UnorderedEquals( v )
```
```cpp
{ 3, 1 } UnorderedEquals: { 1, 2, 3 }
```
--------------------------------
### MatchAnyOfGeneric Nesting Example
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.multi.approved.txt
Illustrates the evaluation of nested MatchAnyOfGeneric expressions. Suitable for complex OR conditions.
```cpp
1, ( MatcherA() || MatcherB() ) || MatcherC()
```
```cpp
1, MatcherA() || ( MatcherB() || MatcherC() )
```
```cpp
1, ( MatcherA() || MatcherB() ) || ( MatcherC() || MatcherD() )
```
--------------------------------
### Benchmark Warmup Time Command Line Option
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/console.sw.approved.txt
Tests the parsing and application of the '--benchmark-warmup-time' command-line option. This sets the warmup duration for benchmarks.
```cpp
CHECK( cli.parse({ "test", "--benchmark-warmup-time=10" }) )
```
```cpp
REQUIRE( config.benchmarkWarmupTime == 10 )
```
--------------------------------
### AnyMatch with SizeIs Matcher
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.approved.txt
Use AnyMatch to check if any element in a collection satisfies a given size constraint. This example verifies if any of the provided collections have a size of 5.
```cpp
data, AnyMatch(SizeIs(5))
```
```cpp
{ { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } any match has size == 5
```
--------------------------------
### Command Line Process Configuration (Empty Args)
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/console.sw.approved.txt
Tests the command-line argument parsing when no arguments are provided. Ensures the process name is empty and no crashes occur.
```cpp
CHECK( result )
```
```cpp
CHECK( config.processName == "" )
```
--------------------------------
### Wait for Keypress
Source: https://github.com/catchorg/catch2/blob/devel/docs/command-line.md
Pauses execution and waits for the Enter key before continuing. Can be set to occur at the start, exit, or both.
```bash
--wait-for-keypress
```
--------------------------------
### SizeIs Matcher - Exact Size
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/console.sw.multi.approved.txt
Use SizeIs to assert the exact size of a container. This example checks for an empty container and a container with a specific size.
```cpp
REQUIRE_THAT( empty_vec, SizeIs(0) )
```
```cpp
REQUIRE_THAT( arr, SizeIs(2) )
```
```cpp
REQUIRE_THAT( map, SizeIs(3) )
```
--------------------------------
### Generator get() Assertion
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.approved.txt
Asserts the current value of a generator using gen.get(). Used with REQUIRE for success.
```cpp
gen.get() == 2
```
```cpp
2 == 2
```
```cpp
gen.get() == 5
```
```cpp
5 == 5
```
--------------------------------
### Final Assertion Set
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/console.sw.multi.approved.txt
The last set of assertion examples, demonstrating successful comparisons with specific values.
```cpp
CHECK( x < y )
with expansion:
3 < 6
```
```cpp
CHECK( y < z )
with expansion:
6 < 9
```
```cpp
REQUIRE( x < z )
with expansion:
3 < 9
```
--------------------------------
### CHECK Assertion Example
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.multi.approved.txt
This snippet shows a successful CHECK assertion where the original expression is evaluated and compared.
```xml
a == 2
2 == 2
```
--------------------------------
### Console Process Configuration (Default Args)
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/console.sw.multi.approved.txt
Verifies the default configuration of the console process when no specific arguments are provided, checking process name, debug break, abort after, and reporter specifications.
```C++
CHECK( result )
```
```C++
CHECK( config.processName == "test" )
```
```C++
CHECK( config.shouldDebugBreak == false )
```
```C++
CHECK( config.abortAfter == -1 )
```
```C++
CHECK( config.noThrow == false )
```
```C++
CHECK( config.reporterSpecifications.empty() )
```
```C++
CHECK_FALSE( cfg.hasTestFilters() )
```
```C++
CHECK( cfg.getReporterSpecs().size() == 1 )
```
```C++
CHECK( cfg.getReporterSpecs()[0] == Catch::ReporterSpec{ expectedReporter, {}, {}, {} } )
```
```C++
CHECK( cfg.getProcessedReporterSpecs().size() == 1 )
```
--------------------------------
### Path Filter Configuration
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.multi.approved.txt
Demonstrates setting up path filters for sections and generators. Ensure the filter type and value match the desired test scope.
```cpp
config.pathFilters[0] == PathFilter( PathFilter::For::Section, "foo-bar" )
```
```cpp
config.pathFilters[1] == PathFilter( PathFilter::For::Generator, "3" )
```
```cpp
config.pathFilters[2] == PathFilter( PathFilter::For::Generator, "123" )
```
```cpp
config.pathFilters[3] == PathFilter( PathFilter::For::Section, "baz" )
```
```cpp
config.pathFilters[0] == PathFilter(PathFilter::For::Section, "untrimmed" )
```
```cpp
config.pathFilters[1] == PathFilter(PathFilter::For::Generator, "42" )
```
--------------------------------
### Test Tag Validation
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/console.sw.approved.txt
These assertions check that tags with invalid starting or ending characters are correctly rejected by the registry.
```cpp
CHECK_THROWS( registry.add( "@no square bracket at start]", "", Catch::SourceLineInfo( "file", 3 ) ) )
```
```cpp
CHECK_THROWS( registry.add( "[@no square bracket at end", "", Catch::SourceLineInfo( "file", 3 ) ) )
```
--------------------------------
### Equality Checks That Should Fail (Floating-Point)
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.multi.approved.txt
Demonstrates failing floating-point equality checks using Approx. These examples show comparisons that do not meet the approximate equality criteria.
```cpp
data.float_nine_point_one == Approx( 9.11f )
```
```cpp
9.100000381f
==
Approx( 9.10999965667724609 )
```
```cpp
data.float_nine_point_one == Approx( 9.0f )
```
```cpp
9.100000381f == Approx( 9.0 )
```
```cpp
data.float_nine_point_one == Approx( 1 )
```
```cpp
9.100000381f == Approx( 1.0 )
```
```cpp
data.float_nine_point_one == Approx( 0 )
```
```cpp
9.100000381f == Approx( 0.0 )
```
```cpp
data.double_pi == Approx( 3.1415 )
```
```cpp
3.14159265350000005
==
Approx( 3.14150000000000018 )
```
--------------------------------
### Catch2 REQUIRE Assertion Example
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/console.sw.approved.txt
A basic REQUIRE assertion used in Catch2 tests. This checks if an input is even.
```cpp
REQUIRE( input % 2 == 0 )
```
--------------------------------
### Configure multiple reporters with output files
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.approved.txt
Tests the parsing of command-line arguments to configure multiple reporters, each with its own output file. It verifies that the reporter specifications are correctly parsed and stored.
```cpp
cli.parse({ "test", "-r", "xml::out=output.xml", "-r", "junit::out=output-junit.xml" })
```
```cpp
config.reporterSpecifications == vec_Specs{ { "xml", "output.xml"s, {}, {} }, { "junit", "output-junit.xml"s, {}, {} } }
```
--------------------------------
### Failed CHECK Assertion Example
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.multi.approved.txt
This snippet illustrates a failed CHECK assertion, highlighting the original and expanded expressions.
```xml
a == 1
2 == 1
```
--------------------------------
### StartsWith String Matcher (Case Sensitive)
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.multi.approved.txt
Checks if a string begins with a specified prefix, with case sensitivity. Use for exact prefix matching.
```cpp
testStringForMatching(), StartsWith( "This String" )
```
```cpp
"this string contains 'abc' as a substring" starts with: "This String"
```
--------------------------------
### Parse Shard Index
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.approved.txt
Demonstrates parsing the shard index from command line arguments. Ensures the shard index is correctly set when provided.
```cpp
cli.parse({ "test", "--shard-index=2" })
config.shardIndex == 2
```
```cpp
cli.parse({ "test", "--shard-index=0" })
config.shardIndex == 0
```
--------------------------------
### Basic main() for Catch2 Test Execution
Source: https://github.com/catchorg/catch2/blob/devel/docs/own-main.md
Use this basic structure when you need to execute code before and after Catch2 runs its tests. Link against the static library without the main part.
```cpp
#include
int main( int argc, char* argv[] ) {
// your setup ...
int result = Catch::Session().run( argc, argv );
// your clean-up...
return result;
}
```
--------------------------------
### StringRef Substring Past End
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/console.sw.approved.txt
Tests creating a substring that starts past the end of the original string. Such substrings should be empty.
```cpp
REQUIRE( s.substr(s.size() + 1, 123).empty() )
```
--------------------------------
### Floating-Point Comparisons with Approx
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.approved.txt
Demonstrates the use of Approx for floating-point comparisons, showing expanded values for precision.
```cpp
data.float_nine_point_one != Approx( 9.0f )
```
```cpp
9.100000381f != Approx( 9.0 )
```
```cpp
data.float_nine_point_one != Approx( 1 )
```
```cpp
9.100000381f != Approx( 1.0 )
```
```cpp
data.float_nine_point_one != Approx( 0 )
```
```cpp
9.100000381f != Approx( 0.0 )
```
```cpp
data.double_pi != Approx( 3.1415 )
```
```cpp
3.14159265350000005
!=
Approx( 3.14150000000000018 )
```
--------------------------------
### Benchmark Introspection Checks
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.approved.txt
These expressions verify the state of benchmark models, checking if they have started or finished, and if a specific function was called.
```xml
model.finished == 0
0 == 0
```
```xml
model.started == 1
1 == 1
```
```xml
model.finished == 1
1 == 1
```
```xml
called == 1
1 == 1
```
--------------------------------
### Generator next() and get() assertions
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.multi.approved.txt
Tests generator behavior by asserting the return value of gen.get() and the boolean result of gen.next().
```cpp
gen.get() == 5
5 == 5
```
```cpp
gen.next()
true
```
```cpp
gen.get() == 2
2 == 2
```
```cpp
gen.next()
true
```
```cpp
gen.get() == -1
-1 == -1
```
```cpp
gen.next()
true
```
```cpp
gen.get() == -4
-4 == -4
```
```cpp
!(gen.next())
!false
```
--------------------------------
### Basic Assertions and String Matching
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/console.sw.multi.approved.txt
Includes examples of basic equality assertions using REQUIRE and CHECK, as well as string matching using Catch::Matchers::EndsWith. These are fundamental for verifying program logic and output.
```C++
REQUIRE( 42 == f )
```
```C++
REQUIRE( a == t )
```
```C++
CHECK( a == t )
```
```C++
REQUIRE_THAT( "aaa", Catch::Matchers::EndsWith("aaa") )
```
--------------------------------
### Get Single Value from Generator
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.multi.approved.txt
Asserts the current value of a generator. Ensure the generator is initialized or has advanced to the desired state.
```cpp
gen.get() == 123
```
--------------------------------
### String StartsWith matcher (case-insensitive)
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.approved.txt
Demonstrates the case-insensitive version of the StartsWith string matcher. It checks if the string begins with a specified prefix, ignoring case.
```cpp
testStringForMatching(), StartsWith( "string", Catch::CaseSensitive::No )
```
```cpp
"this string contains 'abc' as a substring" starts with: "string" (case insensitive)
```
--------------------------------
### Example C++ Microbenchmark with Catch2
Source: https://github.com/catchorg/catch2/blob/devel/README.md
Shows how to benchmark a function (e.g., Fibonacci) using Catch2's BENCHMARK macro. Note that benchmarks require explicit execution, often via tags like `[!benchmark]`.
```cpp
#include
#include
#include
uint64_t fibonacci(uint64_t number) {
return number < 2 ? number : fibonacci(number - 1) + fibonacci(number - 2);
}
TEST_CASE("Benchmark Fibonacci", "[!benchmark]") {
REQUIRE(fibonacci(5) == 5);
REQUIRE(fibonacci(20) == 6'765);
BENCHMARK("fibonacci 20") {
return fibonacci(20);
};
REQUIRE(fibonacci(25) == 75'025);
BENCHMARK("fibonacci 25") {
return fibonacci(25);
};
}
```
--------------------------------
### Combined Single-Character Flags
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.multi.approved.txt
This example shows how to parse combined single-character flags. Ensure that the flags are valid and supported for combination.
```cpp
cli.parse({"test", "-abe"})
```
--------------------------------
### Configure Wait For Keypress (0)
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/console.sw.multi.approved.txt
Verifies that 'waitForKeypress' is set to 0 when '--wait-for-keypress' is parsed with a corresponding input.
```cpp
REQUIRE( config.waitForKeypress == std::get<1>(input) )
```
--------------------------------
### Multiple Failed CHECK Assertions
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.multi.approved.txt
This example shows a sequence of failed CHECK assertions, demonstrating how multiple failures are reported.
```xml
a == 0
2 == 0
```
--------------------------------
### Approximate Comparisons with Epsilon
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.approved.txt
Illustrates using Catch2's Approx functionality for floating-point comparisons, including setting a custom epsilon for tolerance. These examples demonstrate less-than-or-equal-to comparisons.
```cpp
d <= Approx( 1.24 )
```
```cpp
d <= Approx( 1.23 )
```
```cpp
!(d <= Approx( 1.22 ))
```
```cpp
d <= Approx( 1.22 ).epsilon(0.1)
```
--------------------------------
### Equality Checks That Should Succeed
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/console.sw.approved.txt
Examples of various equality checks that are expected to succeed, including integer and approximate floating-point comparisons.
```cpp
REQUIRE( data.int_seven == 7 )
```
```cpp
REQUIRE( data.float_nine_point_one == Approx( 9.1f ) )
```
```cpp
REQUIRE( data.double_pi == Approx( 3.1415926535 ) )
```
--------------------------------
### Integer Ordering Comparisons (Succeed)
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.multi.approved.txt
Illustrates integer ordering comparisons that are expected to succeed. These tests cover conditions such as less than, greater than, greater than or equal to, and less than or equal to for integer values.
```cpp
7 < 8
```
```cpp
7 > 6
```
```cpp
7 > 0
```
```cpp
7 > -1
```
```cpp
7 >= 7
```
```cpp
7 >= 6
```
```cpp
7 <= 7
```
```cpp
7 <= 8
```
--------------------------------
### Assertion with a Message
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/console.sw.approved.txt
Example of asserting a condition and providing a custom message. This message is displayed if the assertion fails, aiding in debugging.
```cpp
REQUIRE( true )
with message:
a
```
--------------------------------
### MatchNotOfGeneric Negation Example
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.multi.approved.txt
Shows the behavior of the MatchNotOfGeneric matcher with varying levels of negation. Useful for asserting that a condition is NOT met.
```cpp
0, !MatcherA()
```
```cpp
1, !!MatcherA()
```
```cpp
0, !!!MatcherA()
```
```cpp
1, !!!!MatcherA()
```
--------------------------------
### Using Matchers with Different Values
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.approved.txt
Demonstrates the use of matchers with different input values and expected outcomes.
```cpp
Using code: 2
A
B
Using code: 0
C
```
```cpp
Using code: 2
A
B
Using code: 0
C
```
--------------------------------
### REQUIRE_FALSE Condition
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.multi.approved.txt
Use REQUIRE_FALSE to assert that a condition evaluates to false. This example demonstrates negation of false values and inequalities.
```cpp
!(false)
```
```cpp
!(falseValue)
```
```cpp
!(1 == 2)
```
--------------------------------
### CHECK False Condition
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.multi.approved.txt
Use CHECK_FALSE to assert that a condition evaluates to false. This example shows negation of a true value.
```cpp
!trueValue
```
```cpp
!(trueValue)
```
```cpp
!(1 == 1)
```
```cpp
!(1 == 1)
```
--------------------------------
### Parse Command Line for Benchmark Samples
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/console.sw.approved.txt
Parses command line arguments to set the number of benchmark samples. Verifies that the benchmark samples count is correctly set.
```cpp
CHECK( cli.parse({ "test", "--benchmark-samples=200" }) )
with expansion:
{?}
```
```cpp
REQUIRE( config.benchmarkSamples == 200 )
with expansion:
200 == 200
```
--------------------------------
### Catch2 Matcher Test: ContainsSubstring (Case Sensitive)
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.approved.txt
Tests the `ContainsSubstring` matcher with case-sensitive comparison. This example is expected to fail.
```cpp
testStringForMatching(), ContainsSubstring( "STRING" )
```
--------------------------------
### Example C++ Unit Test with Catch2
Source: https://github.com/catchorg/catch2/blob/devel/README.md
Demonstrates a basic unit test for a factorial function using Catch2's TEST_CASE and REQUIRE macros. Ensure Catch2 headers are included.
```cpp
#include
#include
uint32_t factorial( uint32_t number ) {
return number <= 1 ? number : factorial(number-1) * number;
}
TEST_CASE( "Factorials are computed", "[factorial]" ) {
REQUIRE( factorial( 1) == 1 );
REQUIRE( factorial( 2) == 2 );
REQUIRE( factorial( 3) == 6 );
REQUIRE( factorial(10) == 3'628'800 );
}
```
--------------------------------
### Catch2 Matcher Test: ContainsSubstring (Case Insensitive)
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.approved.txt
Tests the `ContainsSubstring` matcher with case-insensitive comparison. This example is expected to fail.
```cpp
testStringForMatching(), ContainsSubstring( "not there", Catch::CaseSensitive::No )
```
--------------------------------
### Ordering Comparison Checks
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/console.std.approved.txt
Examples of failing ordering comparisons. These checks verify greater than and less than conditions, all of which are designed to fail.
```cpp
CHECK( data.int_seven > 7 )
```
```cpp
CHECK( data.int_seven < 7 )
```
```cpp
CHECK( data.int_seven > 8 )
```
```cpp
CHECK( data.int_seven < 6 )
```
--------------------------------
### String Comparisons
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.approved.txt
Illustrates direct string comparisons for equality and inequality.
```cpp
data.str_hello != "goodbye"
```
```cpp
"hello" != "goodbye"
```
```cpp
data.str_hello != "hell"
```
```cpp
"hello" != "hell"
```
```cpp
data.str_hello != "hello1"
```
```cpp
"hello" != "hello1"
```
--------------------------------
### Configure Process to Abort After N Failures
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/console.sw.approved.txt
Tests parsing the command line for the '-x' option followed by a numeric value, configuring the process to abort after a specified number of failures. Ensure the value provided is numeric.
```cpp
CHECK( cli.parse({"test", "-x", "2"}) )
```
--------------------------------
### Composed Matchers with OR and AND
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/console.std.approved.txt
Demonstrates composing matchers using logical OR (`||`) and AND (`&&`). This example fails because the string contains 'string' but not 'random'.
```cpp
CHECK_THAT( testStringForMatching(), ( ContainsSubstring( "string" ) || ContainsSubstring( "different" ) ) && ContainsSubstring( "random" ) )
```
--------------------------------
### Catch2 Include Guard Pattern
Source: https://github.com/catchorg/catch2/blob/devel/docs/contributing.md
Header files should use this include guard pattern: {FILENAME}_INCLUDED.
```cpp
#define CATCH_MATCHERS_FOO_HPP_INCLUDED
```
--------------------------------
### Get Fifth Value from Preset Generator
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.multi.approved.txt
Retrieves the fifth value from a generator with preset values. Asserts the expected fifth element.
```cpp
gen.get() == 5
```
--------------------------------
### Get Third Value from Preset Generator
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.multi.approved.txt
Retrieves the third value from a generator with preset values. Asserts the expected third element.
```cpp
gen.get() == 3
```
--------------------------------
### String Comparisons
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/xml.sw.multi.approved.txt
Illustrates direct string comparisons and length checks.
```cpp
data.str_hello != "goodbye"
```
```cpp
"hello" != "goodbye"
```
```cpp
data.str_hello != "hell"
```
```cpp
"hello" != "hell"
```
```cpp
data.str_hello != "hello1"
```
```cpp
"hello" != "hello1"
```
```cpp
data.str_hello.size() != 6
```
```cpp
5 != 6
```
--------------------------------
### Vector Approx Matcher - Failing Example
Source: https://github.com/catchorg/catch2/blob/devel/tests/SelfTest/Baselines/console.sw.multi.approved.txt
Demonstrates a failing case for the Approx matcher when comparing two vectors with different elements.
```cpp
CHECK_THAT( v1, Approx( v2 ) )
```
--------------------------------
### Measuring Constructor Time with Catch2
Source: https://github.com/catchorg/catch2/blob/devel/docs/benchmarks.md
Use `Catch::Benchmark::storage_for` to manually construct objects in raw storage and measure constructor time separately from object lifetime.
```c++
BENCHMARK_ADVANCED("construct")(Catch::Benchmark::Chronometer meter) {
std::vector> storage(meter.runs());
meter.measure([&](int i) { storage[i].construct("thing"); });
};
```