From e7b56d4e3cff2154df3c613e7dfb3ad709a050ec Mon Sep 17 00:00:00 2001 From: Austin Gilbert Date: Fri, 17 Oct 2014 17:12:55 -0500 Subject: [PATCH 01/79] Introducing additional functionality to allow client code to stop a unit test when an assert fails. The following macro has been added: REQUIRE An example of when these type of checks are useful: std::vector v = foo(); REQUIRE(CHECK_EQUAL(3, v.size())); // test stops here on a fail // so we don't segfault looking at // v[0] below. CHECK_EQUAL(1, v[0]); CHECK_EQUAL(2, v[1]); CHECK_EQUAL(3, v[2]); Multiple checks are supported as follows: REQUIRE({ CHECK_EQUAL(1, 2); CHECK(true); }; In the multiple check scenario, all the checks in the REQUIRE block will be run. After which, if any failures were reported, the TEST case will be stopped. When UNITTEST_NO_EXCEPTIONS is defined, REQUIRE is a noop. --- UnitTest++/RequireMacros.h | 28 ++ UnitTest++/UnitTestPP.h | 1 + tests/TestRequireMacros.cpp | 842 ++++++++++++++++++++++++++++++++++++ 3 files changed, 871 insertions(+) create mode 100644 UnitTest++/RequireMacros.h create mode 100644 tests/TestRequireMacros.cpp diff --git a/UnitTest++/RequireMacros.h b/UnitTest++/RequireMacros.h new file mode 100644 index 0000000..65817d9 --- /dev/null +++ b/UnitTest++/RequireMacros.h @@ -0,0 +1,28 @@ +#ifndef UNITTEST_REQUIREMACROS_H +#define UNITTEST_REQUIREMACROS_H + +#include "HelperMacros.h" +#include "ExceptionMacros.h" +#include "CurrentTest.h" + +#ifdef REQUIRE + #error UnitTest++ redefines REQUIRE +#endif + +#ifndef UNITTEST_NO_EXCEPTIONS + #define REQUIRE(test) \ + UNITTEST_MULTILINE_MACRO_BEGIN \ + int const failuresBeforeTest = UnitTest::CurrentTest::Results()->GetFailureCount(); \ + test; \ + int const failuresAfterTest = UnitTest::CurrentTest::Results()->GetFailureCount(); \ + if(failuresAfterTest > failuresBeforeTest) \ + { \ + UT_THROW(UnitTest::AssertException()); \ + } \ + UNITTEST_MULTILINE_MACRO_END + #endif +#endif + +#ifdef UNITTEST_NO_EXCEPTIONS + #define REQUIRE(test) test; +#endif diff --git a/UnitTest++/UnitTestPP.h b/UnitTest++/UnitTestPP.h index c9bbc0c..3e02d31 100644 --- a/UnitTest++/UnitTestPP.h +++ b/UnitTest++/UnitTestPP.h @@ -4,6 +4,7 @@ #include "Config.h" #include "TestMacros.h" #include "CheckMacros.h" +#include "RequireMacros.h" #include "TestRunner.h" #include "TimeConstraint.h" #include "ReportAssert.h" diff --git a/tests/TestRequireMacros.cpp b/tests/TestRequireMacros.cpp new file mode 100644 index 0000000..3025a34 --- /dev/null +++ b/tests/TestRequireMacros.cpp @@ -0,0 +1,842 @@ +#include "UnitTest++/UnitTestPP.h" +#include "UnitTest++/CurrentTest.h" +#include "RecordingReporter.h" +#include "ScopedCurrentTest.h" + +using namespace std; + +#ifndef UNITTEST_NO_EXCEPTIONS + +namespace { + +TEST(RequireCheckSucceedsOnTrue) +{ + bool failure = true; + bool exception = false; + { + RecordingReporter reporter; + UnitTest::TestResults testResults(&reporter); + + ScopedCurrentTest scopedResults(testResults); + + try + { + REQUIRE(CHECK(true)); + } + catch(const UnitTest::AssertException&) + { + exception = true; + } + + failure = (testResults.GetFailureCount() > 0); + } + + CHECK(!failure); + CHECK(!exception); +} + +TEST(RequiredCheckFailsOnFalse) +{ + bool failure = false; + bool exception = false; + { + RecordingReporter reporter; + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + try + { + REQUIRE(CHECK(false)); + } + catch (const UnitTest::AssertException&) + { + exception = true; + } + + failure = (testResults.GetFailureCount() > 0); + } + + CHECK(failure); + CHECK(exception); +} + + +TEST(RequireMacroSupportsMultipleChecks) +{ + bool failure = false; + bool exception = false; + { + RecordingReporter reporter; + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + try{ + REQUIRE({ + CHECK(true); + CHECK_EQUAL(1,1); + }); + } + catch (const UnitTest::AssertException&) + { + exception = true; + } + + failure = (testResults.GetFailureCount() > 0); + } + + CHECK(!failure); + CHECK(!exception); +} + + +TEST(RequireMacroSupportsMultipleChecksWithFailingChecks) +{ + bool failure = false; + bool exception = false; + { + RecordingReporter reporter; + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + try{ + REQUIRE({ + CHECK(true); + CHECK_EQUAL(1,2); + }); + } + catch (const UnitTest::AssertException&) + { + exception = true; + } + + failure = (testResults.GetFailureCount() > 0); + } + + CHECK(failure); + CHECK(exception); +} + +TEST(FailureReportsCorrectTestName) +{ + RecordingReporter reporter; + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + try + { + REQUIRE(CHECK(false)); + } + catch (const UnitTest::AssertException&) + { + } + } + + CHECK_EQUAL(m_details.testName, reporter.lastFailedTest); +} + +TEST(RequiredCheckFailureIncludesCheckContents) +{ + RecordingReporter reporter; + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + const bool yaddayadda = false; + + try + { + REQUIRE(CHECK(yaddayadda)); + } + catch (const UnitTest::AssertException&) + { + } + } + + CHECK(strstr(reporter.lastFailedMessage, "yaddayadda")); +} + +TEST(RequiredCheckEqualSucceedsOnEqual) +{ + bool failure = true; + bool exception = false; + { + RecordingReporter reporter; + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + try + { + REQUIRE(CHECK_EQUAL(1,1)); + } + catch (const UnitTest::AssertException&) + { + exception = true; + } + + failure = (testResults.GetFailureCount() > 0); + } + + CHECK(!failure); + CHECK(!exception); +} + +TEST(RequiredCheckEqualFailsOnNotEqual) +{ + bool failure = false; + bool exception = false; + { + RecordingReporter reporter; + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + try + { + REQUIRE(CHECK_EQUAL(1, 2)); + } + catch (const UnitTest::AssertException&) + { + exception = true; + } + + failure = (testResults.GetFailureCount() > 0); + } + + CHECK(failure); + CHECK(exception); +} + +TEST(RequiredCheckEqualFailureContainsCorrectDetails) +{ + int line = 0; + RecordingReporter reporter; + { + UnitTest::TestResults testResults(&reporter); + UnitTest::TestDetails const testDetails("testName", "suiteName", "filename", -1); + ScopedCurrentTest scopedResults(testResults, &testDetails); + + try + { + line = __LINE__; REQUIRE(CHECK_EQUAL(1, 123)); + } + catch (const UnitTest::AssertException&) + { + } + } + + CHECK_EQUAL("testName", reporter.lastFailedTest); + CHECK_EQUAL("suiteName", reporter.lastFailedSuite); + CHECK_EQUAL("filename", reporter.lastFailedFile); + CHECK_EQUAL(line, reporter.lastFailedLine); +} + +int g_sideEffect = 0; +int FunctionWithSideEffects() +{ + ++g_sideEffect; + return 1; +} + +TEST(RequiredCheckEqualDoesNotHaveSideEffectsWhenPassing) +{ + g_sideEffect = 0; + { + UnitTest::TestResults testResults; + ScopedCurrentTest scopedResults(testResults); + + try + { + REQUIRE(CHECK_EQUAL(1, FunctionWithSideEffects())); + } + catch (const UnitTest::AssertException&) + { + } + } + CHECK_EQUAL(1, g_sideEffect); +} + +TEST(RequiredCheckEqualDoesNotHaveSideEffectsWhenFailing) +{ + g_sideEffect = 0; + { + UnitTest::TestResults testResults; + ScopedCurrentTest scopedResults(testResults); + + try + { + REQUIRE(CHECK_EQUAL(2, FunctionWithSideEffects())); + } + catch (const UnitTest::AssertException&) + { + } + } + CHECK_EQUAL(1, g_sideEffect); +} + + +TEST(RequiredCheckCloseSucceedsOnEqual) +{ + bool failure = true; + bool exception = false; + { + RecordingReporter reporter; + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + try + { + REQUIRE(CHECK_CLOSE(1.0f, 1.001f, 0.01f)); + } + catch (const UnitTest::AssertException&) + { + exception = true; + } + + failure = (testResults.GetFailureCount() > 0); + } + + CHECK(!failure); + CHECK(!exception); +} + +TEST(RequiredCheckCloseFailsOnNotEqual) +{ + bool failure = false; + bool exception = false; + { + RecordingReporter reporter; + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + try + { + REQUIRE(CHECK_CLOSE (1.0f, 1.1f, 0.01f)); + } + catch (const UnitTest::AssertException&) + { + exception = true; + } + + failure = (testResults.GetFailureCount() > 0); + } + + CHECK(failure); + CHECK(exception); +} + +TEST(RequiredCheckCloseFailureContainsCorrectDetails) +{ + int line = 0; + RecordingReporter reporter; + { + UnitTest::TestResults testResults(&reporter); + UnitTest::TestDetails testDetails("test", "suite", "filename", -1); + ScopedCurrentTest scopedResults(testResults, &testDetails); + + try + { + line = __LINE__; REQUIRE(CHECK_CLOSE(1.0f, 1.1f, 0.01f)); + CHECK(false); + } + catch (const UnitTest::AssertException&) + { + } + } + + CHECK_EQUAL("test", reporter.lastFailedTest); + CHECK_EQUAL("suite", reporter.lastFailedSuite); + CHECK_EQUAL("filename", reporter.lastFailedFile); + CHECK_EQUAL(line, reporter.lastFailedLine); +} + +TEST(RequiredCheckCloseDoesNotHaveSideEffectsWhenPassing) +{ + g_sideEffect = 0; + { + UnitTest::TestResults testResults; + ScopedCurrentTest scopedResults(testResults); + + try + { + REQUIRE(CHECK_CLOSE (1, FunctionWithSideEffects(), 0.1f)); + } + catch (const UnitTest::AssertException&) + { + } + } + CHECK_EQUAL(1, g_sideEffect); +} + +TEST(RequiredCheckCloseDoesNotHaveSideEffectsWhenFailing) +{ + g_sideEffect = 0; + { + UnitTest::TestResults testResults; + ScopedCurrentTest scopedResults(testResults); + + try + { + REQUIRE(CHECK_CLOSE(2, FunctionWithSideEffects(), 0.1f)); + } + catch (const UnitTest::AssertException&) + { + } + } + CHECK_EQUAL(1, g_sideEffect); +} + +TEST(RequiredCheckArrayCloseSucceedsOnEqual) +{ + bool failure = true; + bool exception = false; + { + RecordingReporter reporter; + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + const float data[4] = { 0, 1, 2, 3 }; + + try + { + REQUIRE(CHECK_ARRAY_CLOSE (data, data, 4, 0.01f)); + } + catch (const UnitTest::AssertException&) + { + exception = true; + } + + failure = (testResults.GetFailureCount() > 0); + } + + CHECK(!failure); + CHECK(!exception); +} + +TEST(RequiredCheckArrayCloseFailsOnNotEqual) +{ + bool failure = false; + bool exception = false; + { + RecordingReporter reporter; + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + int const data1[4] = { 0, 1, 2, 3 }; + int const data2[4] = { 0, 1, 3, 3 }; + + try + { + REQUIRE(CHECK_ARRAY_CLOSE (data1, data2, 4, 0.01f)); + } + catch (const UnitTest::AssertException&) + { + exception = true; + } + + failure = (testResults.GetFailureCount() > 0); + } + + CHECK(failure); + CHECK(exception); +} + +TEST(RequiredCheckArrayCloseFailureIncludesCheckExpectedAndActual) +{ + RecordingReporter reporter; + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + int const data1[4] = { 0, 1, 2, 3 }; + int const data2[4] = { 0, 1, 3, 3 }; + + try + { + REQUIRE(CHECK_ARRAY_CLOSE(data1, data2, 4, 0.01f)); + } + catch (const UnitTest::AssertException&) + { + } + } + + CHECK(strstr(reporter.lastFailedMessage, "xpected [ 0 1 2 3 ]")); + CHECK(strstr(reporter.lastFailedMessage, "was [ 0 1 3 3 ]")); +} + +TEST(RequiredCheckArrayCloseFailureContainsCorrectDetails) +{ + int line = 0; + RecordingReporter reporter; + { + UnitTest::TestResults testResults(&reporter); + UnitTest::TestDetails testDetails("arrayCloseTest", "arrayCloseSuite", "filename", -1); + ScopedCurrentTest scopedResults(testResults, &testDetails); + + int const data1[4] = { 0, 1, 2, 3 }; + int const data2[4] = { 0, 1, 3, 3 }; + + try + { + line = __LINE__; REQUIRE(CHECK_ARRAY_CLOSE (data1, data2, 4, 0.01f)); + } + catch (const UnitTest::AssertException&) + { + } + } + + CHECK_EQUAL("arrayCloseTest", reporter.lastFailedTest); + CHECK_EQUAL("arrayCloseSuite", reporter.lastFailedSuite); + CHECK_EQUAL("filename", reporter.lastFailedFile); + CHECK_EQUAL(line, reporter.lastFailedLine); +} + +TEST(RequiredCheckArrayCloseFailureIncludesTolerance) +{ + RecordingReporter reporter; + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + float const data1[4] = { 0, 1, 2, 3 }; + float const data2[4] = { 0, 1, 3, 3 }; + + try + { + REQUIRE(CHECK_ARRAY_CLOSE (data1, data2, 4, 0.01f)); + } + catch (const UnitTest::AssertException&) + { + } + } + + CHECK(strstr(reporter.lastFailedMessage, "0.01")); +} + +TEST(RequiredCheckArrayEqualSuceedsOnEqual) +{ + bool failure = true; + bool exception = false; + { + RecordingReporter reporter; + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + const float data[4] = { 0, 1, 2, 3 }; + + try + { + REQUIRE(CHECK_ARRAY_EQUAL (data, data, 4)); + } + catch (const UnitTest::AssertException&) + { + exception = true; + } + + failure = (testResults.GetFailureCount() > 0); + } + + CHECK(!failure); + CHECK(!exception); +} + +TEST(RequiredCheckArrayEqualFailsOnNotEqual) +{ + bool failure = false; + bool exception = false; + { + RecordingReporter reporter; + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + int const data1[4] = { 0, 1, 2, 3 }; + int const data2[4] = { 0, 1, 3, 3 }; + + try + { + REQUIRE(CHECK_ARRAY_EQUAL (data1, data2, 4)); + } + catch (const UnitTest::AssertException&) + { + exception = true; + } + + failure = (testResults.GetFailureCount() > 0); + } + + CHECK(failure); + CHECK(exception); +} + +TEST(RequiredCheckArrayEqualFailureIncludesCheckExpectedAndActual) +{ + RecordingReporter reporter; + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + int const data1[4] = { 0, 1, 2, 3 }; + int const data2[4] = { 0, 1, 3, 3 }; + + try + { + REQUIRE(CHECK_ARRAY_EQUAL (data1, data2, 4)); + } + catch (const UnitTest::AssertException&) + { + } + } + + CHECK(strstr(reporter.lastFailedMessage, "xpected [ 0 1 2 3 ]")); + CHECK(strstr(reporter.lastFailedMessage, "was [ 0 1 3 3 ]")); +} + +TEST(RequiredCheckArrayEqualFailureContainsCorrectInfo) +{ + int line = 0; + RecordingReporter reporter; + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + int const data1[4] = { 0, 1, 2, 3 }; + int const data2[4] = { 0, 1, 3, 3 }; + + try + { + line = __LINE__; REQUIRE(CHECK_ARRAY_EQUAL (data1, data2, 4)); + } + catch (const UnitTest::AssertException&) + { + } + } + + CHECK_EQUAL("RequiredCheckArrayEqualFailureContainsCorrectInfo", reporter.lastFailedTest); + CHECK_EQUAL(__FILE__, reporter.lastFailedFile); + CHECK_EQUAL(line, reporter.lastFailedLine); +} + +float const* FunctionWithSideEffects2() +{ + ++g_sideEffect; + static float const data[] = {1,2,3,4}; + return data; +} + +TEST(RequiredCheckArrayCloseDoesNotHaveSideEffectsWhenPassing) +{ + g_sideEffect = 0; + { + UnitTest::TestResults testResults; + ScopedCurrentTest scopedResults(testResults); + + const float data[] = { 0, 1, 2, 3 }; + + try + { + REQUIRE(CHECK_ARRAY_CLOSE (data, FunctionWithSideEffects2(), 4, 0.01f)); + } + catch (const UnitTest::AssertException&) + { + } + } + CHECK_EQUAL(1, g_sideEffect); +} + +TEST(RequiredCheckArrayCloseDoesNotHaveSideEffectsWhenFailing) +{ + g_sideEffect = 0; + { + UnitTest::TestResults testResults; + ScopedCurrentTest scopedResults(testResults); + + const float data[] = { 0, 1, 3, 3 }; + + try + { + REQUIRE(CHECK_ARRAY_CLOSE (data, FunctionWithSideEffects2(), 4, 0.01f)); + } + catch (const UnitTest::AssertException&) + { + } + } + + CHECK_EQUAL(1, g_sideEffect); +} + +TEST(RequiredCheckArray2DCloseSucceedsOnEqual) +{ + bool failure = true; + bool exception = false; + { + RecordingReporter reporter; + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + const float data[2][2] = { {0, 1}, {2, 3} }; + + try + { + REQUIRE(CHECK_ARRAY2D_CLOSE(data, data, 2, 2, 0.01f)); + } + catch (const UnitTest::AssertException&) + { + exception = true; + } + + failure = (testResults.GetFailureCount() > 0); + } + + CHECK(!failure); + CHECK(!exception); +} + +TEST(RequiredCheckArray2DCloseFailsOnNotEqual) +{ + bool failure = false; + bool exception = false; + { + RecordingReporter reporter; + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + int const data1[2][2] = { {0, 1}, {2, 3} }; + int const data2[2][2] = { {0, 1}, {3, 3} }; + + try + { + REQUIRE(CHECK_ARRAY2D_CLOSE (data1, data2, 2, 2, 0.01f)); + } + catch (const UnitTest::AssertException&) + { + exception = true; + } + + failure = (testResults.GetFailureCount() > 0); + } + + CHECK(failure); + CHECK(exception); +} + +TEST(RequiredCheckArray2DCloseFailureIncludesCheckExpectedAndActual) +{ + RecordingReporter reporter; + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + int const data1[2][2] = { {0, 1}, {2, 3} }; + int const data2[2][2] = { {0, 1}, {3, 3} }; + + try + { + REQUIRE(CHECK_ARRAY2D_CLOSE (data1, data2, 2, 2, 0.01f)); + } + catch (const UnitTest::AssertException&) + { + } + } + + CHECK(strstr(reporter.lastFailedMessage, "xpected [ [ 0 1 ] [ 2 3 ] ]")); + CHECK(strstr(reporter.lastFailedMessage, "was [ [ 0 1 ] [ 3 3 ] ]")); +} + +TEST(RequiredCheckArray2DCloseFailureContainsCorrectDetails) +{ + int line = 0; + RecordingReporter reporter; + { + UnitTest::TestResults testResults(&reporter); + UnitTest::TestDetails testDetails("array2DCloseTest", "array2DCloseSuite", "filename", -1); + ScopedCurrentTest scopedResults(testResults, &testDetails); + + int const data1[2][2] = { {0, 1}, {2, 3} }; + int const data2[2][2] = { {0, 1}, {3, 3} }; + + try + { + line = __LINE__; REQUIRE(CHECK_ARRAY2D_CLOSE (data1, data2, 2, 2, 0.01f)); + } + catch (const UnitTest::AssertException&) + { + } + } + + CHECK_EQUAL("array2DCloseTest", reporter.lastFailedTest); + CHECK_EQUAL("array2DCloseSuite", reporter.lastFailedSuite); + CHECK_EQUAL("filename", reporter.lastFailedFile); + CHECK_EQUAL(line, reporter.lastFailedLine); +} + +TEST(RequiredCheckArray2DCloseFailureIncludesTolerance) +{ + RecordingReporter reporter; + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + float const data1[2][2] = { {0, 1}, {2, 3} }; + float const data2[2][2] = { {0, 1}, {3, 3} }; + + try + { + REQUIRE(CHECK_ARRAY2D_CLOSE (data1, data2, 2, 2, 0.01f)); + } + catch (const UnitTest::AssertException&) + { + } + } + + CHECK(strstr(reporter.lastFailedMessage, "0.01")); +} + +float const* const* FunctionWithSideEffects3() +{ + ++g_sideEffect; + static float const data1[] = {0,1}; + static float const data2[] = {2,3}; + static const float* const data[] = {data1, data2}; + return data; +} + +TEST(RequiredCheckArray2DCloseDoesNotHaveSideEffectsWhenPassing) +{ + g_sideEffect = 0; + { + UnitTest::TestResults testResults; + ScopedCurrentTest scopedResults(testResults); + + const float data[2][2] = { {0, 1}, {2, 3} }; + + try + { + REQUIRE(CHECK_ARRAY2D_CLOSE (data, FunctionWithSideEffects3(), 2, 2, 0.01f)); + } + catch (const UnitTest::AssertException&) + { + } + } + CHECK_EQUAL(1, g_sideEffect); +} + +TEST(RequiredCheckArray2DCloseDoesNotHaveSideEffectsWhenFailing) +{ + g_sideEffect = 0; + { + UnitTest::TestResults testResults; + ScopedCurrentTest scopedResults(testResults); + + const float data[2][2] = { {0, 1}, {3, 3} }; + + try + { + REQUIRE(CHECK_ARRAY2D_CLOSE (data, FunctionWithSideEffects3(), 2, 2, 0.01f)); + } + catch (const UnitTest::AssertException&) + { + } + } + CHECK_EQUAL(1, g_sideEffect); +} + +} + +#endif From 06308ee8023de4a0070e45cbdeb52e45ea002b9a Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Tue, 4 Nov 2014 23:41:05 -0600 Subject: [PATCH 02/79] Use for loop to achieve REQUIRE with no parens I changed the definition of the REQUIRE macro to use for loops and some comma operator shenanigans to allow things like: REQUIRE { CHECK(...); CHECK_EQUAL(..., ...); } or REQUIRE CHECK(...); I updated the tests and they all passed on my machine. My only concern is that some compilers might complain about the unreachable code in the (throw UnitTest::AssertException(), true) expression. --- UnitTest++/RequireMacros.h | 19 ++++------ tests/TestRequireMacros.cpp | 74 +++++++++++++++++++------------------ 2 files changed, 45 insertions(+), 48 deletions(-) diff --git a/UnitTest++/RequireMacros.h b/UnitTest++/RequireMacros.h index 65817d9..747bda7 100644 --- a/UnitTest++/RequireMacros.h +++ b/UnitTest++/RequireMacros.h @@ -10,19 +10,14 @@ #endif #ifndef UNITTEST_NO_EXCEPTIONS - #define REQUIRE(test) \ - UNITTEST_MULTILINE_MACRO_BEGIN \ - int const failuresBeforeTest = UnitTest::CurrentTest::Results()->GetFailureCount(); \ - test; \ - int const failuresAfterTest = UnitTest::CurrentTest::Results()->GetFailureCount(); \ - if(failuresAfterTest > failuresBeforeTest) \ - { \ - UT_THROW(UnitTest::AssertException()); \ - } \ - UNITTEST_MULTILINE_MACRO_END - #endif + #define REQUIRE \ + for (int failuresBeforeTest = UnitTest::CurrentTest::Results()->GetFailureCount(), newFailures = 0, run = 0; \ + (run == 0) || ((newFailures != 0) && (throw UnitTest::AssertException(), true)); \ + newFailures = UnitTest::CurrentTest::Results()->GetFailureCount() - failuresBeforeTest, run = 1) #endif #ifdef UNITTEST_NO_EXCEPTIONS - #define REQUIRE(test) test; + #define REQUIRE #endif + +#endif \ No newline at end of file diff --git a/tests/TestRequireMacros.cpp b/tests/TestRequireMacros.cpp index 3025a34..869de32 100644 --- a/tests/TestRequireMacros.cpp +++ b/tests/TestRequireMacros.cpp @@ -21,7 +21,7 @@ TEST(RequireCheckSucceedsOnTrue) try { - REQUIRE(CHECK(true)); + REQUIRE CHECK(true); } catch(const UnitTest::AssertException&) { @@ -46,7 +46,7 @@ TEST(RequiredCheckFailsOnFalse) try { - REQUIRE(CHECK(false)); + REQUIRE CHECK(false); } catch (const UnitTest::AssertException&) { @@ -71,10 +71,11 @@ TEST(RequireMacroSupportsMultipleChecks) ScopedCurrentTest scopedResults(testResults); try{ - REQUIRE({ + REQUIRE + { CHECK(true); CHECK_EQUAL(1,1); - }); + } } catch (const UnitTest::AssertException&) { @@ -99,10 +100,11 @@ TEST(RequireMacroSupportsMultipleChecksWithFailingChecks) ScopedCurrentTest scopedResults(testResults); try{ - REQUIRE({ + REQUIRE + { CHECK(true); CHECK_EQUAL(1,2); - }); + } } catch (const UnitTest::AssertException&) { @@ -125,7 +127,7 @@ TEST(FailureReportsCorrectTestName) try { - REQUIRE(CHECK(false)); + REQUIRE CHECK(false); } catch (const UnitTest::AssertException&) { @@ -145,7 +147,7 @@ TEST(RequiredCheckFailureIncludesCheckContents) try { - REQUIRE(CHECK(yaddayadda)); + REQUIRE CHECK(yaddayadda); } catch (const UnitTest::AssertException&) { @@ -166,7 +168,7 @@ TEST(RequiredCheckEqualSucceedsOnEqual) try { - REQUIRE(CHECK_EQUAL(1,1)); + REQUIRE CHECK_EQUAL(1,1); } catch (const UnitTest::AssertException&) { @@ -191,7 +193,7 @@ TEST(RequiredCheckEqualFailsOnNotEqual) try { - REQUIRE(CHECK_EQUAL(1, 2)); + REQUIRE CHECK_EQUAL(1, 2); } catch (const UnitTest::AssertException&) { @@ -216,7 +218,7 @@ TEST(RequiredCheckEqualFailureContainsCorrectDetails) try { - line = __LINE__; REQUIRE(CHECK_EQUAL(1, 123)); + line = __LINE__; REQUIRE CHECK_EQUAL(1, 123); } catch (const UnitTest::AssertException&) { @@ -245,7 +247,7 @@ TEST(RequiredCheckEqualDoesNotHaveSideEffectsWhenPassing) try { - REQUIRE(CHECK_EQUAL(1, FunctionWithSideEffects())); + REQUIRE CHECK_EQUAL(1, FunctionWithSideEffects()); } catch (const UnitTest::AssertException&) { @@ -263,7 +265,7 @@ TEST(RequiredCheckEqualDoesNotHaveSideEffectsWhenFailing) try { - REQUIRE(CHECK_EQUAL(2, FunctionWithSideEffects())); + REQUIRE CHECK_EQUAL(2, FunctionWithSideEffects()); } catch (const UnitTest::AssertException&) { @@ -284,7 +286,7 @@ TEST(RequiredCheckCloseSucceedsOnEqual) try { - REQUIRE(CHECK_CLOSE(1.0f, 1.001f, 0.01f)); + REQUIRE CHECK_CLOSE(1.0f, 1.001f, 0.01f); } catch (const UnitTest::AssertException&) { @@ -309,7 +311,7 @@ TEST(RequiredCheckCloseFailsOnNotEqual) try { - REQUIRE(CHECK_CLOSE (1.0f, 1.1f, 0.01f)); + REQUIRE CHECK_CLOSE (1.0f, 1.1f, 0.01f); } catch (const UnitTest::AssertException&) { @@ -334,7 +336,7 @@ TEST(RequiredCheckCloseFailureContainsCorrectDetails) try { - line = __LINE__; REQUIRE(CHECK_CLOSE(1.0f, 1.1f, 0.01f)); + line = __LINE__; REQUIRE CHECK_CLOSE(1.0f, 1.1f, 0.01f); CHECK(false); } catch (const UnitTest::AssertException&) @@ -357,7 +359,7 @@ TEST(RequiredCheckCloseDoesNotHaveSideEffectsWhenPassing) try { - REQUIRE(CHECK_CLOSE (1, FunctionWithSideEffects(), 0.1f)); + REQUIRE CHECK_CLOSE (1, FunctionWithSideEffects(), 0.1f); } catch (const UnitTest::AssertException&) { @@ -375,7 +377,7 @@ TEST(RequiredCheckCloseDoesNotHaveSideEffectsWhenFailing) try { - REQUIRE(CHECK_CLOSE(2, FunctionWithSideEffects(), 0.1f)); + REQUIRE CHECK_CLOSE(2, FunctionWithSideEffects(), 0.1f); } catch (const UnitTest::AssertException&) { @@ -396,7 +398,7 @@ TEST(RequiredCheckArrayCloseSucceedsOnEqual) try { - REQUIRE(CHECK_ARRAY_CLOSE (data, data, 4, 0.01f)); + REQUIRE CHECK_ARRAY_CLOSE (data, data, 4, 0.01f); } catch (const UnitTest::AssertException&) { @@ -424,7 +426,7 @@ TEST(RequiredCheckArrayCloseFailsOnNotEqual) try { - REQUIRE(CHECK_ARRAY_CLOSE (data1, data2, 4, 0.01f)); + REQUIRE CHECK_ARRAY_CLOSE (data1, data2, 4, 0.01f); } catch (const UnitTest::AssertException&) { @@ -450,7 +452,7 @@ TEST(RequiredCheckArrayCloseFailureIncludesCheckExpectedAndActual) try { - REQUIRE(CHECK_ARRAY_CLOSE(data1, data2, 4, 0.01f)); + REQUIRE CHECK_ARRAY_CLOSE(data1, data2, 4, 0.01f); } catch (const UnitTest::AssertException&) { @@ -475,7 +477,7 @@ TEST(RequiredCheckArrayCloseFailureContainsCorrectDetails) try { - line = __LINE__; REQUIRE(CHECK_ARRAY_CLOSE (data1, data2, 4, 0.01f)); + line = __LINE__; REQUIRE CHECK_ARRAY_CLOSE (data1, data2, 4, 0.01f); } catch (const UnitTest::AssertException&) { @@ -500,7 +502,7 @@ TEST(RequiredCheckArrayCloseFailureIncludesTolerance) try { - REQUIRE(CHECK_ARRAY_CLOSE (data1, data2, 4, 0.01f)); + REQUIRE CHECK_ARRAY_CLOSE (data1, data2, 4, 0.01f); } catch (const UnitTest::AssertException&) { @@ -523,7 +525,7 @@ TEST(RequiredCheckArrayEqualSuceedsOnEqual) try { - REQUIRE(CHECK_ARRAY_EQUAL (data, data, 4)); + REQUIRE CHECK_ARRAY_EQUAL (data, data, 4); } catch (const UnitTest::AssertException&) { @@ -551,7 +553,7 @@ TEST(RequiredCheckArrayEqualFailsOnNotEqual) try { - REQUIRE(CHECK_ARRAY_EQUAL (data1, data2, 4)); + REQUIRE CHECK_ARRAY_EQUAL (data1, data2, 4); } catch (const UnitTest::AssertException&) { @@ -577,7 +579,7 @@ TEST(RequiredCheckArrayEqualFailureIncludesCheckExpectedAndActual) try { - REQUIRE(CHECK_ARRAY_EQUAL (data1, data2, 4)); + REQUIRE CHECK_ARRAY_EQUAL (data1, data2, 4); } catch (const UnitTest::AssertException&) { @@ -601,7 +603,7 @@ TEST(RequiredCheckArrayEqualFailureContainsCorrectInfo) try { - line = __LINE__; REQUIRE(CHECK_ARRAY_EQUAL (data1, data2, 4)); + line = __LINE__; REQUIRE CHECK_ARRAY_EQUAL (data1, data2, 4); } catch (const UnitTest::AssertException&) { @@ -631,7 +633,7 @@ TEST(RequiredCheckArrayCloseDoesNotHaveSideEffectsWhenPassing) try { - REQUIRE(CHECK_ARRAY_CLOSE (data, FunctionWithSideEffects2(), 4, 0.01f)); + REQUIRE CHECK_ARRAY_CLOSE (data, FunctionWithSideEffects2(), 4, 0.01f); } catch (const UnitTest::AssertException&) { @@ -651,7 +653,7 @@ TEST(RequiredCheckArrayCloseDoesNotHaveSideEffectsWhenFailing) try { - REQUIRE(CHECK_ARRAY_CLOSE (data, FunctionWithSideEffects2(), 4, 0.01f)); + REQUIRE CHECK_ARRAY_CLOSE (data, FunctionWithSideEffects2(), 4, 0.01f); } catch (const UnitTest::AssertException&) { @@ -674,7 +676,7 @@ TEST(RequiredCheckArray2DCloseSucceedsOnEqual) try { - REQUIRE(CHECK_ARRAY2D_CLOSE(data, data, 2, 2, 0.01f)); + REQUIRE CHECK_ARRAY2D_CLOSE(data, data, 2, 2, 0.01f); } catch (const UnitTest::AssertException&) { @@ -702,7 +704,7 @@ TEST(RequiredCheckArray2DCloseFailsOnNotEqual) try { - REQUIRE(CHECK_ARRAY2D_CLOSE (data1, data2, 2, 2, 0.01f)); + REQUIRE CHECK_ARRAY2D_CLOSE (data1, data2, 2, 2, 0.01f); } catch (const UnitTest::AssertException&) { @@ -728,7 +730,7 @@ TEST(RequiredCheckArray2DCloseFailureIncludesCheckExpectedAndActual) try { - REQUIRE(CHECK_ARRAY2D_CLOSE (data1, data2, 2, 2, 0.01f)); + REQUIRE CHECK_ARRAY2D_CLOSE (data1, data2, 2, 2, 0.01f); } catch (const UnitTest::AssertException&) { @@ -753,7 +755,7 @@ TEST(RequiredCheckArray2DCloseFailureContainsCorrectDetails) try { - line = __LINE__; REQUIRE(CHECK_ARRAY2D_CLOSE (data1, data2, 2, 2, 0.01f)); + line = __LINE__; REQUIRE CHECK_ARRAY2D_CLOSE (data1, data2, 2, 2, 0.01f); } catch (const UnitTest::AssertException&) { @@ -778,7 +780,7 @@ TEST(RequiredCheckArray2DCloseFailureIncludesTolerance) try { - REQUIRE(CHECK_ARRAY2D_CLOSE (data1, data2, 2, 2, 0.01f)); + REQUIRE CHECK_ARRAY2D_CLOSE (data1, data2, 2, 2, 0.01f); } catch (const UnitTest::AssertException&) { @@ -808,7 +810,7 @@ TEST(RequiredCheckArray2DCloseDoesNotHaveSideEffectsWhenPassing) try { - REQUIRE(CHECK_ARRAY2D_CLOSE (data, FunctionWithSideEffects3(), 2, 2, 0.01f)); + REQUIRE CHECK_ARRAY2D_CLOSE (data, FunctionWithSideEffects3(), 2, 2, 0.01f); } catch (const UnitTest::AssertException&) { @@ -828,7 +830,7 @@ TEST(RequiredCheckArray2DCloseDoesNotHaveSideEffectsWhenFailing) try { - REQUIRE(CHECK_ARRAY2D_CLOSE (data, FunctionWithSideEffects3(), 2, 2, 0.01f)); + REQUIRE CHECK_ARRAY2D_CLOSE (data, FunctionWithSideEffects3(), 2, 2, 0.01f); } catch (const UnitTest::AssertException&) { From a9161c1ba6f62584c435f56323e5a21891ecdffc Mon Sep 17 00:00:00 2001 From: Austin Gilbert Date: Sat, 6 Dec 2014 22:59:28 -0600 Subject: [PATCH 03/79] This commit addresses two issues: (1) unreachable code in for loop shenanigans is eliminated. (2) code after a failing REQUIRE check no longer executes. Used a decorating TestReporter to achive this. --- UnitTest++/CheckMacros.h | 30 ++++++++++++-- UnitTest++/RequireMacros.h | 9 +---- UnitTest++/RequiredCheckTestReporter.cpp | 29 ++++++++++++++ UnitTest++/RequiredCheckTestReporter.h | 29 ++++++++++++++ UnitTest++/TestResults.h | 4 ++ UnitTest++/ThrowingTestReporter.cpp | 51 ++++++++++++++++++++++++ UnitTest++/ThrowingTestReporter.h | 29 ++++++++++++++ tests/TestRequireMacros.cpp | 30 ++++++++++++++ 8 files changed, 201 insertions(+), 10 deletions(-) create mode 100644 UnitTest++/RequiredCheckTestReporter.cpp create mode 100644 UnitTest++/RequiredCheckTestReporter.h create mode 100644 UnitTest++/ThrowingTestReporter.cpp create mode 100644 UnitTest++/ThrowingTestReporter.h diff --git a/UnitTest++/CheckMacros.h b/UnitTest++/CheckMacros.h index d79d503..bc9fbcf 100644 --- a/UnitTest++/CheckMacros.h +++ b/UnitTest++/CheckMacros.h @@ -41,6 +41,10 @@ if (!UnitTest::Check(value)) \ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), #value); \ }) \ + UT_CATCH (UnitTest::AssertException, e, \ + { \ + UT_THROW(); \ + }) \ UT_CATCH (std::exception, e, \ { \ UnitTest::MemoryOutStream message; \ @@ -60,7 +64,11 @@ UT_TRY \ ({ \ UnitTest::CheckEqual(*UnitTest::CurrentTest::Results(), expected, actual, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ - }) \ + }) \ + UT_CATCH (UnitTest::AssertException, e, \ + { \ + UT_THROW(); \ + }) \ UT_CATCH (std::exception, e, \ { \ UnitTest::MemoryOutStream message; \ @@ -81,6 +89,10 @@ ({ \ UnitTest::CheckClose(*UnitTest::CurrentTest::Results(), expected, actual, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ }) \ + UT_CATCH (UnitTest::AssertException, e, \ + { \ + UT_THROW(); \ + }) \ UT_CATCH (std::exception, e, \ { \ UnitTest::MemoryOutStream message; \ @@ -100,7 +112,11 @@ UT_TRY \ ({ \ UnitTest::CheckArrayEqual(*UnitTest::CurrentTest::Results(), expected, actual, count, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ - }) \ + }) \ + UT_CATCH (UnitTest::AssertException, e, \ + { \ + UT_THROW(); \ + }) \ UT_CATCH (std::exception, e, \ { \ UnitTest::MemoryOutStream message; \ @@ -121,6 +137,10 @@ ({ \ UnitTest::CheckArrayClose(*UnitTest::CurrentTest::Results(), expected, actual, count, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ }) \ + UT_CATCH (UnitTest::AssertException, e, \ + { \ + UT_THROW(); \ + }) \ UT_CATCH (std::exception, e, \ { \ UnitTest::MemoryOutStream message; \ @@ -140,7 +160,11 @@ UT_TRY \ ({ \ UnitTest::CheckArray2DClose(*UnitTest::CurrentTest::Results(), expected, actual, rows, columns, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ - }) \ + }) \ + UT_CATCH (UnitTest::AssertException, e, \ + { \ + UT_THROW(); \ + }) \ UT_CATCH (std::exception, e, \ { \ UnitTest::MemoryOutStream message; \ diff --git a/UnitTest++/RequireMacros.h b/UnitTest++/RequireMacros.h index 747bda7..9fee8eb 100644 --- a/UnitTest++/RequireMacros.h +++ b/UnitTest++/RequireMacros.h @@ -1,19 +1,14 @@ #ifndef UNITTEST_REQUIREMACROS_H #define UNITTEST_REQUIREMACROS_H -#include "HelperMacros.h" -#include "ExceptionMacros.h" -#include "CurrentTest.h" +#include "RequiredCheckTestReporter.h" #ifdef REQUIRE #error UnitTest++ redefines REQUIRE #endif #ifndef UNITTEST_NO_EXCEPTIONS - #define REQUIRE \ - for (int failuresBeforeTest = UnitTest::CurrentTest::Results()->GetFailureCount(), newFailures = 0, run = 0; \ - (run == 0) || ((newFailures != 0) && (throw UnitTest::AssertException(), true)); \ - newFailures = UnitTest::CurrentTest::Results()->GetFailureCount() - failuresBeforeTest, run = 1) + #define REQUIRE for(UnitTest::RequiredCheckTestReporter decoratedReporter(UnitTest::CurrentTest::Results()); decoratedReporter.next(); ) #endif #ifdef UNITTEST_NO_EXCEPTIONS diff --git a/UnitTest++/RequiredCheckTestReporter.cpp b/UnitTest++/RequiredCheckTestReporter.cpp new file mode 100644 index 0000000..cae20db --- /dev/null +++ b/UnitTest++/RequiredCheckTestReporter.cpp @@ -0,0 +1,29 @@ +#include "RequiredCheckTestReporter.h" + +#include "CurrentTest.h" +#include "TestResults.h" + +namespace UnitTest { + + RequiredCheckTestReporter::RequiredCheckTestReporter(TestResults* results) + : m_results(results) + , m_throwingReporter(0) + , m_continue(0) + { + if(m_results) + { + m_throwingReporter.setDecorated(m_results->m_testReporter); + m_results->m_testReporter = &m_throwingReporter; + } + } + + RequiredCheckTestReporter::~RequiredCheckTestReporter() + { + if(m_results) m_results->m_testReporter = m_throwingReporter.getDecorated(); + } + + bool RequiredCheckTestReporter::next() + { + return m_continue++ == 0; + } +} \ No newline at end of file diff --git a/UnitTest++/RequiredCheckTestReporter.h b/UnitTest++/RequiredCheckTestReporter.h new file mode 100644 index 0000000..22613e9 --- /dev/null +++ b/UnitTest++/RequiredCheckTestReporter.h @@ -0,0 +1,29 @@ +#ifndef UNITTEST_REQUIRED_CHECK_TEST_REPORTER_H +#define UNITTEST_REQUIRED_CHECK_TEST_REPORTER_H + +#include "HelperMacros.h" +#include "ThrowingTestReporter.h" + +namespace UnitTest { + + class TestResults; + + // This RAII class decorates the current TestReporter with + // a version that throws after reporting a failure. + class UNITTEST_LINKAGE RequiredCheckTestReporter + { + public: + explicit RequiredCheckTestReporter(TestResults* results); + ~RequiredCheckTestReporter(); + + bool next(); + + private: + TestResults* m_results; + ThrowingTestReporter m_throwingReporter; + int m_continue; + }; +} + +#endif + diff --git a/UnitTest++/TestResults.h b/UnitTest++/TestResults.h index c56a632..024ace3 100644 --- a/UnitTest++/TestResults.h +++ b/UnitTest++/TestResults.h @@ -5,6 +5,7 @@ namespace UnitTest { +class RequiredCheckTestReporter; class TestReporter; class TestDetails; @@ -22,6 +23,9 @@ namespace UnitTest { int GetFailureCount() const; private: + friend class RequiredCheckTestReporter; + +private: TestReporter* m_testReporter; int m_totalTestCount; int m_failedTestCount; diff --git a/UnitTest++/ThrowingTestReporter.cpp b/UnitTest++/ThrowingTestReporter.cpp new file mode 100644 index 0000000..45ccade --- /dev/null +++ b/UnitTest++/ThrowingTestReporter.cpp @@ -0,0 +1,51 @@ +#include "ThrowingTestReporter.h" +#include "AssertException.h" + +namespace UnitTest { + + ThrowingTestReporter::ThrowingTestReporter(TestReporter* decoratedReporter) + : m_decoratedReporter(decoratedReporter) + { + } + + //virtual + ThrowingTestReporter::~ThrowingTestReporter() + { + } + + //virtual + void ThrowingTestReporter::ReportTestStart(TestDetails const& test) + { + if(m_decoratedReporter) m_decoratedReporter->ReportTestStart(test); + } + + //virtual + void ThrowingTestReporter::ReportFailure(TestDetails const& test, char const* failure) + { + if(m_decoratedReporter) m_decoratedReporter->ReportFailure(test, failure); + throw AssertException(); + } + + //virtual + void ThrowingTestReporter::ReportTestFinish(TestDetails const& test, float secondsElapsed) + { + if(m_decoratedReporter) m_decoratedReporter->ReportTestFinish(test, secondsElapsed); + } + + //virtual + void ThrowingTestReporter::ReportSummary(int totalTestCount, int failedTestCount, int failureCount, float secondsElapsed) + { + if(m_decoratedReporter) m_decoratedReporter->ReportSummary(totalTestCount, failedTestCount, failureCount, secondsElapsed); + } + + TestReporter* ThrowingTestReporter::getDecorated() const + { + return m_decoratedReporter; + } + + void ThrowingTestReporter::setDecorated(TestReporter* reporter) + { + m_decoratedReporter = reporter; + } + +} diff --git a/UnitTest++/ThrowingTestReporter.h b/UnitTest++/ThrowingTestReporter.h new file mode 100644 index 0000000..0a02a51 --- /dev/null +++ b/UnitTest++/ThrowingTestReporter.h @@ -0,0 +1,29 @@ +#ifndef UNITTEST_THROWINGTESTREPORTER_H +#define UNITTEST_THROWINGTESTREPORTER_H + +#include "TestReporter.h" + +namespace UnitTest { + + // A TestReporter that throws when ReportFailure is called. Otherwise it + // forwards the calls to a decorated TestReporter + class ThrowingTestReporter : public TestReporter + { + public: + explicit ThrowingTestReporter(TestReporter* reporter); + + virtual ~ThrowingTestReporter(); + virtual void ReportTestStart(TestDetails const& test); + virtual void ReportFailure(TestDetails const& test, char const* failure); + virtual void ReportTestFinish(TestDetails const& test, float secondsElapsed); + virtual void ReportSummary(int totalTestCount, int failedTestCount, int failureCount, float secondsElapsed); + + TestReporter* getDecorated() const; + void setDecorated(TestReporter* reporter); + + private: + TestReporter* m_decoratedReporter; + }; +} + +#endif diff --git a/tests/TestRequireMacros.cpp b/tests/TestRequireMacros.cpp index 869de32..46732a2 100644 --- a/tests/TestRequireMacros.cpp +++ b/tests/TestRequireMacros.cpp @@ -117,7 +117,37 @@ TEST(RequireMacroSupportsMultipleChecksWithFailingChecks) CHECK(failure); CHECK(exception); } + +TEST(RequireMacroDoesntExecuteCodeAfterAFailingCheck) +{ + bool failure = false; + bool exception = false; + bool run = false; + { + RecordingReporter reporter; + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + try{ + REQUIRE + { + CHECK(false); + run = true; // this shouldn't get executed. + } + } + catch (const UnitTest::AssertException&) + { + exception = true; + } + + failure = (testResults.GetFailureCount() > 0); + } + CHECK(failure); + CHECK(exception); + CHECK(!run); +} + TEST(FailureReportsCorrectTestName) { RecordingReporter reporter; From 89ff2596ee12aeea98975f17ced70184ab5a0322 Mon Sep 17 00:00:00 2001 From: Austin Gilbert Date: Sun, 17 May 2015 21:21:10 -0500 Subject: [PATCH 04/79] Eliminating 'unused exception variable' warnings. --- UnitTest++/CheckMacros.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/UnitTest++/CheckMacros.h b/UnitTest++/CheckMacros.h index bc9fbcf..96b98ba 100644 --- a/UnitTest++/CheckMacros.h +++ b/UnitTest++/CheckMacros.h @@ -41,7 +41,7 @@ if (!UnitTest::Check(value)) \ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), #value); \ }) \ - UT_CATCH (UnitTest::AssertException, e, \ + UT_CATCH (UnitTest::AssertException, , \ { \ UT_THROW(); \ }) \ @@ -65,7 +65,7 @@ ({ \ UnitTest::CheckEqual(*UnitTest::CurrentTest::Results(), expected, actual, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ }) \ - UT_CATCH (UnitTest::AssertException, e, \ + UT_CATCH (UnitTest::AssertException, , \ { \ UT_THROW(); \ }) \ @@ -89,7 +89,7 @@ ({ \ UnitTest::CheckClose(*UnitTest::CurrentTest::Results(), expected, actual, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ }) \ - UT_CATCH (UnitTest::AssertException, e, \ + UT_CATCH (UnitTest::AssertException, , \ { \ UT_THROW(); \ }) \ @@ -113,7 +113,7 @@ ({ \ UnitTest::CheckArrayEqual(*UnitTest::CurrentTest::Results(), expected, actual, count, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ }) \ - UT_CATCH (UnitTest::AssertException, e, \ + UT_CATCH (UnitTest::AssertException, , \ { \ UT_THROW(); \ }) \ @@ -137,7 +137,7 @@ ({ \ UnitTest::CheckArrayClose(*UnitTest::CurrentTest::Results(), expected, actual, count, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ }) \ - UT_CATCH (UnitTest::AssertException, e, \ + UT_CATCH (UnitTest::AssertException, , \ { \ UT_THROW(); \ }) \ @@ -161,7 +161,7 @@ ({ \ UnitTest::CheckArray2DClose(*UnitTest::CurrentTest::Results(), expected, actual, rows, columns, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ }) \ - UT_CATCH (UnitTest::AssertException, e, \ + UT_CATCH (UnitTest::AssertException, , \ { \ UT_THROW(); \ }) \ From 74ca0c301f84abd7833dc9c927261e05ee04b276 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Thu, 4 Feb 2016 21:16:45 -0600 Subject: [PATCH 05/79] Merge and uncrustify. --- UnitTest++/CheckMacros.h | 54 +- UnitTest++/RequireMacros.h | 4 +- UnitTest++/RequiredCheckTestReporter.cpp | 38 +- UnitTest++/RequiredCheckTestReporter.h | 30 +- UnitTest++/TestResults.h | 6 +- UnitTest++/ThrowingTestReporter.cpp | 72 +- UnitTest++/ThrowingTestReporter.h | 32 +- tests/TestRequireMacros.cpp | 1394 +++++++++++----------- 8 files changed, 804 insertions(+), 826 deletions(-) diff --git a/UnitTest++/CheckMacros.h b/UnitTest++/CheckMacros.h index 96b98ba..82a4042 100644 --- a/UnitTest++/CheckMacros.h +++ b/UnitTest++/CheckMacros.h @@ -41,10 +41,10 @@ if (!UnitTest::Check(value)) \ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), #value); \ }) \ - UT_CATCH (UnitTest::AssertException, , \ - { \ - UT_THROW(); \ - }) \ + UT_CATCH (UnitTest::AssertException, , \ + { \ + UT_THROW(); \ + }) \ UT_CATCH (std::exception, e, \ { \ UnitTest::MemoryOutStream message; \ @@ -64,11 +64,11 @@ UT_TRY \ ({ \ UnitTest::CheckEqual(*UnitTest::CurrentTest::Results(), expected, actual, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ - }) \ - UT_CATCH (UnitTest::AssertException, , \ - { \ - UT_THROW(); \ - }) \ + }) \ + UT_CATCH (UnitTest::AssertException, , \ + { \ + UT_THROW(); \ + }) \ UT_CATCH (std::exception, e, \ { \ UnitTest::MemoryOutStream message; \ @@ -89,10 +89,10 @@ ({ \ UnitTest::CheckClose(*UnitTest::CurrentTest::Results(), expected, actual, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ }) \ - UT_CATCH (UnitTest::AssertException, , \ - { \ - UT_THROW(); \ - }) \ + UT_CATCH (UnitTest::AssertException, , \ + { \ + UT_THROW(); \ + }) \ UT_CATCH (std::exception, e, \ { \ UnitTest::MemoryOutStream message; \ @@ -112,11 +112,11 @@ UT_TRY \ ({ \ UnitTest::CheckArrayEqual(*UnitTest::CurrentTest::Results(), expected, actual, count, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ - }) \ - UT_CATCH (UnitTest::AssertException, , \ - { \ - UT_THROW(); \ - }) \ + }) \ + UT_CATCH (UnitTest::AssertException, , \ + { \ + UT_THROW(); \ + }) \ UT_CATCH (std::exception, e, \ { \ UnitTest::MemoryOutStream message; \ @@ -137,10 +137,10 @@ ({ \ UnitTest::CheckArrayClose(*UnitTest::CurrentTest::Results(), expected, actual, count, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ }) \ - UT_CATCH (UnitTest::AssertException, , \ - { \ - UT_THROW(); \ - }) \ + UT_CATCH (UnitTest::AssertException, , \ + { \ + UT_THROW(); \ + }) \ UT_CATCH (std::exception, e, \ { \ UnitTest::MemoryOutStream message; \ @@ -160,11 +160,11 @@ UT_TRY \ ({ \ UnitTest::CheckArray2DClose(*UnitTest::CurrentTest::Results(), expected, actual, rows, columns, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ - }) \ - UT_CATCH (UnitTest::AssertException, , \ - { \ - UT_THROW(); \ - }) \ + }) \ + UT_CATCH (UnitTest::AssertException, , \ + { \ + UT_THROW(); \ + }) \ UT_CATCH (std::exception, e, \ { \ UnitTest::MemoryOutStream message; \ diff --git a/UnitTest++/RequireMacros.h b/UnitTest++/RequireMacros.h index 9fee8eb..4a107d4 100644 --- a/UnitTest++/RequireMacros.h +++ b/UnitTest++/RequireMacros.h @@ -8,11 +8,11 @@ #endif #ifndef UNITTEST_NO_EXCEPTIONS - #define REQUIRE for(UnitTest::RequiredCheckTestReporter decoratedReporter(UnitTest::CurrentTest::Results()); decoratedReporter.next(); ) +#define REQUIRE for(UnitTest::RequiredCheckTestReporter decoratedReporter(UnitTest::CurrentTest::Results()); decoratedReporter.next(); ) #endif #ifdef UNITTEST_NO_EXCEPTIONS - #define REQUIRE +#define REQUIRE #endif #endif \ No newline at end of file diff --git a/UnitTest++/RequiredCheckTestReporter.cpp b/UnitTest++/RequiredCheckTestReporter.cpp index cae20db..1fd2ec7 100644 --- a/UnitTest++/RequiredCheckTestReporter.cpp +++ b/UnitTest++/RequiredCheckTestReporter.cpp @@ -5,25 +5,25 @@ namespace UnitTest { - RequiredCheckTestReporter::RequiredCheckTestReporter(TestResults* results) - : m_results(results) - , m_throwingReporter(0) - , m_continue(0) - { - if(m_results) - { - m_throwingReporter.setDecorated(m_results->m_testReporter); - m_results->m_testReporter = &m_throwingReporter; - } - } + RequiredCheckTestReporter::RequiredCheckTestReporter(TestResults* results) + : m_results(results) + , m_throwingReporter(0) + , m_continue(0) + { + if(m_results) + { + m_throwingReporter.setDecorated(m_results->m_testReporter); + m_results->m_testReporter = &m_throwingReporter; + } + } - RequiredCheckTestReporter::~RequiredCheckTestReporter() - { - if(m_results) m_results->m_testReporter = m_throwingReporter.getDecorated(); - } + RequiredCheckTestReporter::~RequiredCheckTestReporter() + { + if(m_results) m_results->m_testReporter = m_throwingReporter.getDecorated(); + } - bool RequiredCheckTestReporter::next() - { - return m_continue++ == 0; - } + bool RequiredCheckTestReporter::next() + { + return m_continue++ == 0; + } } \ No newline at end of file diff --git a/UnitTest++/RequiredCheckTestReporter.h b/UnitTest++/RequiredCheckTestReporter.h index 22613e9..a8c635e 100644 --- a/UnitTest++/RequiredCheckTestReporter.h +++ b/UnitTest++/RequiredCheckTestReporter.h @@ -6,23 +6,23 @@ namespace UnitTest { - class TestResults; + class TestResults; - // This RAII class decorates the current TestReporter with - // a version that throws after reporting a failure. - class UNITTEST_LINKAGE RequiredCheckTestReporter - { - public: - explicit RequiredCheckTestReporter(TestResults* results); - ~RequiredCheckTestReporter(); + // This RAII class decorates the current TestReporter with + // a version that throws after reporting a failure. + class UNITTEST_LINKAGE RequiredCheckTestReporter + { + public: + explicit RequiredCheckTestReporter(TestResults* results); + ~RequiredCheckTestReporter(); - bool next(); - - private: - TestResults* m_results; - ThrowingTestReporter m_throwingReporter; - int m_continue; - }; + bool next(); + + private: + TestResults* m_results; + ThrowingTestReporter m_throwingReporter; + int m_continue; + }; } #endif diff --git a/UnitTest++/TestResults.h b/UnitTest++/TestResults.h index 024ace3..b23418c 100644 --- a/UnitTest++/TestResults.h +++ b/UnitTest++/TestResults.h @@ -5,7 +5,7 @@ namespace UnitTest { -class RequiredCheckTestReporter; + class RequiredCheckTestReporter; class TestReporter; class TestDetails; @@ -23,9 +23,9 @@ class RequiredCheckTestReporter; int GetFailureCount() const; private: - friend class RequiredCheckTestReporter; + friend class RequiredCheckTestReporter; -private: + private: TestReporter* m_testReporter; int m_totalTestCount; int m_failedTestCount; diff --git a/UnitTest++/ThrowingTestReporter.cpp b/UnitTest++/ThrowingTestReporter.cpp index 45ccade..367a8b3 100644 --- a/UnitTest++/ThrowingTestReporter.cpp +++ b/UnitTest++/ThrowingTestReporter.cpp @@ -3,49 +3,47 @@ namespace UnitTest { - ThrowingTestReporter::ThrowingTestReporter(TestReporter* decoratedReporter) - : m_decoratedReporter(decoratedReporter) - { - } + ThrowingTestReporter::ThrowingTestReporter(TestReporter* decoratedReporter) + : m_decoratedReporter(decoratedReporter) + {} - //virtual - ThrowingTestReporter::~ThrowingTestReporter() - { - } + //virtual + ThrowingTestReporter::~ThrowingTestReporter() + {} - //virtual - void ThrowingTestReporter::ReportTestStart(TestDetails const& test) - { - if(m_decoratedReporter) m_decoratedReporter->ReportTestStart(test); - } + //virtual + void ThrowingTestReporter::ReportTestStart(TestDetails const& test) + { + if(m_decoratedReporter) m_decoratedReporter->ReportTestStart(test); + } - //virtual - void ThrowingTestReporter::ReportFailure(TestDetails const& test, char const* failure) - { - if(m_decoratedReporter) m_decoratedReporter->ReportFailure(test, failure); - throw AssertException(); - } + //virtual + void ThrowingTestReporter::ReportFailure(TestDetails const& test, char const* failure) + { + if(m_decoratedReporter) m_decoratedReporter->ReportFailure(test, failure); + throw AssertException(); + } - //virtual - void ThrowingTestReporter::ReportTestFinish(TestDetails const& test, float secondsElapsed) - { - if(m_decoratedReporter) m_decoratedReporter->ReportTestFinish(test, secondsElapsed); - } + //virtual + void ThrowingTestReporter::ReportTestFinish(TestDetails const& test, float secondsElapsed) + { + if(m_decoratedReporter) m_decoratedReporter->ReportTestFinish(test, secondsElapsed); + } - //virtual - void ThrowingTestReporter::ReportSummary(int totalTestCount, int failedTestCount, int failureCount, float secondsElapsed) - { - if(m_decoratedReporter) m_decoratedReporter->ReportSummary(totalTestCount, failedTestCount, failureCount, secondsElapsed); - } + //virtual + void ThrowingTestReporter::ReportSummary(int totalTestCount, int failedTestCount, int failureCount, float secondsElapsed) + { + if(m_decoratedReporter) m_decoratedReporter->ReportSummary(totalTestCount, failedTestCount, failureCount, secondsElapsed); + } - TestReporter* ThrowingTestReporter::getDecorated() const - { - return m_decoratedReporter; - } + TestReporter* ThrowingTestReporter::getDecorated() const + { + return m_decoratedReporter; + } - void ThrowingTestReporter::setDecorated(TestReporter* reporter) - { - m_decoratedReporter = reporter; - } + void ThrowingTestReporter::setDecorated(TestReporter* reporter) + { + m_decoratedReporter = reporter; + } } diff --git a/UnitTest++/ThrowingTestReporter.h b/UnitTest++/ThrowingTestReporter.h index 0a02a51..8ed91da 100644 --- a/UnitTest++/ThrowingTestReporter.h +++ b/UnitTest++/ThrowingTestReporter.h @@ -5,25 +5,25 @@ namespace UnitTest { - // A TestReporter that throws when ReportFailure is called. Otherwise it - // forwards the calls to a decorated TestReporter - class ThrowingTestReporter : public TestReporter - { - public: - explicit ThrowingTestReporter(TestReporter* reporter); + // A TestReporter that throws when ReportFailure is called. Otherwise it + // forwards the calls to a decorated TestReporter + class ThrowingTestReporter : public TestReporter + { + public: + explicit ThrowingTestReporter(TestReporter* reporter); - virtual ~ThrowingTestReporter(); - virtual void ReportTestStart(TestDetails const& test); - virtual void ReportFailure(TestDetails const& test, char const* failure); - virtual void ReportTestFinish(TestDetails const& test, float secondsElapsed); - virtual void ReportSummary(int totalTestCount, int failedTestCount, int failureCount, float secondsElapsed); + virtual ~ThrowingTestReporter(); + virtual void ReportTestStart(TestDetails const& test); + virtual void ReportFailure(TestDetails const& test, char const* failure); + virtual void ReportTestFinish(TestDetails const& test, float secondsElapsed); + virtual void ReportSummary(int totalTestCount, int failedTestCount, int failureCount, float secondsElapsed); - TestReporter* getDecorated() const; - void setDecorated(TestReporter* reporter); + TestReporter* getDecorated() const; + void setDecorated(TestReporter* reporter); - private: - TestReporter* m_decoratedReporter; - }; + private: + TestReporter* m_decoratedReporter; + }; } #endif diff --git a/tests/TestRequireMacros.cpp b/tests/TestRequireMacros.cpp index 46732a2..88cb128 100644 --- a/tests/TestRequireMacros.cpp +++ b/tests/TestRequireMacros.cpp @@ -9,865 +9,845 @@ using namespace std; namespace { -TEST(RequireCheckSucceedsOnTrue) -{ - bool failure = true; - bool exception = false; - { - RecordingReporter reporter; - UnitTest::TestResults testResults(&reporter); + TEST(RequireCheckSucceedsOnTrue) + { + bool failure = true; + bool exception = false; + { + RecordingReporter reporter; + UnitTest::TestResults testResults(&reporter); - ScopedCurrentTest scopedResults(testResults); - - try - { + ScopedCurrentTest scopedResults(testResults); + + try + { REQUIRE CHECK(true); - } - catch(const UnitTest::AssertException&) - { + } + catch(const UnitTest::AssertException&) + { exception = true; - } - - failure = (testResults.GetFailureCount() > 0); - } + } - CHECK(!failure); - CHECK(!exception); -} + failure = (testResults.GetFailureCount() > 0); + } -TEST(RequiredCheckFailsOnFalse) -{ - bool failure = false; - bool exception = false; - { - RecordingReporter reporter; - UnitTest::TestResults testResults(&reporter); - ScopedCurrentTest scopedResults(testResults); - - try - { + CHECK(!failure); + CHECK(!exception); + } + + TEST(RequiredCheckFailsOnFalse) + { + bool failure = false; + bool exception = false; + { + RecordingReporter reporter; + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + try + { REQUIRE CHECK(false); - } - catch (const UnitTest::AssertException&) - { + } + catch (const UnitTest::AssertException&) + { exception = true; - } - - failure = (testResults.GetFailureCount() > 0); - } + } - CHECK(failure); - CHECK(exception); -} + failure = (testResults.GetFailureCount() > 0); + } - -TEST(RequireMacroSupportsMultipleChecks) -{ - bool failure = false; - bool exception = false; - { - RecordingReporter reporter; - UnitTest::TestResults testResults(&reporter); - ScopedCurrentTest scopedResults(testResults); - - try{ + CHECK(failure); + CHECK(exception); + } + + + TEST(RequireMacroSupportsMultipleChecks) + { + bool failure = false; + bool exception = false; + { + RecordingReporter reporter; + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + try{ REQUIRE { - CHECK(true); - CHECK_EQUAL(1,1); + CHECK(true); + CHECK_EQUAL(1,1); } - } - catch (const UnitTest::AssertException&) - { + } + catch (const UnitTest::AssertException&) + { exception = true; - } - - failure = (testResults.GetFailureCount() > 0); - } - - CHECK(!failure); - CHECK(!exception); -} + } + + failure = (testResults.GetFailureCount() > 0); + } + + CHECK(!failure); + CHECK(!exception); + } -TEST(RequireMacroSupportsMultipleChecksWithFailingChecks) -{ - bool failure = false; - bool exception = false; - { - RecordingReporter reporter; - UnitTest::TestResults testResults(&reporter); - ScopedCurrentTest scopedResults(testResults); - - try{ + TEST(RequireMacroSupportsMultipleChecksWithFailingChecks) + { + bool failure = false; + bool exception = false; + { + RecordingReporter reporter; + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + try{ REQUIRE { - CHECK(true); - CHECK_EQUAL(1,2); + CHECK(true); + CHECK_EQUAL(1,2); } - } - catch (const UnitTest::AssertException&) - { + } + catch (const UnitTest::AssertException&) + { exception = true; - } - - failure = (testResults.GetFailureCount() > 0); - } - - CHECK(failure); - CHECK(exception); -} + } -TEST(RequireMacroDoesntExecuteCodeAfterAFailingCheck) -{ - bool failure = false; - bool exception = false; - bool run = false; - { - RecordingReporter reporter; - UnitTest::TestResults testResults(&reporter); - ScopedCurrentTest scopedResults(testResults); + failure = (testResults.GetFailureCount() > 0); + } - try{ + CHECK(failure); + CHECK(exception); + } + + TEST(RequireMacroDoesntExecuteCodeAfterAFailingCheck) + { + bool failure = false; + bool exception = false; + bool run = false; + { + RecordingReporter reporter; + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + try{ REQUIRE { - CHECK(false); - run = true; // this shouldn't get executed. + CHECK(false); + run = true; // this shouldn't get executed. } - } - catch (const UnitTest::AssertException&) - { + } + catch (const UnitTest::AssertException&) + { exception = true; - } + } - failure = (testResults.GetFailureCount() > 0); - } - - CHECK(failure); - CHECK(exception); - CHECK(!run); -} + failure = (testResults.GetFailureCount() > 0); + } -TEST(FailureReportsCorrectTestName) -{ - RecordingReporter reporter; - { - UnitTest::TestResults testResults(&reporter); - ScopedCurrentTest scopedResults(testResults); - - try - { + CHECK(failure); + CHECK(exception); + CHECK(!run); + } + + TEST(FailureReportsCorrectTestName) + { + RecordingReporter reporter; + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + try + { REQUIRE CHECK(false); - } - catch (const UnitTest::AssertException&) - { - } - } + } + catch (const UnitTest::AssertException&) + {} + } - CHECK_EQUAL(m_details.testName, reporter.lastFailedTest); -} + CHECK_EQUAL(m_details.testName, reporter.lastFailedTest); + } -TEST(RequiredCheckFailureIncludesCheckContents) -{ - RecordingReporter reporter; - { - UnitTest::TestResults testResults(&reporter); - ScopedCurrentTest scopedResults(testResults); - const bool yaddayadda = false; - - try - { + TEST(RequiredCheckFailureIncludesCheckContents) + { + RecordingReporter reporter; + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + const bool yaddayadda = false; + + try + { REQUIRE CHECK(yaddayadda); - } - catch (const UnitTest::AssertException&) - { - } - } + } + catch (const UnitTest::AssertException&) + {} + } - CHECK(strstr(reporter.lastFailedMessage, "yaddayadda")); -} + CHECK(strstr(reporter.lastFailedMessage, "yaddayadda")); + } -TEST(RequiredCheckEqualSucceedsOnEqual) -{ - bool failure = true; - bool exception = false; - { - RecordingReporter reporter; - UnitTest::TestResults testResults(&reporter); - ScopedCurrentTest scopedResults(testResults); - - try - { + TEST(RequiredCheckEqualSucceedsOnEqual) + { + bool failure = true; + bool exception = false; + { + RecordingReporter reporter; + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + try + { REQUIRE CHECK_EQUAL(1,1); - } - catch (const UnitTest::AssertException&) - { + } + catch (const UnitTest::AssertException&) + { exception = true; - } + } - failure = (testResults.GetFailureCount() > 0); - } + failure = (testResults.GetFailureCount() > 0); + } - CHECK(!failure); - CHECK(!exception); -} + CHECK(!failure); + CHECK(!exception); + } -TEST(RequiredCheckEqualFailsOnNotEqual) -{ - bool failure = false; - bool exception = false; - { - RecordingReporter reporter; - UnitTest::TestResults testResults(&reporter); - ScopedCurrentTest scopedResults(testResults); + TEST(RequiredCheckEqualFailsOnNotEqual) + { + bool failure = false; + bool exception = false; + { + RecordingReporter reporter; + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); - try - { + try + { REQUIRE CHECK_EQUAL(1, 2); - } - catch (const UnitTest::AssertException&) - { + } + catch (const UnitTest::AssertException&) + { exception = true; - } + } - failure = (testResults.GetFailureCount() > 0); - } + failure = (testResults.GetFailureCount() > 0); + } - CHECK(failure); - CHECK(exception); -} + CHECK(failure); + CHECK(exception); + } -TEST(RequiredCheckEqualFailureContainsCorrectDetails) -{ - int line = 0; - RecordingReporter reporter; - { - UnitTest::TestResults testResults(&reporter); - UnitTest::TestDetails const testDetails("testName", "suiteName", "filename", -1); - ScopedCurrentTest scopedResults(testResults, &testDetails); + TEST(RequiredCheckEqualFailureContainsCorrectDetails) + { + int line = 0; + RecordingReporter reporter; + { + UnitTest::TestResults testResults(&reporter); + UnitTest::TestDetails const testDetails("testName", "suiteName", "filename", -1); + ScopedCurrentTest scopedResults(testResults, &testDetails); - try - { + try + { line = __LINE__; REQUIRE CHECK_EQUAL(1, 123); - } - catch (const UnitTest::AssertException&) - { - } - } + } + catch (const UnitTest::AssertException&) + {} + } - CHECK_EQUAL("testName", reporter.lastFailedTest); - CHECK_EQUAL("suiteName", reporter.lastFailedSuite); - CHECK_EQUAL("filename", reporter.lastFailedFile); - CHECK_EQUAL(line, reporter.lastFailedLine); -} + CHECK_EQUAL("testName", reporter.lastFailedTest); + CHECK_EQUAL("suiteName", reporter.lastFailedSuite); + CHECK_EQUAL("filename", reporter.lastFailedFile); + CHECK_EQUAL(line, reporter.lastFailedLine); + } -int g_sideEffect = 0; -int FunctionWithSideEffects() -{ - ++g_sideEffect; - return 1; -} + int g_sideEffect = 0; + int FunctionWithSideEffects() + { + ++g_sideEffect; + return 1; + } -TEST(RequiredCheckEqualDoesNotHaveSideEffectsWhenPassing) -{ - g_sideEffect = 0; - { - UnitTest::TestResults testResults; - ScopedCurrentTest scopedResults(testResults); - - try - { + TEST(RequiredCheckEqualDoesNotHaveSideEffectsWhenPassing) + { + g_sideEffect = 0; + { + UnitTest::TestResults testResults; + ScopedCurrentTest scopedResults(testResults); + + try + { REQUIRE CHECK_EQUAL(1, FunctionWithSideEffects()); - } - catch (const UnitTest::AssertException&) - { - } - } - CHECK_EQUAL(1, g_sideEffect); -} + } + catch (const UnitTest::AssertException&) + {} + } + CHECK_EQUAL(1, g_sideEffect); + } -TEST(RequiredCheckEqualDoesNotHaveSideEffectsWhenFailing) -{ - g_sideEffect = 0; - { - UnitTest::TestResults testResults; - ScopedCurrentTest scopedResults(testResults); + TEST(RequiredCheckEqualDoesNotHaveSideEffectsWhenFailing) + { + g_sideEffect = 0; + { + UnitTest::TestResults testResults; + ScopedCurrentTest scopedResults(testResults); - try - { + try + { REQUIRE CHECK_EQUAL(2, FunctionWithSideEffects()); - } - catch (const UnitTest::AssertException&) - { - } - } - CHECK_EQUAL(1, g_sideEffect); -} + } + catch (const UnitTest::AssertException&) + {} + } + CHECK_EQUAL(1, g_sideEffect); + } -TEST(RequiredCheckCloseSucceedsOnEqual) -{ - bool failure = true; - bool exception = false; - { - RecordingReporter reporter; - UnitTest::TestResults testResults(&reporter); - ScopedCurrentTest scopedResults(testResults); + TEST(RequiredCheckCloseSucceedsOnEqual) + { + bool failure = true; + bool exception = false; + { + RecordingReporter reporter; + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); - try - { + try + { REQUIRE CHECK_CLOSE(1.0f, 1.001f, 0.01f); - } - catch (const UnitTest::AssertException&) - { + } + catch (const UnitTest::AssertException&) + { exception = true; - } + } - failure = (testResults.GetFailureCount() > 0); - } + failure = (testResults.GetFailureCount() > 0); + } - CHECK(!failure); - CHECK(!exception); -} + CHECK(!failure); + CHECK(!exception); + } -TEST(RequiredCheckCloseFailsOnNotEqual) -{ - bool failure = false; - bool exception = false; - { - RecordingReporter reporter; - UnitTest::TestResults testResults(&reporter); - ScopedCurrentTest scopedResults(testResults); - - try - { + TEST(RequiredCheckCloseFailsOnNotEqual) + { + bool failure = false; + bool exception = false; + { + RecordingReporter reporter; + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + try + { REQUIRE CHECK_CLOSE (1.0f, 1.1f, 0.01f); - } - catch (const UnitTest::AssertException&) - { + } + catch (const UnitTest::AssertException&) + { exception = true; - } - - failure = (testResults.GetFailureCount() > 0); - } + } - CHECK(failure); - CHECK(exception); -} + failure = (testResults.GetFailureCount() > 0); + } -TEST(RequiredCheckCloseFailureContainsCorrectDetails) -{ - int line = 0; - RecordingReporter reporter; - { - UnitTest::TestResults testResults(&reporter); - UnitTest::TestDetails testDetails("test", "suite", "filename", -1); - ScopedCurrentTest scopedResults(testResults, &testDetails); + CHECK(failure); + CHECK(exception); + } - try - { + TEST(RequiredCheckCloseFailureContainsCorrectDetails) + { + int line = 0; + RecordingReporter reporter; + { + UnitTest::TestResults testResults(&reporter); + UnitTest::TestDetails testDetails("test", "suite", "filename", -1); + ScopedCurrentTest scopedResults(testResults, &testDetails); + + try + { line = __LINE__; REQUIRE CHECK_CLOSE(1.0f, 1.1f, 0.01f); CHECK(false); - } - catch (const UnitTest::AssertException&) - { - } - } + } + catch (const UnitTest::AssertException&) + {} + } - CHECK_EQUAL("test", reporter.lastFailedTest); - CHECK_EQUAL("suite", reporter.lastFailedSuite); - CHECK_EQUAL("filename", reporter.lastFailedFile); - CHECK_EQUAL(line, reporter.lastFailedLine); -} + CHECK_EQUAL("test", reporter.lastFailedTest); + CHECK_EQUAL("suite", reporter.lastFailedSuite); + CHECK_EQUAL("filename", reporter.lastFailedFile); + CHECK_EQUAL(line, reporter.lastFailedLine); + } -TEST(RequiredCheckCloseDoesNotHaveSideEffectsWhenPassing) -{ - g_sideEffect = 0; - { - UnitTest::TestResults testResults; - ScopedCurrentTest scopedResults(testResults); - - try - { + TEST(RequiredCheckCloseDoesNotHaveSideEffectsWhenPassing) + { + g_sideEffect = 0; + { + UnitTest::TestResults testResults; + ScopedCurrentTest scopedResults(testResults); + + try + { REQUIRE CHECK_CLOSE (1, FunctionWithSideEffects(), 0.1f); - } - catch (const UnitTest::AssertException&) - { - } - } - CHECK_EQUAL(1, g_sideEffect); -} + } + catch (const UnitTest::AssertException&) + {} + } + CHECK_EQUAL(1, g_sideEffect); + } -TEST(RequiredCheckCloseDoesNotHaveSideEffectsWhenFailing) -{ - g_sideEffect = 0; - { - UnitTest::TestResults testResults; - ScopedCurrentTest scopedResults(testResults); - - try - { + TEST(RequiredCheckCloseDoesNotHaveSideEffectsWhenFailing) + { + g_sideEffect = 0; + { + UnitTest::TestResults testResults; + ScopedCurrentTest scopedResults(testResults); + + try + { REQUIRE CHECK_CLOSE(2, FunctionWithSideEffects(), 0.1f); - } - catch (const UnitTest::AssertException&) - { - } - } - CHECK_EQUAL(1, g_sideEffect); -} + } + catch (const UnitTest::AssertException&) + {} + } + CHECK_EQUAL(1, g_sideEffect); + } -TEST(RequiredCheckArrayCloseSucceedsOnEqual) -{ - bool failure = true; - bool exception = false; - { - RecordingReporter reporter; - UnitTest::TestResults testResults(&reporter); - ScopedCurrentTest scopedResults(testResults); - const float data[4] = { 0, 1, 2, 3 }; - - try - { + TEST(RequiredCheckArrayCloseSucceedsOnEqual) + { + bool failure = true; + bool exception = false; + { + RecordingReporter reporter; + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + const float data[4] = { 0, 1, 2, 3 }; + + try + { REQUIRE CHECK_ARRAY_CLOSE (data, data, 4, 0.01f); - } - catch (const UnitTest::AssertException&) - { + } + catch (const UnitTest::AssertException&) + { exception = true; - } - - failure = (testResults.GetFailureCount() > 0); - } + } - CHECK(!failure); - CHECK(!exception); -} + failure = (testResults.GetFailureCount() > 0); + } -TEST(RequiredCheckArrayCloseFailsOnNotEqual) -{ - bool failure = false; - bool exception = false; - { - RecordingReporter reporter; - UnitTest::TestResults testResults(&reporter); - ScopedCurrentTest scopedResults(testResults); + CHECK(!failure); + CHECK(!exception); + } - int const data1[4] = { 0, 1, 2, 3 }; - int const data2[4] = { 0, 1, 3, 3 }; - - try - { + TEST(RequiredCheckArrayCloseFailsOnNotEqual) + { + bool failure = false; + bool exception = false; + { + RecordingReporter reporter; + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + int const data1[4] = { 0, 1, 2, 3 }; + int const data2[4] = { 0, 1, 3, 3 }; + + try + { REQUIRE CHECK_ARRAY_CLOSE (data1, data2, 4, 0.01f); - } - catch (const UnitTest::AssertException&) - { + } + catch (const UnitTest::AssertException&) + { exception = true; - } + } - failure = (testResults.GetFailureCount() > 0); - } + failure = (testResults.GetFailureCount() > 0); + } - CHECK(failure); - CHECK(exception); -} + CHECK(failure); + CHECK(exception); + } -TEST(RequiredCheckArrayCloseFailureIncludesCheckExpectedAndActual) -{ - RecordingReporter reporter; - { - UnitTest::TestResults testResults(&reporter); - ScopedCurrentTest scopedResults(testResults); + TEST(RequiredCheckArrayCloseFailureIncludesCheckExpectedAndActual) + { + RecordingReporter reporter; + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); - int const data1[4] = { 0, 1, 2, 3 }; - int const data2[4] = { 0, 1, 3, 3 }; - - try - { + int const data1[4] = { 0, 1, 2, 3 }; + int const data2[4] = { 0, 1, 3, 3 }; + + try + { REQUIRE CHECK_ARRAY_CLOSE(data1, data2, 4, 0.01f); - } - catch (const UnitTest::AssertException&) - { - } - } + } + catch (const UnitTest::AssertException&) + {} + } - CHECK(strstr(reporter.lastFailedMessage, "xpected [ 0 1 2 3 ]")); - CHECK(strstr(reporter.lastFailedMessage, "was [ 0 1 3 3 ]")); -} + CHECK(strstr(reporter.lastFailedMessage, "xpected [ 0 1 2 3 ]")); + CHECK(strstr(reporter.lastFailedMessage, "was [ 0 1 3 3 ]")); + } -TEST(RequiredCheckArrayCloseFailureContainsCorrectDetails) -{ - int line = 0; - RecordingReporter reporter; - { - UnitTest::TestResults testResults(&reporter); - UnitTest::TestDetails testDetails("arrayCloseTest", "arrayCloseSuite", "filename", -1); - ScopedCurrentTest scopedResults(testResults, &testDetails); + TEST(RequiredCheckArrayCloseFailureContainsCorrectDetails) + { + int line = 0; + RecordingReporter reporter; + { + UnitTest::TestResults testResults(&reporter); + UnitTest::TestDetails testDetails("arrayCloseTest", "arrayCloseSuite", "filename", -1); + ScopedCurrentTest scopedResults(testResults, &testDetails); - int const data1[4] = { 0, 1, 2, 3 }; - int const data2[4] = { 0, 1, 3, 3 }; - - try - { + int const data1[4] = { 0, 1, 2, 3 }; + int const data2[4] = { 0, 1, 3, 3 }; + + try + { line = __LINE__; REQUIRE CHECK_ARRAY_CLOSE (data1, data2, 4, 0.01f); - } - catch (const UnitTest::AssertException&) - { - } - } + } + catch (const UnitTest::AssertException&) + {} + } - CHECK_EQUAL("arrayCloseTest", reporter.lastFailedTest); - CHECK_EQUAL("arrayCloseSuite", reporter.lastFailedSuite); - CHECK_EQUAL("filename", reporter.lastFailedFile); - CHECK_EQUAL(line, reporter.lastFailedLine); -} + CHECK_EQUAL("arrayCloseTest", reporter.lastFailedTest); + CHECK_EQUAL("arrayCloseSuite", reporter.lastFailedSuite); + CHECK_EQUAL("filename", reporter.lastFailedFile); + CHECK_EQUAL(line, reporter.lastFailedLine); + } -TEST(RequiredCheckArrayCloseFailureIncludesTolerance) -{ - RecordingReporter reporter; - { - UnitTest::TestResults testResults(&reporter); - ScopedCurrentTest scopedResults(testResults); + TEST(RequiredCheckArrayCloseFailureIncludesTolerance) + { + RecordingReporter reporter; + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); - float const data1[4] = { 0, 1, 2, 3 }; - float const data2[4] = { 0, 1, 3, 3 }; - - try - { + float const data1[4] = { 0, 1, 2, 3 }; + float const data2[4] = { 0, 1, 3, 3 }; + + try + { REQUIRE CHECK_ARRAY_CLOSE (data1, data2, 4, 0.01f); - } - catch (const UnitTest::AssertException&) - { - } - } + } + catch (const UnitTest::AssertException&) + {} + } - CHECK(strstr(reporter.lastFailedMessage, "0.01")); -} + CHECK(strstr(reporter.lastFailedMessage, "0.01")); + } -TEST(RequiredCheckArrayEqualSuceedsOnEqual) -{ - bool failure = true; - bool exception = false; - { - RecordingReporter reporter; - UnitTest::TestResults testResults(&reporter); - ScopedCurrentTest scopedResults(testResults); + TEST(RequiredCheckArrayEqualSuceedsOnEqual) + { + bool failure = true; + bool exception = false; + { + RecordingReporter reporter; + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); - const float data[4] = { 0, 1, 2, 3 }; - - try - { + const float data[4] = { 0, 1, 2, 3 }; + + try + { REQUIRE CHECK_ARRAY_EQUAL (data, data, 4); - } - catch (const UnitTest::AssertException&) - { + } + catch (const UnitTest::AssertException&) + { exception = true; - } - - failure = (testResults.GetFailureCount() > 0); - } + } - CHECK(!failure); - CHECK(!exception); -} + failure = (testResults.GetFailureCount() > 0); + } -TEST(RequiredCheckArrayEqualFailsOnNotEqual) -{ - bool failure = false; - bool exception = false; - { - RecordingReporter reporter; - UnitTest::TestResults testResults(&reporter); - ScopedCurrentTest scopedResults(testResults); + CHECK(!failure); + CHECK(!exception); + } - int const data1[4] = { 0, 1, 2, 3 }; - int const data2[4] = { 0, 1, 3, 3 }; - - try - { + TEST(RequiredCheckArrayEqualFailsOnNotEqual) + { + bool failure = false; + bool exception = false; + { + RecordingReporter reporter; + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + int const data1[4] = { 0, 1, 2, 3 }; + int const data2[4] = { 0, 1, 3, 3 }; + + try + { REQUIRE CHECK_ARRAY_EQUAL (data1, data2, 4); - } - catch (const UnitTest::AssertException&) - { + } + catch (const UnitTest::AssertException&) + { exception = true; - } - - failure = (testResults.GetFailureCount() > 0); - } + } - CHECK(failure); - CHECK(exception); -} + failure = (testResults.GetFailureCount() > 0); + } -TEST(RequiredCheckArrayEqualFailureIncludesCheckExpectedAndActual) -{ - RecordingReporter reporter; - { - UnitTest::TestResults testResults(&reporter); - ScopedCurrentTest scopedResults(testResults); + CHECK(failure); + CHECK(exception); + } - int const data1[4] = { 0, 1, 2, 3 }; - int const data2[4] = { 0, 1, 3, 3 }; - - try - { + TEST(RequiredCheckArrayEqualFailureIncludesCheckExpectedAndActual) + { + RecordingReporter reporter; + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + int const data1[4] = { 0, 1, 2, 3 }; + int const data2[4] = { 0, 1, 3, 3 }; + + try + { REQUIRE CHECK_ARRAY_EQUAL (data1, data2, 4); - } - catch (const UnitTest::AssertException&) - { - } - } + } + catch (const UnitTest::AssertException&) + {} + } - CHECK(strstr(reporter.lastFailedMessage, "xpected [ 0 1 2 3 ]")); - CHECK(strstr(reporter.lastFailedMessage, "was [ 0 1 3 3 ]")); -} + CHECK(strstr(reporter.lastFailedMessage, "xpected [ 0 1 2 3 ]")); + CHECK(strstr(reporter.lastFailedMessage, "was [ 0 1 3 3 ]")); + } -TEST(RequiredCheckArrayEqualFailureContainsCorrectInfo) -{ - int line = 0; - RecordingReporter reporter; - { - UnitTest::TestResults testResults(&reporter); - ScopedCurrentTest scopedResults(testResults); + TEST(RequiredCheckArrayEqualFailureContainsCorrectInfo) + { + int line = 0; + RecordingReporter reporter; + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); - int const data1[4] = { 0, 1, 2, 3 }; - int const data2[4] = { 0, 1, 3, 3 }; - - try - { + int const data1[4] = { 0, 1, 2, 3 }; + int const data2[4] = { 0, 1, 3, 3 }; + + try + { line = __LINE__; REQUIRE CHECK_ARRAY_EQUAL (data1, data2, 4); - } - catch (const UnitTest::AssertException&) - { - } - } + } + catch (const UnitTest::AssertException&) + {} + } - CHECK_EQUAL("RequiredCheckArrayEqualFailureContainsCorrectInfo", reporter.lastFailedTest); - CHECK_EQUAL(__FILE__, reporter.lastFailedFile); - CHECK_EQUAL(line, reporter.lastFailedLine); -} + CHECK_EQUAL("RequiredCheckArrayEqualFailureContainsCorrectInfo", reporter.lastFailedTest); + CHECK_EQUAL(__FILE__, reporter.lastFailedFile); + CHECK_EQUAL(line, reporter.lastFailedLine); + } -float const* FunctionWithSideEffects2() -{ - ++g_sideEffect; - static float const data[] = {1,2,3,4}; - return data; -} + float const* FunctionWithSideEffects2() + { + ++g_sideEffect; + static float const data[] = {1,2,3,4}; + return data; + } -TEST(RequiredCheckArrayCloseDoesNotHaveSideEffectsWhenPassing) -{ - g_sideEffect = 0; - { - UnitTest::TestResults testResults; - ScopedCurrentTest scopedResults(testResults); + TEST(RequiredCheckArrayCloseDoesNotHaveSideEffectsWhenPassing) + { + g_sideEffect = 0; + { + UnitTest::TestResults testResults; + ScopedCurrentTest scopedResults(testResults); - const float data[] = { 0, 1, 2, 3 }; - - try - { + const float data[] = { 0, 1, 2, 3 }; + + try + { REQUIRE CHECK_ARRAY_CLOSE (data, FunctionWithSideEffects2(), 4, 0.01f); - } - catch (const UnitTest::AssertException&) - { - } - } - CHECK_EQUAL(1, g_sideEffect); -} + } + catch (const UnitTest::AssertException&) + {} + } + CHECK_EQUAL(1, g_sideEffect); + } -TEST(RequiredCheckArrayCloseDoesNotHaveSideEffectsWhenFailing) -{ - g_sideEffect = 0; - { - UnitTest::TestResults testResults; - ScopedCurrentTest scopedResults(testResults); + TEST(RequiredCheckArrayCloseDoesNotHaveSideEffectsWhenFailing) + { + g_sideEffect = 0; + { + UnitTest::TestResults testResults; + ScopedCurrentTest scopedResults(testResults); - const float data[] = { 0, 1, 3, 3 }; - - try - { + const float data[] = { 0, 1, 3, 3 }; + + try + { REQUIRE CHECK_ARRAY_CLOSE (data, FunctionWithSideEffects2(), 4, 0.01f); - } - catch (const UnitTest::AssertException&) - { - } - } + } + catch (const UnitTest::AssertException&) + {} + } - CHECK_EQUAL(1, g_sideEffect); -} + CHECK_EQUAL(1, g_sideEffect); + } -TEST(RequiredCheckArray2DCloseSucceedsOnEqual) -{ - bool failure = true; - bool exception = false; - { - RecordingReporter reporter; - UnitTest::TestResults testResults(&reporter); - ScopedCurrentTest scopedResults(testResults); + TEST(RequiredCheckArray2DCloseSucceedsOnEqual) + { + bool failure = true; + bool exception = false; + { + RecordingReporter reporter; + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); - const float data[2][2] = { {0, 1}, {2, 3} }; - - try - { + const float data[2][2] = { {0, 1}, {2, 3} }; + + try + { REQUIRE CHECK_ARRAY2D_CLOSE(data, data, 2, 2, 0.01f); - } - catch (const UnitTest::AssertException&) - { + } + catch (const UnitTest::AssertException&) + { exception = true; - } - - failure = (testResults.GetFailureCount() > 0); - } + } - CHECK(!failure); - CHECK(!exception); -} + failure = (testResults.GetFailureCount() > 0); + } -TEST(RequiredCheckArray2DCloseFailsOnNotEqual) -{ - bool failure = false; - bool exception = false; - { - RecordingReporter reporter; - UnitTest::TestResults testResults(&reporter); - ScopedCurrentTest scopedResults(testResults); + CHECK(!failure); + CHECK(!exception); + } - int const data1[2][2] = { {0, 1}, {2, 3} }; - int const data2[2][2] = { {0, 1}, {3, 3} }; - - try - { + TEST(RequiredCheckArray2DCloseFailsOnNotEqual) + { + bool failure = false; + bool exception = false; + { + RecordingReporter reporter; + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + int const data1[2][2] = { {0, 1}, {2, 3} }; + int const data2[2][2] = { {0, 1}, {3, 3} }; + + try + { REQUIRE CHECK_ARRAY2D_CLOSE (data1, data2, 2, 2, 0.01f); - } - catch (const UnitTest::AssertException&) - { + } + catch (const UnitTest::AssertException&) + { exception = true; - } + } - failure = (testResults.GetFailureCount() > 0); - } + failure = (testResults.GetFailureCount() > 0); + } - CHECK(failure); - CHECK(exception); -} + CHECK(failure); + CHECK(exception); + } -TEST(RequiredCheckArray2DCloseFailureIncludesCheckExpectedAndActual) -{ - RecordingReporter reporter; - { - UnitTest::TestResults testResults(&reporter); - ScopedCurrentTest scopedResults(testResults); + TEST(RequiredCheckArray2DCloseFailureIncludesCheckExpectedAndActual) + { + RecordingReporter reporter; + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); - int const data1[2][2] = { {0, 1}, {2, 3} }; - int const data2[2][2] = { {0, 1}, {3, 3} }; + int const data1[2][2] = { {0, 1}, {2, 3} }; + int const data2[2][2] = { {0, 1}, {3, 3} }; - try - { + try + { REQUIRE CHECK_ARRAY2D_CLOSE (data1, data2, 2, 2, 0.01f); - } - catch (const UnitTest::AssertException&) - { - } - } + } + catch (const UnitTest::AssertException&) + {} + } - CHECK(strstr(reporter.lastFailedMessage, "xpected [ [ 0 1 ] [ 2 3 ] ]")); - CHECK(strstr(reporter.lastFailedMessage, "was [ [ 0 1 ] [ 3 3 ] ]")); -} + CHECK(strstr(reporter.lastFailedMessage, "xpected [ [ 0 1 ] [ 2 3 ] ]")); + CHECK(strstr(reporter.lastFailedMessage, "was [ [ 0 1 ] [ 3 3 ] ]")); + } -TEST(RequiredCheckArray2DCloseFailureContainsCorrectDetails) -{ - int line = 0; - RecordingReporter reporter; - { - UnitTest::TestResults testResults(&reporter); - UnitTest::TestDetails testDetails("array2DCloseTest", "array2DCloseSuite", "filename", -1); - ScopedCurrentTest scopedResults(testResults, &testDetails); + TEST(RequiredCheckArray2DCloseFailureContainsCorrectDetails) + { + int line = 0; + RecordingReporter reporter; + { + UnitTest::TestResults testResults(&reporter); + UnitTest::TestDetails testDetails("array2DCloseTest", "array2DCloseSuite", "filename", -1); + ScopedCurrentTest scopedResults(testResults, &testDetails); - int const data1[2][2] = { {0, 1}, {2, 3} }; - int const data2[2][2] = { {0, 1}, {3, 3} }; - - try - { + int const data1[2][2] = { {0, 1}, {2, 3} }; + int const data2[2][2] = { {0, 1}, {3, 3} }; + + try + { line = __LINE__; REQUIRE CHECK_ARRAY2D_CLOSE (data1, data2, 2, 2, 0.01f); - } - catch (const UnitTest::AssertException&) - { - } - } + } + catch (const UnitTest::AssertException&) + {} + } - CHECK_EQUAL("array2DCloseTest", reporter.lastFailedTest); - CHECK_EQUAL("array2DCloseSuite", reporter.lastFailedSuite); - CHECK_EQUAL("filename", reporter.lastFailedFile); - CHECK_EQUAL(line, reporter.lastFailedLine); -} + CHECK_EQUAL("array2DCloseTest", reporter.lastFailedTest); + CHECK_EQUAL("array2DCloseSuite", reporter.lastFailedSuite); + CHECK_EQUAL("filename", reporter.lastFailedFile); + CHECK_EQUAL(line, reporter.lastFailedLine); + } -TEST(RequiredCheckArray2DCloseFailureIncludesTolerance) -{ - RecordingReporter reporter; - { - UnitTest::TestResults testResults(&reporter); - ScopedCurrentTest scopedResults(testResults); + TEST(RequiredCheckArray2DCloseFailureIncludesTolerance) + { + RecordingReporter reporter; + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); - float const data1[2][2] = { {0, 1}, {2, 3} }; - float const data2[2][2] = { {0, 1}, {3, 3} }; - - try - { + float const data1[2][2] = { {0, 1}, {2, 3} }; + float const data2[2][2] = { {0, 1}, {3, 3} }; + + try + { REQUIRE CHECK_ARRAY2D_CLOSE (data1, data2, 2, 2, 0.01f); - } - catch (const UnitTest::AssertException&) - { - } - } + } + catch (const UnitTest::AssertException&) + {} + } - CHECK(strstr(reporter.lastFailedMessage, "0.01")); -} + CHECK(strstr(reporter.lastFailedMessage, "0.01")); + } -float const* const* FunctionWithSideEffects3() -{ - ++g_sideEffect; - static float const data1[] = {0,1}; - static float const data2[] = {2,3}; - static const float* const data[] = {data1, data2}; - return data; -} + float const* const* FunctionWithSideEffects3() + { + ++g_sideEffect; + static float const data1[] = {0,1}; + static float const data2[] = {2,3}; + static const float* const data[] = {data1, data2}; + return data; + } -TEST(RequiredCheckArray2DCloseDoesNotHaveSideEffectsWhenPassing) -{ - g_sideEffect = 0; - { - UnitTest::TestResults testResults; - ScopedCurrentTest scopedResults(testResults); + TEST(RequiredCheckArray2DCloseDoesNotHaveSideEffectsWhenPassing) + { + g_sideEffect = 0; + { + UnitTest::TestResults testResults; + ScopedCurrentTest scopedResults(testResults); - const float data[2][2] = { {0, 1}, {2, 3} }; - - try - { + const float data[2][2] = { {0, 1}, {2, 3} }; + + try + { REQUIRE CHECK_ARRAY2D_CLOSE (data, FunctionWithSideEffects3(), 2, 2, 0.01f); - } - catch (const UnitTest::AssertException&) - { - } - } - CHECK_EQUAL(1, g_sideEffect); -} + } + catch (const UnitTest::AssertException&) + {} + } + CHECK_EQUAL(1, g_sideEffect); + } -TEST(RequiredCheckArray2DCloseDoesNotHaveSideEffectsWhenFailing) -{ - g_sideEffect = 0; - { - UnitTest::TestResults testResults; - ScopedCurrentTest scopedResults(testResults); + TEST(RequiredCheckArray2DCloseDoesNotHaveSideEffectsWhenFailing) + { + g_sideEffect = 0; + { + UnitTest::TestResults testResults; + ScopedCurrentTest scopedResults(testResults); - const float data[2][2] = { {0, 1}, {3, 3} }; - - try - { + const float data[2][2] = { {0, 1}, {3, 3} }; + + try + { REQUIRE CHECK_ARRAY2D_CLOSE (data, FunctionWithSideEffects3(), 2, 2, 0.01f); - } - catch (const UnitTest::AssertException&) - { - } - } - CHECK_EQUAL(1, g_sideEffect); -} + } + catch (const UnitTest::AssertException&) + {} + } + CHECK_EQUAL(1, g_sideEffect); + } } From 40b8f0b17b0a9db2af01529e8e9a6db56830a471 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Thu, 4 Feb 2016 22:33:37 -0600 Subject: [PATCH 06/79] Use new RequiredCheckException for REQUIRE Rather than re-using AssertException, it felt more correct to create a new special-purpose exception. --- UnitTest++/CheckMacros.h | 13 ++--- UnitTest++/RequiredCheckException.cpp | 17 +++++++ UnitTest++/RequiredCheckException.h | 23 +++++++++ UnitTest++/ThrowingTestReporter.cpp | 4 +- tests/TestRequireMacros.cpp | 70 +++++++++++++-------------- 5 files changed, 84 insertions(+), 43 deletions(-) create mode 100644 UnitTest++/RequiredCheckException.cpp create mode 100644 UnitTest++/RequiredCheckException.h diff --git a/UnitTest++/CheckMacros.h b/UnitTest++/CheckMacros.h index 82a4042..9547c32 100644 --- a/UnitTest++/CheckMacros.h +++ b/UnitTest++/CheckMacros.h @@ -5,6 +5,7 @@ #include "ExceptionMacros.h" #include "Checks.h" #include "AssertException.h" +#include "RequiredCheckException.h" #include "MemoryOutStream.h" #include "TestDetails.h" #include "CurrentTest.h" @@ -41,7 +42,7 @@ if (!UnitTest::Check(value)) \ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), #value); \ }) \ - UT_CATCH (UnitTest::AssertException, , \ + UT_CATCH (UnitTest::RequiredCheckException, , \ { \ UT_THROW(); \ }) \ @@ -65,7 +66,7 @@ ({ \ UnitTest::CheckEqual(*UnitTest::CurrentTest::Results(), expected, actual, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ }) \ - UT_CATCH (UnitTest::AssertException, , \ + UT_CATCH (UnitTest::RequiredCheckException, , \ { \ UT_THROW(); \ }) \ @@ -89,7 +90,7 @@ ({ \ UnitTest::CheckClose(*UnitTest::CurrentTest::Results(), expected, actual, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ }) \ - UT_CATCH (UnitTest::AssertException, , \ + UT_CATCH (UnitTest::RequiredCheckException, , \ { \ UT_THROW(); \ }) \ @@ -113,7 +114,7 @@ ({ \ UnitTest::CheckArrayEqual(*UnitTest::CurrentTest::Results(), expected, actual, count, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ }) \ - UT_CATCH (UnitTest::AssertException, , \ + UT_CATCH (UnitTest::RequiredCheckException, , \ { \ UT_THROW(); \ }) \ @@ -137,7 +138,7 @@ ({ \ UnitTest::CheckArrayClose(*UnitTest::CurrentTest::Results(), expected, actual, count, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ }) \ - UT_CATCH (UnitTest::AssertException, , \ + UT_CATCH (UnitTest::RequiredCheckException, , \ { \ UT_THROW(); \ }) \ @@ -161,7 +162,7 @@ ({ \ UnitTest::CheckArray2DClose(*UnitTest::CurrentTest::Results(), expected, actual, rows, columns, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ }) \ - UT_CATCH (UnitTest::AssertException, , \ + UT_CATCH (UnitTest::RequiredCheckException, , \ { \ UT_THROW(); \ }) \ diff --git a/UnitTest++/RequiredCheckException.cpp b/UnitTest++/RequiredCheckException.cpp new file mode 100644 index 0000000..874370e --- /dev/null +++ b/UnitTest++/RequiredCheckException.cpp @@ -0,0 +1,17 @@ +#include "RequiredCheckException.h" + +#ifndef UNITTEST_NO_EXCEPTIONS + +namespace UnitTest { + + RequiredCheckException::RequiredCheckException() + { + } + + RequiredCheckException::~RequiredCheckException() throw() + { + } + +} + +#endif diff --git a/UnitTest++/RequiredCheckException.h b/UnitTest++/RequiredCheckException.h new file mode 100644 index 0000000..c9a36da --- /dev/null +++ b/UnitTest++/RequiredCheckException.h @@ -0,0 +1,23 @@ +#ifndef UNITTEST_REQUIREDCHECKEXCEPTION_H +#define UNITTEST_REQUIREDCHECKEXCEPTION_H + +#include "Config.h" +#ifndef UNITTEST_NO_EXCEPTIONS + +#include "HelperMacros.h" +#include + +namespace UnitTest { + + class UNITTEST_LINKAGE RequiredCheckException : public std::exception + { + public: + RequiredCheckException(); + virtual ~RequiredCheckException() throw(); + }; + +} + +#endif + +#endif diff --git a/UnitTest++/ThrowingTestReporter.cpp b/UnitTest++/ThrowingTestReporter.cpp index 367a8b3..f48e308 100644 --- a/UnitTest++/ThrowingTestReporter.cpp +++ b/UnitTest++/ThrowingTestReporter.cpp @@ -1,5 +1,5 @@ #include "ThrowingTestReporter.h" -#include "AssertException.h" +#include "RequiredCheckException.h" namespace UnitTest { @@ -21,7 +21,7 @@ namespace UnitTest { void ThrowingTestReporter::ReportFailure(TestDetails const& test, char const* failure) { if(m_decoratedReporter) m_decoratedReporter->ReportFailure(test, failure); - throw AssertException(); + throw RequiredCheckException(); } //virtual diff --git a/tests/TestRequireMacros.cpp b/tests/TestRequireMacros.cpp index 88cb128..6b76004 100644 --- a/tests/TestRequireMacros.cpp +++ b/tests/TestRequireMacros.cpp @@ -23,7 +23,7 @@ namespace { { REQUIRE CHECK(true); } - catch(const UnitTest::AssertException&) + catch(const UnitTest::RequiredCheckException&) { exception = true; } @@ -48,7 +48,7 @@ namespace { { REQUIRE CHECK(false); } - catch (const UnitTest::AssertException&) + catch (const UnitTest::RequiredCheckException&) { exception = true; } @@ -77,7 +77,7 @@ namespace { CHECK_EQUAL(1,1); } } - catch (const UnitTest::AssertException&) + catch (const UnitTest::RequiredCheckException&) { exception = true; } @@ -106,7 +106,7 @@ namespace { CHECK_EQUAL(1,2); } } - catch (const UnitTest::AssertException&) + catch (const UnitTest::RequiredCheckException&) { exception = true; } @@ -135,7 +135,7 @@ namespace { run = true; // this shouldn't get executed. } } - catch (const UnitTest::AssertException&) + catch (const UnitTest::RequiredCheckException&) { exception = true; } @@ -159,7 +159,7 @@ namespace { { REQUIRE CHECK(false); } - catch (const UnitTest::AssertException&) + catch (const UnitTest::RequiredCheckException&) {} } @@ -178,7 +178,7 @@ namespace { { REQUIRE CHECK(yaddayadda); } - catch (const UnitTest::AssertException&) + catch (const UnitTest::RequiredCheckException&) {} } @@ -198,7 +198,7 @@ namespace { { REQUIRE CHECK_EQUAL(1,1); } - catch (const UnitTest::AssertException&) + catch (const UnitTest::RequiredCheckException&) { exception = true; } @@ -223,7 +223,7 @@ namespace { { REQUIRE CHECK_EQUAL(1, 2); } - catch (const UnitTest::AssertException&) + catch (const UnitTest::RequiredCheckException&) { exception = true; } @@ -248,7 +248,7 @@ namespace { { line = __LINE__; REQUIRE CHECK_EQUAL(1, 123); } - catch (const UnitTest::AssertException&) + catch (const UnitTest::RequiredCheckException&) {} } @@ -276,7 +276,7 @@ namespace { { REQUIRE CHECK_EQUAL(1, FunctionWithSideEffects()); } - catch (const UnitTest::AssertException&) + catch (const UnitTest::RequiredCheckException&) {} } CHECK_EQUAL(1, g_sideEffect); @@ -293,7 +293,7 @@ namespace { { REQUIRE CHECK_EQUAL(2, FunctionWithSideEffects()); } - catch (const UnitTest::AssertException&) + catch (const UnitTest::RequiredCheckException&) {} } CHECK_EQUAL(1, g_sideEffect); @@ -313,7 +313,7 @@ namespace { { REQUIRE CHECK_CLOSE(1.0f, 1.001f, 0.01f); } - catch (const UnitTest::AssertException&) + catch (const UnitTest::RequiredCheckException&) { exception = true; } @@ -338,7 +338,7 @@ namespace { { REQUIRE CHECK_CLOSE (1.0f, 1.1f, 0.01f); } - catch (const UnitTest::AssertException&) + catch (const UnitTest::RequiredCheckException&) { exception = true; } @@ -364,7 +364,7 @@ namespace { line = __LINE__; REQUIRE CHECK_CLOSE(1.0f, 1.1f, 0.01f); CHECK(false); } - catch (const UnitTest::AssertException&) + catch (const UnitTest::RequiredCheckException&) {} } @@ -385,7 +385,7 @@ namespace { { REQUIRE CHECK_CLOSE (1, FunctionWithSideEffects(), 0.1f); } - catch (const UnitTest::AssertException&) + catch (const UnitTest::RequiredCheckException&) {} } CHECK_EQUAL(1, g_sideEffect); @@ -402,7 +402,7 @@ namespace { { REQUIRE CHECK_CLOSE(2, FunctionWithSideEffects(), 0.1f); } - catch (const UnitTest::AssertException&) + catch (const UnitTest::RequiredCheckException&) {} } CHECK_EQUAL(1, g_sideEffect); @@ -422,7 +422,7 @@ namespace { { REQUIRE CHECK_ARRAY_CLOSE (data, data, 4, 0.01f); } - catch (const UnitTest::AssertException&) + catch (const UnitTest::RequiredCheckException&) { exception = true; } @@ -450,7 +450,7 @@ namespace { { REQUIRE CHECK_ARRAY_CLOSE (data1, data2, 4, 0.01f); } - catch (const UnitTest::AssertException&) + catch (const UnitTest::RequiredCheckException&) { exception = true; } @@ -476,7 +476,7 @@ namespace { { REQUIRE CHECK_ARRAY_CLOSE(data1, data2, 4, 0.01f); } - catch (const UnitTest::AssertException&) + catch (const UnitTest::RequiredCheckException&) {} } @@ -500,7 +500,7 @@ namespace { { line = __LINE__; REQUIRE CHECK_ARRAY_CLOSE (data1, data2, 4, 0.01f); } - catch (const UnitTest::AssertException&) + catch (const UnitTest::RequiredCheckException&) {} } @@ -524,7 +524,7 @@ namespace { { REQUIRE CHECK_ARRAY_CLOSE (data1, data2, 4, 0.01f); } - catch (const UnitTest::AssertException&) + catch (const UnitTest::RequiredCheckException&) {} } @@ -546,7 +546,7 @@ namespace { { REQUIRE CHECK_ARRAY_EQUAL (data, data, 4); } - catch (const UnitTest::AssertException&) + catch (const UnitTest::RequiredCheckException&) { exception = true; } @@ -574,7 +574,7 @@ namespace { { REQUIRE CHECK_ARRAY_EQUAL (data1, data2, 4); } - catch (const UnitTest::AssertException&) + catch (const UnitTest::RequiredCheckException&) { exception = true; } @@ -600,7 +600,7 @@ namespace { { REQUIRE CHECK_ARRAY_EQUAL (data1, data2, 4); } - catch (const UnitTest::AssertException&) + catch (const UnitTest::RequiredCheckException&) {} } @@ -623,7 +623,7 @@ namespace { { line = __LINE__; REQUIRE CHECK_ARRAY_EQUAL (data1, data2, 4); } - catch (const UnitTest::AssertException&) + catch (const UnitTest::RequiredCheckException&) {} } @@ -652,7 +652,7 @@ namespace { { REQUIRE CHECK_ARRAY_CLOSE (data, FunctionWithSideEffects2(), 4, 0.01f); } - catch (const UnitTest::AssertException&) + catch (const UnitTest::RequiredCheckException&) {} } CHECK_EQUAL(1, g_sideEffect); @@ -671,7 +671,7 @@ namespace { { REQUIRE CHECK_ARRAY_CLOSE (data, FunctionWithSideEffects2(), 4, 0.01f); } - catch (const UnitTest::AssertException&) + catch (const UnitTest::RequiredCheckException&) {} } @@ -693,7 +693,7 @@ namespace { { REQUIRE CHECK_ARRAY2D_CLOSE(data, data, 2, 2, 0.01f); } - catch (const UnitTest::AssertException&) + catch (const UnitTest::RequiredCheckException&) { exception = true; } @@ -721,7 +721,7 @@ namespace { { REQUIRE CHECK_ARRAY2D_CLOSE (data1, data2, 2, 2, 0.01f); } - catch (const UnitTest::AssertException&) + catch (const UnitTest::RequiredCheckException&) { exception = true; } @@ -747,7 +747,7 @@ namespace { { REQUIRE CHECK_ARRAY2D_CLOSE (data1, data2, 2, 2, 0.01f); } - catch (const UnitTest::AssertException&) + catch (const UnitTest::RequiredCheckException&) {} } @@ -771,7 +771,7 @@ namespace { { line = __LINE__; REQUIRE CHECK_ARRAY2D_CLOSE (data1, data2, 2, 2, 0.01f); } - catch (const UnitTest::AssertException&) + catch (const UnitTest::RequiredCheckException&) {} } @@ -795,7 +795,7 @@ namespace { { REQUIRE CHECK_ARRAY2D_CLOSE (data1, data2, 2, 2, 0.01f); } - catch (const UnitTest::AssertException&) + catch (const UnitTest::RequiredCheckException&) {} } @@ -824,7 +824,7 @@ namespace { { REQUIRE CHECK_ARRAY2D_CLOSE (data, FunctionWithSideEffects3(), 2, 2, 0.01f); } - catch (const UnitTest::AssertException&) + catch (const UnitTest::RequiredCheckException&) {} } CHECK_EQUAL(1, g_sideEffect); @@ -843,7 +843,7 @@ namespace { { REQUIRE CHECK_ARRAY2D_CLOSE (data, FunctionWithSideEffects3(), 2, 2, 0.01f); } - catch (const UnitTest::AssertException&) + catch (const UnitTest::RequiredCheckException&) {} } CHECK_EQUAL(1, g_sideEffect); From 57fc32c1143a5e94da910ed6b6b345d2d278a3b1 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Thu, 4 Feb 2016 22:45:36 -0600 Subject: [PATCH 07/79] Change camelCase methods to PascalCase --- UnitTest++/RequireMacros.h | 4 ++-- UnitTest++/RequiredCheckTestReporter.cpp | 6 +++--- UnitTest++/RequiredCheckTestReporter.h | 2 +- UnitTest++/TestResults.h | 1 - UnitTest++/ThrowingTestReporter.cpp | 4 ++-- UnitTest++/ThrowingTestReporter.h | 4 ++-- 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/UnitTest++/RequireMacros.h b/UnitTest++/RequireMacros.h index 4a107d4..f20353a 100644 --- a/UnitTest++/RequireMacros.h +++ b/UnitTest++/RequireMacros.h @@ -8,11 +8,11 @@ #endif #ifndef UNITTEST_NO_EXCEPTIONS -#define REQUIRE for(UnitTest::RequiredCheckTestReporter decoratedReporter(UnitTest::CurrentTest::Results()); decoratedReporter.next(); ) + #define REQUIRE for(UnitTest::RequiredCheckTestReporter decoratedReporter(UnitTest::CurrentTest::Results()); decoratedReporter.Next(); ) #endif #ifdef UNITTEST_NO_EXCEPTIONS -#define REQUIRE + #define REQUIRE #endif #endif \ No newline at end of file diff --git a/UnitTest++/RequiredCheckTestReporter.cpp b/UnitTest++/RequiredCheckTestReporter.cpp index 1fd2ec7..689827a 100644 --- a/UnitTest++/RequiredCheckTestReporter.cpp +++ b/UnitTest++/RequiredCheckTestReporter.cpp @@ -12,17 +12,17 @@ namespace UnitTest { { if(m_results) { - m_throwingReporter.setDecorated(m_results->m_testReporter); + m_throwingReporter.SetDecorated(m_results->m_testReporter); m_results->m_testReporter = &m_throwingReporter; } } RequiredCheckTestReporter::~RequiredCheckTestReporter() { - if(m_results) m_results->m_testReporter = m_throwingReporter.getDecorated(); + if(m_results) m_results->m_testReporter = m_throwingReporter.GetDecorated(); } - bool RequiredCheckTestReporter::next() + bool RequiredCheckTestReporter::Next() { return m_continue++ == 0; } diff --git a/UnitTest++/RequiredCheckTestReporter.h b/UnitTest++/RequiredCheckTestReporter.h index a8c635e..220ae9b 100644 --- a/UnitTest++/RequiredCheckTestReporter.h +++ b/UnitTest++/RequiredCheckTestReporter.h @@ -16,7 +16,7 @@ namespace UnitTest { explicit RequiredCheckTestReporter(TestResults* results); ~RequiredCheckTestReporter(); - bool next(); + bool Next(); private: TestResults* m_results; diff --git a/UnitTest++/TestResults.h b/UnitTest++/TestResults.h index b23418c..a4d8e60 100644 --- a/UnitTest++/TestResults.h +++ b/UnitTest++/TestResults.h @@ -25,7 +25,6 @@ namespace UnitTest { private: friend class RequiredCheckTestReporter; - private: TestReporter* m_testReporter; int m_totalTestCount; int m_failedTestCount; diff --git a/UnitTest++/ThrowingTestReporter.cpp b/UnitTest++/ThrowingTestReporter.cpp index f48e308..acdc38c 100644 --- a/UnitTest++/ThrowingTestReporter.cpp +++ b/UnitTest++/ThrowingTestReporter.cpp @@ -36,12 +36,12 @@ namespace UnitTest { if(m_decoratedReporter) m_decoratedReporter->ReportSummary(totalTestCount, failedTestCount, failureCount, secondsElapsed); } - TestReporter* ThrowingTestReporter::getDecorated() const + TestReporter* ThrowingTestReporter::GetDecorated() const { return m_decoratedReporter; } - void ThrowingTestReporter::setDecorated(TestReporter* reporter) + void ThrowingTestReporter::SetDecorated(TestReporter* reporter) { m_decoratedReporter = reporter; } diff --git a/UnitTest++/ThrowingTestReporter.h b/UnitTest++/ThrowingTestReporter.h index 8ed91da..15766b8 100644 --- a/UnitTest++/ThrowingTestReporter.h +++ b/UnitTest++/ThrowingTestReporter.h @@ -18,8 +18,8 @@ namespace UnitTest { virtual void ReportTestFinish(TestDetails const& test, float secondsElapsed); virtual void ReportSummary(int totalTestCount, int failedTestCount, int failureCount, float secondsElapsed); - TestReporter* getDecorated() const; - void setDecorated(TestReporter* reporter); + TestReporter* GetDecorated() const; + void SetDecorated(TestReporter* reporter); private: TestReporter* m_decoratedReporter; From 5eec0a255f366b58df25e7626a3a65fedfdeba41 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Thu, 4 Feb 2016 23:00:52 -0600 Subject: [PATCH 08/79] Simplify required check reporter interactions Was able to remove ThrowingTestReporter::SetDecorated and ::GetDecorated by changing RequiredCheckTestReporter to accept its TestResults by reference. This simple change removed several if-checks and some functions. --- UnitTest++/RequireMacros.h | 2 +- UnitTest++/RequiredCheckTestReporter.cpp | 13 +++++-------- UnitTest++/RequiredCheckTestReporter.h | 5 +++-- UnitTest++/ThrowingTestReporter.cpp | 10 ---------- UnitTest++/ThrowingTestReporter.h | 3 --- 5 files changed, 9 insertions(+), 24 deletions(-) diff --git a/UnitTest++/RequireMacros.h b/UnitTest++/RequireMacros.h index f20353a..ea1f6b9 100644 --- a/UnitTest++/RequireMacros.h +++ b/UnitTest++/RequireMacros.h @@ -8,7 +8,7 @@ #endif #ifndef UNITTEST_NO_EXCEPTIONS - #define REQUIRE for(UnitTest::RequiredCheckTestReporter decoratedReporter(UnitTest::CurrentTest::Results()); decoratedReporter.Next(); ) + #define REQUIRE for(UnitTest::RequiredCheckTestReporter decoratedReporter(*UnitTest::CurrentTest::Results()); decoratedReporter.Next(); ) #endif #ifdef UNITTEST_NO_EXCEPTIONS diff --git a/UnitTest++/RequiredCheckTestReporter.cpp b/UnitTest++/RequiredCheckTestReporter.cpp index 689827a..7c21d20 100644 --- a/UnitTest++/RequiredCheckTestReporter.cpp +++ b/UnitTest++/RequiredCheckTestReporter.cpp @@ -5,21 +5,18 @@ namespace UnitTest { - RequiredCheckTestReporter::RequiredCheckTestReporter(TestResults* results) + RequiredCheckTestReporter::RequiredCheckTestReporter(TestResults& results) : m_results(results) - , m_throwingReporter(0) + , m_originalTestReporter(results.m_testReporter) + , m_throwingReporter(results.m_testReporter) , m_continue(0) { - if(m_results) - { - m_throwingReporter.SetDecorated(m_results->m_testReporter); - m_results->m_testReporter = &m_throwingReporter; - } + m_results.m_testReporter = &m_throwingReporter; } RequiredCheckTestReporter::~RequiredCheckTestReporter() { - if(m_results) m_results->m_testReporter = m_throwingReporter.GetDecorated(); + m_results.m_testReporter = m_originalTestReporter; } bool RequiredCheckTestReporter::Next() diff --git a/UnitTest++/RequiredCheckTestReporter.h b/UnitTest++/RequiredCheckTestReporter.h index 220ae9b..117ae01 100644 --- a/UnitTest++/RequiredCheckTestReporter.h +++ b/UnitTest++/RequiredCheckTestReporter.h @@ -13,13 +13,14 @@ namespace UnitTest { class UNITTEST_LINKAGE RequiredCheckTestReporter { public: - explicit RequiredCheckTestReporter(TestResults* results); + explicit RequiredCheckTestReporter(TestResults& results); ~RequiredCheckTestReporter(); bool Next(); private: - TestResults* m_results; + TestResults& m_results; + TestReporter* m_originalTestReporter; ThrowingTestReporter m_throwingReporter; int m_continue; }; diff --git a/UnitTest++/ThrowingTestReporter.cpp b/UnitTest++/ThrowingTestReporter.cpp index acdc38c..7fb670b 100644 --- a/UnitTest++/ThrowingTestReporter.cpp +++ b/UnitTest++/ThrowingTestReporter.cpp @@ -36,14 +36,4 @@ namespace UnitTest { if(m_decoratedReporter) m_decoratedReporter->ReportSummary(totalTestCount, failedTestCount, failureCount, secondsElapsed); } - TestReporter* ThrowingTestReporter::GetDecorated() const - { - return m_decoratedReporter; - } - - void ThrowingTestReporter::SetDecorated(TestReporter* reporter) - { - m_decoratedReporter = reporter; - } - } diff --git a/UnitTest++/ThrowingTestReporter.h b/UnitTest++/ThrowingTestReporter.h index 15766b8..34e105e 100644 --- a/UnitTest++/ThrowingTestReporter.h +++ b/UnitTest++/ThrowingTestReporter.h @@ -18,9 +18,6 @@ namespace UnitTest { virtual void ReportTestFinish(TestDetails const& test, float secondsElapsed); virtual void ReportSummary(int totalTestCount, int failedTestCount, int failureCount, float secondsElapsed); - TestReporter* GetDecorated() const; - void SetDecorated(TestReporter* reporter); - private: TestReporter* m_decoratedReporter; }; From 3f5095ba13dda9aea740e6085fc8fe37b8ecf81a Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Thu, 4 Feb 2016 23:14:42 -0600 Subject: [PATCH 09/79] Eliminate some single-line if statements. --- UnitTest++/ThrowingTestReporter.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/UnitTest++/ThrowingTestReporter.cpp b/UnitTest++/ThrowingTestReporter.cpp index 7fb670b..672f042 100644 --- a/UnitTest++/ThrowingTestReporter.cpp +++ b/UnitTest++/ThrowingTestReporter.cpp @@ -14,26 +14,38 @@ namespace UnitTest { //virtual void ThrowingTestReporter::ReportTestStart(TestDetails const& test) { - if(m_decoratedReporter) m_decoratedReporter->ReportTestStart(test); + if(m_decoratedReporter) + { + m_decoratedReporter->ReportTestStart(test); + } } //virtual void ThrowingTestReporter::ReportFailure(TestDetails const& test, char const* failure) { - if(m_decoratedReporter) m_decoratedReporter->ReportFailure(test, failure); + if(m_decoratedReporter) + { + m_decoratedReporter->ReportFailure(test, failure); + } throw RequiredCheckException(); } //virtual void ThrowingTestReporter::ReportTestFinish(TestDetails const& test, float secondsElapsed) { - if(m_decoratedReporter) m_decoratedReporter->ReportTestFinish(test, secondsElapsed); + if(m_decoratedReporter) + { + m_decoratedReporter->ReportTestFinish(test, secondsElapsed); + } } //virtual void ThrowingTestReporter::ReportSummary(int totalTestCount, int failedTestCount, int failureCount, float secondsElapsed) { - if(m_decoratedReporter) m_decoratedReporter->ReportSummary(totalTestCount, failedTestCount, failureCount, secondsElapsed); + if(m_decoratedReporter) + { + m_decoratedReporter->ReportSummary(totalTestCount, failedTestCount, failureCount, secondsElapsed); + } } } From 6bb9541ae2d82c04018eb4f1152f99b59db23dff Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Sat, 6 Feb 2016 22:04:52 -0600 Subject: [PATCH 10/79] 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. --- UnitTest++/CheckMacros.h | 40 ++++++++++-------------------------- UnitTest++/ExceptionMacros.h | 2 ++ UnitTest++/ExecuteTest.h | 2 ++ 3 files changed, 15 insertions(+), 29 deletions(-) diff --git a/UnitTest++/CheckMacros.h b/UnitTest++/CheckMacros.h index 9547c32..e9dae64 100644 --- a/UnitTest++/CheckMacros.h +++ b/UnitTest++/CheckMacros.h @@ -38,14 +38,11 @@ #define CHECK(value) \ UNITTEST_MULTILINE_MACRO_BEGIN \ UT_TRY \ - ({ \ + ({ \ if (!UnitTest::Check(value)) \ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), #value); \ }) \ - UT_CATCH (UnitTest::RequiredCheckException, , \ - { \ - UT_THROW(); \ - }) \ + UT_RETHROW (UnitTest::RequiredCheckException) \ UT_CATCH (std::exception, e, \ { \ UnitTest::MemoryOutStream message; \ @@ -63,13 +60,10 @@ #define CHECK_EQUAL(expected, actual) \ UNITTEST_MULTILINE_MACRO_BEGIN \ UT_TRY \ - ({ \ + ({ \ UnitTest::CheckEqual(*UnitTest::CurrentTest::Results(), expected, actual, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ }) \ - UT_CATCH (UnitTest::RequiredCheckException, , \ - { \ - UT_THROW(); \ - }) \ + UT_RETHROW (UnitTest::RequiredCheckException) \ UT_CATCH (std::exception, e, \ { \ UnitTest::MemoryOutStream message; \ @@ -78,7 +72,7 @@ message.GetText()); \ }) \ UT_CATCH_ALL \ - ({ \ + ({ \ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \ "Unhandled exception in CHECK_EQUAL(" #expected ", " #actual ")"); \ }) \ @@ -87,13 +81,10 @@ #define CHECK_CLOSE(expected, actual, tolerance) \ UNITTEST_MULTILINE_MACRO_BEGIN \ UT_TRY \ - ({ \ + ({ \ UnitTest::CheckClose(*UnitTest::CurrentTest::Results(), expected, actual, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ }) \ - UT_CATCH (UnitTest::RequiredCheckException, , \ - { \ - UT_THROW(); \ - }) \ + UT_RETHROW (UnitTest::RequiredCheckException) \ UT_CATCH (std::exception, e, \ { \ UnitTest::MemoryOutStream message; \ @@ -102,7 +93,7 @@ message.GetText()); \ }) \ UT_CATCH_ALL \ - ({ \ + ({ \ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \ "Unhandled exception in CHECK_CLOSE(" #expected ", " #actual ")"); \ }) \ @@ -114,10 +105,7 @@ ({ \ UnitTest::CheckArrayEqual(*UnitTest::CurrentTest::Results(), expected, actual, count, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ }) \ - UT_CATCH (UnitTest::RequiredCheckException, , \ - { \ - UT_THROW(); \ - }) \ + UT_RETHROW (UnitTest::RequiredCheckException) \ UT_CATCH (std::exception, e, \ { \ UnitTest::MemoryOutStream message; \ @@ -138,10 +126,7 @@ ({ \ UnitTest::CheckArrayClose(*UnitTest::CurrentTest::Results(), expected, actual, count, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ }) \ - UT_CATCH (UnitTest::RequiredCheckException, , \ - { \ - UT_THROW(); \ - }) \ + UT_RETHROW (UnitTest::RequiredCheckException) \ UT_CATCH (std::exception, e, \ { \ UnitTest::MemoryOutStream message; \ @@ -162,10 +147,7 @@ ({ \ UnitTest::CheckArray2DClose(*UnitTest::CurrentTest::Results(), expected, actual, rows, columns, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ }) \ - UT_CATCH (UnitTest::RequiredCheckException, , \ - { \ - UT_THROW(); \ - }) \ + UT_RETHROW (UnitTest::RequiredCheckException) \ UT_CATCH (std::exception, e, \ { \ UnitTest::MemoryOutStream message; \ diff --git a/UnitTest++/ExceptionMacros.h b/UnitTest++/ExceptionMacros.h index ca8757e..027a5da 100644 --- a/UnitTest++/ExceptionMacros.h +++ b/UnitTest++/ExceptionMacros.h @@ -6,11 +6,13 @@ #ifndef UNITTEST_NO_EXCEPTIONS #define UT_TRY(x) try x #define UT_THROW(x) throw x + #define UT_RETHROW(ExceptionType) catch(ExceptionType&) { throw; } #define UT_CATCH(ExceptionType, ExceptionName, CatchBody) catch(ExceptionType& ExceptionName) CatchBody #define UT_CATCH_ALL(CatchBody) catch(...) CatchBody #else #define UT_TRY(x) x #define UT_THROW(x) + #define UT_RETHROW() #define UT_CATCH(ExceptionType, ExceptionName, CatchBody) #define UT_CATCH_ALL(CatchBody) #endif diff --git a/UnitTest++/ExecuteTest.h b/UnitTest++/ExecuteTest.h index c6917fc..8e516db 100644 --- a/UnitTest++/ExecuteTest.h +++ b/UnitTest++/ExecuteTest.h @@ -7,6 +7,7 @@ #include "TestResults.h" #include "MemoryOutStream.h" #include "AssertException.h" +#include "RequiredCheckException.h" #include "CurrentTest.h" #ifdef UNITTEST_NO_EXCEPTIONS @@ -38,6 +39,7 @@ namespace UnitTest { testObject.RunImpl(); }) #endif + UT_CATCH(RequiredCheckException, e, { (void)e; }) UT_CATCH(AssertException, e, { (void)e; }) UT_CATCH(std::exception, e, { From 7a68264b0fe7a8da3569a31b8815b4a78b710155 Mon Sep 17 00:00:00 2001 From: Austin Gilbert Date: Mon, 8 Feb 2016 19:11:05 -0600 Subject: [PATCH 11/79] Renaming tests/TestRequireMacros.cpp -> tests/TestRequireMacrosWithExceptionsOn.cpp, testing REQUIRE with exceptions turned off will require a significantly different approach. --- ...estRequireMacros.cpp => TestRequireMacrosWithExceptionsOn.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/{TestRequireMacros.cpp => TestRequireMacrosWithExceptionsOn.cpp} (100%) diff --git a/tests/TestRequireMacros.cpp b/tests/TestRequireMacrosWithExceptionsOn.cpp similarity index 100% rename from tests/TestRequireMacros.cpp rename to tests/TestRequireMacrosWithExceptionsOn.cpp From 4b0ac3f34a598fbd6ad7e0158e9663f0481ab965 Mon Sep 17 00:00:00 2001 From: Austin Gilbert Date: Mon, 8 Feb 2016 21:36:05 -0600 Subject: [PATCH 12/79] UT_RETHROW needed to take an argument when UNITTEST_NO_EXCEPTIONS=1. --- UnitTest++/ExceptionMacros.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UnitTest++/ExceptionMacros.h b/UnitTest++/ExceptionMacros.h index 027a5da..c3b1e30 100644 --- a/UnitTest++/ExceptionMacros.h +++ b/UnitTest++/ExceptionMacros.h @@ -12,7 +12,7 @@ #else #define UT_TRY(x) x #define UT_THROW(x) - #define UT_RETHROW() + #define UT_RETHROW(ExceptionType) #define UT_CATCH(ExceptionType, ExceptionName, CatchBody) #define UT_CATCH_ALL(CatchBody) #endif From 2e53a17d7e85d11efeef3ca88d852d2c80b2e5b1 Mon Sep 17 00:00:00 2001 From: Austin Gilbert Date: Mon, 8 Feb 2016 21:38:56 -0600 Subject: [PATCH 13/79] 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. --- UnitTest++/RequireMacros.h | 8 +- UnitTest++/ThrowingTestReporter.cpp | 12 +- tests/TestRequireMacrosWithExceptionsOff.cpp | 738 +++++++++++++++++++ 3 files changed, 750 insertions(+), 8 deletions(-) create mode 100644 tests/TestRequireMacrosWithExceptionsOff.cpp diff --git a/UnitTest++/RequireMacros.h b/UnitTest++/RequireMacros.h index ea1f6b9..0830e99 100644 --- a/UnitTest++/RequireMacros.h +++ b/UnitTest++/RequireMacros.h @@ -7,12 +7,6 @@ #error UnitTest++ redefines REQUIRE #endif -#ifndef UNITTEST_NO_EXCEPTIONS - #define REQUIRE for(UnitTest::RequiredCheckTestReporter decoratedReporter(*UnitTest::CurrentTest::Results()); decoratedReporter.Next(); ) -#endif +#define REQUIRE for(UnitTest::RequiredCheckTestReporter decoratedReporter(*UnitTest::CurrentTest::Results()); decoratedReporter.Next(); ) -#ifdef UNITTEST_NO_EXCEPTIONS - #define REQUIRE #endif - -#endif \ No newline at end of file diff --git a/UnitTest++/ThrowingTestReporter.cpp b/UnitTest++/ThrowingTestReporter.cpp index 672f042..4e56149 100644 --- a/UnitTest++/ThrowingTestReporter.cpp +++ b/UnitTest++/ThrowingTestReporter.cpp @@ -1,6 +1,10 @@ #include "ThrowingTestReporter.h" #include "RequiredCheckException.h" +#ifdef UNITTEST_NO_EXCEPTIONS +#include "ReportAssertImpl.h" +#endif + namespace UnitTest { ThrowingTestReporter::ThrowingTestReporter(TestReporter* decoratedReporter) @@ -27,7 +31,13 @@ namespace UnitTest { { m_decoratedReporter->ReportFailure(test, failure); } - throw RequiredCheckException(); + + #ifndef UNITTEST_NO_EXCEPTIONS + throw RequiredCheckException(); + #else + static const int stopTest = 1; + UNITTEST_LONGJMP(*UnitTest::Detail::GetAssertJmpBuf(), stopTest); + #endif } //virtual diff --git a/tests/TestRequireMacrosWithExceptionsOff.cpp b/tests/TestRequireMacrosWithExceptionsOff.cpp new file mode 100644 index 0000000..d43fbc1 --- /dev/null +++ b/tests/TestRequireMacrosWithExceptionsOff.cpp @@ -0,0 +1,738 @@ +#include "UnitTest++/UnitTestPP.h" +#include "UnitTest++/CurrentTest.h" +#include "RecordingReporter.h" +#include "ScopedCurrentTest.h" + +#include + +using namespace std; + +#ifdef UNITTEST_NO_EXCEPTIONS + +// NOTE: unit tests here use a work around for std::longjmp +// taking us out of the current running unit test. We use a +// follow on test to check the previous test exhibited correct +// behavior. + +namespace { + + static RecordingReporter reporter; + static std::string testName; + static bool next = false; + static int line = 0; + + // Use destructor to reset our globals + struct DoValidationOn + { + ~DoValidationOn() + { + testName = ""; + next = false; + line = 0; + + reporter.lastFailedLine = 0; + memset(reporter.lastFailedTest, 0, sizeof(reporter.lastFailedTest)); + memset(reporter.lastFailedSuite, 0, sizeof(reporter.lastFailedSuite)); + memset(reporter.lastFailedFile, 0, sizeof(reporter.lastFailedFile)); + } + }; + + TEST(RequireCheckSucceedsOnTrue) + { + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + REQUIRE CHECK(true); + next = true; + } + } + + TEST_FIXTURE(DoValidationOn, RequireCheckSucceedsOnTrue_FollowOn) + { + CHECK(next); + } + + TEST(RequiredCheckFailsOnFalse) + { + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + REQUIRE CHECK(false); + next = true; + } + } + + TEST_FIXTURE(DoValidationOn, RequiredCheckFailsOnFalse_FollowOn) + { + CHECK(!next); + } + + TEST(RequireMacroSupportsMultipleChecks) + { + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + REQUIRE + { + CHECK(true); + CHECK_EQUAL(1,1); + } + + next = true; + } + } + + TEST_FIXTURE(DoValidationOn, RequireMacroSupportsMultipleChecks_FollowOn) + { + CHECK(next); + } + + TEST(RequireMacroSupportsMultipleChecksWithFailingChecks) + { + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + REQUIRE + { + CHECK(true); + CHECK_EQUAL(1,2); + } + + next = true; + } + } + + TEST_FIXTURE(DoValidationOn, RequireMacroSupportsMultipleChecksWithFailingChecks_FollowOn) + { + CHECK(!next); + } + + TEST(RequireMacroDoesntExecuteCodeAfterAFailingCheck) + { + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + REQUIRE + { + CHECK(false); + next = true; + } + } + } + + TEST_FIXTURE(DoValidationOn, RequireMacroDoesntExecuteCodeAfterAFailingCheck_FollowOn) + { + CHECK(!next); + } + + TEST(FailureReportsCorrectTestName) + { + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + testName = m_details.testName; + REQUIRE CHECK(false); + } + } + + TEST_FIXTURE(DoValidationOn, FailureReportsCorrectTestName_FollowOn) + { + CHECK_EQUAL(testName, reporter.lastFailedTest); + } + + TEST(RequiredCheckFailureIncludesCheckContents) + { + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + testName = m_details.testName; + const bool yaddayadda = false; + + REQUIRE CHECK(yaddayadda); + } + } + + TEST_FIXTURE(DoValidationOn, RequiredCheckFailureIncludesCheckContents_FollowOn) + { + CHECK(strstr(reporter.lastFailedMessage, "yaddayadda")); + } + + TEST(RequiredCheckEqualSucceedsOnEqual) + { + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + REQUIRE CHECK_EQUAL(1,1); + next = true; + } + } + + TEST_FIXTURE(DoValidationOn, RequiredCheckEqualSucceedsOnEqual_FollowOn) + { + CHECK(next); + } + + TEST(RequiredCheckEqualFailsOnNotEqual) + { + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + REQUIRE CHECK_EQUAL(1, 2); + next = true; + } + } + + TEST_FIXTURE(DoValidationOn, RequiredCheckEqualFailsOnNotEqual_FollowOn) + { +// TODO: check reporter last test name + CHECK(!next); + } + + TEST(RequiredCheckEqualFailureContainsCorrectDetails) + { + { + UnitTest::TestResults testResults(&reporter); + UnitTest::TestDetails const testDetails("testName", "suiteName", "filename", -1); + ScopedCurrentTest scopedResults(testResults, &testDetails); + + line = __LINE__; REQUIRE CHECK_EQUAL(1, 123); + } + } + + TEST_FIXTURE(DoValidationOn, RequiredCheckEqualFailureContainsCorrectDetails_FollowOn) + { + CHECK_EQUAL("testName", reporter.lastFailedTest); + CHECK_EQUAL("suiteName", reporter.lastFailedSuite); + CHECK_EQUAL("filename", reporter.lastFailedFile); + CHECK_EQUAL(line, reporter.lastFailedLine); + } + + int g_sideEffect = 0; + int FunctionWithSideEffects() + { + ++g_sideEffect; + return 1; + } + + TEST(RequiredCheckEqualDoesNotHaveSideEffectsWhenPassing) + { + g_sideEffect = 0; + { + UnitTest::TestResults testResults; + ScopedCurrentTest scopedResults(testResults); + + REQUIRE CHECK_EQUAL(1, FunctionWithSideEffects()); + next = true; + } + } + + TEST_FIXTURE(DoValidationOn, RequiredCheckEqualDoesNotHaveSideEffectsWhenPassing_FollowOn) + { + CHECK_EQUAL(1, g_sideEffect); + CHECK(next); + } + + TEST(RequiredCheckEqualDoesNotHaveSideEffectsWhenFailing) + { + g_sideEffect = 0; + { + UnitTest::TestResults testResults; + ScopedCurrentTest scopedResults(testResults); + + REQUIRE CHECK_EQUAL(2, FunctionWithSideEffects()); + next = true; + } + } + + TEST_FIXTURE(DoValidationOn, RequiredCheckEqualDoesNotHaveSideEffectsWhenFailing_FollowOn) + { + CHECK_EQUAL(1, g_sideEffect); + CHECK(!next); + } + + TEST(RequiredCheckCloseSucceedsOnEqual) + { + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + REQUIRE CHECK_CLOSE(1.0f, 1.001f, 0.01f); + next = true; + } + } + + TEST_FIXTURE(DoValidationOn, RequiredCheckCloseSucceedsOnEqual_FollowOn) + { + CHECK(next); + } + + TEST(RequiredCheckCloseFailsOnNotEqual) + { + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + REQUIRE CHECK_CLOSE (1.0f, 1.1f, 0.01f); + next = true; + } + } + + TEST_FIXTURE(DoValidationOn, RequiredCheckCloseFailsOnNotEqual_FollowOn) + { + CHECK(!next); + } + + TEST(RequiredCheckCloseFailureContainsCorrectDetails) + { + { + UnitTest::TestResults testResults(&reporter); + UnitTest::TestDetails testDetails("test", "suite", "filename", -1); + ScopedCurrentTest scopedResults(testResults, &testDetails); + + line = __LINE__; REQUIRE CHECK_CLOSE(1.0f, 1.1f, 0.01f); + next = true; + } + } + + TEST_FIXTURE(DoValidationOn, RequiredCheckCloseFailureContainsCorrectDetails_FollowOn) + { + CHECK_EQUAL("test", reporter.lastFailedTest); + CHECK_EQUAL("suite", reporter.lastFailedSuite); + CHECK_EQUAL("filename", reporter.lastFailedFile); + CHECK_EQUAL(line, reporter.lastFailedLine); + + CHECK(!next); + } + + TEST(RequiredCheckCloseDoesNotHaveSideEffectsWhenPassing) + { + g_sideEffect = 0; + { + UnitTest::TestResults testResults; + ScopedCurrentTest scopedResults(testResults); + + REQUIRE CHECK_CLOSE (1, FunctionWithSideEffects(), 0.1f); + next = true; + } + } + + TEST_FIXTURE(DoValidationOn, RequiredCheckCloseDoesNotHaveSideEffectsWhenPassing_FollowOn) + { + CHECK_EQUAL(1, g_sideEffect); + CHECK(next); + } + + TEST(RequiredCheckCloseDoesNotHaveSideEffectsWhenFailing) + { + g_sideEffect = 0; + { + UnitTest::TestResults testResults; + ScopedCurrentTest scopedResults(testResults); + + REQUIRE CHECK_CLOSE(2, FunctionWithSideEffects(), 0.1f); + next = true; + } + } + + TEST_FIXTURE(DoValidationOn, RequiredCheckCloseDoesNotHaveSideEffectsWhenFailingOn) + { + CHECK_EQUAL(1, g_sideEffect); + CHECK(!next); + } + + TEST(RequiredCheckArrayCloseSucceedsOnEqual) + { + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + const float data[4] = { 0, 1, 2, 3 }; + + REQUIRE CHECK_ARRAY_CLOSE (data, data, 4, 0.01f); + next = true; + } + } + + TEST_FIXTURE(DoValidationOn, RequiredCheckArrayCloseSucceedsOnEqual_FollowOn) + { + CHECK(next); + } + + TEST(RequiredCheckArrayCloseFailsOnNotEqual) + { + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + int const data1[4] = { 0, 1, 2, 3 }; + int const data2[4] = { 0, 1, 3, 3 }; + + REQUIRE CHECK_ARRAY_CLOSE (data1, data2, 4, 0.01f); + next = true; + } + } + + TEST_FIXTURE(DoValidationOn, RequiredCheckArrayCloseFailsOnNotEqual_FollowOn) + { + CHECK(!next); + } + + TEST(RequiredCheckArrayCloseFailureIncludesCheckExpectedAndActual) + { + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + int const data1[4] = { 0, 1, 2, 3 }; + int const data2[4] = { 0, 1, 3, 3 }; + + REQUIRE CHECK_ARRAY_CLOSE(data1, data2, 4, 0.01f); + next = true; + } + } + + TEST_FIXTURE(DoValidationOn, RequiredCheckArrayCloseFailureIncludesCheckExpectedAndActual_FollowOn) + { + CHECK(!next); + + CHECK(strstr(reporter.lastFailedMessage, "xpected [ 0 1 2 3 ]")); + CHECK(strstr(reporter.lastFailedMessage, "was [ 0 1 3 3 ]")); + } + + TEST(RequiredCheckArrayCloseFailureContainsCorrectDetails) + { + { + UnitTest::TestResults testResults(&reporter); + UnitTest::TestDetails testDetails("arrayCloseTest", "arrayCloseSuite", "filename", -1); + ScopedCurrentTest scopedResults(testResults, &testDetails); + + int const data1[4] = { 0, 1, 2, 3 }; + int const data2[4] = { 0, 1, 3, 3 }; + + line = __LINE__; REQUIRE CHECK_ARRAY_CLOSE (data1, data2, 4, 0.01f); + next = true; + } + } + + TEST_FIXTURE(DoValidationOn, RequiredCheckArrayCloseFailureContainsCorrectDetails_FollowOn) + { + CHECK(!next); + + CHECK_EQUAL("arrayCloseTest", reporter.lastFailedTest); + CHECK_EQUAL("arrayCloseSuite", reporter.lastFailedSuite); + CHECK_EQUAL("filename", reporter.lastFailedFile); + CHECK_EQUAL(line, reporter.lastFailedLine); + } + + TEST(RequiredCheckArrayCloseFailureIncludesTolerance) + { + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + float const data1[4] = { 0, 1, 2, 3 }; + float const data2[4] = { 0, 1, 3, 3 }; + + REQUIRE CHECK_ARRAY_CLOSE (data1, data2, 4, 0.01f); + next = true; + } + } + + TEST_FIXTURE(DoValidationOn, RequiredCheckArrayCloseFailureIncludesTolerance_FollowOn) + { + CHECK(!next); + CHECK(strstr(reporter.lastFailedMessage, "0.01")); + } + + TEST(RequiredCheckArrayEqualSuceedsOnEqual) + { + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + const float data[4] = { 0, 1, 2, 3 }; + + REQUIRE CHECK_ARRAY_EQUAL (data, data, 4); + next = true; + } + } + + TEST_FIXTURE(DoValidationOn, RequiredCheckArrayEqualSuceedsOnEqual_FollowOn) + { + CHECK(next); + } + + TEST(RequiredCheckArrayEqualFailsOnNotEqual) + { + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + int const data1[4] = { 0, 1, 2, 3 }; + int const data2[4] = { 0, 1, 3, 3 }; + + REQUIRE CHECK_ARRAY_EQUAL (data1, data2, 4); + next = true; + } + } + + TEST_FIXTURE(DoValidationOn, RequiredCheckArrayEqualFailsOnNotEqual) + { + CHECK(!next); + } + + TEST(RequiredCheckArrayEqualFailureIncludesCheckExpectedAndActual) + { + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + int const data1[4] = { 0, 1, 2, 3 }; + int const data2[4] = { 0, 1, 3, 3 }; + + REQUIRE CHECK_ARRAY_EQUAL (data1, data2, 4); + next = true; + } + } + + TEST_FIXTURE(DoValidationOn, RequiredCheckArrayEqualFailureIncludesCheckExpectedAndActual_FollowOn) + { + CHECK(!next); + + CHECK(strstr(reporter.lastFailedMessage, "xpected [ 0 1 2 3 ]")); + CHECK(strstr(reporter.lastFailedMessage, "was [ 0 1 3 3 ]")); + } + + TEST(RequiredCheckArrayEqualFailureContainsCorrectInfo) + { + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + int const data1[4] = { 0, 1, 2, 3 }; + int const data2[4] = { 0, 1, 3, 3 }; + + line = __LINE__; REQUIRE CHECK_ARRAY_EQUAL (data1, data2, 4); + next = true; + } + } + + TEST_FIXTURE(DoValidationOn, RequiredCheckArrayEqualFailureContainsCorrectInfo_FollowOn) + { + CHECK(!next); + + CHECK_EQUAL("RequiredCheckArrayEqualFailureContainsCorrectInfo", reporter.lastFailedTest); + CHECK_EQUAL(__FILE__, reporter.lastFailedFile); + CHECK_EQUAL(line, reporter.lastFailedLine); + } + + float const* FunctionWithSideEffects2() + { + ++g_sideEffect; + static float const data[] = { 0, 1, 2, 3}; + return data; + } + + TEST(RequiredCheckArrayCloseDoesNotHaveSideEffectsWhenPassing) + { + g_sideEffect = 0; + { + UnitTest::TestResults testResults; + ScopedCurrentTest scopedResults(testResults); + + const float data[] = { 0, 1, 2, 3 }; + + REQUIRE CHECK_ARRAY_CLOSE (data, FunctionWithSideEffects2(), 4, 0.01f); + next = true; + } + } + + TEST_FIXTURE(DoValidationOn, RequiredCheckArrayCloseDoesNotHaveSideEffectsWhenPassing_FollowOn) + { + CHECK_EQUAL(1, g_sideEffect); + CHECK(next); + } + + TEST(RequiredCheckArrayCloseDoesNotHaveSideEffectsWhenFailing) + { + g_sideEffect = 0; + { + UnitTest::TestResults testResults; + ScopedCurrentTest scopedResults(testResults); + + const float data[] = { 0, 1, 3, 3 }; + + REQUIRE CHECK_ARRAY_CLOSE (data, FunctionWithSideEffects2(), 4, 0.01f); + next = true; + } + } + + TEST_FIXTURE(DoValidationOn, RequiredCheckArrayCloseDoesNotHaveSideEffectsWhenFailing_FollowOn) + { + CHECK_EQUAL(1, g_sideEffect); + CHECK(!next); + } + + TEST(RequiredCheckArray2DCloseSucceedsOnEqual) + { + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + const float data[2][2] = { {0, 1}, {2, 3} }; + + REQUIRE CHECK_ARRAY2D_CLOSE(data, data, 2, 2, 0.01f); + next = true; + } + } + + TEST_FIXTURE(DoValidationOn, RequiredCheckArray2DCloseSucceedsOnEqual_FollowOn) + { + CHECK(next); + } + + TEST(RequiredCheckArray2DCloseFailsOnNotEqual) + { + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + int const data1[2][2] = { {0, 1}, {2, 3} }; + int const data2[2][2] = { {0, 1}, {3, 3} }; + + REQUIRE CHECK_ARRAY2D_CLOSE (data1, data2, 2, 2, 0.01f); + next = true; + } + } + + TEST_FIXTURE(DoValidationOn, RequiredCheckArray2DCloseFailsOnNotEqual_FollowOn) + { + CHECK(!next); + } + + TEST(RequiredCheckArray2DCloseFailureIncludesCheckExpectedAndActual) + { + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + int const data1[2][2] = { {0, 1}, {2, 3} }; + int const data2[2][2] = { {0, 1}, {3, 3} }; + + REQUIRE CHECK_ARRAY2D_CLOSE (data1, data2, 2, 2, 0.01f); + next = true; + } + } + + TEST_FIXTURE(DoValidationOn, RequiredCheckArray2DCloseFailureIncludesCheckExpectedAndActual_FollowOn) + { + CHECK(!next); + + CHECK(strstr(reporter.lastFailedMessage, "xpected [ [ 0 1 ] [ 2 3 ] ]")); + CHECK(strstr(reporter.lastFailedMessage, "was [ [ 0 1 ] [ 3 3 ] ]")); + } + + TEST(RequiredCheckArray2DCloseFailureContainsCorrectDetails) + { + { + UnitTest::TestResults testResults(&reporter); + UnitTest::TestDetails testDetails("array2DCloseTest", "array2DCloseSuite", "filename", -1); + ScopedCurrentTest scopedResults(testResults, &testDetails); + + int const data1[2][2] = { {0, 1}, {2, 3} }; + int const data2[2][2] = { {0, 1}, {3, 3} }; + + line = __LINE__; REQUIRE CHECK_ARRAY2D_CLOSE (data1, data2, 2, 2, 0.01f); + next = true; + } + } + + TEST_FIXTURE(DoValidationOn, RequiredCheckArray2DCloseFailureContainsCorrectDetails_FollowOn) + { + CHECK(!next); + + CHECK_EQUAL("array2DCloseTest", reporter.lastFailedTest); + CHECK_EQUAL("array2DCloseSuite", reporter.lastFailedSuite); + CHECK_EQUAL("filename", reporter.lastFailedFile); + CHECK_EQUAL(line, reporter.lastFailedLine); + } + + TEST(RequiredCheckArray2DCloseFailureIncludesTolerance) + { + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + float const data1[2][2] = { {0, 1}, {2, 3} }; + float const data2[2][2] = { {0, 1}, {3, 3} }; + + REQUIRE CHECK_ARRAY2D_CLOSE (data1, data2, 2, 2, 0.01f); + next = true; + } + } + + TEST_FIXTURE(DoValidationOn, RequiredCheckArray2DCloseFailureIncludesTolerance_FollowOn) + { + CHECK(!next); + CHECK(strstr(reporter.lastFailedMessage, "0.01")); + } + + float const* const* FunctionWithSideEffects3() + { + ++g_sideEffect; + static float const data1[] = {0,1}; + static float const data2[] = {2,3}; + static const float* const data[] = {data1, data2}; + return data; + } + + TEST(RequiredCheckArray2DCloseDoesNotHaveSideEffectsWhenPassing) + { + g_sideEffect = 0; + { + UnitTest::TestResults testResults; + ScopedCurrentTest scopedResults(testResults); + + const float data[2][2] = { {0, 1}, {2, 3} }; + + REQUIRE CHECK_ARRAY2D_CLOSE (data, FunctionWithSideEffects3(), 2, 2, 0.01f); + next = true; + } + } + + TEST_FIXTURE(DoValidationOn, RequiredCheckArray2DCloseDoesNotHaveSideEffectsWhenPassing_FollowOn) + { + CHECK(next); + CHECK_EQUAL(1, g_sideEffect); + } + + TEST(RequiredCheckArray2DCloseDoesNotHaveSideEffectsWhenFailing) + { + g_sideEffect = 0; + { + UnitTest::TestResults testResults; + ScopedCurrentTest scopedResults(testResults); + + const float data[2][2] = { {0, 1}, {3, 3} }; + + REQUIRE CHECK_ARRAY2D_CLOSE (data, FunctionWithSideEffects3(), 2, 2, 0.01f); + next = true; + } + } + + TEST_FIXTURE(DoValidationOn, RequiredCheckArray2DCloseDoesNotHaveSideEffectsWhenFailing_FollowOn) + { + CHECK(!next); + CHECK_EQUAL(1, g_sideEffect); + } +} + +#endif From 1c30bcd16b1c69eb7cde4894bc446d47d4268c92 Mon Sep 17 00:00:00 2001 From: Austin Gilbert Date: Mon, 8 Feb 2016 21:54:58 -0600 Subject: [PATCH 14/79] Correcting RequiredCheckArrayCloseDoesNotHaveSideEffectsWhenPassing to exercise the passing case (per the UT name). --- tests/TestRequireMacros.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/tests/TestRequireMacros.cpp b/tests/TestRequireMacros.cpp index 6b76004..f904708 100644 --- a/tests/TestRequireMacros.cpp +++ b/tests/TestRequireMacros.cpp @@ -646,14 +646,9 @@ namespace { UnitTest::TestResults testResults; ScopedCurrentTest scopedResults(testResults); - const float data[] = { 0, 1, 2, 3 }; + const float data[] = { 1, 2, 3, 4 }; - try - { - REQUIRE CHECK_ARRAY_CLOSE (data, FunctionWithSideEffects2(), 4, 0.01f); - } - catch (const UnitTest::RequiredCheckException&) - {} + REQUIRE CHECK_ARRAY_CLOSE (data, FunctionWithSideEffects2(), 4, 0.01f); } CHECK_EQUAL(1, g_sideEffect); } From adebd8376a1e16d7661405e6ff214b2b617163da Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Tue, 23 Feb 2016 21:11:19 -0600 Subject: [PATCH 15/79] Update autotools for new source files. --- UnitTest++/Makefile.am | 4 ++-- tests/Makefile.am | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/UnitTest++/Makefile.am b/UnitTest++/Makefile.am index 32f6477..a512fca 100644 --- a/UnitTest++/Makefile.am +++ b/UnitTest++/Makefile.am @@ -1,7 +1,7 @@ lib_LTLIBRARIES = UnitTest++/libUnitTest++.la pkgincludedir = $(includedir)/UnitTest++/ -nobase_pkginclude_HEADERS = UnitTest++/UnitTest++.h UnitTest++/UnitTestPP.h UnitTest++/Config.h UnitTest++/HelperMacros.h UnitTest++/Test.h UnitTest++/TestDetails.h UnitTest++/TestList.h UnitTest++/TestSuite.h UnitTest++/TestResults.h UnitTest++/TestMacros.h UnitTest++/CheckMacros.h UnitTest++/TestRunner.h UnitTest++/TimeConstraint.h UnitTest++/ExecuteTest.h UnitTest++/AssertException.h UnitTest++/MemoryOutStream.h UnitTest++/CurrentTest.h UnitTest++/Checks.h UnitTest++/TimeHelpers.h UnitTest++/ExceptionMacros.h UnitTest++/ReportAssert.h UnitTest++/ReportAssertImpl.h UnitTest++/TestReporter.h UnitTest++/TestReporterStdout.h UnitTest++/CompositeTestReporter.h UnitTest++/DeferredTestReporter.h UnitTest++/DeferredTestResult.h -UnitTest___libUnitTest___la_SOURCES = UnitTest++/AssertException.cpp UnitTest++/Test.cpp UnitTest++/Checks.cpp UnitTest++/TestRunner.cpp UnitTest++/TestResults.cpp UnitTest++/TestReporter.cpp UnitTest++/TestReporterStdout.cpp UnitTest++/ReportAssert.cpp UnitTest++/TestList.cpp UnitTest++/TimeConstraint.cpp UnitTest++/TestDetails.cpp UnitTest++/MemoryOutStream.cpp UnitTest++/DeferredTestReporter.cpp UnitTest++/DeferredTestResult.cpp UnitTest++/XmlTestReporter.cpp UnitTest++/CurrentTest.cpp UnitTest++/CompositeTestReporter.cpp +nobase_pkginclude_HEADERS = UnitTest++/AssertException.h UnitTest++/CheckMacros.h UnitTest++/Checks.h UnitTest++/CompositeTestReporter.h UnitTest++/Config.h UnitTest++/CurrentTest.h UnitTest++/DeferredTestReporter.h UnitTest++/DeferredTestResult.h UnitTest++/ExceptionMacros.h UnitTest++/ExecuteTest.h UnitTest++/HelperMacros.h UnitTest++/MemoryOutStream.h UnitTest++/ReportAssert.h UnitTest++/ReportAssertImpl.h UnitTest++/RequireMacros.h UnitTest++/RequiredCheckException.h UnitTest++/RequiredCheckTestReporter.h UnitTest++/Test.h UnitTest++/TestDetails.h UnitTest++/TestList.h UnitTest++/TestMacros.h UnitTest++/TestReporter.h UnitTest++/TestReporterStdout.h UnitTest++/TestResults.h UnitTest++/TestRunner.h UnitTest++/TestSuite.h UnitTest++/ThrowingTestReporter.h UnitTest++/TimeConstraint.h UnitTest++/TimeHelpers.h UnitTest++/UnitTest++.h UnitTest++/UnitTestPP.h UnitTest++/XmlTestReporter.h +UnitTest___libUnitTest___la_SOURCES = UnitTest++/AssertException.cpp UnitTest++/Checks.cpp UnitTest++/CompositeTestReporter.cpp UnitTest++/CurrentTest.cpp UnitTest++/DeferredTestReporter.cpp UnitTest++/DeferredTestResult.cpp UnitTest++/MemoryOutStream.cpp UnitTest++/ReportAssert.cpp UnitTest++/RequiredCheckException.cpp UnitTest++/RequiredCheckTestReporter.cpp UnitTest++/Test.cpp UnitTest++/TestDetails.cpp UnitTest++/TestList.cpp UnitTest++/TestReporter.cpp UnitTest++/TestReporterStdout.cpp UnitTest++/TestResults.cpp UnitTest++/TestRunner.cpp UnitTest++/ThrowingTestReporter.cpp UnitTest++/TimeConstraint.cpp UnitTest++/XmlTestReporter.cpp if WINDOWS nobase_pkginclude_HEADERS += UnitTest++/Win32/TimeHelpers.h diff --git a/tests/Makefile.am b/tests/Makefile.am index 5306292..fe7cffd 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,4 +1,4 @@ check_PROGRAMS = UnitTest++/TestUnitTest++ -UnitTest___TestUnitTest___SOURCES = tests/Main.cpp tests/TestAssertHandler.cpp tests/TestCheckMacros.cpp tests/TestChecks.cpp tests/TestCompositeTestReporter.cpp tests/TestCurrentTest.cpp tests/TestDeferredTestReporter.cpp tests/TestExceptions.cpp tests/TestMemoryOutStream.cpp tests/TestTest.cpp tests/TestTestList.cpp tests/TestTestMacros.cpp tests/TestTestResults.cpp tests/TestTestRunner.cpp tests/TestTestSuite.cpp tests/TestTimeConstraint.cpp tests/TestTimeConstraintMacro.cpp tests/TestUnitTestPP.cpp tests/TestXmlTestReporter.cpp +UnitTest___TestUnitTest___SOURCES = tests/Main.cpp tests/TestAssertHandler.cpp tests/TestCheckMacros.cpp tests/TestChecks.cpp tests/TestCompositeTestReporter.cpp tests/TestCurrentTest.cpp tests/TestDeferredTestReporter.cpp tests/TestExceptions.cpp tests/TestMemoryOutStream.cpp tests/TestRequireMacros.cpp tests/TestTest.cpp tests/TestTestList.cpp tests/TestTestMacros.cpp tests/TestTestResults.cpp tests/TestTestRunner.cpp tests/TestTestSuite.cpp tests/TestTimeConstraint.cpp tests/TestTimeConstraintMacro.cpp tests/TestUnitTestPP.cpp tests/TestXmlTestReporter.cpp UnitTest___TestUnitTest___LDADD = UnitTest++/libUnitTest++.la TESTS = UnitTest++/TestUnitTest++ From 073a1ea0e1a484128bf4efa1d803e009c2356e2f Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Tue, 23 Feb 2016 21:44:25 -0600 Subject: [PATCH 16/79] Enable C++11 support in autoconf --- configure.ac | 2 + m4/ax_cxx_compile_stdcxx.m4 | 558 +++++++++++++++++++++++++++++++++ m4/ax_cxx_compile_stdcxx_11.m4 | 39 +++ 3 files changed, 599 insertions(+) create mode 100644 m4/ax_cxx_compile_stdcxx.m4 create mode 100644 m4/ax_cxx_compile_stdcxx_11.m4 diff --git a/configure.ac b/configure.ac index 7b77b73..46e3be6 100644 --- a/configure.ac +++ b/configure.ac @@ -19,6 +19,8 @@ AC_SUBST([LIBUNITTEST_SO_VERSION], [1:5:1]) AC_PROG_CXX AC_PROG_CC +AX_CXX_COMPILE_STDCXX_11(noext, optional) + # Checks for libraries. # Checks for header files. diff --git a/m4/ax_cxx_compile_stdcxx.m4 b/m4/ax_cxx_compile_stdcxx.m4 new file mode 100644 index 0000000..66d41f5 --- /dev/null +++ b/m4/ax_cxx_compile_stdcxx.m4 @@ -0,0 +1,558 @@ +# =========================================================================== +# http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_CXX_COMPILE_STDCXX(VERSION, [ext|noext], [mandatory|optional]) +# +# DESCRIPTION +# +# Check for baseline language coverage in the compiler for the specified +# version of the C++ standard. If necessary, add switches to CXXFLAGS to +# enable support. VERSION may be '11' (for the C++11 standard) or '14' +# (for the C++14 standard). +# +# The second argument, if specified, indicates whether you insist on an +# extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g. +# -std=c++11). If neither is specified, you get whatever works, with +# preference for an extended mode. +# +# The third argument, if specified 'mandatory' or if left unspecified, +# indicates that baseline support for the specified C++ standard is +# required and that the macro should error out if no mode with that +# support is found. If specified 'optional', then configuration proceeds +# regardless, after defining HAVE_CXX${VERSION} if and only if a +# supporting mode is found. +# +# LICENSE +# +# Copyright (c) 2008 Benjamin Kosnik +# Copyright (c) 2012 Zack Weinberg +# Copyright (c) 2013 Roy Stogner +# Copyright (c) 2014, 2015 Google Inc.; contributed by Alexey Sokolov +# Copyright (c) 2015 Paul Norman +# Copyright (c) 2015 Moritz Klammler +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 1 + +dnl This macro is based on the code from the AX_CXX_COMPILE_STDCXX_11 macro +dnl (serial version number 13). + +AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl + m4_if([$1], [11], [], + [$1], [14], [], + [$1], [17], [m4_fatal([support for C++17 not yet implemented in AX_CXX_COMPILE_STDCXX])], + [m4_fatal([invalid first argument `$1' to AX_CXX_COMPILE_STDCXX])])dnl + m4_if([$2], [], [], + [$2], [ext], [], + [$2], [noext], [], + [m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX])])dnl + m4_if([$3], [], [ax_cxx_compile_cxx$1_required=true], + [$3], [mandatory], [ax_cxx_compile_cxx$1_required=true], + [$3], [optional], [ax_cxx_compile_cxx$1_required=false], + [m4_fatal([invalid third argument `$3' to AX_CXX_COMPILE_STDCXX])]) + AC_LANG_PUSH([C++])dnl + ac_success=no + AC_CACHE_CHECK(whether $CXX supports C++$1 features by default, + ax_cv_cxx_compile_cxx$1, + [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])], + [ax_cv_cxx_compile_cxx$1=yes], + [ax_cv_cxx_compile_cxx$1=no])]) + if test x$ax_cv_cxx_compile_cxx$1 = xyes; then + ac_success=yes + fi + + m4_if([$2], [noext], [], [dnl + if test x$ac_success = xno; then + for switch in -std=gnu++$1 -std=gnu++0x; do + cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch]) + AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch, + $cachevar, + [ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS $switch" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])], + [eval $cachevar=yes], + [eval $cachevar=no]) + CXXFLAGS="$ac_save_CXXFLAGS"]) + if eval test x\$$cachevar = xyes; then + CXXFLAGS="$CXXFLAGS $switch" + ac_success=yes + break + fi + done + fi]) + + m4_if([$2], [ext], [], [dnl + if test x$ac_success = xno; then + dnl HP's aCC needs +std=c++11 according to: + dnl http://h21007.www2.hp.com/portal/download/files/unprot/aCxx/PDF_Release_Notes/769149-001.pdf + dnl Cray's crayCC needs "-h std=c++11" + for switch in -std=c++$1 -std=c++0x +std=c++$1 "-h std=c++$1"; do + cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch]) + AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch, + $cachevar, + [ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS $switch" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])], + [eval $cachevar=yes], + [eval $cachevar=no]) + CXXFLAGS="$ac_save_CXXFLAGS"]) + if eval test x\$$cachevar = xyes; then + CXXFLAGS="$CXXFLAGS $switch" + ac_success=yes + break + fi + done + fi]) + AC_LANG_POP([C++]) + if test x$ax_cxx_compile_cxx$1_required = xtrue; then + if test x$ac_success = xno; then + AC_MSG_ERROR([*** A compiler with support for C++$1 language features is required.]) + fi + else + if test x$ac_success = xno; then + HAVE_CXX$1=0 + AC_MSG_NOTICE([No compiler with C++$1 support was found]) + else + HAVE_CXX$1=1 + AC_DEFINE(HAVE_CXX$1,1, + [define if the compiler supports basic C++$1 syntax]) + fi + + AC_SUBST(HAVE_CXX$1) + fi +]) + + +dnl Test body for checking C++11 support + +m4_define([_AX_CXX_COMPILE_STDCXX_testbody_11], + _AX_CXX_COMPILE_STDCXX_testbody_new_in_11 +) + + +dnl Test body for checking C++14 support + +m4_define([_AX_CXX_COMPILE_STDCXX_testbody_14], + _AX_CXX_COMPILE_STDCXX_testbody_new_in_11 + _AX_CXX_COMPILE_STDCXX_testbody_new_in_14 +) + + +dnl Tests for new features in C++11 + +m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_11], [[ + +// If the compiler admits that it is not ready for C++11, why torture it? +// Hopefully, this will speed up the test. + +#ifndef __cplusplus + +#error "This is not a C++ compiler" + +#elif __cplusplus < 201103L + +#error "This is not a C++11 compiler" + +#else + +namespace cxx11 +{ + + namespace test_static_assert + { + + template + struct check + { + static_assert(sizeof(int) <= sizeof(T), "not big enough"); + }; + + } + + namespace test_final_override + { + + struct Base + { + virtual void f() {} + }; + + struct Derived : public Base + { + virtual void f() override {} + }; + + } + + namespace test_double_right_angle_brackets + { + + template < typename T > + struct check {}; + + typedef check single_type; + typedef check> double_type; + typedef check>> triple_type; + typedef check>>> quadruple_type; + + } + + namespace test_decltype + { + + int + f() + { + int a = 1; + decltype(a) b = 2; + return a + b; + } + + } + + namespace test_type_deduction + { + + template < typename T1, typename T2 > + struct is_same + { + static const bool value = false; + }; + + template < typename T > + struct is_same + { + static const bool value = true; + }; + + template < typename T1, typename T2 > + auto + add(T1 a1, T2 a2) -> decltype(a1 + a2) + { + return a1 + a2; + } + + int + test(const int c, volatile int v) + { + static_assert(is_same::value == true, ""); + static_assert(is_same::value == false, ""); + static_assert(is_same::value == false, ""); + auto ac = c; + auto av = v; + auto sumi = ac + av + 'x'; + auto sumf = ac + av + 1.0; + static_assert(is_same::value == true, ""); + static_assert(is_same::value == true, ""); + static_assert(is_same::value == true, ""); + static_assert(is_same::value == false, ""); + static_assert(is_same::value == true, ""); + return (sumf > 0.0) ? sumi : add(c, v); + } + + } + + namespace test_noexcept + { + + int f() { return 0; } + int g() noexcept { return 0; } + + static_assert(noexcept(f()) == false, ""); + static_assert(noexcept(g()) == true, ""); + + } + + namespace test_constexpr + { + + template < typename CharT > + unsigned long constexpr + strlen_c_r(const CharT *const s, const unsigned long acc) noexcept + { + return *s ? strlen_c_r(s + 1, acc + 1) : acc; + } + + template < typename CharT > + unsigned long constexpr + strlen_c(const CharT *const s) noexcept + { + return strlen_c_r(s, 0UL); + } + + static_assert(strlen_c("") == 0UL, ""); + static_assert(strlen_c("1") == 1UL, ""); + static_assert(strlen_c("example") == 7UL, ""); + static_assert(strlen_c("another\0example") == 7UL, ""); + + } + + namespace test_rvalue_references + { + + template < int N > + struct answer + { + static constexpr int value = N; + }; + + answer<1> f(int&) { return answer<1>(); } + answer<2> f(const int&) { return answer<2>(); } + answer<3> f(int&&) { return answer<3>(); } + + void + test() + { + int i = 0; + const int c = 0; + static_assert(decltype(f(i))::value == 1, ""); + static_assert(decltype(f(c))::value == 2, ""); + static_assert(decltype(f(0))::value == 3, ""); + } + + } + + namespace test_uniform_initialization + { + + struct test + { + static const int zero {}; + static const int one {1}; + }; + + static_assert(test::zero == 0, ""); + static_assert(test::one == 1, ""); + + } + + namespace test_lambdas + { + + void + test1() + { + auto lambda1 = [](){}; + auto lambda2 = lambda1; + lambda1(); + lambda2(); + } + + int + test2() + { + auto a = [](int i, int j){ return i + j; }(1, 2); + auto b = []() -> int { return '0'; }(); + auto c = [=](){ return a + b; }(); + auto d = [&](){ return c; }(); + auto e = [a, &b](int x) mutable { + const auto identity = [](int y){ return y; }; + for (auto i = 0; i < a; ++i) + a += b--; + return x + identity(a + b); + }(0); + return a + b + c + d + e; + } + + int + test3() + { + const auto nullary = [](){ return 0; }; + const auto unary = [](int x){ return x; }; + using nullary_t = decltype(nullary); + using unary_t = decltype(unary); + const auto higher1st = [](nullary_t f){ return f(); }; + const auto higher2nd = [unary](nullary_t f1){ + return [unary, f1](unary_t f2){ return f2(unary(f1())); }; + }; + return higher1st(nullary) + higher2nd(nullary)(unary); + } + + } + + namespace test_variadic_templates + { + + template + struct sum; + + template + struct sum + { + static constexpr auto value = N0 + sum::value; + }; + + template <> + struct sum<> + { + static constexpr auto value = 0; + }; + + static_assert(sum<>::value == 0, ""); + static_assert(sum<1>::value == 1, ""); + static_assert(sum<23>::value == 23, ""); + static_assert(sum<1, 2>::value == 3, ""); + static_assert(sum<5, 5, 11>::value == 21, ""); + static_assert(sum<2, 3, 5, 7, 11, 13>::value == 41, ""); + + } + + // http://stackoverflow.com/questions/13728184/template-aliases-and-sfinae + // Clang 3.1 fails with headers of libstd++ 4.8.3 when using std::function + // because of this. + namespace test_template_alias_sfinae + { + + struct foo {}; + + template + using member = typename T::member_type; + + template + void func(...) {} + + template + void func(member*) {} + + void test(); + + void test() { func(0); } + + } + +} // namespace cxx11 + +#endif // __cplusplus >= 201103L + +]]) + + +dnl Tests for new features in C++14 + +m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_14], [[ + +// If the compiler admits that it is not ready for C++14, why torture it? +// Hopefully, this will speed up the test. + +#ifndef __cplusplus + +#error "This is not a C++ compiler" + +#elif __cplusplus < 201402L + +#error "This is not a C++14 compiler" + +#else + +namespace cxx14 +{ + + namespace test_polymorphic_lambdas + { + + int + test() + { + const auto lambda = [](auto&&... args){ + const auto istiny = [](auto x){ + return (sizeof(x) == 1UL) ? 1 : 0; + }; + const int aretiny[] = { istiny(args)... }; + return aretiny[0]; + }; + return lambda(1, 1L, 1.0f, '1'); + } + + } + + namespace test_binary_literals + { + + constexpr auto ivii = 0b0000000000101010; + static_assert(ivii == 42, "wrong value"); + + } + + namespace test_generalized_constexpr + { + + template < typename CharT > + constexpr unsigned long + strlen_c(const CharT *const s) noexcept + { + auto length = 0UL; + for (auto p = s; *p; ++p) + ++length; + return length; + } + + static_assert(strlen_c("") == 0UL, ""); + static_assert(strlen_c("x") == 1UL, ""); + static_assert(strlen_c("test") == 4UL, ""); + static_assert(strlen_c("another\0test") == 7UL, ""); + + } + + namespace test_lambda_init_capture + { + + int + test() + { + auto x = 0; + const auto lambda1 = [a = x](int b){ return a + b; }; + const auto lambda2 = [a = lambda1(x)](){ return a; }; + return lambda2(); + } + + } + + namespace test_digit_seperators + { + + constexpr auto ten_million = 100'000'000; + static_assert(ten_million == 100000000, ""); + + } + + namespace test_return_type_deduction + { + + auto f(int& x) { return x; } + decltype(auto) g(int& x) { return x; } + + template < typename T1, typename T2 > + struct is_same + { + static constexpr auto value = false; + }; + + template < typename T > + struct is_same + { + static constexpr auto value = true; + }; + + int + test() + { + auto x = 0; + static_assert(is_same::value, ""); + static_assert(is_same::value, ""); + return x; + } + + } + +} // namespace cxx14 + +#endif // __cplusplus >= 201402L + +]]) \ No newline at end of file diff --git a/m4/ax_cxx_compile_stdcxx_11.m4 b/m4/ax_cxx_compile_stdcxx_11.m4 new file mode 100644 index 0000000..09db383 --- /dev/null +++ b/m4/ax_cxx_compile_stdcxx_11.m4 @@ -0,0 +1,39 @@ +# ============================================================================ +# http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html +# ============================================================================ +# +# SYNOPSIS +# +# AX_CXX_COMPILE_STDCXX_11([ext|noext], [mandatory|optional]) +# +# DESCRIPTION +# +# Check for baseline language coverage in the compiler for the C++11 +# standard; if necessary, add switches to CXXFLAGS to enable support. +# +# This macro is a convenience alias for calling the AX_CXX_COMPILE_STDCXX +# macro with the version set to C++11. The two optional arguments are +# forwarded literally as the second and third argument respectively. +# Please see the documentation for the AX_CXX_COMPILE_STDCXX macro for +# more information. If you want to use this macro, you also need to +# download the ax_cxx_compile_stdcxx.m4 file. +# +# LICENSE +# +# Copyright (c) 2008 Benjamin Kosnik +# Copyright (c) 2012 Zack Weinberg +# Copyright (c) 2013 Roy Stogner +# Copyright (c) 2014, 2015 Google Inc.; contributed by Alexey Sokolov +# Copyright (c) 2015 Paul Norman +# Copyright (c) 2015 Moritz Klammler +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 14 + +include([ax_cxx_compile_stdcxx.m4]) + +AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [AX_CXX_COMPILE_STDCXX([11], [$1], [$2])]) From 0a99a9a5c9d1bd48f4efc0f31ac0c82eaffa6651 Mon Sep 17 00:00:00 2001 From: Austin Gilbert Date: Mon, 8 Feb 2016 21:54:58 -0600 Subject: [PATCH 17/79] Correcting RequiredCheckArrayCloseDoesNotHaveSideEffectsWhenPassing to exercise the passing case (per the UT name). --- tests/TestRequireMacrosWithExceptionsOn.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/tests/TestRequireMacrosWithExceptionsOn.cpp b/tests/TestRequireMacrosWithExceptionsOn.cpp index 6b76004..f904708 100644 --- a/tests/TestRequireMacrosWithExceptionsOn.cpp +++ b/tests/TestRequireMacrosWithExceptionsOn.cpp @@ -646,14 +646,9 @@ namespace { UnitTest::TestResults testResults; ScopedCurrentTest scopedResults(testResults); - const float data[] = { 0, 1, 2, 3 }; + const float data[] = { 1, 2, 3, 4 }; - try - { - REQUIRE CHECK_ARRAY_CLOSE (data, FunctionWithSideEffects2(), 4, 0.01f); - } - catch (const UnitTest::RequiredCheckException&) - {} + REQUIRE CHECK_ARRAY_CLOSE (data, FunctionWithSideEffects2(), 4, 0.01f); } CHECK_EQUAL(1, g_sideEffect); } From 962387ce5d275f1d7dc920796239ae07e7b2a441 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Tue, 23 Feb 2016 21:11:19 -0600 Subject: [PATCH 18/79] Update autotools for new source files. --- UnitTest++/Makefile.am | 4 ++-- tests/Makefile.am | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/UnitTest++/Makefile.am b/UnitTest++/Makefile.am index 32f6477..a512fca 100644 --- a/UnitTest++/Makefile.am +++ b/UnitTest++/Makefile.am @@ -1,7 +1,7 @@ lib_LTLIBRARIES = UnitTest++/libUnitTest++.la pkgincludedir = $(includedir)/UnitTest++/ -nobase_pkginclude_HEADERS = UnitTest++/UnitTest++.h UnitTest++/UnitTestPP.h UnitTest++/Config.h UnitTest++/HelperMacros.h UnitTest++/Test.h UnitTest++/TestDetails.h UnitTest++/TestList.h UnitTest++/TestSuite.h UnitTest++/TestResults.h UnitTest++/TestMacros.h UnitTest++/CheckMacros.h UnitTest++/TestRunner.h UnitTest++/TimeConstraint.h UnitTest++/ExecuteTest.h UnitTest++/AssertException.h UnitTest++/MemoryOutStream.h UnitTest++/CurrentTest.h UnitTest++/Checks.h UnitTest++/TimeHelpers.h UnitTest++/ExceptionMacros.h UnitTest++/ReportAssert.h UnitTest++/ReportAssertImpl.h UnitTest++/TestReporter.h UnitTest++/TestReporterStdout.h UnitTest++/CompositeTestReporter.h UnitTest++/DeferredTestReporter.h UnitTest++/DeferredTestResult.h -UnitTest___libUnitTest___la_SOURCES = UnitTest++/AssertException.cpp UnitTest++/Test.cpp UnitTest++/Checks.cpp UnitTest++/TestRunner.cpp UnitTest++/TestResults.cpp UnitTest++/TestReporter.cpp UnitTest++/TestReporterStdout.cpp UnitTest++/ReportAssert.cpp UnitTest++/TestList.cpp UnitTest++/TimeConstraint.cpp UnitTest++/TestDetails.cpp UnitTest++/MemoryOutStream.cpp UnitTest++/DeferredTestReporter.cpp UnitTest++/DeferredTestResult.cpp UnitTest++/XmlTestReporter.cpp UnitTest++/CurrentTest.cpp UnitTest++/CompositeTestReporter.cpp +nobase_pkginclude_HEADERS = UnitTest++/AssertException.h UnitTest++/CheckMacros.h UnitTest++/Checks.h UnitTest++/CompositeTestReporter.h UnitTest++/Config.h UnitTest++/CurrentTest.h UnitTest++/DeferredTestReporter.h UnitTest++/DeferredTestResult.h UnitTest++/ExceptionMacros.h UnitTest++/ExecuteTest.h UnitTest++/HelperMacros.h UnitTest++/MemoryOutStream.h UnitTest++/ReportAssert.h UnitTest++/ReportAssertImpl.h UnitTest++/RequireMacros.h UnitTest++/RequiredCheckException.h UnitTest++/RequiredCheckTestReporter.h UnitTest++/Test.h UnitTest++/TestDetails.h UnitTest++/TestList.h UnitTest++/TestMacros.h UnitTest++/TestReporter.h UnitTest++/TestReporterStdout.h UnitTest++/TestResults.h UnitTest++/TestRunner.h UnitTest++/TestSuite.h UnitTest++/ThrowingTestReporter.h UnitTest++/TimeConstraint.h UnitTest++/TimeHelpers.h UnitTest++/UnitTest++.h UnitTest++/UnitTestPP.h UnitTest++/XmlTestReporter.h +UnitTest___libUnitTest___la_SOURCES = UnitTest++/AssertException.cpp UnitTest++/Checks.cpp UnitTest++/CompositeTestReporter.cpp UnitTest++/CurrentTest.cpp UnitTest++/DeferredTestReporter.cpp UnitTest++/DeferredTestResult.cpp UnitTest++/MemoryOutStream.cpp UnitTest++/ReportAssert.cpp UnitTest++/RequiredCheckException.cpp UnitTest++/RequiredCheckTestReporter.cpp UnitTest++/Test.cpp UnitTest++/TestDetails.cpp UnitTest++/TestList.cpp UnitTest++/TestReporter.cpp UnitTest++/TestReporterStdout.cpp UnitTest++/TestResults.cpp UnitTest++/TestRunner.cpp UnitTest++/ThrowingTestReporter.cpp UnitTest++/TimeConstraint.cpp UnitTest++/XmlTestReporter.cpp if WINDOWS nobase_pkginclude_HEADERS += UnitTest++/Win32/TimeHelpers.h diff --git a/tests/Makefile.am b/tests/Makefile.am index 5306292..fe7cffd 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,4 +1,4 @@ check_PROGRAMS = UnitTest++/TestUnitTest++ -UnitTest___TestUnitTest___SOURCES = tests/Main.cpp tests/TestAssertHandler.cpp tests/TestCheckMacros.cpp tests/TestChecks.cpp tests/TestCompositeTestReporter.cpp tests/TestCurrentTest.cpp tests/TestDeferredTestReporter.cpp tests/TestExceptions.cpp tests/TestMemoryOutStream.cpp tests/TestTest.cpp tests/TestTestList.cpp tests/TestTestMacros.cpp tests/TestTestResults.cpp tests/TestTestRunner.cpp tests/TestTestSuite.cpp tests/TestTimeConstraint.cpp tests/TestTimeConstraintMacro.cpp tests/TestUnitTestPP.cpp tests/TestXmlTestReporter.cpp +UnitTest___TestUnitTest___SOURCES = tests/Main.cpp tests/TestAssertHandler.cpp tests/TestCheckMacros.cpp tests/TestChecks.cpp tests/TestCompositeTestReporter.cpp tests/TestCurrentTest.cpp tests/TestDeferredTestReporter.cpp tests/TestExceptions.cpp tests/TestMemoryOutStream.cpp tests/TestRequireMacros.cpp tests/TestTest.cpp tests/TestTestList.cpp tests/TestTestMacros.cpp tests/TestTestResults.cpp tests/TestTestRunner.cpp tests/TestTestSuite.cpp tests/TestTimeConstraint.cpp tests/TestTimeConstraintMacro.cpp tests/TestUnitTestPP.cpp tests/TestXmlTestReporter.cpp UnitTest___TestUnitTest___LDADD = UnitTest++/libUnitTest++.la TESTS = UnitTest++/TestUnitTest++ From 898f18d799ecb2cf335c6070183e72f3ee59d79b Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Tue, 23 Feb 2016 21:44:25 -0600 Subject: [PATCH 19/79] Enable C++11 support in autoconf --- configure.ac | 2 + m4/ax_cxx_compile_stdcxx.m4 | 558 +++++++++++++++++++++++++++++++++ m4/ax_cxx_compile_stdcxx_11.m4 | 39 +++ 3 files changed, 599 insertions(+) create mode 100644 m4/ax_cxx_compile_stdcxx.m4 create mode 100644 m4/ax_cxx_compile_stdcxx_11.m4 diff --git a/configure.ac b/configure.ac index 7b77b73..46e3be6 100644 --- a/configure.ac +++ b/configure.ac @@ -19,6 +19,8 @@ AC_SUBST([LIBUNITTEST_SO_VERSION], [1:5:1]) AC_PROG_CXX AC_PROG_CC +AX_CXX_COMPILE_STDCXX_11(noext, optional) + # Checks for libraries. # Checks for header files. diff --git a/m4/ax_cxx_compile_stdcxx.m4 b/m4/ax_cxx_compile_stdcxx.m4 new file mode 100644 index 0000000..66d41f5 --- /dev/null +++ b/m4/ax_cxx_compile_stdcxx.m4 @@ -0,0 +1,558 @@ +# =========================================================================== +# http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_CXX_COMPILE_STDCXX(VERSION, [ext|noext], [mandatory|optional]) +# +# DESCRIPTION +# +# Check for baseline language coverage in the compiler for the specified +# version of the C++ standard. If necessary, add switches to CXXFLAGS to +# enable support. VERSION may be '11' (for the C++11 standard) or '14' +# (for the C++14 standard). +# +# The second argument, if specified, indicates whether you insist on an +# extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g. +# -std=c++11). If neither is specified, you get whatever works, with +# preference for an extended mode. +# +# The third argument, if specified 'mandatory' or if left unspecified, +# indicates that baseline support for the specified C++ standard is +# required and that the macro should error out if no mode with that +# support is found. If specified 'optional', then configuration proceeds +# regardless, after defining HAVE_CXX${VERSION} if and only if a +# supporting mode is found. +# +# LICENSE +# +# Copyright (c) 2008 Benjamin Kosnik +# Copyright (c) 2012 Zack Weinberg +# Copyright (c) 2013 Roy Stogner +# Copyright (c) 2014, 2015 Google Inc.; contributed by Alexey Sokolov +# Copyright (c) 2015 Paul Norman +# Copyright (c) 2015 Moritz Klammler +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 1 + +dnl This macro is based on the code from the AX_CXX_COMPILE_STDCXX_11 macro +dnl (serial version number 13). + +AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl + m4_if([$1], [11], [], + [$1], [14], [], + [$1], [17], [m4_fatal([support for C++17 not yet implemented in AX_CXX_COMPILE_STDCXX])], + [m4_fatal([invalid first argument `$1' to AX_CXX_COMPILE_STDCXX])])dnl + m4_if([$2], [], [], + [$2], [ext], [], + [$2], [noext], [], + [m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX])])dnl + m4_if([$3], [], [ax_cxx_compile_cxx$1_required=true], + [$3], [mandatory], [ax_cxx_compile_cxx$1_required=true], + [$3], [optional], [ax_cxx_compile_cxx$1_required=false], + [m4_fatal([invalid third argument `$3' to AX_CXX_COMPILE_STDCXX])]) + AC_LANG_PUSH([C++])dnl + ac_success=no + AC_CACHE_CHECK(whether $CXX supports C++$1 features by default, + ax_cv_cxx_compile_cxx$1, + [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])], + [ax_cv_cxx_compile_cxx$1=yes], + [ax_cv_cxx_compile_cxx$1=no])]) + if test x$ax_cv_cxx_compile_cxx$1 = xyes; then + ac_success=yes + fi + + m4_if([$2], [noext], [], [dnl + if test x$ac_success = xno; then + for switch in -std=gnu++$1 -std=gnu++0x; do + cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch]) + AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch, + $cachevar, + [ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS $switch" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])], + [eval $cachevar=yes], + [eval $cachevar=no]) + CXXFLAGS="$ac_save_CXXFLAGS"]) + if eval test x\$$cachevar = xyes; then + CXXFLAGS="$CXXFLAGS $switch" + ac_success=yes + break + fi + done + fi]) + + m4_if([$2], [ext], [], [dnl + if test x$ac_success = xno; then + dnl HP's aCC needs +std=c++11 according to: + dnl http://h21007.www2.hp.com/portal/download/files/unprot/aCxx/PDF_Release_Notes/769149-001.pdf + dnl Cray's crayCC needs "-h std=c++11" + for switch in -std=c++$1 -std=c++0x +std=c++$1 "-h std=c++$1"; do + cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch]) + AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch, + $cachevar, + [ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS $switch" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])], + [eval $cachevar=yes], + [eval $cachevar=no]) + CXXFLAGS="$ac_save_CXXFLAGS"]) + if eval test x\$$cachevar = xyes; then + CXXFLAGS="$CXXFLAGS $switch" + ac_success=yes + break + fi + done + fi]) + AC_LANG_POP([C++]) + if test x$ax_cxx_compile_cxx$1_required = xtrue; then + if test x$ac_success = xno; then + AC_MSG_ERROR([*** A compiler with support for C++$1 language features is required.]) + fi + else + if test x$ac_success = xno; then + HAVE_CXX$1=0 + AC_MSG_NOTICE([No compiler with C++$1 support was found]) + else + HAVE_CXX$1=1 + AC_DEFINE(HAVE_CXX$1,1, + [define if the compiler supports basic C++$1 syntax]) + fi + + AC_SUBST(HAVE_CXX$1) + fi +]) + + +dnl Test body for checking C++11 support + +m4_define([_AX_CXX_COMPILE_STDCXX_testbody_11], + _AX_CXX_COMPILE_STDCXX_testbody_new_in_11 +) + + +dnl Test body for checking C++14 support + +m4_define([_AX_CXX_COMPILE_STDCXX_testbody_14], + _AX_CXX_COMPILE_STDCXX_testbody_new_in_11 + _AX_CXX_COMPILE_STDCXX_testbody_new_in_14 +) + + +dnl Tests for new features in C++11 + +m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_11], [[ + +// If the compiler admits that it is not ready for C++11, why torture it? +// Hopefully, this will speed up the test. + +#ifndef __cplusplus + +#error "This is not a C++ compiler" + +#elif __cplusplus < 201103L + +#error "This is not a C++11 compiler" + +#else + +namespace cxx11 +{ + + namespace test_static_assert + { + + template + struct check + { + static_assert(sizeof(int) <= sizeof(T), "not big enough"); + }; + + } + + namespace test_final_override + { + + struct Base + { + virtual void f() {} + }; + + struct Derived : public Base + { + virtual void f() override {} + }; + + } + + namespace test_double_right_angle_brackets + { + + template < typename T > + struct check {}; + + typedef check single_type; + typedef check> double_type; + typedef check>> triple_type; + typedef check>>> quadruple_type; + + } + + namespace test_decltype + { + + int + f() + { + int a = 1; + decltype(a) b = 2; + return a + b; + } + + } + + namespace test_type_deduction + { + + template < typename T1, typename T2 > + struct is_same + { + static const bool value = false; + }; + + template < typename T > + struct is_same + { + static const bool value = true; + }; + + template < typename T1, typename T2 > + auto + add(T1 a1, T2 a2) -> decltype(a1 + a2) + { + return a1 + a2; + } + + int + test(const int c, volatile int v) + { + static_assert(is_same::value == true, ""); + static_assert(is_same::value == false, ""); + static_assert(is_same::value == false, ""); + auto ac = c; + auto av = v; + auto sumi = ac + av + 'x'; + auto sumf = ac + av + 1.0; + static_assert(is_same::value == true, ""); + static_assert(is_same::value == true, ""); + static_assert(is_same::value == true, ""); + static_assert(is_same::value == false, ""); + static_assert(is_same::value == true, ""); + return (sumf > 0.0) ? sumi : add(c, v); + } + + } + + namespace test_noexcept + { + + int f() { return 0; } + int g() noexcept { return 0; } + + static_assert(noexcept(f()) == false, ""); + static_assert(noexcept(g()) == true, ""); + + } + + namespace test_constexpr + { + + template < typename CharT > + unsigned long constexpr + strlen_c_r(const CharT *const s, const unsigned long acc) noexcept + { + return *s ? strlen_c_r(s + 1, acc + 1) : acc; + } + + template < typename CharT > + unsigned long constexpr + strlen_c(const CharT *const s) noexcept + { + return strlen_c_r(s, 0UL); + } + + static_assert(strlen_c("") == 0UL, ""); + static_assert(strlen_c("1") == 1UL, ""); + static_assert(strlen_c("example") == 7UL, ""); + static_assert(strlen_c("another\0example") == 7UL, ""); + + } + + namespace test_rvalue_references + { + + template < int N > + struct answer + { + static constexpr int value = N; + }; + + answer<1> f(int&) { return answer<1>(); } + answer<2> f(const int&) { return answer<2>(); } + answer<3> f(int&&) { return answer<3>(); } + + void + test() + { + int i = 0; + const int c = 0; + static_assert(decltype(f(i))::value == 1, ""); + static_assert(decltype(f(c))::value == 2, ""); + static_assert(decltype(f(0))::value == 3, ""); + } + + } + + namespace test_uniform_initialization + { + + struct test + { + static const int zero {}; + static const int one {1}; + }; + + static_assert(test::zero == 0, ""); + static_assert(test::one == 1, ""); + + } + + namespace test_lambdas + { + + void + test1() + { + auto lambda1 = [](){}; + auto lambda2 = lambda1; + lambda1(); + lambda2(); + } + + int + test2() + { + auto a = [](int i, int j){ return i + j; }(1, 2); + auto b = []() -> int { return '0'; }(); + auto c = [=](){ return a + b; }(); + auto d = [&](){ return c; }(); + auto e = [a, &b](int x) mutable { + const auto identity = [](int y){ return y; }; + for (auto i = 0; i < a; ++i) + a += b--; + return x + identity(a + b); + }(0); + return a + b + c + d + e; + } + + int + test3() + { + const auto nullary = [](){ return 0; }; + const auto unary = [](int x){ return x; }; + using nullary_t = decltype(nullary); + using unary_t = decltype(unary); + const auto higher1st = [](nullary_t f){ return f(); }; + const auto higher2nd = [unary](nullary_t f1){ + return [unary, f1](unary_t f2){ return f2(unary(f1())); }; + }; + return higher1st(nullary) + higher2nd(nullary)(unary); + } + + } + + namespace test_variadic_templates + { + + template + struct sum; + + template + struct sum + { + static constexpr auto value = N0 + sum::value; + }; + + template <> + struct sum<> + { + static constexpr auto value = 0; + }; + + static_assert(sum<>::value == 0, ""); + static_assert(sum<1>::value == 1, ""); + static_assert(sum<23>::value == 23, ""); + static_assert(sum<1, 2>::value == 3, ""); + static_assert(sum<5, 5, 11>::value == 21, ""); + static_assert(sum<2, 3, 5, 7, 11, 13>::value == 41, ""); + + } + + // http://stackoverflow.com/questions/13728184/template-aliases-and-sfinae + // Clang 3.1 fails with headers of libstd++ 4.8.3 when using std::function + // because of this. + namespace test_template_alias_sfinae + { + + struct foo {}; + + template + using member = typename T::member_type; + + template + void func(...) {} + + template + void func(member*) {} + + void test(); + + void test() { func(0); } + + } + +} // namespace cxx11 + +#endif // __cplusplus >= 201103L + +]]) + + +dnl Tests for new features in C++14 + +m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_14], [[ + +// If the compiler admits that it is not ready for C++14, why torture it? +// Hopefully, this will speed up the test. + +#ifndef __cplusplus + +#error "This is not a C++ compiler" + +#elif __cplusplus < 201402L + +#error "This is not a C++14 compiler" + +#else + +namespace cxx14 +{ + + namespace test_polymorphic_lambdas + { + + int + test() + { + const auto lambda = [](auto&&... args){ + const auto istiny = [](auto x){ + return (sizeof(x) == 1UL) ? 1 : 0; + }; + const int aretiny[] = { istiny(args)... }; + return aretiny[0]; + }; + return lambda(1, 1L, 1.0f, '1'); + } + + } + + namespace test_binary_literals + { + + constexpr auto ivii = 0b0000000000101010; + static_assert(ivii == 42, "wrong value"); + + } + + namespace test_generalized_constexpr + { + + template < typename CharT > + constexpr unsigned long + strlen_c(const CharT *const s) noexcept + { + auto length = 0UL; + for (auto p = s; *p; ++p) + ++length; + return length; + } + + static_assert(strlen_c("") == 0UL, ""); + static_assert(strlen_c("x") == 1UL, ""); + static_assert(strlen_c("test") == 4UL, ""); + static_assert(strlen_c("another\0test") == 7UL, ""); + + } + + namespace test_lambda_init_capture + { + + int + test() + { + auto x = 0; + const auto lambda1 = [a = x](int b){ return a + b; }; + const auto lambda2 = [a = lambda1(x)](){ return a; }; + return lambda2(); + } + + } + + namespace test_digit_seperators + { + + constexpr auto ten_million = 100'000'000; + static_assert(ten_million == 100000000, ""); + + } + + namespace test_return_type_deduction + { + + auto f(int& x) { return x; } + decltype(auto) g(int& x) { return x; } + + template < typename T1, typename T2 > + struct is_same + { + static constexpr auto value = false; + }; + + template < typename T > + struct is_same + { + static constexpr auto value = true; + }; + + int + test() + { + auto x = 0; + static_assert(is_same::value, ""); + static_assert(is_same::value, ""); + return x; + } + + } + +} // namespace cxx14 + +#endif // __cplusplus >= 201402L + +]]) \ No newline at end of file diff --git a/m4/ax_cxx_compile_stdcxx_11.m4 b/m4/ax_cxx_compile_stdcxx_11.m4 new file mode 100644 index 0000000..09db383 --- /dev/null +++ b/m4/ax_cxx_compile_stdcxx_11.m4 @@ -0,0 +1,39 @@ +# ============================================================================ +# http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html +# ============================================================================ +# +# SYNOPSIS +# +# AX_CXX_COMPILE_STDCXX_11([ext|noext], [mandatory|optional]) +# +# DESCRIPTION +# +# Check for baseline language coverage in the compiler for the C++11 +# standard; if necessary, add switches to CXXFLAGS to enable support. +# +# This macro is a convenience alias for calling the AX_CXX_COMPILE_STDCXX +# macro with the version set to C++11. The two optional arguments are +# forwarded literally as the second and third argument respectively. +# Please see the documentation for the AX_CXX_COMPILE_STDCXX macro for +# more information. If you want to use this macro, you also need to +# download the ax_cxx_compile_stdcxx.m4 file. +# +# LICENSE +# +# Copyright (c) 2008 Benjamin Kosnik +# Copyright (c) 2012 Zack Weinberg +# Copyright (c) 2013 Roy Stogner +# Copyright (c) 2014, 2015 Google Inc.; contributed by Alexey Sokolov +# Copyright (c) 2015 Paul Norman +# Copyright (c) 2015 Moritz Klammler +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 14 + +include([ax_cxx_compile_stdcxx.m4]) + +AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [AX_CXX_COMPILE_STDCXX([11], [$1], [$2])]) From 5ad8cd86c9cd4b30fb7dc1f926a8861bf34d5659 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Tue, 23 Feb 2016 23:12:40 -0600 Subject: [PATCH 20/79] Add new tests to Makefile.am --- tests/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index fe7cffd..647476e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,4 +1,4 @@ check_PROGRAMS = UnitTest++/TestUnitTest++ -UnitTest___TestUnitTest___SOURCES = tests/Main.cpp tests/TestAssertHandler.cpp tests/TestCheckMacros.cpp tests/TestChecks.cpp tests/TestCompositeTestReporter.cpp tests/TestCurrentTest.cpp tests/TestDeferredTestReporter.cpp tests/TestExceptions.cpp tests/TestMemoryOutStream.cpp tests/TestRequireMacros.cpp tests/TestTest.cpp tests/TestTestList.cpp tests/TestTestMacros.cpp tests/TestTestResults.cpp tests/TestTestRunner.cpp tests/TestTestSuite.cpp tests/TestTimeConstraint.cpp tests/TestTimeConstraintMacro.cpp tests/TestUnitTestPP.cpp tests/TestXmlTestReporter.cpp +UnitTest___TestUnitTest___SOURCES = tests/Main.cpp tests/TestAssertHandler.cpp tests/TestCheckMacros.cpp tests/TestChecks.cpp tests/TestCompositeTestReporter.cpp tests/TestCurrentTest.cpp tests/TestDeferredTestReporter.cpp tests/TestExceptions.cpp tests/TestMemoryOutStream.cpp tests/TestRequireMacrosWithExceptionsOff.cpp tests/TestRequireMacrosWithExceptionsOn.cpp tests/TestTest.cpp tests/TestTestList.cpp tests/TestTestMacros.cpp tests/TestTestResults.cpp tests/TestTestRunner.cpp tests/TestTestSuite.cpp tests/TestTimeConstraint.cpp tests/TestTimeConstraintMacro.cpp tests/TestUnitTestPP.cpp tests/TestXmlTestReporter.cpp UnitTest___TestUnitTest___LDADD = UnitTest++/libUnitTest++.la TESTS = UnitTest++/TestUnitTest++ From 6c78c6ea2b1f4d9c9e7b0addcb3672b27d57bc67 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Tue, 23 Feb 2016 23:45:52 -0600 Subject: [PATCH 21/79] Add more compilers to appveyor config --- appveyor.yml | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index c36218a..e7b1cfb 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,10 +1,26 @@ +version: 1.6.0.{build} + os: - Windows Server 2012 R2 -install: +environment: + matrix: + + - CMAKE_GENERATOR: Visual Studio 9 + BUILD_FOLDER: 'vs2008' + - CMAKE_GENERATOR: Visual Studio 10 + BUILD_FOLDER: 'vs2010' + - CMAKE_GENERATOR: Visual Studio 11 + BUILD_FOLDER: 'vs2012' + - CMAKE_GENERATOR: Visual Studio 12 + BUILD_FOLDER: 'vs2013' + - CMAKE_GENERATOR: Visual Studio 14 + BUILD_FOLDER: 'vs2015' + +before_build: # Generate solution files using cmake, in 'builds' directory. # No need to create it because it's part of the repo. - - cd builds && cmake -G "Visual Studio 12" ../ && cd .. + - mkdir builds\%BUILD_FOLDER% && cd builds\%BUILD_FOLDER% && cmake -G %CMAKE_GENERATOR% ..\..\ && cd ..\.. configuration: - Debug From 5908e00efbc1d6879eea56f17f298e0caee862d1 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Tue, 23 Feb 2016 23:49:15 -0600 Subject: [PATCH 22/79] Add forgotten quotes around CMAKE_GENERATOR --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index e7b1cfb..5ed1f2b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -20,7 +20,7 @@ environment: before_build: # Generate solution files using cmake, in 'builds' directory. # No need to create it because it's part of the repo. - - mkdir builds\%BUILD_FOLDER% && cd builds\%BUILD_FOLDER% && cmake -G %CMAKE_GENERATOR% ..\..\ && cd ..\.. + - mkdir builds\%BUILD_FOLDER% && cd builds\%BUILD_FOLDER% && cmake -G "%CMAKE_GENERATOR%" ..\..\ && cd ..\.. configuration: - Debug From 8080a0c798512f398bbca85cb66ff9de9af93f6c Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Tue, 23 Feb 2016 23:54:50 -0600 Subject: [PATCH 23/79] Fix CMAKE_GENERATOR values --- appveyor.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 5ed1f2b..a34d3b0 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -6,21 +6,16 @@ os: environment: matrix: - - CMAKE_GENERATOR: Visual Studio 9 - BUILD_FOLDER: 'vs2008' - - CMAKE_GENERATOR: Visual Studio 10 - BUILD_FOLDER: 'vs2010' - - CMAKE_GENERATOR: Visual Studio 11 - BUILD_FOLDER: 'vs2012' - - CMAKE_GENERATOR: Visual Studio 12 - BUILD_FOLDER: 'vs2013' - - CMAKE_GENERATOR: Visual Studio 14 - BUILD_FOLDER: 'vs2015' + - CMAKE_GENERATOR: Visual Studio 9 2008 + - CMAKE_GENERATOR: Visual Studio 10 2010 + - CMAKE_GENERATOR: Visual Studio 11 2012 + - CMAKE_GENERATOR: Visual Studio 12 2013 + - CMAKE_GENERATOR: Visual Studio 14 2015 before_build: # Generate solution files using cmake, in 'builds' directory. # No need to create it because it's part of the repo. - - mkdir builds\%BUILD_FOLDER% && cd builds\%BUILD_FOLDER% && cmake -G "%CMAKE_GENERATOR%" ..\..\ && cd ..\.. + - pushd builds && cmake -G "%CMAKE_GENERATOR%" ..\ && popd configuration: - Debug @@ -28,3 +23,8 @@ configuration: build: project: builds/UnitTest++.sln + +matrix: + fast_finish: true + + From 6ce4bbe8d916d55e5fd57f69bf08b34693834072 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Tue, 23 Feb 2016 23:59:31 -0600 Subject: [PATCH 24/79] Use build_script instead of build for appveyor Using build_script to run cmake --build fixes issues with msbuild not always finding the correct file formats, etc. --- appveyor.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index a34d3b0..28dc4fc 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -21,8 +21,8 @@ configuration: - Debug - Release -build: - project: builds/UnitTest++.sln +build_script: + - pushd builds && cmake --build . && popd matrix: fast_finish: true From b69b63ac2bf4a967b35e853026abb68b3f8442ad Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Mon, 29 Feb 2016 22:32:58 -0600 Subject: [PATCH 25/79] Update docs, versions for 1.6.0. --- .gitmodules | 1 + README.md | 14 +++++++++----- configure.ac | 4 ++-- docs | 2 +- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/.gitmodules b/.gitmodules index d3c2970..58e923a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,4 @@ [submodule "docs"] path = docs url = https://github.com/unittest-cpp/unittest-cpp.wiki.git + ignore = dirty \ No newline at end of file diff --git a/README.md b/README.md index be3573f..cf88fea 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ UnitTest++ =========== -UnitTest++ is a lightweight unit testing framework for C++. It was designed to do test-driven development on a wide variety of platforms. Simplicity, portability, speed, and small footprint are all very important aspects of UnitTest++. UnitTest++ is ANSI portable C++ and makes minimal use of advanced library and languages features, which means it should be easily portable to just about any platform. Out of the box, the following platforms are supported: +UnitTest++ is a lightweight unit testing framework for C++. It was designed to do test-driven development on a wide variety of platforms. Simplicity, portability, speed, and small footprint are all very important aspects of UnitTest++. UnitTest++ is mostly standard C++ and makes minimal use of advanced library and language features, which means it should be easily portable to just about any platform. Out of the box, the following platforms are supported: * Windows * Linux @@ -16,7 +16,7 @@ The full documentation for building and using UnitTest++ can be found on the [Gi Pre-requisites --------------- -While there are currently some bundled makefiles and projects, UnitTest++ is primarily built and supported using [CMake](http://cmake.org). +While there are currently some bundled automake files, UnitTest++ is primarily built and supported using [CMake](http://cmake.org). Downloading ------------ @@ -30,17 +30,17 @@ Via svn: svn checkout https://github.com/unittest-cpp/unittest-cpp/trunk unittest-cpp -### Latest release (v1.5.1) ### +### Latest release (v1.6.0) ### Via git: git clone https://github.com/unittest-cpp/unittest-cpp cd unittest-cpp - git checkout v1.5.1 + git checkout v1.6.0 Via svn: - svn checkout https://github.com/unittest-cpp/unittest-cpp/tags/v1.5.1 unittest-cpp + svn checkout https://github.com/unittest-cpp/unittest-cpp/tags/v1.6.0 unittest-cpp License --------- @@ -77,6 +77,10 @@ Contributors Historic release notes ---------------------- +### Version 1.6.0 (2016-02-29) ### +- Add REQUIRE macro to end tests early when selected checks fail +- [Full List](https://github.com/unittest-cpp/unittest-cpp/issues?q=milestone%3A1.6.0+) + ### Version 1.5.1 (2016-01-30) ### - pkg-config support - Fix for Visual Studio 2010 compilation issue in 1.5.0 diff --git a/configure.ac b/configure.ac index 46e3be6..001ced8 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ([2.69]) -AC_INIT([UnitTest++], [1.5.1], [pjohnmeyer@gmail.com]) +AC_INIT([UnitTest++], [1.6.0], [pjohnmeyer@gmail.com]) AC_CONFIG_SRCDIR([UnitTest++/TestDetails.cpp]) AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_HEADERS([config.h]) @@ -13,7 +13,7 @@ AM_CONDITIONAL([WINDOWS], [test "${host#*mingw}" != "${host}" -o "${host#*msvc}" != "${host}"]) LT_INIT() -AC_SUBST([LIBUNITTEST_SO_VERSION], [1:5:1]) +AC_SUBST([LIBUNITTEST_SO_VERSION], [1:6:0]) # Checks for programs. AC_PROG_CXX diff --git a/docs b/docs index 8d4ad23..14495a3 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 8d4ad2348f13d35ed7af7c11d6dad2f5ed67f6b4 +Subproject commit 14495a3a81568e9ce187231b629e4eb7bc7e0350 From e88121f69e1b4bf36e9d72b129f27ee7b1ed6fdb Mon Sep 17 00:00:00 2001 From: Jason Horsburgh Date: Tue, 15 Mar 2016 12:14:19 +0000 Subject: [PATCH 26/79] Add support for CMake find_package() Added export configuration for UnitTest++ target and installed the export and config file in libs/cmake/UnitTest++. Added basic UnitTest++Config.cmake file which includes exported targets file and sets UTPP_INCLUDE_DIRS to the install location of the includes directory, this allows UnitTest++ to be used as a normal target in your own CMakeLists.txt file. e.g.: find_package(UnitTest++ REQUIRED NO_MODULE) add_executable(foo ...) include_directories(${UTPP_INCLUDE_DIRS}) target_link_libraries(foo UnitTest++) which will ensure the library and installed headers paths are set up correctly for your own target. --- CMakeLists.txt | 9 +++++++-- cmake/UnitTest++Config.cmake | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 cmake/UnitTest++Config.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index c573ef9..ea7cf24 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,6 +69,11 @@ else() set (UTPP_INSTALL_DESTINATION "include/UnitTestPP") endif() -install(TARGETS UnitTest++ DESTINATION lib) +set(config_install_dir_ lib/cmake/${PROJECT_NAME}) +set(targets_export_name_ "${PROJECT_NAME}Targets") + +install(TARGETS UnitTest++ EXPORT "${targets_export_name_}" DESTINATION lib) install(FILES ${headers_} DESTINATION ${UTPP_INSTALL_DESTINATION}) -install(FILES ${platformHeaders_} DESTINATION ${UTPP_INSTALL_DESTINATION}/${platformDir_}) \ No newline at end of file +install(FILES ${platformHeaders_} DESTINATION ${UTPP_INSTALL_DESTINATION}/${platformDir_}) +install(FILES cmake/UnitTest++Config.cmake DESTINATION "${config_install_dir_}") +install(EXPORT "${targets_export_name_}" DESTINATION "${config_install_dir_}") diff --git a/cmake/UnitTest++Config.cmake b/cmake/UnitTest++Config.cmake new file mode 100644 index 0000000..afe165c --- /dev/null +++ b/cmake/UnitTest++Config.cmake @@ -0,0 +1,2 @@ +include("${CMAKE_CURRENT_LIST_DIR}/UnitTest++Targets.cmake") +get_filename_component(UTPP_INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}/../../../include/" ABSOLUTE) From 8544b5b6bee4c80000b400642d6527c84fba2011 Mon Sep 17 00:00:00 2001 From: Saul Beniquez Date: Thu, 7 Apr 2016 14:55:53 -0400 Subject: [PATCH 27/79] Fix for #105 - Automake improvements: fixing pkgincludedir. --- UnitTest++/Makefile.am | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/UnitTest++/Makefile.am b/UnitTest++/Makefile.am index a512fca..62e246f 100644 --- a/UnitTest++/Makefile.am +++ b/UnitTest++/Makefile.am @@ -1,12 +1,13 @@ lib_LTLIBRARIES = UnitTest++/libUnitTest++.la -pkgincludedir = $(includedir)/UnitTest++/ +pkgincludedir = $(includedir) + nobase_pkginclude_HEADERS = UnitTest++/AssertException.h UnitTest++/CheckMacros.h UnitTest++/Checks.h UnitTest++/CompositeTestReporter.h UnitTest++/Config.h UnitTest++/CurrentTest.h UnitTest++/DeferredTestReporter.h UnitTest++/DeferredTestResult.h UnitTest++/ExceptionMacros.h UnitTest++/ExecuteTest.h UnitTest++/HelperMacros.h UnitTest++/MemoryOutStream.h UnitTest++/ReportAssert.h UnitTest++/ReportAssertImpl.h UnitTest++/RequireMacros.h UnitTest++/RequiredCheckException.h UnitTest++/RequiredCheckTestReporter.h UnitTest++/Test.h UnitTest++/TestDetails.h UnitTest++/TestList.h UnitTest++/TestMacros.h UnitTest++/TestReporter.h UnitTest++/TestReporterStdout.h UnitTest++/TestResults.h UnitTest++/TestRunner.h UnitTest++/TestSuite.h UnitTest++/ThrowingTestReporter.h UnitTest++/TimeConstraint.h UnitTest++/TimeHelpers.h UnitTest++/UnitTest++.h UnitTest++/UnitTestPP.h UnitTest++/XmlTestReporter.h UnitTest___libUnitTest___la_SOURCES = UnitTest++/AssertException.cpp UnitTest++/Checks.cpp UnitTest++/CompositeTestReporter.cpp UnitTest++/CurrentTest.cpp UnitTest++/DeferredTestReporter.cpp UnitTest++/DeferredTestResult.cpp UnitTest++/MemoryOutStream.cpp UnitTest++/ReportAssert.cpp UnitTest++/RequiredCheckException.cpp UnitTest++/RequiredCheckTestReporter.cpp UnitTest++/Test.cpp UnitTest++/TestDetails.cpp UnitTest++/TestList.cpp UnitTest++/TestReporter.cpp UnitTest++/TestReporterStdout.cpp UnitTest++/TestResults.cpp UnitTest++/TestRunner.cpp UnitTest++/ThrowingTestReporter.cpp UnitTest++/TimeConstraint.cpp UnitTest++/XmlTestReporter.cpp -if WINDOWS +if WINDOWS nobase_pkginclude_HEADERS += UnitTest++/Win32/TimeHelpers.h UnitTest___libUnitTest___la_SOURCES += UnitTest++/Win32/TimeHelpers.cpp -else +else nobase_pkginclude_HEADERS += UnitTest++/Posix/SignalTranslator.h UnitTest++/Posix/TimeHelpers.h UnitTest___libUnitTest___la_SOURCES += UnitTest++/Posix/SignalTranslator.cpp UnitTest++/Posix/TimeHelpers.cpp endif From 80d6bf7568beb707861f6e1929399a1b57ca4d11 Mon Sep 17 00:00:00 2001 From: Saul Beniquez Date: Thu, 7 Apr 2016 14:56:31 -0400 Subject: [PATCH 28/79] Better native OS detection using AC_CANONICAL_HOST. More information here: https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Canonicalizing.html --- configure.ac | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 001ced8..df63ac9 100644 --- a/configure.ac +++ b/configure.ac @@ -9,8 +9,14 @@ AC_CONFIG_HEADERS([config.h]) AC_CONFIG_FILES([UnitTest++.pc]) AM_INIT_AUTOMAKE([foreign subdir-objects]) + +AC_CANONICAL_HOST + +dnl Detect OS and set automake variables +dnl Always the red-headed stepchild... AM_CONDITIONAL([WINDOWS], - [test "${host#*mingw}" != "${host}" -o "${host#*msvc}" != "${host}"]) + [test "${host//mingw/}" != "${host}" -o "${host//msvc/}" != "${host}"]) + LT_INIT() AC_SUBST([LIBUNITTEST_SO_VERSION], [1:6:0]) From 2a806451b1fb99cecff55e48d90a8b80185345ad Mon Sep 17 00:00:00 2001 From: bittwiddler1 Date: Thu, 7 Apr 2016 15:03:34 -0400 Subject: [PATCH 29/79] Comment changes Making the comments more explicative and less opinionated. :) --- configure.ac | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index df63ac9..d833196 100644 --- a/configure.ac +++ b/configure.ac @@ -12,8 +12,7 @@ AM_INIT_AUTOMAKE([foreign subdir-objects]) AC_CANONICAL_HOST -dnl Detect OS and set automake variables -dnl Always the red-headed stepchild... +dnl Detect Windows, as it doesn't implement UNIX signals and requires special code AM_CONDITIONAL([WINDOWS], [test "${host//mingw/}" != "${host}" -o "${host//msvc/}" != "${host}"]) From 451ba1e2bc4715aa93d15d502d6bd11f116e7381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kilian=20K=C3=B6ppchen?= Date: Thu, 14 Apr 2016 15:23:10 +0200 Subject: [PATCH 30/79] Fix spelling of UTPP_USE_PLUS_SIGN option comment. --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c573ef9..3f49660 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 2.8.1) project(UnitTest++) -option(UTPP_USE_PLUS_SIGN "Set this to OFF is you with to use '-cpp' instead of '++' in lib/include paths" ON) +option(UTPP_USE_PLUS_SIGN "Set this to OFF if you wish to use '-cpp' instead of '++' in lib/include paths" ON) if(MSVC14 OR MSVC12) # has the support we need @@ -71,4 +71,4 @@ endif() install(TARGETS UnitTest++ DESTINATION lib) install(FILES ${headers_} DESTINATION ${UTPP_INSTALL_DESTINATION}) -install(FILES ${platformHeaders_} DESTINATION ${UTPP_INSTALL_DESTINATION}/${platformDir_}) \ No newline at end of file +install(FILES ${platformHeaders_} DESTINATION ${UTPP_INSTALL_DESTINATION}/${platformDir_}) From 791c37a9f1b6b51c8bf7448f93e6a20cedf1c861 Mon Sep 17 00:00:00 2001 From: bittwiddler1 Date: Sat, 16 Apr 2016 19:12:21 -0400 Subject: [PATCH 31/79] Enabling silent build rules for automake --- configure.ac | 1 + 1 file changed, 1 insertion(+) diff --git a/configure.ac b/configure.ac index d833196..fbf92c8 100644 --- a/configure.ac +++ b/configure.ac @@ -9,6 +9,7 @@ AC_CONFIG_HEADERS([config.h]) AC_CONFIG_FILES([UnitTest++.pc]) AM_INIT_AUTOMAKE([foreign subdir-objects]) +AM_SILENT_RULES([yes]) AC_CANONICAL_HOST From b7e0d70a63a0b862ec4bce37c14ae11446fc5e42 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Mon, 25 Apr 2016 13:37:31 -0500 Subject: [PATCH 32/79] Fix failures in `make distcheck` --- tests/Makefile.am | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index 647476e..06cc26c 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,4 +1,5 @@ check_PROGRAMS = UnitTest++/TestUnitTest++ -UnitTest___TestUnitTest___SOURCES = tests/Main.cpp tests/TestAssertHandler.cpp tests/TestCheckMacros.cpp tests/TestChecks.cpp tests/TestCompositeTestReporter.cpp tests/TestCurrentTest.cpp tests/TestDeferredTestReporter.cpp tests/TestExceptions.cpp tests/TestMemoryOutStream.cpp tests/TestRequireMacrosWithExceptionsOff.cpp tests/TestRequireMacrosWithExceptionsOn.cpp tests/TestTest.cpp tests/TestTestList.cpp tests/TestTestMacros.cpp tests/TestTestResults.cpp tests/TestTestRunner.cpp tests/TestTestSuite.cpp tests/TestTimeConstraint.cpp tests/TestTimeConstraintMacro.cpp tests/TestUnitTestPP.cpp tests/TestXmlTestReporter.cpp + +UnitTest___TestUnitTest___SOURCES = tests/Main.cpp tests/TestAssertHandler.cpp tests/TestCheckMacros.cpp tests/TestChecks.cpp tests/TestCompositeTestReporter.cpp tests/TestCurrentTest.cpp tests/TestDeferredTestReporter.cpp tests/TestExceptions.cpp tests/TestMemoryOutStream.cpp tests/TestRequireMacrosWithExceptionsOff.cpp tests/TestRequireMacrosWithExceptionsOn.cpp tests/TestTest.cpp tests/TestTestList.cpp tests/TestTestMacros.cpp tests/TestTestResults.cpp tests/TestTestRunner.cpp tests/TestTestSuite.cpp tests/TestTimeConstraint.cpp tests/TestTimeConstraintMacro.cpp tests/TestUnitTestPP.cpp tests/TestXmlTestReporter.cpp tests/RecordingReporter.h tests/ScopedCurrentTest.h UnitTest___TestUnitTest___LDADD = UnitTest++/libUnitTest++.la TESTS = UnitTest++/TestUnitTest++ From 1a62540b790345001fe584b8be05b076a46da403 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Wed, 4 May 2016 21:30:44 -0500 Subject: [PATCH 33/79] Determine autoconf package version from git tags --- configure.ac | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index fbf92c8..6b81131 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,11 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ([2.69]) -AC_INIT([UnitTest++], [1.6.0], [pjohnmeyer@gmail.com]) +AC_INIT([UnitTest++], + m4_esyscmd_s([git describe --tags | cut -c2-]), + [pjohnmeyer@gmail.com], + [unittest-cpp]) + AC_CONFIG_SRCDIR([UnitTest++/TestDetails.cpp]) AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_HEADERS([config.h]) From 782e620fbb6e03bb479eeae012b68b86c06f650f Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Wed, 4 May 2016 21:36:40 -0500 Subject: [PATCH 34/79] Update versions to 1.6.1 --- README.md | 10 +++++----- appveyor.yml | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index cf88fea..8a49c3d 100644 --- a/README.md +++ b/README.md @@ -30,17 +30,17 @@ Via svn: svn checkout https://github.com/unittest-cpp/unittest-cpp/trunk unittest-cpp -### Latest release (v1.6.0) ### +### Latest release (v1.6.1) ### Via git: git clone https://github.com/unittest-cpp/unittest-cpp cd unittest-cpp - git checkout v1.6.0 + git checkout v1.6.1 Via svn: - svn checkout https://github.com/unittest-cpp/unittest-cpp/tags/v1.6.0 unittest-cpp + svn checkout https://github.com/unittest-cpp/unittest-cpp/tags/v1.6.1 unittest-cpp License --------- @@ -58,7 +58,7 @@ Contributors * Charles Nicholson (charles.nicholson@gmail.com) @charlesnicholson ### Original Authors: ### -* Noel Llopis (llopis@convexhull.com) +* Noel Llopis (llopis@convexhull.com) * Charles Nicholson (charles.nicholson@gmail.com) ### Contributors not included in github history ### @@ -114,7 +114,7 @@ Historic release notes - Standard streams can be optionally compiled off by defining UNITTEST_USE_CUSTOM_STREAMS in Config.h - Added named test suites -- Added CHECK_ARRAY2D_CLOSE +- Added CHECK_ARRAY2D_CLOSE - Posix library name is libUnitTest++.a now - Floating point numbers are postfixed with 'f' in the failure reports diff --git a/appveyor.yml b/appveyor.yml index 28dc4fc..71e4398 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -version: 1.6.0.{build} +version: 1.6.1.{build} os: - Windows Server 2012 R2 From 185b3d5086d4e369bdb7da23abfda23bd248866f Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Fri, 6 May 2016 23:44:02 -0500 Subject: [PATCH 35/79] 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. --- UnitTest++/CheckMacros.h | 92 ++++++++++++++++++++++++++-------------- UnitTest++/Config.h | 8 +++- 2 files changed, 67 insertions(+), 33 deletions(-) diff --git a/UnitTest++/CheckMacros.h b/UnitTest++/CheckMacros.h index e9dae64..b5c6858 100644 --- a/UnitTest++/CheckMacros.h +++ b/UnitTest++/CheckMacros.h @@ -11,31 +11,7 @@ #include "CurrentTest.h" #include "ReportAssertImpl.h" -#ifdef CHECK - #error UnitTest++ redefines CHECK -#endif - -#ifdef CHECK_EQUAL - #error UnitTest++ redefines CHECK_EQUAL -#endif - -#ifdef CHECK_CLOSE - #error UnitTest++ redefines CHECK_CLOSE -#endif - -#ifdef CHECK_ARRAY_EQUAL - #error UnitTest++ redefines CHECK_ARRAY_EQUAL -#endif - -#ifdef CHECK_ARRAY_CLOSE - #error UnitTest++ redefines CHECK_ARRAY_CLOSE -#endif - -#ifdef CHECK_ARRAY2D_CLOSE - #error UnitTest++ redefines CHECK_ARRAY2D_CLOSE -#endif - -#define CHECK(value) \ +#define UNITTEST_CHECK(value) \ UNITTEST_MULTILINE_MACRO_BEGIN \ UT_TRY \ ({ \ @@ -57,7 +33,7 @@ }) \ UNITTEST_MULTILINE_MACRO_END -#define CHECK_EQUAL(expected, actual) \ +#define UNITTEST_CHECK_EQUAL(expected, actual) \ UNITTEST_MULTILINE_MACRO_BEGIN \ UT_TRY \ ({ \ @@ -78,7 +54,7 @@ }) \ UNITTEST_MULTILINE_MACRO_END -#define CHECK_CLOSE(expected, actual, tolerance) \ +#define UNITTEST_CHECK_CLOSE(expected, actual, tolerance) \ UNITTEST_MULTILINE_MACRO_BEGIN \ UT_TRY \ ({ \ @@ -99,7 +75,7 @@ }) \ UNITTEST_MULTILINE_MACRO_END -#define CHECK_ARRAY_EQUAL(expected, actual, count) \ +#define UNITTEST_CHECK_ARRAY_EQUAL(expected, actual, count) \ UNITTEST_MULTILINE_MACRO_BEGIN \ UT_TRY \ ({ \ @@ -120,7 +96,7 @@ }) \ UNITTEST_MULTILINE_MACRO_END -#define CHECK_ARRAY_CLOSE(expected, actual, count, tolerance) \ +#define UNITTEST_CHECK_ARRAY_CLOSE(expected, actual, count, tolerance) \ UNITTEST_MULTILINE_MACRO_BEGIN \ UT_TRY \ ({ \ @@ -141,7 +117,7 @@ }) \ UNITTEST_MULTILINE_MACRO_END -#define CHECK_ARRAY2D_CLOSE(expected, actual, rows, columns, tolerance) \ +#define UNITTEST_CHECK_ARRAY2D_CLOSE(expected, actual, rows, columns, tolerance) \ UNITTEST_MULTILINE_MACRO_BEGIN \ UT_TRY \ ({ \ @@ -162,11 +138,48 @@ }) \ UNITTEST_MULTILINE_MACRO_END +#if UNITTEST_ENABLE_SHORT_MACROS + #ifdef CHECK + #error CHECK already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK instead + #else + #define CHECK UNITTEST_CHECK + #endif + + #ifdef CHECK_EQUAL + #error CHECK_EQUAL already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_EQUAL instead + #else + #define CHECK_EQUAL UNITTEST_CHECK_EQUAL + #endif + + #ifdef CHECK_CLOSE + #error CHECK_CLOSE already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_CLOSE instead + #else + #define CHECK_CLOSE UNITTEST_CHECK_CLOSE + #endif + + #ifdef CHECK_ARRAY_EQUAL + #error CHECK_ARRAY_EQUAL already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_ARRAY_EQUAL instead + #else + #define CHECK_ARRAY_EQUAL UNITTEST_CHECK_ARRAY_EQUAL + #endif + + #ifdef CHECK_ARRAY_CLOSE + #error CHECK_ARRAY_CLOSE already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_ARRAY_CLOSE instead + #else + #define CHECK_ARRAY_CLOSE UNITTEST_CHECK_ARRAY_CLOSE + #endif + + #ifdef CHECK_ARRAY2D_CLOSE + #error CHECK_ARRAY2D_CLOSE already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_ARRAY2D_CLOSE instead + #else + #define CHECK_ARRAY2D_CLOSE UNITTEST_CHECK_ARRAY2D_CLOSE + #endif +#endif // CHECK_THROW and CHECK_ASSERT only exist when UNITTEST_NO_EXCEPTIONS isn't defined (see config.h) #ifndef UNITTEST_NO_EXCEPTIONS -#define CHECK_THROW(expression, ExpectedExceptionType) \ +#define UNITTEST_CHECK_THROW(expression, ExpectedExceptionType) \ UNITTEST_MULTILINE_MACRO_BEGIN \ bool caught_ = false; \ try { expression; } \ @@ -177,7 +190,7 @@ UNITTEST_MULTILINE_MACRO_END -#define CHECK_ASSERT(expression) \ +#define UNITTEST_CHECK_ASSERT(expression) \ UNITTEST_MULTILINE_MACRO_BEGIN \ UnitTest::Detail::ExpectAssert(true); \ CHECK_THROW(expression, UnitTest::AssertException); \ @@ -185,4 +198,19 @@ UNITTEST_MULTILINE_MACRO_END #endif +#if UNITTEST_ENABLE_SHORT_MACROS + #ifdef CHECK_THROW + #error CHECK_THROW already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_THROW instead + #else + #define CHECK_THROW UNITTEST_CHECK_THROW + #endif + + #ifdef CHECK_ASSERT + #error CHECK_ASSERT already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_ASSERT instead + #else + #define CHECK_ASSERT UNITTEST_CHECK_ASSERT + #endif #endif + +#endif + diff --git a/UnitTest++/Config.h b/UnitTest++/Config.h index ff62b4e..f0e23d3 100644 --- a/UnitTest++/Config.h +++ b/UnitTest++/Config.h @@ -16,7 +16,7 @@ #ifdef _USRDLL #define UNITTEST_WIN32_DLL #endif - + #define UNITTEST_WIN32 #endif @@ -71,4 +71,10 @@ #define UNIITEST_NS_QUAL_STD(x) ::std::x #endif +// By default, UnitTest++ will attempt to define "short" macro names like CHECK, CHECK_EQUAL, +// etc. Setting UNITTEST_ENABLE_SHORT_MACROS to 0 will disable this behavior, leaving +// only the longer macros "namespaced" with the UNITTEST_ prefix. + +#define UNITTEST_ENABLE_SHORT_MACROS 1 + #endif From c96bf526136997ff97ef81e8d74b59cc502c6b20 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Fri, 6 May 2016 23:57:59 -0500 Subject: [PATCH 36/79] Replace UT_ macro prefix with UNITTEST_IMPL_ The UT_ prefix was primarily for "internal" macros. This commit seeks to more consistently "namespace" UnitTest++ macros with the UNITTEST_ prefix, while also marking these particular macros as "private" implementation details with the IMPL_ wart. --- UnitTest++/CheckMacros.h | 48 ++++++++++++++++++------------------ UnitTest++/Config.h | 8 +++--- UnitTest++/ExceptionMacros.h | 20 +++++++-------- UnitTest++/ExecuteTest.h | 12 ++++----- UnitTest++/TestMacros.h | 8 +++--- 5 files changed, 48 insertions(+), 48 deletions(-) diff --git a/UnitTest++/CheckMacros.h b/UnitTest++/CheckMacros.h index b5c6858..bb45964 100644 --- a/UnitTest++/CheckMacros.h +++ b/UnitTest++/CheckMacros.h @@ -13,20 +13,20 @@ #define UNITTEST_CHECK(value) \ UNITTEST_MULTILINE_MACRO_BEGIN \ - UT_TRY \ + UNITTEST_IMPL_TRY \ ({ \ if (!UnitTest::Check(value)) \ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), #value); \ }) \ - UT_RETHROW (UnitTest::RequiredCheckException) \ - UT_CATCH (std::exception, e, \ + UNITTEST_IMPL_RETHROW (UnitTest::RequiredCheckException) \ + UNITTEST_IMPL_CATCH (std::exception, e, \ { \ UnitTest::MemoryOutStream message; \ message << "Unhandled exception (" << e.what() << ") in CHECK(" #value ")"; \ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \ message.GetText()); \ }) \ - UT_CATCH_ALL \ + UNITTEST_IMPL_CATCH_ALL \ ({ \ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \ "Unhandled exception in CHECK(" #value ")"); \ @@ -35,19 +35,19 @@ #define UNITTEST_CHECK_EQUAL(expected, actual) \ UNITTEST_MULTILINE_MACRO_BEGIN \ - UT_TRY \ + UNITTEST_IMPL_TRY \ ({ \ UnitTest::CheckEqual(*UnitTest::CurrentTest::Results(), expected, actual, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ }) \ - UT_RETHROW (UnitTest::RequiredCheckException) \ - UT_CATCH (std::exception, e, \ + UNITTEST_IMPL_RETHROW (UnitTest::RequiredCheckException) \ + UNITTEST_IMPL_CATCH (std::exception, e, \ { \ UnitTest::MemoryOutStream message; \ message << "Unhandled exception (" << e.what() << ") in CHECK_EQUAL(" #expected ", " #actual ")"; \ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \ message.GetText()); \ }) \ - UT_CATCH_ALL \ + UNITTEST_IMPL_CATCH_ALL \ ({ \ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \ "Unhandled exception in CHECK_EQUAL(" #expected ", " #actual ")"); \ @@ -56,19 +56,19 @@ #define UNITTEST_CHECK_CLOSE(expected, actual, tolerance) \ UNITTEST_MULTILINE_MACRO_BEGIN \ - UT_TRY \ + UNITTEST_IMPL_TRY \ ({ \ UnitTest::CheckClose(*UnitTest::CurrentTest::Results(), expected, actual, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ }) \ - UT_RETHROW (UnitTest::RequiredCheckException) \ - UT_CATCH (std::exception, e, \ + UNITTEST_IMPL_RETHROW (UnitTest::RequiredCheckException) \ + UNITTEST_IMPL_CATCH (std::exception, e, \ { \ UnitTest::MemoryOutStream message; \ message << "Unhandled exception (" << e.what() << ") in CHECK_CLOSE(" #expected ", " #actual ")"; \ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \ message.GetText()); \ }) \ - UT_CATCH_ALL \ + UNITTEST_IMPL_CATCH_ALL \ ({ \ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \ "Unhandled exception in CHECK_CLOSE(" #expected ", " #actual ")"); \ @@ -77,19 +77,19 @@ #define UNITTEST_CHECK_ARRAY_EQUAL(expected, actual, count) \ UNITTEST_MULTILINE_MACRO_BEGIN \ - UT_TRY \ + UNITTEST_IMPL_TRY \ ({ \ UnitTest::CheckArrayEqual(*UnitTest::CurrentTest::Results(), expected, actual, count, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ }) \ - UT_RETHROW (UnitTest::RequiredCheckException) \ - UT_CATCH (std::exception, e, \ + UNITTEST_IMPL_RETHROW (UnitTest::RequiredCheckException) \ + UNITTEST_IMPL_CATCH (std::exception, e, \ { \ UnitTest::MemoryOutStream message; \ message << "Unhandled exception (" << e.what() << ") in CHECK_ARRAY_EQUAL(" #expected ", " #actual ")"; \ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \ message.GetText()); \ }) \ - UT_CATCH_ALL \ + UNITTEST_IMPL_CATCH_ALL \ ({ \ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \ "Unhandled exception in CHECK_ARRAY_EQUAL(" #expected ", " #actual ")"); \ @@ -98,19 +98,19 @@ #define UNITTEST_CHECK_ARRAY_CLOSE(expected, actual, count, tolerance) \ UNITTEST_MULTILINE_MACRO_BEGIN \ - UT_TRY \ + UNITTEST_IMPL_TRY \ ({ \ UnitTest::CheckArrayClose(*UnitTest::CurrentTest::Results(), expected, actual, count, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ }) \ - UT_RETHROW (UnitTest::RequiredCheckException) \ - UT_CATCH (std::exception, e, \ + UNITTEST_IMPL_RETHROW (UnitTest::RequiredCheckException) \ + UNITTEST_IMPL_CATCH (std::exception, e, \ { \ UnitTest::MemoryOutStream message; \ message << "Unhandled exception (" << e.what() << ") in CHECK_ARRAY_CLOSE(" #expected ", " #actual ")"; \ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \ message.GetText()); \ }) \ - UT_CATCH_ALL \ + UNITTEST_IMPL_CATCH_ALL \ ({ \ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \ "Unhandled exception in CHECK_ARRAY_CLOSE(" #expected ", " #actual ")"); \ @@ -119,19 +119,19 @@ #define UNITTEST_CHECK_ARRAY2D_CLOSE(expected, actual, rows, columns, tolerance) \ UNITTEST_MULTILINE_MACRO_BEGIN \ - UT_TRY \ + UNITTEST_IMPL_TRY \ ({ \ UnitTest::CheckArray2DClose(*UnitTest::CurrentTest::Results(), expected, actual, rows, columns, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ }) \ - UT_RETHROW (UnitTest::RequiredCheckException) \ - UT_CATCH (std::exception, e, \ + UNITTEST_IMPL_RETHROW (UnitTest::RequiredCheckException) \ + UNITTEST_IMPL_CATCH (std::exception, e, \ { \ UnitTest::MemoryOutStream message; \ message << "Unhandled exception (" << e.what() << ") in CHECK_ARRAY2D_CLOSE(" #expected ", " #actual ")"; \ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \ message.GetText()); \ }) \ - UT_CATCH_ALL \ + UNITTEST_IMPL_CATCH_ALL \ ({ \ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \ "Unhandled exception in CHECK_ARRAY2D_CLOSE(" #expected ", " #actual ")"); \ diff --git a/UnitTest++/Config.h b/UnitTest++/Config.h index f0e23d3..364fe8d 100644 --- a/UnitTest++/Config.h +++ b/UnitTest++/Config.h @@ -71,10 +71,10 @@ #define UNIITEST_NS_QUAL_STD(x) ::std::x #endif -// By default, UnitTest++ will attempt to define "short" macro names like CHECK, CHECK_EQUAL, -// etc. Setting UNITTEST_ENABLE_SHORT_MACROS to 0 will disable this behavior, leaving -// only the longer macros "namespaced" with the UNITTEST_ prefix. - +// By default, UnitTest++ will attempt to define "short" macro names like CHECK and CHECK_EQUAL +// for "public" interface macros etc. Setting UNITTEST_ENABLE_SHORT_MACROS to 0 will disable +// this behavior, leaving only the longer macros "namespaced" with the UNITTEST_ prefix. +// "Internal" utility macros will only have the UNITTEST_IMPL_ prefix. #define UNITTEST_ENABLE_SHORT_MACROS 1 #endif diff --git a/UnitTest++/ExceptionMacros.h b/UnitTest++/ExceptionMacros.h index c3b1e30..9b2bad4 100644 --- a/UnitTest++/ExceptionMacros.h +++ b/UnitTest++/ExceptionMacros.h @@ -4,17 +4,17 @@ #include "Config.h" #ifndef UNITTEST_NO_EXCEPTIONS - #define UT_TRY(x) try x - #define UT_THROW(x) throw x - #define UT_RETHROW(ExceptionType) catch(ExceptionType&) { throw; } - #define UT_CATCH(ExceptionType, ExceptionName, CatchBody) catch(ExceptionType& ExceptionName) CatchBody - #define UT_CATCH_ALL(CatchBody) catch(...) CatchBody + #define UNITTEST_IMPL_TRY(x) try x + #define UNITTEST_IMPL_THROW(x) throw x + #define UNITTEST_IMPL_RETHROW(ExceptionType) catch(ExceptionType&) { throw; } + #define UNITTEST_IMPL_CATCH(ExceptionType, ExceptionName, CatchBody) catch(ExceptionType& ExceptionName) CatchBody + #define UNITTEST_IMPL_CATCH_ALL(CatchBody) catch(...) CatchBody #else - #define UT_TRY(x) x - #define UT_THROW(x) - #define UT_RETHROW(ExceptionType) - #define UT_CATCH(ExceptionType, ExceptionName, CatchBody) - #define UT_CATCH_ALL(CatchBody) + #define UNITTEST_IMPL_TRY(x) x + #define UNITTEST_IMPL_THROW(x) + #define UNITTEST_IMPL_RETHROW(ExceptionType) + #define UNITTEST_IMPL_CATCH(ExceptionType, ExceptionName, CatchBody) + #define UNITTEST_IMPL_CATCH_ALL(CatchBody) #endif #endif diff --git a/UnitTest++/ExecuteTest.h b/UnitTest++/ExecuteTest.h index 8e516db..2759aad 100644 --- a/UnitTest++/ExecuteTest.h +++ b/UnitTest++/ExecuteTest.h @@ -31,23 +31,23 @@ namespace UnitTest { { #endif #ifndef UNITTEST_POSIX - UT_TRY({ testObject.RunImpl(); }) + UNITTEST_IMPL_TRY({ testObject.RunImpl(); }) #else - UT_TRY + UNITTEST_IMPL_TRY ({ UNITTEST_THROW_SIGNALS_POSIX_ONLY testObject.RunImpl(); }) #endif - UT_CATCH(RequiredCheckException, e, { (void)e; }) - UT_CATCH(AssertException, e, { (void)e; }) - UT_CATCH(std::exception, e, + UNITTEST_IMPL_CATCH(RequiredCheckException, e, { (void)e; }) + UNITTEST_IMPL_CATCH(AssertException, e, { (void)e; }) + UNITTEST_IMPL_CATCH(std::exception, e, { MemoryOutStream stream; stream << "Unhandled exception: " << e.what(); CurrentTest::Results()->OnTestFailure(details, stream.GetText()); }) - UT_CATCH_ALL + UNITTEST_IMPL_CATCH_ALL ({ CurrentTest::Results()->OnTestFailure(details, "Unhandled exception: test crashed"); }) diff --git a/UnitTest++/TestMacros.h b/UnitTest++/TestMacros.h index 738c56b..efe455e 100644 --- a/UnitTest++/TestMacros.h +++ b/UnitTest++/TestMacros.h @@ -79,23 +79,23 @@ void Test ## Fixture ## Name::RunImpl() const \ { \ volatile bool ctorOk = false; \ - UT_TRY \ + UNITTEST_IMPL_TRY \ ({ \ Fixture ## Name ## Helper fixtureHelper(m_details); \ ctorOk = true; \ UnitTest::ExecuteTest(fixtureHelper, m_details, false); \ }) \ - UT_CATCH (UnitTest::AssertException, e, \ + UNITTEST_IMPL_CATCH (UnitTest::AssertException, e, \ { \ (void)e; \ }) \ - UT_CATCH (std::exception, e, \ + UNITTEST_IMPL_CATCH (std::exception, e, \ { \ UnitTest::MemoryOutStream stream; \ stream << "Unhandled exception: " << e.what(); \ UnitTest::CurrentTest::Results()->OnTestFailure(m_details, stream.GetText()); \ }) \ - UT_CATCH_ALL \ + UNITTEST_IMPL_CATCH_ALL \ ({ \ if (ctorOk) \ { \ From df386f189f3b5c60ffa15a195194edbb011857da Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Sat, 7 May 2016 00:12:09 -0500 Subject: [PATCH 37/79] 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) From 910381fadc6674089c3eb9e9be5911464273b7bc Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Sat, 7 May 2016 01:02:20 -0500 Subject: [PATCH 38/79] Change UNITTEST_ENABLE_SHORT_MACROS to DISABLE Also add a test file. --- UnitTest++/CheckMacros.h | 4 ++-- UnitTest++/Config.h | 9 +++++--- UnitTest++/RequireMacros.h | 2 +- UnitTest++/TestMacros.h | 2 +- tests/TestLongMacros.cpp | 45 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 55 insertions(+), 7 deletions(-) create mode 100644 tests/TestLongMacros.cpp diff --git a/UnitTest++/CheckMacros.h b/UnitTest++/CheckMacros.h index bb45964..261afbb 100644 --- a/UnitTest++/CheckMacros.h +++ b/UnitTest++/CheckMacros.h @@ -138,7 +138,7 @@ }) \ UNITTEST_MULTILINE_MACRO_END -#if UNITTEST_ENABLE_SHORT_MACROS +#ifndef UNITTEST_DISABLE_SHORT_MACROS #ifdef CHECK #error CHECK already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK instead #else @@ -198,7 +198,7 @@ UNITTEST_MULTILINE_MACRO_END #endif -#if UNITTEST_ENABLE_SHORT_MACROS +#ifndef UNITTEST_DISABLE_SHORT_MACROS #ifdef CHECK_THROW #error CHECK_THROW already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_THROW instead #else diff --git a/UnitTest++/Config.h b/UnitTest++/Config.h index 364fe8d..a653e45 100644 --- a/UnitTest++/Config.h +++ b/UnitTest++/Config.h @@ -72,9 +72,12 @@ #endif // By default, UnitTest++ will attempt to define "short" macro names like CHECK and CHECK_EQUAL -// for "public" interface macros etc. Setting UNITTEST_ENABLE_SHORT_MACROS to 0 will disable -// this behavior, leaving only the longer macros "namespaced" with the UNITTEST_ prefix. +// for "public" interface macros etc. Defining UNITTEST_DISABLE_SHORT_MACROS in your project +// will disable this behavior, leaving only the longer macros "namespaced" with the UNITTEST_ +// prefix. +// // "Internal" utility macros will only have the UNITTEST_IMPL_ prefix. -#define UNITTEST_ENABLE_SHORT_MACROS 1 + +// #define UNITTEST_DISABLE_SHORT_MACROS #endif diff --git a/UnitTest++/RequireMacros.h b/UnitTest++/RequireMacros.h index f25899b..7fe793b 100644 --- a/UnitTest++/RequireMacros.h +++ b/UnitTest++/RequireMacros.h @@ -5,7 +5,7 @@ #define UNITTEST_REQUIRE for(UnitTest::RequiredCheckTestReporter decoratedReporter(*UnitTest::CurrentTest::Results()); decoratedReporter.Next(); ) -#if UNITTEST_ENABLE_SHORT_MACROS +#ifndef UNITTEST_DISABLE_SHORT_MACROS #ifdef REQUIRE #error REQUIRE already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_REQUIRE instead #else diff --git a/UnitTest++/TestMacros.h b/UnitTest++/TestMacros.h index 03cf3bb..d6bc204 100644 --- a/UnitTest++/TestMacros.h +++ b/UnitTest++/TestMacros.h @@ -101,7 +101,7 @@ #define UNITTEST_TEST_FIXTURE(Fixture,Name) UNITTEST_IMPL_TEST_FIXTURE(Fixture, Name, UnitTest::Test::GetTestList()) -#if UNITTEST_ENABLE_SHORT_MACROS +#ifndef UNITTEST_DISABLE_SHORT_MACROS #ifdef SUITE #error SUITE already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_SUITE instead #else diff --git a/tests/TestLongMacros.cpp b/tests/TestLongMacros.cpp new file mode 100644 index 0000000..6720a97 --- /dev/null +++ b/tests/TestLongMacros.cpp @@ -0,0 +1,45 @@ +#define UNITTEST_DISABLE_SHORT_MACROS + +#include "UnitTest++/UnitTestPP.h" + +// This file is not intended to test every little thing, just a few basics to hopefully ensure +// the macros are working and the short macros are not defined. +UNITTEST_SUITE(LongMacros) +{ + UNITTEST_TEST(LongCheckMacroWorks) + { + UNITTEST_CHECK(true); + } + + class Fixture + { + public: + Fixture() : sanity_(true) {} + protected: + bool sanity_; + }; + + UNITTEST_TEST_FIXTURE(Fixture, LongFixtureMacroWorks) + { + UNITTEST_REQUIRE UNITTEST_CHECK(sanity_); + } + + UNITTEST_TEST(ShortMacrosAreNotDefined) + { +#if defined(CHECK) || \ + defined(CHECK_EQUAL) || \ + defined(CHECK_CLOSE) || \ + defined(CHECK_ARRAY_EQUAL) || \ + defined(CHECK_ARRAY_CLOSE) || \ + defined(CHECK_ARRAY2D_CLOSE) || \ + defined(CHECK_THROW) || \ + defined(CHECK_ASSERT) || \ + defined(SUITE) || \ + defined(TEST) || \ + defined(TEST_FIXTURE) || \ + defined(REQUIRE) + + UNITTEST_CHECK(false); +#endif + } +} From 27317ec0773157ba1d479d0f78fc402ada323336 Mon Sep 17 00:00:00 2001 From: JonChesterfield Date: Mon, 16 May 2016 11:13:51 +0100 Subject: [PATCH 39/79] Prefix local variable message in CHECK macros with UnitTest_ to reduce the risk of name collisions with application code --- UnitTest++/CheckMacros.h | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/UnitTest++/CheckMacros.h b/UnitTest++/CheckMacros.h index e9dae64..3bfbaf8 100644 --- a/UnitTest++/CheckMacros.h +++ b/UnitTest++/CheckMacros.h @@ -45,10 +45,10 @@ UT_RETHROW (UnitTest::RequiredCheckException) \ UT_CATCH (std::exception, e, \ { \ - UnitTest::MemoryOutStream message; \ - message << "Unhandled exception (" << e.what() << ") in CHECK(" #value ")"; \ + UnitTest::MemoryOutStream UnitTest_message; \ + UnitTest_message << "Unhandled exception (" << e.what() << ") in CHECK(" #value ")"; \ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \ - message.GetText()); \ + UnitTest_message.GetText()); \ }) \ UT_CATCH_ALL \ ({ \ @@ -66,10 +66,10 @@ UT_RETHROW (UnitTest::RequiredCheckException) \ UT_CATCH (std::exception, e, \ { \ - UnitTest::MemoryOutStream message; \ - message << "Unhandled exception (" << e.what() << ") in CHECK_EQUAL(" #expected ", " #actual ")"; \ + UnitTest::MemoryOutStream UnitTest_message; \ + UnitTest_message << "Unhandled exception (" << e.what() << ") in CHECK_EQUAL(" #expected ", " #actual ")"; \ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \ - message.GetText()); \ + UnitTest_message.GetText()); \ }) \ UT_CATCH_ALL \ ({ \ @@ -87,10 +87,10 @@ UT_RETHROW (UnitTest::RequiredCheckException) \ UT_CATCH (std::exception, e, \ { \ - UnitTest::MemoryOutStream message; \ - message << "Unhandled exception (" << e.what() << ") in CHECK_CLOSE(" #expected ", " #actual ")"; \ + UnitTest::MemoryOutStream UnitTest_message; \ + UnitTest_message << "Unhandled exception (" << e.what() << ") in CHECK_CLOSE(" #expected ", " #actual ")"; \ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \ - message.GetText()); \ + UnitTest_message.GetText()); \ }) \ UT_CATCH_ALL \ ({ \ @@ -108,10 +108,10 @@ UT_RETHROW (UnitTest::RequiredCheckException) \ UT_CATCH (std::exception, e, \ { \ - UnitTest::MemoryOutStream message; \ - message << "Unhandled exception (" << e.what() << ") in CHECK_ARRAY_EQUAL(" #expected ", " #actual ")"; \ + UnitTest::MemoryOutStream UnitTest_message; \ + UnitTest_message << "Unhandled exception (" << e.what() << ") in CHECK_ARRAY_EQUAL(" #expected ", " #actual ")"; \ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \ - message.GetText()); \ + UnitTest_message.GetText()); \ }) \ UT_CATCH_ALL \ ({ \ @@ -129,10 +129,10 @@ UT_RETHROW (UnitTest::RequiredCheckException) \ UT_CATCH (std::exception, e, \ { \ - UnitTest::MemoryOutStream message; \ - message << "Unhandled exception (" << e.what() << ") in CHECK_ARRAY_CLOSE(" #expected ", " #actual ")"; \ + UnitTest::MemoryOutStream UnitTest_message; \ + UnitTest_message << "Unhandled exception (" << e.what() << ") in CHECK_ARRAY_CLOSE(" #expected ", " #actual ")"; \ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \ - message.GetText()); \ + UnitTest_message.GetText()); \ }) \ UT_CATCH_ALL \ ({ \ @@ -150,10 +150,10 @@ UT_RETHROW (UnitTest::RequiredCheckException) \ UT_CATCH (std::exception, e, \ { \ - UnitTest::MemoryOutStream message; \ - message << "Unhandled exception (" << e.what() << ") in CHECK_ARRAY2D_CLOSE(" #expected ", " #actual ")"; \ + UnitTest::MemoryOutStream UnitTest_message; \ + UnitTest_message << "Unhandled exception (" << e.what() << ") in CHECK_ARRAY2D_CLOSE(" #expected ", " #actual ")"; \ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \ - message.GetText()); \ + UnitTest_message.GetText()); \ }) \ UT_CATCH_ALL \ ({ \ From 053bcfc9c7760fbaecaa9c882a6f0bcf11c318fd Mon Sep 17 00:00:00 2001 From: Jerome Duval Date: Thu, 2 Jun 2016 19:49:48 +0200 Subject: [PATCH 40/79] Add support for Haiku. --- UnitTest++/Config.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/UnitTest++/Config.h b/UnitTest++/Config.h index ff62b4e..4bd31fe 100644 --- a/UnitTest++/Config.h +++ b/UnitTest++/Config.h @@ -21,7 +21,8 @@ #endif #if defined(unix) || defined(__unix__) || defined(__unix) || defined(linux) || \ - defined(__APPLE__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) + defined(__APPLE__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) \ + || defined (__HAIKU__) #define UNITTEST_POSIX #endif From 21589e561214664249d2872c13642ced555cd23a Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Fri, 15 Jul 2016 23:23:45 -0500 Subject: [PATCH 41/79] Take UnitTest::Check parameter by const reference Fixes #119 and #7 --- UnitTest++/Checks.h | 2 +- tests/TestChecks.cpp | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/UnitTest++/Checks.h b/UnitTest++/Checks.h index 5b09768..70bd51b 100644 --- a/UnitTest++/Checks.h +++ b/UnitTest++/Checks.h @@ -9,7 +9,7 @@ namespace UnitTest { template< typename Value > - bool Check(Value const value) + bool Check(Value const& value) { return !!value; // doing double negative to avoid silly VS warnings } diff --git a/tests/TestChecks.cpp b/tests/TestChecks.cpp index 1ec64ee..233b8a8 100644 --- a/tests/TestChecks.cpp +++ b/tests/TestChecks.cpp @@ -315,4 +315,32 @@ namespace { CHECK_EQUAL(1234, reporter.lastFailedLine); } + TEST(CheckProperlyDealsWithOperatorBoolOverrides) + { + class TruthyUnlessCopied + { + public: + TruthyUnlessCopied() + : truthy_(true) + { + } + + TruthyUnlessCopied(const TruthyUnlessCopied& orig) + : truthy_(false) + { + } + + operator bool() const + { + return truthy_; + } + + private: + bool truthy_; + }; + + TruthyUnlessCopied objectThatShouldBeTruthy; + CHECK(objectThatShouldBeTruthy); + } + } From bec6ba56ec0988815034656cfb8a7957e728d6d6 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Fri, 15 Jul 2016 23:54:59 -0500 Subject: [PATCH 42/79] Attempted fix for Travis build. --- tests/TestChecks.cpp | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/tests/TestChecks.cpp b/tests/TestChecks.cpp index 233b8a8..645c3d9 100644 --- a/tests/TestChecks.cpp +++ b/tests/TestChecks.cpp @@ -315,30 +315,30 @@ namespace { CHECK_EQUAL(1234, reporter.lastFailedLine); } + class TruthyUnlessCopied + { + public: + TruthyUnlessCopied() + : truthy_(true) + { + } + + TruthyUnlessCopied(const TruthyUnlessCopied& orig) + : truthy_(false) + { + } + + operator bool() const + { + return truthy_; + } + + private: + bool truthy_; + }; + TEST(CheckProperlyDealsWithOperatorBoolOverrides) { - class TruthyUnlessCopied - { - public: - TruthyUnlessCopied() - : truthy_(true) - { - } - - TruthyUnlessCopied(const TruthyUnlessCopied& orig) - : truthy_(false) - { - } - - operator bool() const - { - return truthy_; - } - - private: - bool truthy_; - }; - TruthyUnlessCopied objectThatShouldBeTruthy; CHECK(objectThatShouldBeTruthy); } From de915185f6f40a3c25bef51eecddab22c40d045d Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Fri, 15 Jul 2016 23:58:48 -0500 Subject: [PATCH 43/79] Remove unused variable from test copy constructor --- tests/TestChecks.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/TestChecks.cpp b/tests/TestChecks.cpp index 645c3d9..2c0ac04 100644 --- a/tests/TestChecks.cpp +++ b/tests/TestChecks.cpp @@ -323,7 +323,7 @@ namespace { { } - TruthyUnlessCopied(const TruthyUnlessCopied& orig) + TruthyUnlessCopied(const TruthyUnlessCopied&) : truthy_(false) { } From fa971526199acfa5a36ae7e85fcd668a1685d582 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Sat, 7 May 2016 02:19:02 -0500 Subject: [PATCH 44/79] Add UTPP_SKIP_TESTS_AS_BUILD_STEP CMake option Helps address #104. --- CMakeLists.txt | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b5aa7e..03f3063 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,12 @@ cmake_minimum_required(VERSION 2.8.1) project(UnitTest++) -option(UTPP_USE_PLUS_SIGN "Set this to OFF if you wish to use '-cpp' instead of '++' in lib/include paths" ON) +option(UTPP_USE_PLUS_SIGN + "Set this to OFF if you wish to use '-cpp' instead of '++' in lib/include paths" + ON) +option(UTPP_SKIP_TESTS_AS_BUILD_STEP + "Set this to ON if you do not wish unit tests to run as part of cmake --build" + OFF) if(MSVC14 OR MSVC12) # has the support we need @@ -55,10 +60,15 @@ endif() target_link_libraries(TestUnitTest++ UnitTest++) -# run unit tests as post build step -add_custom_command(TARGET TestUnitTest++ - POST_BUILD COMMAND TestUnitTest++ - COMMENT "Running unit tests") +if(${UTPP_SKIP_TESTS_AS_BUILD_STEP}) + add_custom_command(TARGET TestUnitTest++ + POST_BUILD COMMAND echo "TestUnitTest++ was not run as a build step because UTPP_SKIP_TESTS_AS_BUILD_STEP is ON") +else() + # run unit tests as post build step + add_custom_command(TARGET TestUnitTest++ + POST_BUILD COMMAND TestUnitTest++ + COMMENT "Running unit tests") +endif() # add install targets # need a custom install path? From 14f317c40c98835d10b0b6072e667dc1911c3b93 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Sat, 7 May 2016 02:29:16 -0500 Subject: [PATCH 45/79] Eliminate double-negative in option name / value UTPP_SKIP_TESTS_AS_BUILD_STEP with a default value of OFF was an unfortunate choice, so this changes it to UTPP_RUN_TESTS_AS_BUILD_STEP with a default value of ON. --- CMakeLists.txt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 03f3063..447f4ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,9 +4,9 @@ project(UnitTest++) option(UTPP_USE_PLUS_SIGN "Set this to OFF if you wish to use '-cpp' instead of '++' in lib/include paths" ON) -option(UTPP_SKIP_TESTS_AS_BUILD_STEP - "Set this to ON if you do not wish unit tests to run as part of cmake --build" - OFF) +option(UTPP_RUN_TESTS_AS_BUILD_STEP + "Set this to OFF if you do not wish unit tests to run as part of cmake --build" + ON) if(MSVC14 OR MSVC12) # has the support we need @@ -60,14 +60,14 @@ endif() target_link_libraries(TestUnitTest++ UnitTest++) -if(${UTPP_SKIP_TESTS_AS_BUILD_STEP}) - add_custom_command(TARGET TestUnitTest++ - POST_BUILD COMMAND echo "TestUnitTest++ was not run as a build step because UTPP_SKIP_TESTS_AS_BUILD_STEP is ON") -else() +if(${UTPP_RUN_TESTS_AS_BUILD_STEP}) # run unit tests as post build step add_custom_command(TARGET TestUnitTest++ - POST_BUILD COMMAND TestUnitTest++ - COMMENT "Running unit tests") + POST_BUILD COMMAND TestUnitTest++ + COMMENT "Running unit tests") +else() + add_custom_command(TARGET TestUnitTest++ + POST_BUILD COMMAND echo "TestUnitTest++ was not run as a build step because UTPP_RUN_TESTS_AS_BUILD_STEP is OFF") endif() # add install targets From 6b69ed78bae727246a6f2e1308feabaf28ded093 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Mon, 18 Jul 2016 21:13:03 -0500 Subject: [PATCH 46/79] Skip test build with same option as run As part of this, changed the option name to `UTPP_INCLUDE_TESTS_IN_BUILD`. The test target is still added to the build and can be built/run separately using the CMake --target option. --- CMakeLists.txt | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 447f4ce..e99ee13 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,8 +4,8 @@ project(UnitTest++) option(UTPP_USE_PLUS_SIGN "Set this to OFF if you wish to use '-cpp' instead of '++' in lib/include paths" ON) -option(UTPP_RUN_TESTS_AS_BUILD_STEP - "Set this to OFF if you do not wish unit tests to run as part of cmake --build" +option(UTPP_INCLUDE_TESTS_IN_BUILD + "Set this to OFF if you do not wish to automatically build or run unit tests as part of the default cmake --build" ON) if(MSVC14 OR MSVC12) @@ -60,14 +60,13 @@ endif() target_link_libraries(TestUnitTest++ UnitTest++) -if(${UTPP_RUN_TESTS_AS_BUILD_STEP}) - # run unit tests as post build step - add_custom_command(TARGET TestUnitTest++ - POST_BUILD COMMAND TestUnitTest++ - COMMENT "Running unit tests") -else() - add_custom_command(TARGET TestUnitTest++ - POST_BUILD COMMAND echo "TestUnitTest++ was not run as a build step because UTPP_RUN_TESTS_AS_BUILD_STEP is OFF") +# run unit tests as post build step +add_custom_command(TARGET TestUnitTest++ + POST_BUILD COMMAND TestUnitTest++ + COMMENT "Running unit tests") + +if(NOT ${UTPP_INCLUDE_TESTS_IN_BUILD}) + set_target_properties(TestUnitTest++ PROPERTIES EXCLUDE_FROM_ALL 1) endif() # add install targets From 7c159427516124ba8c01262b15f492b6b6789dce Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Sat, 27 Aug 2016 08:26:05 -0500 Subject: [PATCH 47/79] Up warning level to /W4 /WX for MSVC-like compilers Also adds a CMake option, UTPP_AMPLIFY_WARNINGS, that can be turned OFF to disable the new behavior. --- CMakeLists.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index e99ee13..89e61f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,9 @@ option(UTPP_USE_PLUS_SIGN option(UTPP_INCLUDE_TESTS_IN_BUILD "Set this to OFF if you do not wish to automatically build or run unit tests as part of the default cmake --build" ON) +option(UTPP_AMPLIFY_WARNINGS + "Set this to OFF if you wish to use CMake default warning levels; should generally only use to work around support issues for your specific compiler" + ON) if(MSVC14 OR MSVC12) # has the support we need @@ -23,6 +26,15 @@ else() endif() endif() +# up warning level for project +if (${UTPP_AMPLIFY_WARNINGS}) + # instead of getting compiler specific, we're going to try making an assumption that an existing /W# means + # we are dealing with an MSVC or MSVC-like compiler (e.g. Intel on Windows) + if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") + string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX") + endif() +endif() + # get the main sources file(GLOB headers_ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} UnitTest++/*.h) file(GLOB sources_ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} UnitTest++/*.cpp) From 7e4fff3bb420820b67562ccd1d706e17d795cf8d Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Sat, 27 Aug 2016 08:27:15 -0500 Subject: [PATCH 48/79] Fix "assignment operator could not be generated" warning This shows up with /W4 on MSVC. Fixes #107. --- UnitTest++/RequiredCheckTestReporter.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/UnitTest++/RequiredCheckTestReporter.h b/UnitTest++/RequiredCheckTestReporter.h index 117ae01..99d9cdd 100644 --- a/UnitTest++/RequiredCheckTestReporter.h +++ b/UnitTest++/RequiredCheckTestReporter.h @@ -19,6 +19,9 @@ namespace UnitTest { bool Next(); private: + RequiredCheckTestReporter(RequiredCheckTestReporter const&); + RequiredCheckTestReporter& operator =(RequiredCheckTestReporter const&); + TestResults& m_results; TestReporter* m_originalTestReporter; ThrowingTestReporter m_throwingReporter; From f0044e919dcae4a171d2db45f2aea92850df2b0c Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Sat, 27 Aug 2016 09:54:32 -0500 Subject: [PATCH 49/79] Up warning level to -Wall/extra/error for non-MSVC UTPP_AMPLIFY_WARNINGS can be turned OFF to disable the new behavior. --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 89e61f5..76c8665 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,6 +32,8 @@ if (${UTPP_AMPLIFY_WARNINGS}) # we are dealing with an MSVC or MSVC-like compiler (e.g. Intel on Windows) if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX") + else() + string(CONCAT CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" " -Wall -Wextra -Werror -Wno-ignored-qualifiers") endif() endif() From 2e2475fa5401c4ef123b3ca26f7a8e60ee5eb425 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Sat, 27 Aug 2016 09:55:37 -0500 Subject: [PATCH 50/79] Fix unused variable warnings --- UnitTest++/Posix/SignalTranslator.cpp | 4 ++-- UnitTest++/Posix/SignalTranslator.h | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/UnitTest++/Posix/SignalTranslator.cpp b/UnitTest++/Posix/SignalTranslator.cpp index 4039896..69cc194 100644 --- a/UnitTest++/Posix/SignalTranslator.cpp +++ b/UnitTest++/Posix/SignalTranslator.cpp @@ -28,12 +28,12 @@ namespace UnitTest { sigaction( SIGFPE, &action, &m_old_SIGFPE_action ); sigaction( SIGTRAP, &action, &m_old_SIGTRAP_action ); sigaction( SIGBUS, &action, &m_old_SIGBUS_action ); - sigaction( SIGILL, &action, &m_old_SIGBUS_action ); + sigaction( SIGILL, &action, &m_old_SIGILL_action ); } SignalTranslator::~SignalTranslator() { - sigaction( SIGILL, &m_old_SIGBUS_action, 0 ); + sigaction( SIGILL, &m_old_SIGILL_action, 0 ); sigaction( SIGBUS, &m_old_SIGBUS_action, 0 ); sigaction( SIGTRAP, &m_old_SIGTRAP_action, 0 ); sigaction( SIGFPE, &m_old_SIGFPE_action, 0 ); diff --git a/UnitTest++/Posix/SignalTranslator.h b/UnitTest++/Posix/SignalTranslator.h index efb3618..66d388d 100644 --- a/UnitTest++/Posix/SignalTranslator.h +++ b/UnitTest++/Posix/SignalTranslator.h @@ -22,8 +22,7 @@ namespace UnitTest { struct sigaction m_old_SIGTRAP_action; struct sigaction m_old_SIGSEGV_action; struct sigaction m_old_SIGBUS_action; - struct sigaction m_old_SIGABRT_action; - struct sigaction m_old_SIGALRM_action; + struct sigaction m_old_SIGILL_action; }; #if !defined (__GNUC__) From e161d44077646e63e8956ce0c70002cecda3d2be Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Sat, 27 Aug 2016 10:04:54 -0500 Subject: [PATCH 51/79] Use CMake SET instead of string CONCAT string(CONCAT...) was not available in older versions of CMake targeted by this project. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 76c8665..32023b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,7 @@ if (${UTPP_AMPLIFY_WARNINGS}) if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX") else() - string(CONCAT CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" " -Wall -Wextra -Werror -Wno-ignored-qualifiers") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -Wno-ignored-qualifiers") endif() endif() From 7d7ba0aba44d5a9d76442e5e8286686e01eaf222 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Sat, 27 Aug 2016 20:41:41 -0500 Subject: [PATCH 52/79] Re-enable ignored-qualifiers warning and fix --- CMakeLists.txt | 2 +- tests/TestMemoryOutStream.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 32023b9..a7411bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,7 @@ if (${UTPP_AMPLIFY_WARNINGS}) if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX") else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -Wno-ignored-qualifiers") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror") endif() endif() diff --git a/tests/TestMemoryOutStream.cpp b/tests/TestMemoryOutStream.cpp index 7c1ffbc..854277e 100644 --- a/tests/TestMemoryOutStream.cpp +++ b/tests/TestMemoryOutStream.cpp @@ -11,7 +11,7 @@ using namespace std; namespace { - const char* const maxSignedIntegralStr(size_t nBytes) + const char* maxSignedIntegralStr(size_t nBytes) { switch(nBytes) { @@ -28,7 +28,7 @@ namespace { } } - const char* const minSignedIntegralStr(size_t nBytes) + const char* minSignedIntegralStr(size_t nBytes) { switch(nBytes) { @@ -45,7 +45,7 @@ namespace { } } - const char* const maxUnsignedIntegralStr(size_t nBytes) + const char* maxUnsignedIntegralStr(size_t nBytes) { switch(nBytes) { From eca039304b7e93ee40e3d733a0c051af7e7943e2 Mon Sep 17 00:00:00 2001 From: Gabriel Schlozer Date: Mon, 29 Aug 2016 22:36:31 +0200 Subject: [PATCH 53/79] Used size_t for CHECK macros --- UnitTest++/Checks.h | 30 +++++++++++++++--------------- tests/TestExceptions.cpp | 8 ++++---- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/UnitTest++/Checks.h b/UnitTest++/Checks.h index 70bd51b..7c37691 100644 --- a/UnitTest++/Checks.h +++ b/UnitTest++/Checks.h @@ -57,10 +57,10 @@ namespace UnitTest { template< typename Expected, typename Actual > void CheckArrayEqual(TestResults& results, Expected const& expected, Actual const& actual, - int const count, TestDetails const& details) + size_t const count, TestDetails const& details) { bool equal = true; - for (int i = 0; i < count; ++i) + for (size_t i = 0; i < count; ++i) equal &= (expected[i] == actual[i]); if (!equal) @@ -69,12 +69,12 @@ namespace UnitTest { stream << "Expected [ "; - for (int expectedIndex = 0; expectedIndex < count; ++expectedIndex) + for (size_t expectedIndex = 0; expectedIndex < count; ++expectedIndex) stream << expected[expectedIndex] << " "; stream << "] but was [ "; - for (int actualIndex = 0; actualIndex < count; ++actualIndex) + for (size_t actualIndex = 0; actualIndex < count; ++actualIndex) stream << actual[actualIndex] << " "; stream << "]"; @@ -84,17 +84,17 @@ namespace UnitTest { } template< typename Expected, typename Actual, typename Tolerance > - bool ArrayAreClose(Expected const& expected, Actual const& actual, int const count, Tolerance const& tolerance) + bool ArrayAreClose(Expected const& expected, Actual const& actual, size_t const count, Tolerance const& tolerance) { bool equal = true; - for (int i = 0; i < count; ++i) + for (size_t i = 0; i < count; ++i) equal &= AreClose(expected[i], actual[i], tolerance); return equal; } template< typename Expected, typename Actual, typename Tolerance > void CheckArrayClose(TestResults& results, Expected const& expected, Actual const& actual, - int const count, Tolerance const& tolerance, TestDetails const& details) + size_t const count, Tolerance const& tolerance, TestDetails const& details) { bool equal = ArrayAreClose(expected, actual, count, tolerance); @@ -103,11 +103,11 @@ namespace UnitTest { UnitTest::MemoryOutStream stream; stream << "Expected [ "; - for (int expectedIndex = 0; expectedIndex < count; ++expectedIndex) + for (size_t expectedIndex = 0; expectedIndex < count; ++expectedIndex) stream << expected[expectedIndex] << " "; stream << "] +/- " << tolerance << " but was [ "; - for (int actualIndex = 0; actualIndex < count; ++actualIndex) + for (size_t actualIndex = 0; actualIndex < count; ++actualIndex) stream << actual[actualIndex] << " "; stream << "]"; @@ -117,10 +117,10 @@ namespace UnitTest { template< typename Expected, typename Actual, typename Tolerance > void CheckArray2DClose(TestResults& results, Expected const& expected, Actual const& actual, - int const rows, int const columns, Tolerance const& tolerance, TestDetails const& details) + size_t const rows, size_t const columns, Tolerance const& tolerance, TestDetails const& details) { bool equal = true; - for (int i = 0; i < rows; ++i) + for (size_t i = 0; i < rows; ++i) equal &= ArrayAreClose(expected[i], actual[i], columns, tolerance); if (!equal) @@ -129,20 +129,20 @@ namespace UnitTest { stream << "Expected [ "; - for (int expectedRow = 0; expectedRow < rows; ++expectedRow) + for (size_t expectedRow = 0; expectedRow < rows; ++expectedRow) { stream << "[ "; - for (int expectedColumn = 0; expectedColumn < columns; ++expectedColumn) + for (size_t expectedColumn = 0; expectedColumn < columns; ++expectedColumn) stream << expected[expectedRow][expectedColumn] << " "; stream << "] "; } stream << "] +/- " << tolerance << " but was [ "; - for (int actualRow = 0; actualRow < rows; ++actualRow) + for (size_t actualRow = 0; actualRow < rows; ++actualRow) { stream << "[ "; - for (int actualColumn = 0; actualColumn < columns; ++actualColumn) + for (size_t actualColumn = 0; actualColumn < columns; ++actualColumn) stream << actual[actualRow][actualColumn] << " "; stream << "] "; } diff --git a/tests/TestExceptions.cpp b/tests/TestExceptions.cpp index 972e64d..08f6547 100644 --- a/tests/TestExceptions.cpp +++ b/tests/TestExceptions.cpp @@ -253,7 +253,7 @@ namespace { class ThrowingObject { public: - float operator[](int) const + float operator[](size_t) const { throw "Test throw"; } @@ -262,7 +262,7 @@ namespace { class StdThrowingObject { public: - float operator[](int) const + float operator[](size_t) const { throw std::runtime_error("Test throw"); } @@ -451,7 +451,7 @@ namespace { class ThrowingObject2D { public: - float* operator[](int) const + float* operator[](size_t) const { throw "Test throw"; } @@ -460,7 +460,7 @@ namespace { class StdThrowingObject2D { public: - float* operator[](int) const + float* operator[](size_t) const { throw std::runtime_error("Test throw"); } From 0d77b1ae10622d39450d905b8aec23267a1085c3 Mon Sep 17 00:00:00 2001 From: Julien Monat Rodier Date: Tue, 11 Oct 2016 13:00:40 -0700 Subject: [PATCH 54/79] Update docs reference to avoid bad path names on windows --- docs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs b/docs index 14495a3..a6963b7 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 14495a3a81568e9ce187231b629e4eb7bc7e0350 +Subproject commit a6963b798400df760e148a6e15e9c13db965a3ec From 40f90dc601eb2107c3e4786a3ebe16e7fd273075 Mon Sep 17 00:00:00 2001 From: Evan Danaher Date: Thu, 1 Dec 2016 12:22:54 -0500 Subject: [PATCH 55/79] Build pkgconfig file with CMake, not just with autoconf. --- CMakeLists.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index a7411bc..fb10f47 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,3 +100,11 @@ install(FILES ${headers_} DESTINATION ${UTPP_INSTALL_DESTINATION}) install(FILES ${platformHeaders_} DESTINATION ${UTPP_INSTALL_DESTINATION}/${platformDir_}) install(FILES cmake/UnitTest++Config.cmake DESTINATION "${config_install_dir_}") install(EXPORT "${targets_export_name_}" DESTINATION "${config_install_dir_}") + +set(prefix ${CMAKE_INSTALL_PREFIX}) +set(exec_prefix ${CMAKE_INSTALL_PREFIX}/bin) +set(libdir ${CMAKE_INSTALL_PREFIX}/lib) +set(includedir ${CMAKE_INSTALL_PREFIX}/include/UnitTest++) +configure_file("UnitTest++.pc.in" "UnitTest++.pc" @ONLY) +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/UnitTest++.pc" + DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig") From 9eba823269fffa8f1a5c780c937c202672b636fe Mon Sep 17 00:00:00 2001 From: Gabriel Hare Date: Wed, 14 Dec 2016 23:11:20 -0800 Subject: [PATCH 56/79] Demonstrate that compiler is identified as MSVC when VS2014 Clang extension is used --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index a7411bc..2d6c28c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,15 +11,19 @@ option(UTPP_AMPLIFY_WARNINGS "Set this to OFF if you wish to use CMake default warning levels; should generally only use to work around support issues for your specific compiler" ON) +message(STATUS "CMAKE_CXX_COMPILER_ID = ${CMAKE_CXX_COMPILER_ID}") if(MSVC14 OR MSVC12) + message(STATUS "Using MSVC compiler") # has the support we need else() include(CheckCXXCompilerFlag) CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14) CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) if(COMPILER_SUPPORTS_CXX14) + message(STATUS "Specify C++14") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") elseif(COMPILER_SUPPORTS_CXX11) + message(STATUS "Specify C++11") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") else() message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.") From 8f7a2634462011b9b366704e480d25fe7fc2f626 Mon Sep 17 00:00:00 2001 From: Gabriel Hare Date: Thu, 15 Dec 2016 00:31:56 -0800 Subject: [PATCH 57/79] Increase CMake version to resolve developer warnings regarding implicit quoted dereference in STREQUAL comparison --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d6c28c..4f8c8db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.8.1) +cmake_minimum_required(VERSION 3.1.0) project(UnitTest++) option(UTPP_USE_PLUS_SIGN From c4ab9d31ed98da89bf1f07738129139eb0034dd8 Mon Sep 17 00:00:00 2001 From: Gabriel Hare Date: Thu, 15 Dec 2016 00:40:03 -0800 Subject: [PATCH 58/79] Identify Clang compiler when used as an MSVC extension --- CMakeLists.txt | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f8c8db..000fd6b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,22 +11,24 @@ option(UTPP_AMPLIFY_WARNINGS "Set this to OFF if you wish to use CMake default warning levels; should generally only use to work around support issues for your specific compiler" ON) -message(STATUS "CMAKE_CXX_COMPILER_ID = ${CMAKE_CXX_COMPILER_ID}") -if(MSVC14 OR MSVC12) - message(STATUS "Using MSVC compiler") - # has the support we need +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + # CHECK_CXX_COMPILER_FLAG could be used + # but MSVC version is preferred for feature requirements + if (MSVC14 OR MSVC12) + # has the support we need + else() + message(WARNING "The MSVC compiler version does not support required C++11 features. Please use a different C++ compiler.") + endif() else() include(CheckCXXCompilerFlag) CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14) CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) if(COMPILER_SUPPORTS_CXX14) - message(STATUS "Specify C++14") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") elseif(COMPILER_SUPPORTS_CXX11) - message(STATUS "Specify C++11") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") else() - message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.") + message(WARNING "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.") endif() endif() From bb495391070e2a87503f9d3dba723b62a90a5032 Mon Sep 17 00:00:00 2001 From: Gabriel Hare Date: Thu, 15 Dec 2016 02:46:13 -0800 Subject: [PATCH 59/79] Revert "Increase CMake version to resolve developer warnings regarding implicit quoted dereference in STREQUAL comparison" This reverts commit 8f7a2634462011b9b366704e480d25fe7fc2f626. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 000fd6b..f075074 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.1.0) +cmake_minimum_required(VERSION 2.8.1) project(UnitTest++) option(UTPP_USE_PLUS_SIGN From a2fe23887a793c42b35c7be54bd9e06023bc36b7 Mon Sep 17 00:00:00 2001 From: Gabriel Hare Date: Thu, 15 Dec 2016 02:50:09 -0800 Subject: [PATCH 60/79] =?UTF-8?q?Use=20=E2=80=9CMATCHES=E2=80=9D=20instead?= =?UTF-8?q?=20of=20=E2=80=9CSTREQUAL=E2=80=9D=20to=20avoid=20ambiguous=20c?= =?UTF-8?q?omparison.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit NOTE: Unlike STREQUAL this comparison is supported pre and post CMake v3.1.0 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f075074..4c39baf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ option(UTPP_AMPLIFY_WARNINGS "Set this to OFF if you wish to use CMake default warning levels; should generally only use to work around support issues for your specific compiler" ON) -if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") +if(${CMAKE_CXX_COMPILER_ID} MATCHES "MSVC") # CHECK_CXX_COMPILER_FLAG could be used # but MSVC version is preferred for feature requirements if (MSVC14 OR MSVC12) From 8d70dff05bbf19bd72ab198e3d4d14a244891123 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Fri, 13 Jan 2017 14:35:21 -0600 Subject: [PATCH 61/79] Delete unused ChangeLog file Closes #138 --- ChangeLog | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 ChangeLog diff --git a/ChangeLog b/ChangeLog deleted file mode 100644 index e69de29..0000000 From 8e5968bb05b03e024c4d783e703e1f416762177d Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Fri, 13 Jan 2017 14:36:38 -0600 Subject: [PATCH 62/79] Roll version number to 2.0.0 --- README.md | 12 +++++++++--- appveyor.yml | 2 +- configure.ac | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8a49c3d..7c138a8 100644 --- a/README.md +++ b/README.md @@ -30,17 +30,17 @@ Via svn: svn checkout https://github.com/unittest-cpp/unittest-cpp/trunk unittest-cpp -### Latest release (v1.6.1) ### +### Latest release (v2.0.0) ### Via git: git clone https://github.com/unittest-cpp/unittest-cpp cd unittest-cpp - git checkout v1.6.1 + git checkout v2.0.0 Via svn: - svn checkout https://github.com/unittest-cpp/unittest-cpp/tags/v1.6.1 unittest-cpp + svn checkout https://github.com/unittest-cpp/unittest-cpp/tags/v2.0.0 unittest-cpp License --------- @@ -77,6 +77,12 @@ Contributors Historic release notes ---------------------- +### Version 2.0.0 (2017-01-13) ### +- Change Check method supporting CHECK macro to accept argument by reference +- Introduce long macro forms (e.g. UNITTEST_CHECK); make short forms optional +- Improved Visual Studio 2015 support +- [Full List](https://github.com/unittest-cpp/unittest-cpp/issues?q=milestone%3A2.0.0+) + ### Version 1.6.0 (2016-02-29) ### - Add REQUIRE macro to end tests early when selected checks fail - [Full List](https://github.com/unittest-cpp/unittest-cpp/issues?q=milestone%3A1.6.0+) diff --git a/appveyor.yml b/appveyor.yml index 71e4398..bebe4f5 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -version: 1.6.1.{build} +version: 2.0.0.{build} os: - Windows Server 2012 R2 diff --git a/configure.ac b/configure.ac index 6b81131..56300a6 100644 --- a/configure.ac +++ b/configure.ac @@ -23,7 +23,7 @@ AM_CONDITIONAL([WINDOWS], LT_INIT() -AC_SUBST([LIBUNITTEST_SO_VERSION], [1:6:0]) +AC_SUBST([LIBUNITTEST_SO_VERSION], [2:0:0]) # Checks for programs. AC_PROG_CXX From 615b6cdd0fa614ab4276c2382889355dd698b556 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Fri, 13 Jan 2017 14:51:19 -0600 Subject: [PATCH 63/79] Add note re: autotools to INSTALL file --- INSTALL | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/INSTALL b/INSTALL index 6e90e07..6c99c94 100644 --- a/INSTALL +++ b/INSTALL @@ -1,3 +1,9 @@ + +Preamble: If you are installing UnitTest++ from source, or from a +release prior to 1.6.1, you will need to have autotools installed and +run `autoreconf -i; autoconf` prior to following the standard +instructions below. + Installation Instructions ************************* From 85bade33f596a4dab33eb6d44f662d64fc20f510 Mon Sep 17 00:00:00 2001 From: Iblis Lin Date: Sat, 14 Jan 2017 23:00:24 +0800 Subject: [PATCH 64/79] cmake: fix pkgconfig dir path on FreeBSD --- CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fb10f47..a0f5511 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,5 +106,10 @@ set(exec_prefix ${CMAKE_INSTALL_PREFIX}/bin) set(libdir ${CMAKE_INSTALL_PREFIX}/lib) set(includedir ${CMAKE_INSTALL_PREFIX}/include/UnitTest++) configure_file("UnitTest++.pc.in" "UnitTest++.pc" @ONLY) +if(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD") + set(pkgconfdir ${CMAKE_INSTALL_PREFIX}/libdata/pkgconfig) +else() + set(pkgconfdir ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig) +endif() install(FILES "${CMAKE_CURRENT_BINARY_DIR}/UnitTest++.pc" - DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig") + DESTINATION "${pkgconfdir}") From 0757ba8f903fc94ac852c8ba394cd96358b0e2c7 Mon Sep 17 00:00:00 2001 From: Christoph Willing Date: Mon, 23 Jan 2017 17:49:12 +1000 Subject: [PATCH 65/79] Add support for LIB_SUFFIX Signed-off-by: Christoph Willing --- CMakeLists.txt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a0f5511..6b490ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,8 @@ option(UTPP_AMPLIFY_WARNINGS "Set this to OFF if you wish to use CMake default warning levels; should generally only use to work around support issues for your specific compiler" ON) +set(LIB_SUFFIX "" CACHE STRING "Identifier to add to end of lib directory name e.g. 64 for lib64") + if(MSVC14 OR MSVC12) # has the support we need else() @@ -92,10 +94,10 @@ else() set (UTPP_INSTALL_DESTINATION "include/UnitTestPP") endif() -set(config_install_dir_ lib/cmake/${PROJECT_NAME}) +set(config_install_dir_ lib${LIB_SUFFIX}/cmake/${PROJECT_NAME}) set(targets_export_name_ "${PROJECT_NAME}Targets") -install(TARGETS UnitTest++ EXPORT "${targets_export_name_}" DESTINATION lib) +install(TARGETS UnitTest++ EXPORT "${targets_export_name_}" DESTINATION lib${LIB_SUFFIX}) install(FILES ${headers_} DESTINATION ${UTPP_INSTALL_DESTINATION}) install(FILES ${platformHeaders_} DESTINATION ${UTPP_INSTALL_DESTINATION}/${platformDir_}) install(FILES cmake/UnitTest++Config.cmake DESTINATION "${config_install_dir_}") @@ -103,13 +105,13 @@ install(EXPORT "${targets_export_name_}" DESTINATION "${config_install_dir_}") set(prefix ${CMAKE_INSTALL_PREFIX}) set(exec_prefix ${CMAKE_INSTALL_PREFIX}/bin) -set(libdir ${CMAKE_INSTALL_PREFIX}/lib) +set(libdir ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}) set(includedir ${CMAKE_INSTALL_PREFIX}/include/UnitTest++) configure_file("UnitTest++.pc.in" "UnitTest++.pc" @ONLY) if(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD") set(pkgconfdir ${CMAKE_INSTALL_PREFIX}/libdata/pkgconfig) else() - set(pkgconfdir ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig) + set(pkgconfdir ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/pkgconfig) endif() install(FILES "${CMAKE_CURRENT_BINARY_DIR}/UnitTest++.pc" DESTINATION "${pkgconfdir}") From d7bd757862916cca0c4888070c9c929a8a9bd089 Mon Sep 17 00:00:00 2001 From: timdave13 Date: Thu, 2 Feb 2017 17:14:27 -0500 Subject: [PATCH 66/79] fix clang warning fix clang warning: 'X' has no out-of-line virtual method definitions; its vtable will be emitted in every translation unit [-Wweak-vtables] --- UnitTest++/TestMacros.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/UnitTest++/TestMacros.h b/UnitTest++/TestMacros.h index d6bc204..8ff87f8 100644 --- a/UnitTest++/TestMacros.h +++ b/UnitTest++/TestMacros.h @@ -49,10 +49,12 @@ explicit Fixture ## Name ## Helper(UnitTest::TestDetails const& details) : m_details(details) {} \ void RunImpl(); \ UnitTest::TestDetails const& m_details; \ + virtual ~Fixture ## Name ## Helper(); \ private: \ Fixture ## Name ## Helper(Fixture ## Name ## Helper const&); \ Fixture ## Name ## Helper& operator =(Fixture ## Name ## Helper const&); \ }; \ + Fixture ## Name ## Helper::~Fixture ## Name ## Helper(){}; \ \ class Test ## Fixture ## Name : public UnitTest::Test \ { \ @@ -60,9 +62,9 @@ Test ## Fixture ## Name() : Test(#Name, UnitTestSuite::GetSuiteName(), __FILE__, __LINE__) {} \ private: \ virtual void RunImpl() const; \ - } test ## Fixture ## Name ## Instance; \ + } static test ## Fixture ## Name ## Instance; \ \ - UnitTest::ListAdder adder ## Fixture ## Name (List, &test ## Fixture ## Name ## Instance); \ + static UnitTest::ListAdder adder ## Fixture ## Name (List, &test ## Fixture ## Name ## Instance); \ \ void Test ## Fixture ## Name::RunImpl() const \ { \ From 0a6857e3883175a5682bc2a7df9e7b53f73f53a9 Mon Sep 17 00:00:00 2001 From: Tim Bochenek Date: Thu, 2 Feb 2017 18:03:59 -0500 Subject: [PATCH 67/79] fix clang warning fix clang warning 'extra ';' outside function is c++11 extension --- UnitTest++/TestMacros.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UnitTest++/TestMacros.h b/UnitTest++/TestMacros.h index 8ff87f8..dbe3430 100644 --- a/UnitTest++/TestMacros.h +++ b/UnitTest++/TestMacros.h @@ -54,7 +54,7 @@ Fixture ## Name ## Helper(Fixture ## Name ## Helper const&); \ Fixture ## Name ## Helper& operator =(Fixture ## Name ## Helper const&); \ }; \ - Fixture ## Name ## Helper::~Fixture ## Name ## Helper(){}; \ + Fixture ## Name ## Helper::~Fixture ## Name ## Helper(){} \ \ class Test ## Fixture ## Name : public UnitTest::Test \ { \ From 0b15459ee4fbee824c6a699d4c64fba8e49b8339 Mon Sep 17 00:00:00 2001 From: Gabriel Hare Date: Thu, 2 Feb 2017 21:56:48 -0800 Subject: [PATCH 68/79] Downgrade message to STATUS and do not declare C++11 as a requirement. --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c39baf..2ed7b67 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ if(${CMAKE_CXX_COMPILER_ID} MATCHES "MSVC") if (MSVC14 OR MSVC12) # has the support we need else() - message(WARNING "The MSVC compiler version does not support required C++11 features. Please use a different C++ compiler.") + message(STATUS "The MSVC compiler version does not support UnitTest++ C++11 features.") endif() else() include(CheckCXXCompilerFlag) @@ -28,7 +28,7 @@ else() elseif(COMPILER_SUPPORTS_CXX11) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") else() - message(WARNING "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.") + message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support.") endif() endif() From 07d4872076b3b7d824149186a230f54ef5cd04df Mon Sep 17 00:00:00 2001 From: Tim Bochenek Date: Fri, 3 Feb 2017 08:19:17 -0500 Subject: [PATCH 69/79] fix clang warnings fix clang warning warning: no previous extern declaration for non-static variable 'X' [-Wmissing-variable-declarations] --- UnitTest++/TestMacros.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/UnitTest++/TestMacros.h b/UnitTest++/TestMacros.h index dbe3430..0c8e903 100644 --- a/UnitTest++/TestMacros.h +++ b/UnitTest++/TestMacros.h @@ -25,16 +25,16 @@ } \ namespace Suite ## Name -#define UNITTEST_IMPL_TEST(Name, List) \ +#define UNITTEST_IMPL_TEST(Name, List) \ class Test ## Name : public UnitTest::Test \ { \ public: \ Test ## Name() : Test(#Name, UnitTestSuite::GetSuiteName(), __FILE__, __LINE__) {} \ private: \ virtual void RunImpl() const; \ - } test ## Name ## Instance; \ + } static test ## Name ## Instance; \ \ - UnitTest::ListAdder adder ## Name (List, &test ## Name ## Instance); \ + static UnitTest::ListAdder adder ## Name (List, &test ## Name ## Instance); \ \ void Test ## Name::RunImpl() const @@ -62,9 +62,9 @@ Test ## Fixture ## Name() : Test(#Name, UnitTestSuite::GetSuiteName(), __FILE__, __LINE__) {} \ private: \ virtual void RunImpl() const; \ - } static test ## Fixture ## Name ## Instance; \ + } static test ## Fixture ## Name ## Instance; \ \ - static UnitTest::ListAdder adder ## Fixture ## Name (List, &test ## Fixture ## Name ## Instance); \ + static UnitTest::ListAdder adder ## Fixture ## Name (List, &test ## Fixture ## Name ## Instance); \ \ void Test ## Fixture ## Name::RunImpl() const \ { \ From 33e63147539750304216b22b01c8968432c959b8 Mon Sep 17 00:00:00 2001 From: Vicente Adolfo Bolea Sanchez Date: Mon, 22 May 2017 00:22:38 +0900 Subject: [PATCH 70/79] Added autogen.sh file to ease autotools installation --- autogen.sh | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100755 autogen.sh diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 0000000..347366d --- /dev/null +++ b/autogen.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +test -e ./.autotools_aux || mkdir .autotools_aux + +libtoolize -cq +aclocal -I m4 --install # Generate aclocal +autoconf # Generate configure script +autoheader # Generate config.h +automake --add-missing --copy # Generate Makefile.in and other scripts From a6fdaeef1269e50c8777989d4338cc39a5a0f6a3 Mon Sep 17 00:00:00 2001 From: Martin Moene Date: Sat, 8 Jul 2017 11:09:38 +0200 Subject: [PATCH 71/79] Use if (MSVC) as per issue #160 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e60f81b..a683ea1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ option(UTPP_AMPLIFY_WARNINGS set(LIB_SUFFIX "" CACHE STRING "Identifier to add to end of lib directory name e.g. 64 for lib64") -if(${CMAKE_CXX_COMPILER_ID} MATCHES "MSVC") +if (MSVC) # CHECK_CXX_COMPILER_FLAG could be used # but MSVC version is preferred for feature requirements if (MSVC14 OR MSVC12) From a7d506d7ebbea35cc089b319443cd899d440132c Mon Sep 17 00:00:00 2001 From: Flow86 Date: Wed, 20 Mar 2019 13:19:15 +0100 Subject: [PATCH 72/79] add support to build unittest cpp on AIX (IBM) --- UnitTest++/Config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UnitTest++/Config.h b/UnitTest++/Config.h index 4bebf1a..14429ee 100644 --- a/UnitTest++/Config.h +++ b/UnitTest++/Config.h @@ -22,7 +22,7 @@ #if defined(unix) || defined(__unix__) || defined(__unix) || defined(linux) || \ defined(__APPLE__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) \ - || defined (__HAIKU__) + || defined (__HAIKU__) || defined(_AIX) #define UNITTEST_POSIX #endif From bdef2bdd62598afc31e17b24349b47d3813eed57 Mon Sep 17 00:00:00 2001 From: Dan Huantes Date: Wed, 14 Aug 2019 11:32:00 -0500 Subject: [PATCH 73/79] UnitTest++ now correctly supports CMake's find_package config mode [CMakeLists.txt] - Bumped cmake minimum requirement to go to 3.0 as this appears to be earliest version that transitive usage requirements are supported. - Added version to project so that is evident when looking at CMakeLists.txt - Removed include_directories as that command affects more than just UnitTest++ in favor of target_include_directories. - The target_include_directories uses the generator expressions to do the same thing for the BUILD_INTERFACE condition but only affects UnitTest++. The INSTALL_INTERFACE ensures that when UnitTest++ is installed client applications calling find_package for UnitTest++ only have to add the UnitTest++ target to the target_link_libraries and will get the correct include path for UnitTest++ added to their include paths. - Added DEBUG_POSTFIX to both library and unit test to distinguish them from each other as they are installed into the same directory and would otherwise overwrite one another. - Added Versioning using write_basic_package_version_file to the install so that a client can call find_package(UnitTest++ 2.1 REQUIRED) and it will be able to confirm the version. If the version is updated you could theoretically ahve a version 2.2, 2.3 ,etc... and the find_package mechanism will find the correct one. the SameMajorVersion option in that call indicates that 2.3 is compatible with 2.1 or in other words if find_package(UnitTest++ 2.1 REQUIRED) is called and 2.3 is installed that satisfies the condition but if only 3.0 was installed it will fail because of 'SameMajorVersion'. - Also added installation for the Version file. --- CMakeLists.txt | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a683ea1..03a4f62 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ -cmake_minimum_required(VERSION 2.8.1) -project(UnitTest++) +cmake_minimum_required(VERSION 3.0) +project(UnitTest++ VERSION 2.1) option(UTPP_USE_PLUS_SIGN "Set this to OFF if you wish to use '-cpp' instead of '++' in lib/include paths" @@ -74,7 +74,7 @@ endif() file(GLOB TEST_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} tests/*.cpp tests/*.h) source_group( "" FILES ${TEST_SRCS}) add_executable(TestUnitTest++ ${TEST_SRCS}) -include_directories(.) + if(${UTPP_USE_PLUS_SIGN}) set_target_properties(TestUnitTest++ PROPERTIES OUTPUT_NAME TestUnitTest++) @@ -100,13 +100,30 @@ else() set (UTPP_INSTALL_DESTINATION "include/UnitTestPP") endif() +target_include_directories( UnitTest++ + PUBLIC + $ + $ + ) +set_target_properties(UnitTest++ PROPERTIES DEBUG_POSTFIX "-d") +set_target_properties(TestUnitTest++ PROPERTIES DEBUG_POSTFIX "-d") + set(config_install_dir_ lib${LIB_SUFFIX}/cmake/${PROJECT_NAME}) set(targets_export_name_ "${PROJECT_NAME}Targets") +include(CMakePackageConfigHelpers) +write_basic_package_version_file( + cmake/UnitTest++ConfigVersion.cmake + VERSION ${UnitTest++_VERSION} + COMPATIBILITY SameMajorVersion + ) install(TARGETS UnitTest++ EXPORT "${targets_export_name_}" DESTINATION lib${LIB_SUFFIX}) install(FILES ${headers_} DESTINATION ${UTPP_INSTALL_DESTINATION}) install(FILES ${platformHeaders_} DESTINATION ${UTPP_INSTALL_DESTINATION}/${platformDir_}) -install(FILES cmake/UnitTest++Config.cmake DESTINATION "${config_install_dir_}") +install(FILES + cmake/UnitTest++Config.cmake + ${CMAKE_CURRENT_BINARY_DIR}/cmake/UnitTest++ConfigVersion.cmake + DESTINATION "${config_install_dir_}") install(EXPORT "${targets_export_name_}" DESTINATION "${config_install_dir_}") set(prefix ${CMAKE_INSTALL_PREFIX}) From 2423fcac7668aa9c331a2dcf024c3ca06742942d Mon Sep 17 00:00:00 2001 From: Dan Huantes Date: Thu, 15 Aug 2019 08:26:41 -0500 Subject: [PATCH 74/79] CrasingTestsAreReportedAsFailures no longer core dumps on Clang Release Found that Crashing tests at some point in Clang history were actually caught but testing on Clang 6.0 and Clang 7.0 this is not the case. So added Clang to the list of compilers that don't run this tests. Noted that several other Pull Requests were failing for the same reason. --- tests/TestTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/TestTest.cpp b/tests/TestTest.cpp index 5a4e1ca..0db0650 100644 --- a/tests/TestTest.cpp +++ b/tests/TestTest.cpp @@ -72,7 +72,7 @@ namespace { CHECK_EQUAL(1, results.GetFailureCount()); } -#if !defined(UNITTEST_MINGW) && !defined(UNITTEST_WIN32) +#if !defined(UNITTEST_MINGW) && !defined(UNITTEST_WIN32) && !defined(__clang__) // Skip this test in debug because some debuggers don't like it. #if defined(NDEBUG) TEST(CrashingTestsAreReportedAsFailures) From c26966668191029f50d3e9f7318e176e5bbd74fc Mon Sep 17 00:00:00 2001 From: Dan Huantes Date: Thu, 17 Oct 2019 08:23:46 -0500 Subject: [PATCH 75/79] Version made explicitly 3 parts - Updated to appveyor.yml and configure.ac to 2.1.0 to match CMake project version. --- CMakeLists.txt | 2 +- appveyor.yml | 2 +- configure.ac | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 03a4f62..7a3fb55 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.0) -project(UnitTest++ VERSION 2.1) +project(UnitTest++ VERSION 2.1.0) option(UTPP_USE_PLUS_SIGN "Set this to OFF if you wish to use '-cpp' instead of '++' in lib/include paths" diff --git a/appveyor.yml b/appveyor.yml index bebe4f5..3a4637d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -version: 2.0.0.{build} +version: 2.1.0.{build} os: - Windows Server 2012 R2 diff --git a/configure.ac b/configure.ac index 56300a6..372f576 100644 --- a/configure.ac +++ b/configure.ac @@ -23,7 +23,7 @@ AM_CONDITIONAL([WINDOWS], LT_INIT() -AC_SUBST([LIBUNITTEST_SO_VERSION], [2:0:0]) +AC_SUBST([LIBUNITTEST_SO_VERSION], [2:1:0]) # Checks for programs. AC_PROG_CXX From f871471d9020788eb0c05582f6430cca36397424 Mon Sep 17 00:00:00 2001 From: Dan Huantes Date: Tue, 7 Apr 2020 18:07:24 -0500 Subject: [PATCH 76/79] Added Namespace to Exported Target [CMakeLists.txt] - It is standard practice to have a namespace for an imported target. Added UnitTest++:: as the namespace argument so that find_package(UnitTest++) will result in UnitTest++::UnitTest++ target that will be used in target_link_libraries. - Updated target_link_libraries for TestUnitTest++ as an example --- CMakeLists.txt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a3fb55..b4c75c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,6 +64,8 @@ source_group(${platformDir_} FILES ${platformHeaders_} ${platformSources_}) # create the lib add_library(UnitTest++ STATIC ${headers_} ${sources_} ${platformHeaders_} ${platformSources_}) +add_library(UnitTest++::UnitTest++ ALIAS UnitTest++) + if(${UTPP_USE_PLUS_SIGN}) set_target_properties(UnitTest++ PROPERTIES OUTPUT_NAME UnitTest++) @@ -80,7 +82,10 @@ if(${UTPP_USE_PLUS_SIGN}) set_target_properties(TestUnitTest++ PROPERTIES OUTPUT_NAME TestUnitTest++) endif() -target_link_libraries(TestUnitTest++ UnitTest++) +target_link_libraries(TestUnitTest++ + PUBLIC + UnitTest++::UnitTest++ + ) # run unit tests as post build step add_custom_command(TARGET TestUnitTest++ @@ -124,7 +129,7 @@ install(FILES cmake/UnitTest++Config.cmake ${CMAKE_CURRENT_BINARY_DIR}/cmake/UnitTest++ConfigVersion.cmake DESTINATION "${config_install_dir_}") -install(EXPORT "${targets_export_name_}" DESTINATION "${config_install_dir_}") +install(EXPORT "${targets_export_name_}" NAMESPACE "UnitTest++::" DESTINATION "${config_install_dir_}") set(prefix ${CMAKE_INSTALL_PREFIX}) set(exec_prefix ${CMAKE_INSTALL_PREFIX}/bin) From 37df68be21fd3bcadea0c54fe5e7d5176c1801ce Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Mon, 17 Aug 2020 19:53:58 -0500 Subject: [PATCH 77/79] Add hiatus note & link to issue --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 7c138a8..e0b2978 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +> ### Maintenance of UnitTest++, recently sporadic, is officially on hiatus until 1 October 2020. Subscribe to https://github.com/unittest-cpp/unittest-cpp/issues/180 for updates. + + [![Build Status](https://travis-ci.org/unittest-cpp/unittest-cpp.svg?branch=master)](https://travis-ci.org/unittest-cpp/unittest-cpp) [![Build status](https://ci.appveyor.com/api/projects/status/ffs2k8dddts5cyok/branch/master?svg=true)](https://ci.appveyor.com/project/pjohnmeyer/unittest-cpp/branch/master) From 854cae2518d280f732b593cbc9a1c305cb6a753a Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Thu, 1 Oct 2020 19:56:11 -0500 Subject: [PATCH 78/79] Extend hiatus to 15 October See #180 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e0b2978..8de8c90 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -> ### Maintenance of UnitTest++, recently sporadic, is officially on hiatus until 1 October 2020. Subscribe to https://github.com/unittest-cpp/unittest-cpp/issues/180 for updates. +> ### Maintenance of UnitTest++, recently sporadic, is officially on hiatus until 15 October 2020. Subscribe to https://github.com/unittest-cpp/unittest-cpp/issues/180 for updates. [![Build Status](https://travis-ci.org/unittest-cpp/unittest-cpp.svg?branch=master)](https://travis-ci.org/unittest-cpp/unittest-cpp) From 10e50ad70c696002b1d5bbefd0ea04b3ea92a03b Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Thu, 12 Nov 2020 23:26:38 -0600 Subject: [PATCH 79/79] Extend hiatus to 26 November --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8de8c90..6ece10e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -> ### Maintenance of UnitTest++, recently sporadic, is officially on hiatus until 15 October 2020. Subscribe to https://github.com/unittest-cpp/unittest-cpp/issues/180 for updates. +> ### Maintenance of UnitTest++, recently sporadic, is officially on hiatus until 26 November 2020. Subscribe to https://github.com/unittest-cpp/unittest-cpp/issues/180 for updates. [![Build Status](https://travis-ci.org/unittest-cpp/unittest-cpp.svg?branch=master)](https://travis-ci.org/unittest-cpp/unittest-cpp)