Debian Codegraph @

src/mpt/test/test_macros.hpp

raw
1 /* SPDX-License-Identifier: BSL-1.0 OR BSD-3-Clause */
2
3 #ifndef MPT_TEST_TEST_MACROS_HPP
4 #define MPT_TEST_TEST_MACROS_HPP
5
6
7
8 #include "mpt/base/namespace.hpp"
9 #include "mpt/base/preprocessor.hpp"
10 #include "mpt/test/test.hpp"
11
12 #include <functional>
13
14
15
16 namespace mpt {
17 inline namespace MPT_INLINE_NS {
18
19
20
21 namespace test {
22
23
24
25 #define MPT_TEST_GROUP_BEGIN(name) \
26 inline mpt::test::group MPT_PP_UNIQUE_IDENTIFIER(mpt_test_group_name) { \
27 name, [](mpt::test::context & mpt_test_context) {
28 #define MPT_TEST_GROUP_END() \
29 } \
30 } \
31 ;
32
33 #define MPT_TEST_GROUP_INLINE_IDENTIFIER(identifier, name) \
34 inline void MPT_PP_JOIN(mpt_test_group_func_, identifier)(mpt::test::context & mpt_test_context); \
35 inline mpt::test::group MPT_PP_JOIN(mpt_test_group_name_, identifier){ \
36 name, [](mpt::test::context & mpt_test_context) { \
37 MPT_PP_JOIN(mpt_test_group_func_, identifier) \
38 (mpt_test_context); \
39 }}; \
40 inline void MPT_PP_UNIQUE_IDENTIFIER(mpt_test_group_func)(mpt::test::context & mpt_test_context)
41
42 #define MPT_TEST_GROUP_INLINE(name) \
43 inline void MPT_PP_UNIQUE_IDENTIFIER(mpt_test_group_func)(mpt::test::context & mpt_test_context); \
44 inline mpt::test::group MPT_PP_UNIQUE_IDENTIFIER(mpt_test_group_name){ \
45 name, [](mpt::test::context & mpt_test_context) { \
46 MPT_PP_UNIQUE_IDENTIFIER(mpt_test_group_func) \
47 (mpt_test_context); \
48 }}; \
49 inline void MPT_PP_UNIQUE_IDENTIFIER(mpt_test_group_func)(mpt::test::context & mpt_test_context)
50
51 #define MPT_TEST_GROUP_STATIC(name) \
52 static void MPT_PP_UNIQUE_IDENTIFIER(mpt_test_group_func)(mpt::test::context & mpt_test_context); \
53 static mpt::test::group MPT_PP_UNIQUE_IDENTIFIER(mpt_test_group_name){ \
54 name, [](mpt::test::context & mpt_test_context) { \
55 MPT_PP_UNIQUE_IDENTIFIER(mpt_test_group_func) \
56 (mpt_test_context); \
57 }}; \
58 static void MPT_PP_UNIQUE_IDENTIFIER(mpt_test_group_func)(mpt::test::context & mpt_test_context)
59
60 #define MPT_TEST_DELAYED(x) [&] { \
61 return x; \
62 }
63
64 #define MPT_TEST_EXPECT mpt::test::test{context}.expect
65
66 #define MPT_TEST_EXPECT_EXPR(e) mpt::test::test{mpt_test_context}.expect([&] { return e; }, #e)
67 #define MPT_TEST_EXPECT_CMP(a, cmp, b) mpt::test::test{mpt_test_context}.expect([&] { return a; }, [](const auto & a_, const auto & b_) { return a_ cmp b_; }, [&] { return b; }, #a, #cmp, #b)
68 #define MPT_TEST_EXPECT_THROWS_ANY(expr) mpt::test::test{mpt_test_context}.expect_throws_any([&] { expr; }, #expr)
69 #define MPT_TEST_EXPECT_THROWS(exception, expr) mpt::test::test{mpt_test_context}.expect_throws<exception>([&] { expr; }, #exception, #expr)
70
71 #define MPT_TEST_EXPECT_EQUAL(a, b) mpt::test::test{mpt_test_context}.expect([&] { return a; }, std::equal_to<>{}, [&] { return b; }, #a, "==", #b)
72
73
74
75 } // namespace test
76
77
78
79 } // namespace MPT_INLINE_NS
80 } // namespace mpt
81
82
83
84 #endif // MPT_TEST_TEST_MACROS_HPP