forked from approvals/ApprovalTests.cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Catch2Approvals.h
83 lines (71 loc) · 2.31 KB
/
Catch2Approvals.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
#pragma once
#include "ApprovalTests/namers/ApprovalTestNamer.h"
#include "ApprovalTests/integrations/FrameworkIntegrations.h"
#if defined(APPROVALS_CATCH_EXISTING_MAIN)
#define APPROVALS_CATCH
#define CATCH_CONFIG_RUNNER
#elif defined(APPROVALS_CATCH)
#define CATCH_CONFIG_MAIN
#endif
#ifdef APPROVALS_CATCH
#define APPROVAL_TESTS_INCLUDE_CPPS
// begin-snippet: required_header_for_catch
#include <catch2/catch.hpp>
// end-snippet
//namespace ApprovalTests {
struct Catch2ApprovalListener : Catch::TestEventListenerBase
{
ApprovalTests::TestName currentTest;
using TestEventListenerBase::
TestEventListenerBase; // This using allows us to use all base-class constructors
virtual void testCaseStarting(Catch::TestCaseInfo const& testInfo) override
{
currentTest.setFileName(testInfo.lineInfo.file);
ApprovalTests::FrameworkIntegrations::setCurrentTest(¤tTest);
ApprovalTests::FrameworkIntegrations::setTestPassedNotification(
[]() { REQUIRE(true); });
}
virtual void testCaseEnded(Catch::TestCaseStats const& /*testCaseStats*/) override
{
while (!currentTest.sections.empty())
{
currentTest.sections.pop_back();
}
}
virtual void sectionStarting(Catch::SectionInfo const& sectionInfo) override
{
currentTest.sections.push_back(sectionInfo.name);
}
virtual void sectionEnded(Catch::SectionStats const& /*sectionStats*/) override
{
currentTest.sections.pop_back();
}
};
//}
CATCH_REGISTER_LISTENER(Catch2ApprovalListener)
#endif
#ifdef TEST_COMMIT_REVERT_CATCH
//namespace ApprovalTests {
struct Catch2TestCommitRevert : Catch::TestEventListenerBase
{
using TestEventListenerBase::
TestEventListenerBase; // This using allows us to use all base-class constructors
virtual void testRunEnded(Catch::TestRunStats const& testRunStats) override
{
bool commit = testRunStats.totals.testCases.allOk();
std::string message = "r ";
if (commit)
{
std::cout << "git add -A \n";
std::cout << "git commit -m " << message;
}
else
{
std::cout << "git clean -fd \n";
std::cout << "git reset --hard HEAD \n";
}
}
};
//}
CATCH_REGISTER_LISTENER(Catch2TestCommitRevert)
#endif