From 21589e561214664249d2872c13642ced555cd23a Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Fri, 15 Jul 2016 23:23:45 -0500 Subject: [PATCH] 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); + } + }