8000 Fix warnings, errors, 2x error reporting in MSVC · Reification/unittest-cpp@6bb9541 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6bb9541

Browse files
committed
Fix warnings, errors, 2x error reporting in MSVC
Visual Studio 2015 complained about calling UT_THROW with zero arguments. Visual Studio 6 complained about calling UT_CATCH with an empty second argument. For these cases, I added UT_RETHROW(ExceptionName). I also added a catch of RequiredCheckException to ExecuteTest to avoid two error messages on each failed REQUIRE check.
1 parent 3f5095b commit 6bb9541

File tree

3 files changed

+15
-29
lines changed

3 files changed

+15
-29
lines changed

UnitTest++/CheckMacros.h

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,11 @@
3838
#define CHECK(value) \
3939
UNITTEST_MULTILINE_MACRO_BEGIN \
4040
UT_TRY \
41-
({ \
41+
({ \
4242
if (!UnitTest::Check(value)) \
4343
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), #value); \
4444
}) \
45-
UT_CATCH (UnitTest::RequiredCheckException, , \
46-
{ \
47-
UT_THROW(); \
48-
}) \
45+
UT_RETHROW (UnitTest::RequiredCheckException) \
4946
UT_CATCH (std::exception, e, \
5047
{ \
5148
UnitTest::MemoryOutStream message; \
@@ -63,13 +60,10 @@
6360
#define CHECK_EQUAL(expected, actual) \
6461
UNITTEST_MULTILINE_MACRO_BEGIN \
6562
UT_TRY \
66-
({ \
63+
({ \
6764
UnitTest::CheckEqual(*UnitTest::CurrentTest::Results(), expected, actual, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
6865
}) \
69-
UT_CATCH (UnitTest::RequiredCheckException, , \
70-
{ \
71-
UT_THROW(); \
72-
}) \
66+
UT_RETHROW (UnitTest::RequiredCheckException) \
7367
UT_CATCH (std::exception, e, \
7468
{ \
7569
UnitTest::MemoryOutStream message; \
@@ -78,7 +72,7 @@
7872
message.GetText()); \
7973
}) \
8074
UT_CATCH_ALL \
81-
({ \
75+
({ \
8276
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
8377
"Unhandled exception in CHECK_EQUAL(" #expected ", " #actual ")"); \
8478
}) \
@@ -87,13 +81,10 @@
8781
#define CHECK_CLOSE(expected, actual, tolerance) \
8882
UNITTEST_MULTILINE_MACRO_BEGIN \
8983
UT_TRY \
90-
({ \
84+
({ \
9185
UnitTest::CheckClose(*UnitTest::CurrentTest::Results(), expected, actual, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
9286
}) \
93-
UT_CATCH (UnitTest::RequiredCheckException, , \
94-
{ \
95-
UT_THROW(); \
96-
}) \
87+
UT_RETHROW (UnitTest::RequiredCheckException) \
9788
UT_CATCH (std::exception, e, \
9889
{ \
9990
UnitTest::MemoryOutStream message; \
@@ -102,7 +93,7 @@
10293
message.GetText()); \
10394
}) \
10495
UT_CATCH_ALL \
105-
({ \
96+
({ \
10697
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
10798
"Unhandled exception in CHECK_CLOSE(" #expected ", " #actual ")"); \
10899
}) \
@@ -114,10 +105,7 @@
114105
({ \
115106
UnitTest::CheckArrayEqual(*UnitTest::CurrentTest::Results(), expected, actual, count, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
116107
}) \
117-
UT_CATCH (UnitTest::RequiredCheckException, , \
118-
{ \
119-
UT_THROW(); \
120-
}) \
108+
UT_RETHROW (UnitTest::RequiredCheckException) \
121109
UT_CATCH (std::exception, e, \
122110
{ \
123111
UnitTest::MemoryOutStream message; \
@@ -138,10 +126,7 @@
138126
({ \
139127
UnitTest::CheckArrayClose(*UnitTest::CurrentTest::Results(), expected, actual, count, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
140128
}) \
141-
UT_CATCH (UnitTest::RequiredCheckException, , \
142-
{ \
143-
UT_THROW(); \
144-
}) \
129+
UT_RETHROW (UnitTest::RequiredCheckException) \
145130
UT_CATCH (std::exception, e, \
146131
{ \
147132
UnitTest::MemoryOutStream message; \
@@ -162,10 +147,7 @@
162147
({ \
163148
UnitTest::CheckArray2DClose(*UnitTest::CurrentTest::Results(), expected, actual, rows, columns, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
164149
}) \
165-
UT_CATCH (UnitTest::RequiredCheckException, , \
166-
{ \
167-
UT_THROW(); \
168-
}) \
150+
UT_RETHROW (UnitTest::RequiredCheckException) \
169151
UT_CATCH (std::exception, e, \
170152
{ \
171153
UnitTest::MemoryOutStream message; \

UnitTest++/ExceptionMacros.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
#ifndef UNITTEST_NO_EXCEPTIONS
77
#define UT_TRY(x) try x
88
#define UT_THROW(x) throw x
9+
#define UT_RETHROW(ExceptionType) catch(ExceptionType&) { throw; }
910
#define UT_CATCH(ExceptionType, ExceptionName, CatchBody) catch(ExceptionType& ExceptionName) CatchBody
1011
#define UT_CATCH_ALL(CatchBody) catch(...) CatchBody
1112 9E81
#else
1213
#define UT_TRY(x) x
1314
#define UT_THROW(x)
15+
#define UT_RETHROW()
1416
#define UT_CATCH(ExceptionType, ExceptionName, CatchBody)
1517
#define UT_CATCH_ALL(CatchBody)
1618
#endif

UnitTest++/ExecuteTest.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "TestResults.h"
88
#include "MemoryOutStream.h"
99
#include "AssertException.h"
10+
#include "RequiredCheckException.h"
1011
#include "CurrentTest.h"
1112

1213
#ifdef UNITTEST_NO_EXCEPTIONS
@@ -38,6 +39,7 @@ namespace UnitTest {
3839
testObject.RunImpl();
3940
})
4041
#endif
42+
UT_CATCH(RequiredCheckException, e, { (void)e; })
4143
UT_CATCH(AssertException, e, { (void)e; })
4244
UT_CATCH(std::exception, e,
4345
{

0 commit comments

Comments
 (0)
0