-
Notifications
You must be signed in to change notification settings - Fork 51
/
UTApprovals.h
113 lines (93 loc) · 3.42 KB
/
UTApprovals.h
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#pragma once
#include "ApprovalTests/namers/ApprovalTestNamer.h"
#include "ApprovalTests/integrations/FrameworkIntegrations.h"
#ifdef APPROVALS_UT
#define APPROVAL_TESTS_INCLUDE_CPPS
#if !(__GNUC__ >= 9 or __clang_major__ >= 9)
#error \
"The [Boost].UT integration with Approval Tests requires source_location support by the compiler"
#endif
// begin-snippet: required_header_for_ut
#include <boost/ut.hpp>
// end-snippet
namespace ApprovalTests
{
namespace cfg
{
void notify_success();
class reporter : public boost::ut::reporter<boost::ut::printer>
{
private:
TestName currentTest;
public:
auto on(boost::ut::events::test_begin test_begin) -> void
{
std::string name = std::string(test_begin.name);
currentTest.sections.emplace_back(name);
currentTest.setFileName(test_begin.location.file_name());
ApprovalTests::FrameworkIntegrations::setCurrentTest(¤tTest);
ApprovalTests::FrameworkIntegrations::setTestPassedNotification(
[]() { notify_success(); });
boost::ut::reporter<boost::ut::printer>::on(test_begin);
}
auto on(boost::ut::events::test_run test_run) -> void
{
boost::ut::reporter<boost::ut::printer>::on(test_run);
}
auto on(boost::ut::events::test_skip test_skip) -> void
{
boost::ut::reporter<boost::ut::printer>::on(test_skip);
}
auto on(boost::ut::events::test_end test_end) -> void
{
while (!currentTest.sections.empty())
{
currentTest.sections.pop_back();
}
boost::ut::reporter<boost::ut::printer>::on(test_end);
}
template <class TMsg> auto on(boost::ut::events::log<TMsg> log) -> void
{
boost::ut::reporter<boost::ut::printer>::on(log);
}
template <class TExpr>
auto on(boost::ut::events::assertion_pass<TExpr> location) -> void
{
boost::ut::reporter<boost::ut::printer>::on(location);
}
template <class TExpr>
auto on(boost::ut::events::assertion_fail<TExpr> fail) -> void
{
boost::ut::reporter<boost::ut::printer>::on(fail);
}
auto on(boost::ut::events::fatal_assertion fatal) -> void
{
boost::ut::reporter<boost::ut::printer>::on(fatal);
}
auto on(boost::ut::events::exception exception) -> void
{
boost::ut::reporter<boost::ut::printer>::on(exception);
}
auto on(boost::ut::events::summary summary) -> void
{
boost::ut::reporter<boost::ut::printer>::on(summary);
}
};
} // namespace cfg
}
template <>
auto boost::ut::cfg<boost::ut::override> =
boost::ut::runner<ApprovalTests::cfg::reporter>{};
namespace ApprovalTests
{
namespace cfg
{
void notify_success()
{
// This needs to be after the registering of our custom listener,
// for compilation to succeed.
boost::ut::expect(true);
}
}
}
#endif // APPROVALS_UT