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

summaryrefslogtreecommitdiffhomepage
path: root/tests/ExtraTests/X07-FastCompileMacros.cpp
blob: 66d11664de0e05a104e85282fba35b3188db3248 (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
55
56
57
58
59
60
61
62
63

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

/**\file
 * Test that various basic macros work with CATCH_CONFIG_FAST_COMPILE.
 *
 * Note that the current checking is rather loose. We check that the
 * macros compile, and that the test cases (don't) fail as they are
 * supposed to.
 */

#include <catch2/catch_test_macros.hpp>

#include <stdexcept>

namespace {

    [[noreturn]]
    static void throws() {
        throw std::runtime_error{ "sup" };
    }
    static void doesnt_throw() {}
    [[noreturn]]
    static int throws_i() {
        throw std::runtime_error{ "sup" };
    }

} // namespace

TEST_CASE( "Passing macros work" ) {
    REQUIRE( 1 != 2 );
    CHECK( 2 == 2 );
    REQUIRE_THROWS( throws() );
    REQUIRE_NOTHROW( doesnt_throw() );
}

TEST_CASE( "Failing macros work", "[!shouldfail]" ) {
    CHECK( 1 != 2 );
    CHECK( 2 == 2 );
    CHECK( 3 == 2 );
}

TEST_CASE( "Failing NOTHROW works", "[!shouldfail]" ) {
    REQUIRE_NOTHROW( throws() );
}

TEST_CASE( "Failing THROW works", "[!shouldfail]" ) {
    REQUIRE_THROWS( doesnt_throw() );
}

TEST_CASE( "Unexpected exception in REQUIRE gets inverted properly",
           "[!shouldfail]" ) {
    REQUIRE( throws_i() == 1 );
}

TEST_CASE( "Unexpected exception in REQUIRE fails properly" ) {
    REQUIRE( throws_i() == 2 );
}