Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/benchmarks/runtime_assertion_benches.cpp
blob: 3145707c0528d40d110b8d3105b208861c953b24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

//              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

#include <Progmasoft/Catch3/TestMacros.hpp>
#include <Progmasoft/Catch3/Matchers/Templated.hpp>

namespace {

class MatchAllMatcher final : public Catch::Matchers::MatcherGenericBase {
public:
    template <typename Any>
    bool match( Any&& ) const {
        return true;
    }

    std::string describe() const override {
        using namespace std::string_literals;
        return "Long string that does not fit into SSO"s;
    }
};

MatchAllMatcher MatchAll() { return MatchAllMatcher(); }


TEST_CASE( "REQUIRE", "[assertions]" ) {
    for ( size_t i = 0; i < 10'000'000; ++i ) {
        REQUIRE( true );
    }
}

TEST_CASE( "REQUIRE_THAT", "[assertions][matchers]" ) {
    for ( size_t i = 0; i < 10'000'000; ++i ) {
        REQUIRE_THAT( 1, MatchAll() );
    }
}

TEST_CASE( "REQUIRE_NOTHROW", "[assertions][exceptions]" ) {
    for ( size_t i = 0; i < 10'000'000; ++i ) {
        REQUIRE_NOTHROW( []() {}() );
    }
}

TEST_CASE( "REQUIRE_THROWS", "[assertions][exceptions]" ) {
    for ( size_t i = 0; i < 10'000'000; ++i ) {
        REQUIRE_THROWS( []() { throw 1; }() );
    }
}

} // namespace