8000 Take UnitTest::Check parameter by const reference · Reification/unittest-cpp@21589e5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 21589e5

Browse files
committed
Take UnitTest::Check parameter by const reference
Fixes unittest-cpp#119 and unittest-cpp#7
1 parent 510903c commit 21589e5

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

UnitTest++/Checks.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace UnitTest {
99

1010

1111
template< typename Value >
12-
bool Check(Value const value)
12+
bool Check(Value const& value)
1313
{
1414
return !!value; // doing double negative to avoid silly VS warnings
1515
}

tests/TestChecks.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,4 +315,32 @@ namespace {
315315
CHECK_EQUAL(1234, reporter.lastFailedLine);
316316
}
317317

318+
TEST(CheckProperlyDealsWithOperatorBoolOverrides)
319+
{
320+
class TruthyUnlessCopied
321+
{
322+
public:
323+
TruthyUnlessCopied()
324+
: truthy_(true)
325+
{
326+
}
327+
328+
TruthyUnlessCopied(const TruthyUnlessCopied& orig)
329+
: truthy_(false)
330+
{
331+
}
332+
333+
operator bool() const
334+
{
335+
return truthy_;
336+
}
337+
338+
private:
339+
bool truthy_;
340+
};
341+
342+
TruthyUnlessCopied objectThatShouldBeTruthy;
343+
CHECK(objectThatShouldBeTruthy);
344+
}
345+
318346
}

0 commit comments

Comments
 (0)
0