Return a bool result from the BOOST_TEST_* macros, f.ex. to allow chaining with &&

This commit is contained in:
Peter Dimov
2020-02-16 20:52:12 +02:00
parent 13e9d3d4d9
commit 5ca752323f

View File

@ -184,13 +184,14 @@ struct lw_test_ge {
};
template<class BinaryPredicate, class T, class U>
inline void test_with_impl(BinaryPredicate pred, char const * expr1, char const * expr2,
inline bool test_with_impl(BinaryPredicate pred, char const * expr1, char const * expr2,
char const * file, int line, char const * function,
T const & t, U const & u)
{
if( pred(t, u) )
{
test_results();
return true;
}
else
{
@ -199,15 +200,17 @@ inline void test_with_impl(BinaryPredicate pred, char const * expr1, char const
<< "' ('" << test_output_impl(t) << "' " << pred.op() << " '" << test_output_impl(u)
<< "') failed in function '" << function << "'" << std::endl;
++test_results().errors();
return false;
}
}
inline void test_cstr_eq_impl( char const * expr1, char const * expr2,
inline bool test_cstr_eq_impl( char const * expr1, char const * expr2,
char const * file, int line, char const * function, char const * const t, char const * const u )
{
if( std::strcmp(t, u) == 0 )
{
test_results();
return true;
}
else
{
@ -215,15 +218,17 @@ inline void test_cstr_eq_impl( char const * expr1, char const * expr2,
<< file << "(" << line << "): test '" << expr1 << " == " << expr2 << "' ('" << t
<< "' == '" << u << "') failed in function '" << function << "'" << std::endl;
++test_results().errors();
return false;
}
}
inline void test_cstr_ne_impl( char const * expr1, char const * expr2,
inline bool test_cstr_ne_impl( char const * expr1, char const * expr2,
char const * file, int line, char const * function, char const * const t, char const * const u )
{
if( std::strcmp(t, u) != 0 )
{
test_results();
return true;
}
else
{
@ -231,11 +236,12 @@ inline void test_cstr_ne_impl( char const * expr1, char const * expr2,
<< file << "(" << line << "): test '" << expr1 << " != " << expr2 << "' ('" << t
<< "' != '" << u << "') failed in function '" << function << "'" << std::endl;
++test_results().errors();
return false;
}
}
template<class FormattedOutputFunction, class InputIterator1, class InputIterator2>
void test_all_eq_impl(FormattedOutputFunction& output,
bool test_all_eq_impl(FormattedOutputFunction& output,
char const * file, int line, char const * function,
InputIterator1 first_begin, InputIterator1 first_end,
InputIterator2 second_begin, InputIterator2 second_end)
@ -294,16 +300,18 @@ void test_all_eq_impl(FormattedOutputFunction& output,
if (error_count == 0)
{
test_results();
return true;
}
else
{
output << std::endl;
++test_results().errors();
return false;
}
}
template<class FormattedOutputFunction, class InputIterator1, class InputIterator2, typename BinaryPredicate>
void test_all_with_impl(FormattedOutputFunction& output,
bool test_all_with_impl(FormattedOutputFunction& output,
char const * file, int line, char const * function,
InputIterator1 first_begin, InputIterator1 first_end,
InputIterator2 second_begin, InputIterator2 second_end,
@ -363,11 +371,13 @@ void test_all_with_impl(FormattedOutputFunction& output,
if (error_count == 0)
{
test_results();
return true;
}
else
{
output << std::endl;
++test_results().errors();
return false;
}
}
@ -407,7 +417,7 @@ inline int report_errors()
} // namespace boost
#define BOOST_TEST(expr) ((expr)? (void)::boost::detail::test_results(): ::boost::detail::test_failed_impl(#expr, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION))
#define BOOST_TEST(expr) ((expr)? ((void)::boost::detail::test_results(), true): (::boost::detail::test_failed_impl(#expr, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION), false))
#define BOOST_TEST_NOT(expr) BOOST_TEST(!(expr))
#define BOOST_ERROR(msg) ( ::boost::detail::error_impl(msg, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION) )