From 0f8b499bca5fd2eb63b217654f726c9ada860dab Mon Sep 17 00:00:00 2001 From: Glen Fernandes Date: Tue, 13 Jun 2017 23:24:38 -0400 Subject: [PATCH 1/2] Use workaround.hpp from boost/config --- include/boost/core/addressof.hpp | 2 +- include/boost/core/no_exceptions_support.hpp | 2 +- include/boost/core/ref.hpp | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/boost/core/addressof.hpp b/include/boost/core/addressof.hpp index b73ea56..8ddda8b 100644 --- a/include/boost/core/addressof.hpp +++ b/include/boost/core/addressof.hpp @@ -42,7 +42,7 @@ addressof(T& o) BOOST_NOEXCEPT } /* boost */ #else -#include +#include #include namespace boost { diff --git a/include/boost/core/no_exceptions_support.hpp b/include/boost/core/no_exceptions_support.hpp index a697f01..e2453d0 100644 --- a/include/boost/core/no_exceptions_support.hpp +++ b/include/boost/core/no_exceptions_support.hpp @@ -21,7 +21,7 @@ //---------------------------------------------------------------------- #include -#include +#include #if !(defined BOOST_NO_EXCEPTIONS) # define BOOST_TRY { try diff --git a/include/boost/core/ref.hpp b/include/boost/core/ref.hpp index 47dc858..7d768ff 100644 --- a/include/boost/core/ref.hpp +++ b/include/boost/core/ref.hpp @@ -8,8 +8,8 @@ #endif #include -#include -#include +#include +#include // // ref.hpp - ref/cref, useful helper functions From 3a2c94df8c9d9359454b7e0343b71c7da53f6ef1 Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Sun, 18 Jun 2017 01:10:43 +0900 Subject: [PATCH 2/2] Added BOOST_TEST_GT and BOOST_TEST_GE. Just LT and LE are insufficient for testing operator overloads. --- doc/lightweight_test.qbk | 25 +++++++++++++++++ include/boost/core/lightweight_test.hpp | 36 +++++++++++++++++++++++++ test/Jamfile.v2 | 3 +++ test/lightweight_test_ge_fail.cpp | 20 ++++++++++++++ test/lightweight_test_gt_fail.cpp | 20 ++++++++++++++ test/lightweight_test_gt_ge_test.cpp | 34 +++++++++++++++++++++++ 6 files changed, 138 insertions(+) create mode 100644 test/lightweight_test_ge_fail.cpp create mode 100644 test/lightweight_test_gt_fail.cpp create mode 100644 test/lightweight_test_gt_ge_test.cpp diff --git a/doc/lightweight_test.qbk b/doc/lightweight_test.qbk index 8391692..8884239 100644 --- a/doc/lightweight_test.qbk +++ b/doc/lightweight_test.qbk @@ -2,6 +2,7 @@ Copyright 2010, 2011 Beman Dawes Copyright 2013 Ion Gaztanaga Copyright 2014, 2017 Peter Dimov + Copyright 2017 Kohei Takahashi Distributed under the Boost Software License, Version 1.0. @@ -38,6 +39,8 @@ When using `lightweight_test.hpp`, *do not forget* to #define BOOST_TEST_NE(expr1, expr2) /*unspecified*/ #define BOOST_TEST_LT(expr1, expr2) /*unspecified*/ #define BOOST_TEST_LE(expr1, expr2) /*unspecified*/ +#define BOOST_TEST_GT(expr1, expr2) /*unspecified*/ +#define BOOST_TEST_GE(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 */ @@ -129,6 +132,28 @@ message containing both expressions. [endsect] +[section BOOST_TEST_GT] + +`` +BOOST_TEST_GT(expr1, expr2) +`` + +If `expr1 > expr2` is not true increases the error count and outputs a +message containing both expressions. + +[endsect] + +[section BOOST_TEST_GE] + +`` +BOOST_TEST_GE(expr1, expr2) +`` + +If `expr1 >= expr2` is not true increases the error count and outputs a +message containing both expressions. + +[endsect] + [section BOOST_TEST_CSTR_EQ] `` diff --git a/include/boost/core/lightweight_test.hpp b/include/boost/core/lightweight_test.hpp index fc8ea74..eca9f61 100644 --- a/include/boost/core/lightweight_test.hpp +++ b/include/boost/core/lightweight_test.hpp @@ -186,6 +186,40 @@ template inline void test_le_impl( char const * expr1, char co } } +template inline void test_gt_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_ge_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 ) { @@ -401,6 +435,8 @@ inline int report_errors() #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_GT(expr1,expr2) ( ::boost::detail::test_gt_impl(#expr1, #expr2, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expr1, expr2) ) +#define BOOST_TEST_GE(expr1,expr2) ( ::boost::detail::test_ge_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 8b1c9b7..204e79e 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -70,6 +70,7 @@ 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 lightweight_test_gt_ge_test.cpp ; run lightweight_test_eq_nullptr.cpp ; @@ -87,6 +88,8 @@ 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-fail lightweight_test_gt_fail.cpp ; +run-fail lightweight_test_ge_fail.cpp ; run is_same_test.cpp ; diff --git a/test/lightweight_test_ge_fail.cpp b/test/lightweight_test_ge_fail.cpp new file mode 100644 index 0000000..6671215 --- /dev/null +++ b/test/lightweight_test_ge_fail.cpp @@ -0,0 +1,20 @@ +// +// Negative test for BOOST_TEST_GE +// +// Copyright 2017 Kohei Takahashi +// +// 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_GE( x, 1 ); + + return boost::report_errors(); +} diff --git a/test/lightweight_test_gt_fail.cpp b/test/lightweight_test_gt_fail.cpp new file mode 100644 index 0000000..3a0bd3c --- /dev/null +++ b/test/lightweight_test_gt_fail.cpp @@ -0,0 +1,20 @@ +// +// Negative test for BOOST_TEST_GT +// +// Copyright 2017 Kohei Takahashi +// +// 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_GT( x, 0 ); + + return boost::report_errors(); +} diff --git a/test/lightweight_test_gt_ge_test.cpp b/test/lightweight_test_gt_ge_test.cpp new file mode 100644 index 0000000..d935a0a --- /dev/null +++ b/test/lightweight_test_gt_ge_test.cpp @@ -0,0 +1,34 @@ +// +// Test for BOOST_TEST_GT, BOOST_TEST_GE +// +// Copyright 2017 Kohei Takahashi +// +// 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_GT( x, -1 ); + BOOST_TEST_GT( ++x, 0 ); + BOOST_TEST_GT( x++, 0 ); + + BOOST_TEST_GE( x, 2 ); + BOOST_TEST_GE( ++x, 3 ); + BOOST_TEST_GE( x++, 3 ); + + int y = 5; + + BOOST_TEST_GT( ++y, ++x ); + BOOST_TEST_GT( y++, x++ ); + + BOOST_TEST_GE( ++y, x ); + BOOST_TEST_GE( y++, x++ ); + + return boost::report_errors(); +}