Please consider a CPPUNIT_ASSERT_LAMBDA macro
Brought to you by:
blep
Hello,
It would be handy to have a CPPUNIT_ASSERT_LAMBDA(condition, lambda) macro where the lambda is only called if the condition is false. This makes extracting error messages from objects easier and the test code simpler.
#if (defined(_MSC_VER) && _MSC_VER >= 1800) || (defined(__cplusplus) && __cplusplus > 199711L)
/** Assertion with a user specified lamda.
* \ingroup Assertions
* \param condition If this condition evaluates to \c false then the
* test failed.
* \param lambda Message detail is generated when needed and reported in
* diagnostic if \a condition evaluates to \c false.
*/
#define CPPUNIT_ASSERT_LAMBDA(condition, lambda) \
( CPPUNIT_NS::Asserter::failIf( !(condition), \
CPPUNIT_NS::Message( "assertion failed", \
"Expression: " \
#condition, \
!(condition) ? lambda() : "" ), \
CPPUNIT_SOURCELINE() ) )
#endif