8000 With code proposed in Pull Request #95, when UNITTEST_NO_EXCEPTIONS i… · unittest-cpp/unittest-cpp@2e53a17 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2e53a17

Browse files
committed
With code proposed in Pull Request #95, when UNITTEST_NO_EXCEPTIONS is defined, the definition for REQUIRE macro is empty.
This commit adds functionality for stopping unit tests early when UNITTEST_NO_EXCEPTIONS is defined via std::longjmp.
1 parent 4b0ac3f commit 2e53a17

File tree

3 files changed

+750
-8
lines changed

3 files changed

+750
-8
lines changed

UnitTest++/RequireMacros.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@
77
#error UnitTest++ redefines REQUIRE
88
#endif
99

10-
#ifndef UNITTEST_NO_EXCEPTIONS
11-
#define REQUIRE for(UnitTest::RequiredCheckTestReporter decoratedReporter(*UnitTest::CurrentTest::Results()); decoratedReporter.Next(); )
12-
#endif
10+
#define REQUIRE for(UnitTest::RequiredCheckTestReporter decoratedReporter(*UnitTest::CurrentTest::Results()); decoratedReporter.Next(); )
1311

14-
#ifdef UNITTEST_NO_EXCEPTIONS
15-
#define REQUIRE
1612
#endif
17-
18-
#endif

UnitTest++/ThrowingTestReporter.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#include "ThrowingTestReporter.h"
22
#include "RequiredCheckException.h"
33

4+
#ifdef UNITTEST_NO_EXCEPTIONS
5+
#include "ReportAssertImpl.h"
6+
#endif
7+
48
namespace UnitTest {
59

610
ThrowingTestReporter::ThrowingTestReporter(TestReporter* decoratedReporter)
@@ -27,7 +31,13 @@ namespace UnitTest {
2731
{
2832
m_decoratedReporter->ReportFailure(test, failure);
2933
}
30-
throw RequiredCheckException();
34+
35+
#ifndef UNITTEST_NO_EXCEPTIONS
36+
throw RequiredCheckException();
37+
#else
38+
static const int stopTest = 1;
39+
UNITTEST_LONGJMP(*UnitTest::Detail::GetAssertJmpBuf(), stopTest);
40+
#endif
3141
}
3242

3343
//virtual

0 commit comments

Comments
 (0)
0