From df386f189f3b5c60ffa15a195194edbb011857da Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Sat, 7 May 2016 00:12:09 -0500 Subject: [PATCH] Add UNITTEST_ prefixes to remaining macros TEST, SUITE, and REQUIRE macros now have UNITTEST_ and UNITTEST_IMPL_ prefixes like the others, completing the set. --- UnitTest++/RequireMacros.h | 12 +++++++---- UnitTest++/TestMacros.h | 41 ++++++++++++++++++++++---------------- tests/TestTestMacros.cpp | 14 ++++++------- 3 files changed, 39 insertions(+), 28 deletions(-) diff --git a/UnitTest++/RequireMacros.h b/UnitTest++/RequireMacros.h index 0830e99..f25899b 100644 --- a/UnitTest++/RequireMacros.h +++ b/UnitTest++/RequireMacros.h @@ -3,10 +3,14 @@ #include "RequiredCheckTestReporter.h" -#ifdef REQUIRE - #error UnitTest++ redefines REQUIRE +#define UNITTEST_REQUIRE for(UnitTest::RequiredCheckTestReporter decoratedReporter(*UnitTest::CurrentTest::Results()); decoratedReporter.Next(); ) + +#if UNITTEST_ENABLE_SHORT_MACROS + #ifdef REQUIRE + #error REQUIRE already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_REQUIRE instead + #else + #define REQUIRE UNITTEST_REQUIRE + #endif #endif -#define REQUIRE for(UnitTest::RequiredCheckTestReporter decoratedReporter(*UnitTest::CurrentTest::Results()); decoratedReporter.Next(); ) - #endif diff --git a/UnitTest++/TestMacros.h b/UnitTest++/TestMacros.h index efe455e..03cf3bb 100644 --- a/UnitTest++/TestMacros.h +++ b/UnitTest++/TestMacros.h @@ -15,19 +15,7 @@ #include "Posix/SignalTranslator.h" #endif -#ifdef TEST -#error UnitTest++ redefines TEST -#endif - -#ifdef TEST_EX -#error UnitTest++ redefines TEST_EX -#endif - -#ifdef TEST_FIXTURE_EX -#error UnitTest++ redefines TEST_FIXTURE_EX -#endif - -#define SUITE(Name) \ +#define UNITTEST_SUITE(Name) \ namespace Suite ## Name { \ namespace UnitTestSuite { \ inline char const* GetSuiteName () { \ @@ -37,7 +25,7 @@ } \ namespace Suite ## Name -#define TEST_EX(Name, List) \ +#define UNITTEST_IMPL_TEST(Name, List) \ class Test ## Name : public UnitTest::Test \ { \ public: \ @@ -51,10 +39,10 @@ void Test ## Name::RunImpl() const -#define TEST(Name) TEST_EX(Name, UnitTest::Test::GetTestList()) +#define UNITTEST_TEST(Name) UNITTEST_IMPL_TEST(Name, UnitTest::Test::GetTestList()) -#define TEST_FIXTURE_EX(Fixture, Name, List) \ +#define UNITTEST_IMPL_TEST_FIXTURE(Fixture, Name, List) \ class Fixture ## Name ## Helper : public Fixture \ { \ public: \ @@ -111,7 +99,26 @@ } \ void Fixture ## Name ## Helper::RunImpl() -#define TEST_FIXTURE(Fixture,Name) TEST_FIXTURE_EX(Fixture, Name, UnitTest::Test::GetTestList()) +#define UNITTEST_TEST_FIXTURE(Fixture,Name) UNITTEST_IMPL_TEST_FIXTURE(Fixture, Name, UnitTest::Test::GetTestList()) +#if UNITTEST_ENABLE_SHORT_MACROS + #ifdef SUITE + #error SUITE already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_SUITE instead + #else + #define SUITE UNITTEST_SUITE + #endif + + #ifdef TEST + #error TEST already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_TEST instead + #else + #define TEST UNITTEST_TEST + #endif + + #ifdef TEST_FIXTURE + #error TEST_FIXTURE already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_TEST_FIXTURE instead + #else + #define TEST_FIXTURE UNITTEST_TEST_FIXTURE + #endif +#endif #endif diff --git a/tests/TestTestMacros.cpp b/tests/TestTestMacros.cpp index 4a13316..e66bfb6 100644 --- a/tests/TestTestMacros.cpp +++ b/tests/TestTestMacros.cpp @@ -46,7 +46,7 @@ using namespace std; namespace { TestList list1; - TEST_EX(DummyTest, list1) + UNITTEST_IMPL_TEST(DummyTest, list1) {} TEST (TestsAreAddedToTheListThroughMacro) @@ -69,7 +69,7 @@ namespace { }; TestList list2; - TEST_FIXTURE_EX(ThrowingThingie, DummyTestName, list2) + UNITTEST_IMPL_TEST_FIXTURE(ThrowingThingie, DummyTestName, list2) {} TEST (ExceptionsInFixtureAreReportedAsHappeningInTheFixture) @@ -113,7 +113,7 @@ namespace { } TestList macroTestList1; - TEST_EX(MacroTestHelper1, macroTestList1) + UNITTEST_IMPL_TEST(MacroTestHelper1, macroTestList1) {} TEST(TestAddedWithTEST_EXMacroGetsDefaultSuite) @@ -124,7 +124,7 @@ namespace { } TestList macroTestList2; - TEST_FIXTURE_EX(DummyFixture, MacroTestHelper2, macroTestList2) + UNITTEST_IMPL_TEST_FIXTURE(DummyFixture, MacroTestHelper2, macroTestList2) {} TEST(TestAddedWithTEST_FIXTURE_EXMacroGetsDefaultSuite) @@ -144,7 +144,7 @@ namespace { }; TestList throwingFixtureTestList1; - TEST_FIXTURE_EX(FixtureCtorThrows, FixtureCtorThrowsTestName, throwingFixtureTestList1) + UNITTEST_IMPL_TEST_FIXTURE(FixtureCtorThrows, FixtureCtorThrowsTestName, throwingFixtureTestList1) {} TEST(FixturesWithThrowingCtorsAreFailures) @@ -170,7 +170,7 @@ namespace { }; TestList throwingFixtureTestList2; - TEST_FIXTURE_EX(FixtureDtorThrows, FixtureDtorThrowsTestName, throwingFixtureTestList2) + UNITTEST_IMPL_TEST_FIXTURE(FixtureDtorThrows, FixtureDtorThrowsTestName, throwingFixtureTestList2) {} TEST(FixturesWithThrowingDtorsAreFailures) @@ -200,7 +200,7 @@ namespace { }; TestList ctorAssertFixtureTestList; - TEST_FIXTURE_EX(FixtureCtorAsserts, CorrectlyReportsAssertFailureInCtor, ctorAssertFixtureTestList) + UNITTEST_IMPL_TEST_FIXTURE(FixtureCtorAsserts, CorrectlyReportsAssertFailureInCtor, ctorAssertFixtureTestList) {} TEST(CorrectlyReportsFixturesWithCtorsThatAssert)