8000 Add UNITTEST_ versions of all CHECK macros · unittest-cpp/unittest-cpp@185b3d5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 185b3d5

Browse files
committed
Add UNITTEST_ versions of all CHECK macros
UNITTEST_ now prefixes the implementation of all CHECK macros. Additionally, the build option UNITTEST_ENABLE_SHORT_MACROS can be shut off, disabling the creation of the existing short forms. This is helpful for users who may have conflicts with their projects or other libs.
1 parent d220612 commit 185b3d5

File tree

2 files changed

+67
-33
lines changed

2 files changed

+67
-33
lines changed

UnitTest++/CheckMacros.h

Lines changed: 60 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,7 @@
1111
#include "CurrentTest.h"
1212
#include "ReportAssertImpl.h"
1313

14-
#ifdef CHECK
15-
#error UnitTest++ redefines CHECK
16-
#endif
17-
18-
#ifdef CHECK_EQUAL
19-
#error UnitTest++ redefines CHECK_EQUAL
20-
#endif
21-
22-
#ifdef CHECK_CLOSE
23-
#error UnitTest++ redefines CHECK_CLOSE
24-
#endif
25-
26-
#ifdef CHECK_ARRAY_EQUAL
27-
#error UnitTest++ redefines CHECK_ARRAY_EQUAL
28-
#endif
29-
30-
#ifdef CHECK_ARRAY_CLOSE
31-
#error UnitTest++ redefines CHECK_ARRAY_CLOSE
32-
#endif
33-
34-
#ifdef CHECK_ARRAY2D_CLOSE
35-
#error UnitTest++ redefines CHECK_ARRAY2D_CLOSE
36-
#endif
37-
38-
#define CHECK(value) \
14+
#define UNITTEST_CHECK(value) \
3915
UNITTEST_MULTILINE_MACRO_BEGIN \
4016
UT_TRY \
4117
({ \
@@ -57,7 +33,7 @@
5733
}) \
5834
UNITTEST_MULTILINE_MACRO_END
5935

60-
#define CHECK_EQUAL(expected, actual) \
36+
#define UNITTEST_CHECK_EQUAL(expected, actual) \
6137
UNITTEST_MULTILINE_MACRO_BEGIN \
6238
UT_TRY \
6339
({ \
@@ -78,7 +54,7 @@
7854
}) \
7955
UNITTEST_MULTILINE_MACRO_END
8056

81-
#define CHECK_CLOSE(expected, actual, tolerance) \
57+
#define UNITTEST_CHECK_CLOSE(expected, actual, tolerance) \
8258
UNITTEST_MULTILINE_MACRO_BEGIN \
8359
UT_TRY \
8460
({ \
@@ -99,7 +75,7 @@
9975
}) \
10076
UNITTEST_MULTILINE_MACRO_END
10177

102-
#define CHECK_ARRAY_EQUAL(expected, actual, count) \
78+
#define UNITTEST_CHECK_ARRAY_EQUAL(expected, actual, count) \
10379
UNITTEST_MULTILINE_MACRO_BEGIN \
10480
UT_TRY \
10581
({ \
@@ -120,7 +96,7 @@
12096
}) \
12197
UNITTEST_MULTILINE_MACRO_END
12298

123-
#define CHECK_ARRAY_CLOSE(expected, actual, count, tolerance) \
99+
#define UNITTEST_CHECK_ARRAY_CLOSE(expected, actual, count, tolerance) \
124100
UNITTEST_MULTILINE_MACRO_BEGIN \
125101
UT_TRY \
126102
({ \
@@ -141,7 +117,7 @@
141117
}) \
142118
UNITTEST_MULTILINE_MACRO_END
143119

144-
#define CHECK_ARRAY2D_CLOSE(expected, actual, rows, columns, tolerance) \
120+
#define UNITTEST_CHECK_ARRAY2D_CLOSE(expected, actual, rows, columns, tolerance) \
145121
UNITTEST_MULTILINE_MACRO_BEGIN \
146122
UT_TRY \
147123
({ \
@@ -162,11 +138,48 @@
162138
}) \
163139
UNITTEST_MULTILINE_MACRO_END
164140

