Add BOOST_TEST_LT, BOOST_TEST_LE

This commit is contained in:
Peter Dimov 2017-03-16 01:31:43 +02:00
parent 064cfd3d73
commit 46545326d8
6 changed files with 143 additions and 5 deletions

View File

@ -1,7 +1,7 @@
[/
Copyright 2010, 2011 Beman Dawes
Copyright 2013 Ion Gaztanaga
Copyright 2014 Peter Dimov
Copyright 2014, 2017 Peter Dimov
Distributed under the Boost Software License, Version 1.0.
@ -36,6 +36,8 @@ When using `lightweight_test.hpp`, *do not forget* to
#define BOOST_ERROR(message) /*unspecified*/
#define BOOST_TEST_EQ(expr1, expr2) /*unspecified*/
#define BOOST_TEST_NE(expr1, expr2) /*unspecified*/
#define BOOST_TEST_LT(expr1, expr2) /*unspecified*/
#define BOOST_TEST_LE(expr1, expr2) /*unspecified*/
#define BOOST_TEST_CSTR_EQ(expr1, expr2) /*unspecified*/
#define BOOST_TEST_CSTR_NE(expr1, expr2) /*unspecified*/
#define BOOST_TEST_ALL_EQ(begin1, end1, begin2, end2) /* unspecified */
@ -89,7 +91,7 @@ Increases error count and outputs a message containing
BOOST_TEST_EQ(expr1, expr2)
``
If `expr1 != expr2` increases the error count and outputs a
If `expr1 == expr2` is not true increases the error count and outputs a
message containing both expressions.
[endsect]
@ -100,7 +102,29 @@ message containing both expressions.
BOOST_TEST_NE(expr1, expr2)
``
If `expr1 == expr2` increases the error count and outputs a
If `expr1 != expr2` is not true increases the error count and outputs a
message containing both expressions.
[endsect]
[section BOOST_TEST_LT]
``
BOOST_TEST_LT(expr1, expr2)
``
If `expr1 < expr2` is not true increases the error count and outputs a
message containing both expressions.
[endsect]
[section BOOST_TEST_LE]
``
BOOST_TEST_LE(expr1, expr2)
``
If `expr1 <= expr2` is not true increases the error count and outputs a
message containing both expressions.
[endsect]
@ -111,7 +135,7 @@ message containing both expressions.
BOOST_TEST_CSTR_EQ(expr1, expr2)
``
Specialization of BOOST_TEST_EQ which interprets expr1 and expr2 as pointers to null-terminated byte strings (C strings). If `std::strcmp(expr1, expr2) != 0`, increase the error count and output a message containing both expressions.
Specialization of `BOOST_TEST_EQ` which interprets `expr1` and `expr2` as pointers to null-terminated byte strings (C strings). If `std::strcmp(expr1, expr2) != 0`, increase the error count and output a message containing both expressions.
[endsect]
@ -121,7 +145,7 @@ Specialization of BOOST_TEST_EQ which interprets expr1 and expr2 as pointers to
BOOST_TEST_CSTR_NE(expr1, expr2)
``
Specialization of BOOST_TEST_NE which interprets expr1 and expr2 as pointers to null-terminated byte strings (C strings). If `std::strcmp(expr1, expr2) == 0`, increase the error count and output a message containing both expressions.
Specialization of `BOOST_TEST_NE` which interprets `expr1` and `expr2` as pointers to null-terminated byte strings (C strings). If `std::strcmp(expr1, expr2) == 0`, increase the error count and output a message containing both expressions.
[endsect]

View File

@ -147,6 +147,40 @@ template<class T, class U> inline void test_ne_impl( char const * expr1, char co
}
}
template<class T, class U> inline void test_lt_impl( char const * expr1, char const * expr2,
char const * file, int line, char const * function, T const & t, U const & u )
{
if( t < u )
{
report_errors_remind();
}
else
{
BOOST_LIGHTWEIGHT_TEST_OSTREAM
<< file << "(" << line << "): test '" << expr1 << " < " << expr2
<< "' failed in function '" << function << "': "
<< "'" << test_output_impl(t) << "' >= '" << test_output_impl(u) << "'" << std::endl;
++test_errors();
}
}
template<class T, class U> inline void test_le_impl( char const * expr1, char const * expr2,
char const * file, int line, char const * function, T const & t, U const & u )
{
if( t <= u )
{
report_errors_remind();
}
else
{
BOOST_LIGHTWEIGHT_TEST_OSTREAM
<< file << "(" << line << "): test '" << expr1 << " <= " << expr2
<< "' failed in function '" << function << "': "
<< "'" << test_output_impl(t) << "' > '" << test_output_impl(u) << "'" << std::endl;
++test_errors();
}
}
inline void 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 )
{
@ -360,6 +394,9 @@ inline int report_errors()
#define BOOST_TEST_EQ(expr1,expr2) ( ::boost::detail::test_eq_impl(#expr1, #expr2, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expr1, expr2) )
#define BOOST_TEST_NE(expr1,expr2) ( ::boost::detail::test_ne_impl(#expr1, #expr2, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expr1, expr2) )
#define BOOST_TEST_LT(expr1,expr2) ( ::boost::detail::test_lt_impl(#expr1, #expr2, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expr1, expr2) )
#define BOOST_TEST_LE(expr1,expr2) ( ::boost::detail::test_le_impl(#expr1, #expr2, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expr1, expr2) )
#define BOOST_TEST_CSTR_EQ(expr1,expr2) ( ::boost::detail::test_cstr_eq_impl(#expr1, #expr2, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expr1, expr2) )
#define BOOST_TEST_CSTR_NE(expr1,expr2) ( ::boost::detail::test_cstr_ne_impl(#expr1, #expr2, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expr1, expr2) )

View File

@ -68,6 +68,7 @@ run lightweight_test_test2.cpp ;
run lightweight_test_all_eq_test.cpp ;
run lightweight_test_all_with_test.cpp ;
run lightweight_test_all_with_fail.cpp ;
run lightweight_test_lt_le_test.cpp ;
run-fail lightweight_test_fail.cpp ;
run-fail lightweight_test_fail2.cpp ;
@ -81,6 +82,8 @@ run-fail lightweight_test_fail8.cpp ;
run-fail lightweight_test_fail8.cpp : : : <rtti>off : lightweight_test_fail8_no_rtti ;
run-fail lightweight_test_fail9.cpp ;
run-fail lightweight_test_fail10.cpp ;
run-fail lightweight_test_lt_fail.cpp ;
run-fail lightweight_test_le_fail.cpp ;
run is_same_test.cpp ;

View File

@ -0,0 +1,20 @@
//
// Negative test for BOOST_TEST_LE
//
// Copyright 2017 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//
#include <boost/core/lightweight_test.hpp>
int main()
{
int x = 1;
BOOST_TEST_LE( x, 0 );
return boost::report_errors();
}

View File

@ -0,0 +1,20 @@
//
// Negative test for BOOST_TEST_LT
//
// Copyright 2014, 2017 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//
#include <boost/core/lightweight_test.hpp>
int main()
{
int x = 0;
BOOST_TEST_LT( x, 0 );
return boost::report_errors();
}

View File

@ -0,0 +1,34 @@
//
// Test for BOOST_TEST_LT, BOOST_TEST_LE
//
// Copyright 2014, 2017 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//
#include <boost/core/lightweight_test.hpp>
int main()
{
int x = 0;
BOOST_TEST_LT( x, 1 );
BOOST_TEST_LT( ++x, 2 );
BOOST_TEST_LT( x++, 3 );
BOOST_TEST_LE( x, 2 );
BOOST_TEST_LE( ++x, 3 );
BOOST_TEST_LE( x++, 4 );
int y = 3;
BOOST_TEST_LT( ++y, ++x );
BOOST_TEST_LT( y++, x++ );
BOOST_TEST_LE( ++y, x );
BOOST_TEST_LE( y++, x++ );
return boost::report_errors();
}