8000 Simplify required check reporter interactions · unittest-cpp/unittest-cpp@5eec0a2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5eec0a2

Browse files
committed
Simplify required check reporter interactions
Was able to remove ThrowingTestReporter::SetDecorated and ::GetDecorated by changing RequiredCheckTestReporter to accept its TestResults by reference. This simple change removed several if-checks and some functions.
1 parent 57fc32c commit 5eec0a2

File tree

5 files changed

+9
-24
lines changed

5 files changed

+9
-24
lines changed

UnitTest++/RequireMacros.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#endif
99

1010
#ifndef UNITTEST_NO_EXCEPTIONS
11-
#define REQUIRE for(UnitTest::RequiredCheckTestReporter decoratedReporter(UnitTest::CurrentTest::Results()); decoratedReporter.Next(); )
11+
#define REQUIRE for(UnitTest::RequiredCheckTestReporter decoratedReporter(*UnitTest::CurrentTest::Results()); decoratedReporter.Next(); )
1212
#endif
1313

1414
#ifdef UNITTEST_NO_EXCEPTIONS

UnitTest++/RequiredCheckTestReporter.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,18 @@
55

66
namespace UnitTest {
77

8-
RequiredCheckTestReporter::RequiredCheckTestReporter(TestResults* results)
8+
RequiredCheckTestReporter::RequiredCheckTestReporter(TestResults& results)
99
: m_results(results)
10-
, m_throwingReporter(0)
10+
, m_originalTestReporter(results.m_testReporter)
11+
, m_throwingReporter(results.m_testReporter)
1112
, m_continue(0)
1213
{
13-
if(m_results)
14-
{
15-
m_throwingReporter.SetDecorated(m_results->m_testReporter);
16-
m_results->m_testReporter = &m_throwingReporter;
17-
}
14+
m_results.m_testReporter = &m_throwingReporter;
1815
}
1916

2017
RequiredCheckTestReporter::~RequiredCheckTestReporter()
2118
{
22-
if(m_results) m_results->m_testReporter = m_throwingReporter.GetDecorated();
19+
m_results.m_testReporter = m_originalTestReporter;
2320
}
2421

2522
bool RequiredCheckTestReporter::Next()

UnitTest++/RequiredCheckTestReporter.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ namespace UnitTest {
1313
class UNITTEST_LINKAGE RequiredCheckTestReporter
1414
{
1515
public:
16-
explicit RequiredCheckTestReporter(TestResults* results);
16+
explicit RequiredCheckTestReporter(TestResults& results);
1717
~RequiredCheckTestReporter();
1818

1919
bool Next();
2020

2121
private:
22-
TestResults* m_results;
22+
TestResults& m_results;
23+
TestReporter* m_originalTestReporter;
2324
ThrowingTestReporter m_throwingReporter;
2425
int m_continue;
2526
};

UnitTest++/ThrowingTestReporter.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,4 @@ namespace UnitTest {
3636
if(m_decoratedReporter) m_decoratedReporter->ReportSummary(totalTestCount, failedTestCount, failureCount, secondsElapsed);
3737
}
3838

39-
TestReporter* ThrowingTestReporter::GetDecorated() const
40-
{
41-
return m_decoratedReporter;
42-
}
43-
44-
void ThrowingTestReporter::SetDecorated(TestReporter* reporter)
45-
{
46-
m_decoratedReporter = reporter;
47-
}
48-
4939
}

UnitTest++/ThrowingTestReporter.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ namespace UnitTest {
1818
virtual void ReportTestFinish(TestDetails const& test, float secondsElapsed);
1919
virtual void ReportSummary(int totalTestCount, int failedTestCount, int failureCount, float secondsElapsed);
2020

21-
TestReporter* GetDecorated() const;
22-
void SetDecorated(TestReporter* reporter);
23-
2421
private:
2522
TestReporter* m_decoratedReporter;
2623
};

0 commit comments

Comments
 (0)
0