8000 Change UNITTEST_ENABLE_SHORT_MACROS to DISABLE · Reification/unittest-cpp@910381f · GitHub
[go: up one dir, main page]

Skip to content

Commit 910381f

Browse files
committed
Change UNITTEST_ENABLE_SHORT_MACROS to DISABLE
Also add a test file.
1 parent df386f1 commit 910381f

File tree

5 files changed

+55
-7
lines changed

5 files changed

+55
-7
lines changed

UnitTest++/CheckMacros.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
}) \
139139
UNITTEST_MULTILINE_MACRO_END
140140

141-
#if UNITTEST_ENABLE_SHORT_MACROS
141+
#ifndef UNITTEST_DISABLE_SHORT_MACROS
142142
#ifdef CHECK
143143
#error CHECK already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK instead
144144
#else
@@ -198,7 +198,7 @@
198198
UNITTEST_MULTILINE_MACRO_END
199199
#endif
200200

201-
#if UNITTEST_ENABLE_SHORT_MACROS
201+
#ifndef UNITTEST_DISABLE_SHORT_MACROS
202202
#ifdef CHECK_THROW
203203
#error CHECK_THROW already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_THROW instead
204204
#else

UnitTest++/Config.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,12 @@
7272
#endif
7373

7474
// By default, UnitTest++ will attempt to define "short" macro names like CHECK and CHECK_EQUAL
75-
// for "public" interface macros etc. Setting UNITTEST_ENABLE_SHORT_MACROS to 0 will disable
76-
// this behavior, leaving only the longer macros "namespaced" with the UNITTEST_ prefix.
75+
// for "public" interface macros etc. Defining UNITTEST_DISABLE_SHORT_MACROS in your project
76+
// will disable this behavior, leaving only the longer macros "namespaced" with the UNITTEST_
77+
// prefix.
78+
//
7779
// "Internal" utility macros will only have the UNITTEST_IMPL_ prefix.
78-
#define UNITTEST_ENABLE_SHORT_MACROS 1
80+
81+
// #define UNITTEST_DISABLE_SHORT_MACROS
7982

8083
#endif

UnitTest++/RequireMacros.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#define UNITTEST_REQUIRE for(UnitTest::RequiredCheckTestReporter decoratedReporter(*UnitTest::CurrentTest::Results()); decoratedReporter.Next(); )
77

8-
#if UNITTEST_ENABLE_SHORT_MACROS
8+
#ifndef UNITTEST_DISABLE_SHORT_MACROS
99
#ifdef REQUIRE
1010
#error REQUIRE already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_REQUIRE instead
1111
#else

UnitTest++/TestMacros.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101

102102
#define UNITTEST_TEST_FIXTURE(Fixture,Name) UNITTEST_IMPL_TEST_FIXTURE(Fixture, Name, UnitTest::Test::GetTestList())
103103

104-
#if UNITTEST_ENABLE_SHORT_MACROS
104+
#ifndef UNITTEST_DISABLE_SHORT_MACROS
105105
#ifdef SUITE
106106
#error SUITE already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_SUITE instead
107107
#else

tests/TestLongMacros.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#define UNITTEST_DISABLE_SHORT_MACROS
2+
3+
#include "UnitTest++/UnitTestPP.h"
4+
5+
// This file is not intended to test every little thing, just a few basics to hopefully ensure
6+
// the macros are working and the short macros are not defined.
7+
UNITTEST_SUITE(LongMacros)
8+
{
9+
UNITTEST_TEST(LongCheckMacroWorks)
10+
{
11+
UNITTEST_CHECK(true);
12+
}
13+
14+
class Fixture
15+
{
16+
public:
17+
Fixture() : sanity_(true) {}
18+
protected:
19+
bool sanity_;
20+
};
21+
22+
UNITTEST_TEST_FIXTURE(Fixture, LongFixtureMacroWorks)
23+
{
24+
UNITTEST_REQUIRE UNITTEST_CHECK(sanity_);
25+
}
26+
27+
UNITTEST_TEST(ShortMacrosAreNotDefined)
28+
{
29+
#if defined(CHECK) || \
30+
defined(CHECK_EQUAL) || \
31+
defined(CHECK_CLOSE) || \
32+
defined(CHECK_ARRAY_EQUAL) || \
33+
defined(CHECK_ARRAY_CLOSE) || \
34+
defined(CHECK_ARRAY2D_CLOSE) || \
35+
defined(CHECK_THROW) || \
36+
defined(CHECK_ASSERT) || \
37+
defined(SUITE) || \
38+
defined(TEST) || \
39+
defined(TEST_FIXTURE) || \
40+
defined(REQUIRE)
41+
42+
UNITTEST_CHECK(false);
43+
#endif
44+
}
45+
}

0 commit comments

Comments
 (0)
0