141+
#if UNITTEST_ENABLE_SHORT_MACROS
142+
#ifdef CHECK
143+
#error CHECK already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK instead
144+
#else
145+
#define CHECK UNITTEST_CHECK
146+
#endif
147+
148+
#ifdef CHECK_EQUAL
149+
#error CHECK_EQUAL already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_EQUAL instead
150+
#else
151+
#define CHECK_EQUAL UNITTEST_CHECK_EQUAL
152+
#endif
153+
154+
#ifdef CHECK_CLOSE
155+
#error CHECK_CLOSE already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_CLOSE instead
156+
#else
157+
#define CHECK_CLOSE UNITTEST_CHECK_CLOSE
158+
#endif
< 67E6 /code>159+
160+
#ifdef CHECK_ARRAY_EQUAL
161+
#error CHECK_ARRAY_EQUAL already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_ARRAY_EQUAL instead
162+
#else
163+
#define CHECK_ARRAY_EQUAL UNITTEST_CHECK_ARRAY_EQUAL
164+
#endif
165+
166+
#ifdef CHECK_ARRAY_CLOSE
167+
#error CHECK_ARRAY_CLOSE already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_ARRAY_CLOSE instead
168+
#else
169+
#define CHECK_ARRAY_CLOSE UNITTEST_CHECK_ARRAY_CLOSE
170+
#endif
171+
172+
#ifdef CHECK_ARRAY2D_CLOSE
173+
#error CHECK_ARRAY2D_CLOSE already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_ARRAY2D_CLOSE instead
174+
#else
175+
#define CHECK_ARRAY2D_CLOSE UNITTEST_CHECK_ARRAY2D_CLOSE
176+
#endif
1 A3E2 77+
#endif
165178

166179
// CHECK_THROW and CHECK_ASSERT only exist when UNITTEST_NO_EXCEPTIONS isn't defined (see config.h)
167180
#ifndef UNITTEST_NO_EXCEPTIONS
168181

169-
#define CHECK_THROW(expression, ExpectedExceptionType) \
182+
#define UNITTEST_CHECK_THROW(expression, ExpectedExceptionType) \
170183
UNITTEST_MULTILINE_MACRO_BEGIN \
171184
bool caught_ = false; \
172185
try { expression; } \
@@ -177,12 +190,27 @@
177190
UNITTEST_MULTILINE_MACRO_END
178191

179192

180-
#define CHECK_ASSERT(expression) \
193+
#define UNITTEST_CHECK_ASSERT(expression) \
181194
UNITTEST_MULTILINE_MACRO_BEGIN \
182195
UnitTest::Detail::ExpectAssert(true); \
183196
CHECK_THROW(expression, UnitTest::AssertException); \
184197
UnitTest::Detail::ExpectAssert(false); \
185198
UNITTEST_MULTILINE_MACRO_END
186199
#endif
187200

201+
#if UNITTEST_ENABLE_SHORT_MACROS
202+
#ifdef CHECK_THROW
203+
#error CHECK_THROW already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_THROW instead
204+
#else
205+
#define CHECK_THROW UNITTEST_CHECK_THROW
206+
#endif
207+
208+
#ifdef CHECK_ASSERT
209+
#error CHECK_ASSERT already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_ASSERT instead
210+
#else
211+
#define CHECK_ASSERT UNITTEST_CHECK_ASSERT
212+
#endif
213+
#endif
214+
188215
#endif
216+

UnitTest++/Config.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#ifdef _USRDLL
1717
#define UNITTEST_WIN32_DLL
1818
#endif
19-
19+
2020
#define UNITTEST_WIN32
2121
#endif
2222

@@ -71,4 +71,10 @@
7171
#define UNIITEST_NS_QUAL_STD(x) ::std::x
7272
#endif
7373

74+
// By default, UnitTest++ will attempt to define "short" macro names like CHECK, CHECK_EQUAL,
75+
// etc. Setting UNITTEST_ENABLE_SHORT_MACROS to 0 will disable this behavior, leaving
76+
// only the longer macros "namespaced" with the UNITTEST_ prefix.
77+
78+
#define UNITTEST_ENABLE_SHORT_MACROS 1
79+
7480
#endif

0 commit comments

Comments
 (0)
0