From 21589e561214664249d2872c13642ced555cd23a Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Fri, 15 Jul 2016 23:23:45 -0500 Subject: [PATCH 1/3] 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 2/3] Attempted fix for Travis build. --- tests/TestChecks.cpp | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 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); } - TEST(CheckProperlyDealsWithOperatorBoolOverrides) + class TruthyUnlessCopied { - class TruthyUnlessCopied + public: + TruthyUnlessCopied() + : truthy_(true) + { + } + + TruthyUnlessCopied(const TruthyUnlessCopied& orig) + : truthy_(false) + { + } + + operator bool() const { - public: - TruthyUnlessCopied() - : truthy_(true) - { - } - - TruthyUnlessCopied(const TruthyUnlessCopied& orig) - : truthy_(false) - { - } - - operator bool() const - { - return truthy_; - } - - private: - bool truthy_; - }; + return truthy_; + } + + private: + bool truthy_; + }; + TEST(CheckProperlyDealsWithOperatorBoolOverrides) + { 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 3/3] 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) { }