diff --git a/doc/lightweight_test.qbk b/doc/lightweight_test.qbk index ed0990b..8391692 100644 --- a/doc/lightweight_test.qbk +++ b/doc/lightweight_test.qbk @@ -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] diff --git a/include/boost/core/lightweight_test.hpp b/include/boost/core/lightweight_test.hpp index b580dd2..260a1ac 100644 --- a/include/boost/core/lightweight_test.hpp +++ b/include/boost/core/lightweight_test.hpp @@ -147,6 +147,40 @@ template inline void test_ne_impl( char const * expr1, char co } } +template 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 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) ) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 1490cf2..72e62a2 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -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 : : : 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 ; diff --git a/test/lightweight_test_le_fail.cpp b/test/lightweight_test_le_fail.cpp new file mode 100644 index 0000000..9706be4 --- /dev/null +++ b/test/lightweight_test_le_fail.cpp @@ -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 + +int main() +{ + int x = 1; + + BOOST_TEST_LE( x, 0 ); + + return boost::report_errors(); +} diff --git a/test/lightweight_test_lt_fail.cpp b/test/lightweight_test_lt_fail.cpp new file mode 100644 index 0000000..ba6d243 --- /dev/null +++ b/test/lightweight_test_lt_fail.cpp @@ -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 + +int main() +{ + int x = 0; + + BOOST_TEST_LT( x, 0 ); + + return boost::report_errors(); +} diff --git a/test/lightweight_test_lt_le_test.cpp b/test/lightweight_test_lt_le_test.cpp new file mode 100644 index 0000000..7f08783 --- /dev/null +++ b/test/lightweight_test_lt_le_test.cpp @@ -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 + +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(); +}