Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r58526 - in trunk/boost/test: . impl
From: gennadiy.rozental_at_[hidden]
Date: 2009-12-25 04:20:29


Author: rogeeff
Date: 2009-12-25 04:20:28 EST (Fri, 25 Dec 2009)
New Revision: 58526
URL: http://svn.boost.org/trac/boost/changeset/58526

Log:
in preparation of production use of test tools
Text files modified:
   trunk/boost/test/impl/test_tools.ipp | 269 +++++++++++++---------------
   trunk/boost/test/test_tools.hpp | 376 ++++++++++++++++++++-------------------
   2 files changed, 316 insertions(+), 329 deletions(-)

Modified: trunk/boost/test/impl/test_tools.ipp
==============================================================================
--- trunk/boost/test/impl/test_tools.ipp (original)
+++ trunk/boost/test/impl/test_tools.ipp 2009-12-25 04:20:28 EST (Fri, 25 Dec 2009)
@@ -113,72 +113,34 @@
 
 using ::boost::unit_test::lazy_ostream;
 
-bool
-check_impl( predicate_result const& pr, lazy_ostream const& check_descr,
- const_string file_name, std::size_t line_num,
- tool_level tl, check_type ct,
- std::size_t num_of_args, ... )
+static char const* check_str [] = { " == ", " != ", " < " , " <= ", " > " , " >= " };
+static char const* rever_str [] = { " != ", " == ", " >= ", " > " , " <= ", " < " };
+
+template<typename OutStream>
+void
+format_report( OutStream& os, predicate_result const& pr, unit_test::lazy_ostream const& assertion_descr,
+ tool_level tl, check_type ct,
+ std::size_t num_args, va_list args,
+ char const* prefix, char const* suffix )
 {
     using namespace unit_test;
 
- if( !framework::is_initialized() )
- throw std::runtime_error( "can't use testing tools before framework is initialized" );
-
- if( !!pr )
- tl = PASS;
-
- log_level ll;
- char const* prefix;
- char const* suffix;
-
- switch( tl ) {
- case PASS:
- ll = log_successful_tests;
- prefix = "check ";
- suffix = " passed";
- break;
- case WARN:
- ll = log_warnings;
- prefix = "condition ";
- suffix = " is not satisfied";
- break;
- case CHECK:
- ll = log_all_errors;
- prefix = "check ";
- suffix = " failed";
- break;
- case REQUIRE:
- ll = log_fatal_errors;
- prefix = "critical check ";
- suffix = " failed";
- break;
- default:
- return true;
- }
-
     switch( ct ) {
     case CHECK_PRED:
- unit_test_log << unit_test::log::begin( file_name, line_num )
- << ll << prefix << check_descr << suffix;
+ os << prefix << assertion_descr << suffix;
         
         if( !pr.has_empty_message() )
- unit_test_log << ". " << pr.message();
-
- unit_test_log << unit_test::log::end();
+ os << ". " << pr.message();
         break;
 
     case CHECK_MSG:
- unit_test_log << unit_test::log::begin( file_name, line_num ) << ll;
-
         if( tl == PASS )
- unit_test_log << prefix << "'" << check_descr << "'" << suffix;
+ os << prefix << "'" << assertion_descr << "'" << suffix;
         else
- unit_test_log << check_descr;
+ os << assertion_descr;
         
         if( !pr.has_empty_message() )
- unit_test_log << ". " << pr.message();
-
- unit_test_log << unit_test::log::end();
+ os << ". " << pr.message();
         break;
 
     case CHECK_EQUAL:
@@ -187,37 +149,23 @@
     case CHECK_LE:
     case CHECK_GT:
     case CHECK_GE: {
- static char const* check_str [] = { " == ", " != ", " < " , " <= ", " > " , " >= " };
- static char const* rever_str [] = { " != ", " == ", " >= ", " > " , " <= ", " < " };
-
- va_list args;
-
- va_start( args, num_of_args );
         char const* arg1_descr = va_arg( args, char const* );
         lazy_ostream const* arg1_val = va_arg( args, lazy_ostream const* );
         char const* arg2_descr = va_arg( args, char const* );
         lazy_ostream const* arg2_val = va_arg( args, lazy_ostream const* );
 
- unit_test_log << unit_test::log::begin( file_name, line_num )
- << ll << prefix << arg1_descr << check_str[ct-CHECK_EQUAL] << arg2_descr << suffix;
+ os << prefix << arg1_descr << check_str[ct-CHECK_EQUAL] << arg2_descr << suffix;
 
         if( tl != PASS )
- unit_test_log << " [" << *arg1_val << rever_str[ct-CHECK_EQUAL] << *arg2_val << "]" ;
-
- va_end( args );
+ os << " [" << *arg1_val << rever_str[ct-CHECK_EQUAL] << *arg2_val << "]" ;
         
         if( !pr.has_empty_message() )
- unit_test_log << ". " << pr.message();
-
- unit_test_log << unit_test::log::end();
+ os << ". " << pr.message();
         break;
     }
 
     case CHECK_CLOSE:
     case CHECK_CLOSE_FRACTION: {
- va_list args;
-
- va_start( args, num_of_args );
         char const* arg1_descr = va_arg( args, char const* );
         lazy_ostream const* arg1_val = va_arg( args, lazy_ostream const* );
         char const* arg2_descr = va_arg( args, char const* );
@@ -225,132 +173,146 @@
         /* toler_descr = */ va_arg( args, char const* );
         lazy_ostream const* toler_val = va_arg( args, lazy_ostream const* );
 
- unit_test_log << unit_test::log::begin( file_name, line_num ) << ll;
-
- unit_test_log << "difference{" << pr.message() << (ct == CHECK_CLOSE ? "%" : "")
- << "} between " << arg1_descr << "{" << *arg1_val
- << "} and " << arg2_descr << "{" << *arg2_val
- << ( tl == PASS ? "} doesn't exceed " : "} exceeds " )
- << *toler_val;
+ os << "difference{" << pr.message() << (ct == CHECK_CLOSE ? "%" : "")
+ << "} between " << arg1_descr << "{" << *arg1_val
+ << "} and " << arg2_descr << "{" << *arg2_val
+ << ( tl == PASS ? "} doesn't exceed " : "} exceeds " )
+ << *toler_val;
         if( ct == CHECK_CLOSE )
- unit_test_log << "%";
-
- va_end( args );
-
- unit_test_log << unit_test::log::end();
+ os << "%";
         break;
     }
     case CHECK_SMALL: {
- va_list args;
-
- va_start( args, num_of_args );
         char const* arg1_descr = va_arg( args, char const* );
         lazy_ostream const* arg1_val = va_arg( args, lazy_ostream const* );
         /* toler_descr = */ va_arg( args, char const* );
         lazy_ostream const* toler_val = va_arg( args, lazy_ostream const* );
 
- unit_test_log << unit_test::log::begin( file_name, line_num ) << ll;
-
- unit_test_log << "absolute value of " << arg1_descr << "{" << *arg1_val << "}"
- << ( tl == PASS ? " doesn't exceed " : " exceeds " )
- << *toler_val;
-
- va_end( args );
+ os << "absolute value of " << arg1_descr << "{" << *arg1_val << "}"
+ << ( tl == PASS ? " doesn't exceed " : " exceeds " )
+ << *toler_val;
         
         if( !pr.has_empty_message() )
- unit_test_log << ". " << pr.message();
-
- unit_test_log << unit_test::log::end();
+ os << ". " << pr.message();
         break;
     }
 
     case CHECK_PRED_WITH_ARGS: {
- unit_test_log << unit_test::log::begin( file_name, line_num )
- << ll << prefix << check_descr;
+ va_list args_copy = args;
+
+ os << prefix << assertion_descr;
 
         // print predicate call description
- {
- va_list args;
- va_start( args, num_of_args );
-
- unit_test_log << "( ";
- for( std::size_t i = 0; i < num_of_args; ++i ) {
- unit_test_log << va_arg( args, char const* );
- va_arg( args, lazy_ostream const* ); // skip argument value;
-
- if( i != num_of_args-1 )
- unit_test_log << ", ";
- }
- unit_test_log << " )" << suffix;
- va_end( args );
+ os << "( ";
+ for( std::size_t i = 0; i < num_args; ++i ) {
+ os << va_arg( args, char const* );
+ va_arg( args, lazy_ostream const* ); // skip argument value;
+
+ if( i != num_args-1 )
+ os << ", ";
         }
+ os << " )" << suffix;
                         
         if( tl != PASS ) {
- va_list args;
- va_start( args, num_of_args );
+ args = args_copy;
 
- unit_test_log << " for ( ";
- for( std::size_t i = 0; i < num_of_args; ++i ) {
+ os << " for ( ";
+ for( std::size_t i = 0; i < num_args; ++i ) {
                 va_arg( args, char const* ); // skip argument description;
- unit_test_log << *va_arg( args, lazy_ostream const* );
+ os << *va_arg( args, lazy_ostream const* );
                 
- if( i != num_of_args-1 )
- unit_test_log << ", ";
+ if( i != num_args-1 )
+ os << ", ";
             }
- unit_test_log << " )";
- va_end( args );
+ os << " )";
         }
        
         if( !pr.has_empty_message() )
- unit_test_log << ". " << pr.message();
-
- unit_test_log << unit_test::log::end();
+ os << ". " << pr.message();
         break;
     }
 
     case CHECK_EQUAL_COLL: {
- va_list args;
-
- va_start( args, num_of_args );
         char const* left_begin_descr = va_arg( args, char const* );
         char const* left_end_descr = va_arg( args, char const* );
         char const* right_begin_descr = va_arg( args, char const* );
         char const* right_end_descr = va_arg( args, char const* );
 
- unit_test_log << unit_test::log::begin( file_name, line_num )
- << ll << prefix
- << "{ " << left_begin_descr << ", " << left_end_descr << " } == { "
- << right_begin_descr << ", " << right_end_descr << " }"
- << suffix;
+ os << prefix << "{ " << left_begin_descr << ", " << left_end_descr << " } == { "
+ << right_begin_descr << ", " << right_end_descr << " }"
+ << suffix;
 
- va_end( args );
-
         if( !pr.has_empty_message() )
- unit_test_log << ". " << pr.message();
-
- unit_test_log << unit_test::log::end();
+ os << ". " << pr.message();
         break;
     }
 
     case CHECK_BITWISE_EQUAL: {
- va_list args;
-
- va_start( args, num_of_args );
         char const* left_descr = va_arg( args, char const* );
         char const* right_descr = va_arg( args, char const* );
 
- unit_test_log << unit_test::log::begin( file_name, line_num )
- << ll << prefix << left_descr << " =.= " << right_descr << suffix;
-
- va_end( args );
+ os << prefix << left_descr << " =.= " << right_descr << suffix;
         
         if( !pr.has_empty_message() )
- unit_test_log << ". " << pr.message();
-
- unit_test_log << unit_test::log::end();
+ os << ". " << pr.message();
         break;
     }
     }
+}
+
+//____________________________________________________________________________//
+
+bool
+check_impl( predicate_result const& pr, lazy_ostream const& assertion_descr,
+ const_string file_name, std::size_t line_num,
+ tool_level tl, check_type ct,
+ std::size_t num_args, ... )
+{
+ using namespace unit_test;
+
+ if( !framework::is_initialized() )
+ throw std::runtime_error( "can't use testing tools before framework is initialized" );
+
+ if( !!pr )
+ tl = PASS;
+
+ log_level ll;
+ char const* prefix;
+ char const* suffix;
+
+ switch( tl ) {
+ case PASS:
+ ll = log_successful_tests;
+ prefix = "check ";
+ suffix = " passed";
+ break;
+ case WARN:
+ ll = log_warnings;
+ prefix = "condition ";
+ suffix = " is not satisfied";
+ break;
+ case CHECK:
+ ll = log_all_errors;
+ prefix = "check ";
+ suffix = " failed";
+ break;
+ case REQUIRE:
+ ll = log_fatal_errors;
+ prefix = "critical check ";
+ suffix = " failed";
+ break;
+ default:
+ return true;
+ }
+
+ unit_test_log << unit_test::log::begin( file_name, line_num ) << ll;
+ va_list args;
+ va_start( args, num_args );
+
+ format_report( unit_test_log, pr, assertion_descr, tl, ct, num_args, args, prefix, suffix );
+
+ va_end( args );
+ unit_test_log << unit_test::log::end();
 
     switch( tl ) {
     case PASS:
@@ -377,6 +339,23 @@
 
 //____________________________________________________________________________//
 
+BOOST_TEST_DECL std::string
+prod_report_format( predicate_result const& pr, unit_test::lazy_ostream const& assertion_descr, check_type ct, std::size_t num_args, ... )
+{
+ std::ostringstream msg_buff;
+
+ va_list args;
+ va_start( args, num_args );
+
+ format_report( msg_buff, pr, assertion_descr, CHECK, ct, num_args, args, "assertion ", " failed" );
+
+ va_end( args );
+
+ return msg_buff.str();
+}
+
+//____________________________________________________________________________//
+
 predicate_result
 equal_impl( char const* left, char const* right )
 {

Modified: trunk/boost/test/test_tools.hpp
==============================================================================
--- trunk/boost/test/test_tools.hpp (original)
+++ trunk/boost/test/test_tools.hpp 2009-12-25 04:20:28 EST (Fri, 25 Dec 2009)
@@ -17,7 +17,13 @@
 
 // Boost.Test
 #include <boost/test/predicate_result.hpp>
+#ifndef BOOST_TEST_PROD
 #include <boost/test/unit_test_log.hpp>
+#define BOOST_TEST_TOOLS_STRINGIZE( arg ) BOOST_TEST_STRINGIZE( arg )
+#else
+#define BOOST_TEST_PASSPOINT()
+#define BOOST_TEST_TOOLS_STRINGIZE( arg ) BOOST_STRINGIZE( arg )
+#endif
 #include <boost/test/floating_point_comparison.hpp>
 
 #include <boost/test/detail/config.hpp>
@@ -31,7 +37,7 @@
 // Boost
 #include <boost/preprocessor/seq/for_each.hpp>
 #include <boost/preprocessor/seq/size.hpp>
-#include <boost/preprocessor/seq/enum.hpp>
+#include <boost/preprocessor/seq/to_tuple.hpp>
 #include <boost/preprocessor/repetition/repeat.hpp>
 #include <boost/preprocessor/punctuation/comma_if.hpp>
 #include <boost/preprocessor/arithmetic/add.hpp>
@@ -71,50 +77,56 @@
 // R - right argument
 // TL - tool level
 // CT - check type
-// ARGS - arguments list
+// ARGS - arguments list (as PP sequence)
 
-#define BOOST_TEST_TOOL_IMPL( func, P, check_descr, TL, CT ) \
- ::boost::test_tools::tt_detail::func( \
- P, \
- ::boost::unit_test::lazy_ostream::instance() << check_descr, \
+// frwd_type:
+// 0 - args exists and need to be forwarded; call check_frwd
+// 1 - args exists, but do not need to be forwarded; call check_impl directly
+// 2 - no arguments; call check_impl directly
+
+#ifndef BOOST_TEST_PROD
+
+#define BOOST_TEST_TOOL_PASS_PRED0( P, ARGS ) P
+#define BOOST_TEST_TOOL_PASS_PRED1( P, ARGS ) P BOOST_PP_SEQ_TO_TUPLE(ARGS)
+#define BOOST_TEST_TOOL_PASS_PRED2( P, ARGS ) P
+
+#define BOOST_TEST_TOOL_PASS_ARG( r, _, arg ) , arg, BOOST_STRINGIZE( arg )
+#define BOOST_TEST_TOOL_PASS_ARG_DSCR( r, _, arg ) , BOOST_STRINGIZE( arg )
+
+#define BOOST_TEST_TOOL_PASS_ARGS0( ARGS ) \
+ BOOST_PP_SEQ_FOR_EACH( BOOST_TEST_TOOL_PASS_ARG, _, ARGS )
+#define BOOST_TEST_TOOL_PASS_ARGS1( ARGS ) \
+ , BOOST_PP_SEQ_SIZE(ARGS) BOOST_PP_SEQ_FOR_EACH( BOOST_TEST_TOOL_PASS_ARG_DSCR, _, ARGS )
+#define BOOST_TEST_TOOL_PASS_ARGS2( ARGS ) \
+ , 0
+
+#define BOOST_TEST_TOOL_IMPL(frwd_type, P, assertion_descr,TL,CT,ARGS) \
+do { \
+ BOOST_TEST_PASSPOINT(); \
+ ::boost::test_tools::tt_detail:: \
+ BOOST_PP_IF( frwd_type, check_impl, check_frwd ) ( \
+ BOOST_JOIN( BOOST_TEST_TOOL_PASS_PRED, frwd_type )( P, ARGS ), \
+ ::boost::unit_test::lazy_ostream::instance() << assertion_descr,\
         BOOST_TEST_L(__FILE__), \
         static_cast<std::size_t>(__LINE__), \
         ::boost::test_tools::tt_detail::TL, \
         ::boost::test_tools::tt_detail::CT \
+ BOOST_JOIN( BOOST_TEST_TOOL_PASS_ARGS, frwd_type )( ARGS ) ); \
+} while( ::boost::test_tools::dummy_cond ) \
 /**/
+#endif
 
 //____________________________________________________________________________//
 
-#define BOOST_CHECK_IMPL( P, check_descr, TL, CT ) \
-do { \
- BOOST_TEST_PASSPOINT(); \
- BOOST_TEST_TOOL_IMPL( check_impl, P, check_descr, TL, CT ), 0 );\
-} while( ::boost::test_tools::dummy_cond ) \
-/**/
-
-//____________________________________________________________________________//
-
-#define BOOST_TEST_PASS_ARG_INFO( r, data, arg ) , arg, BOOST_STRINGIZE( arg )
-
-#define BOOST_CHECK_WITH_ARGS_IMPL( P, check_descr, TL, CT, ARGS ) \
-do { \
- BOOST_TEST_PASSPOINT(); \
- BOOST_TEST_TOOL_IMPL( check_frwd, P, check_descr, TL, CT ) \
- BOOST_PP_SEQ_FOR_EACH( BOOST_TEST_PASS_ARG_INFO, '_', ARGS ) ); \
-} while( ::boost::test_tools::dummy_cond ) \
-/**/
-
-//____________________________________________________________________________//
-
-#define BOOST_WARN( P ) BOOST_CHECK_IMPL( (P), BOOST_TEST_STRINGIZE( P ), WARN, CHECK_PRED )
-#define BOOST_CHECK( P ) BOOST_CHECK_IMPL( (P), BOOST_TEST_STRINGIZE( P ), CHECK, CHECK_PRED )
-#define BOOST_REQUIRE( P ) BOOST_CHECK_IMPL( (P), BOOST_TEST_STRINGIZE( P ), REQUIRE, CHECK_PRED )
+#define BOOST_WARN( P ) BOOST_TEST_TOOL_IMPL( 2, (P), BOOST_TEST_TOOLS_STRINGIZE( P ), WARN, CHECK_PRED, _ )
+#define BOOST_CHECK( P ) BOOST_TEST_TOOL_IMPL( 2, (P), BOOST_TEST_TOOLS_STRINGIZE( P ), CHECK, CHECK_PRED, _ )
+#define BOOST_REQUIRE( P ) BOOST_TEST_TOOL_IMPL( 2, (P), BOOST_TEST_TOOLS_STRINGIZE( P ), REQUIRE, CHECK_PRED, _ )
 
 //____________________________________________________________________________//
 
-#define BOOST_WARN_MESSAGE( P, M ) BOOST_CHECK_IMPL( (P), M, WARN, CHECK_MSG )
-#define BOOST_CHECK_MESSAGE( P, M ) BOOST_CHECK_IMPL( (P), M, CHECK, CHECK_MSG )
-#define BOOST_REQUIRE_MESSAGE( P, M ) BOOST_CHECK_IMPL( (P), M, REQUIRE, CHECK_MSG )
+#define BOOST_WARN_MESSAGE( P, M ) BOOST_TEST_TOOL_IMPL( 2, (P), M, WARN, CHECK_MSG, _ )
+#define BOOST_CHECK_MESSAGE( P, M ) BOOST_TEST_TOOL_IMPL( 2, (P), M, CHECK, CHECK_MSG, _ )
+#define BOOST_REQUIRE_MESSAGE( P, M ) BOOST_TEST_TOOL_IMPL( 2, (P), M, REQUIRE, CHECK_MSG, _ )
 
 //____________________________________________________________________________//
 
@@ -127,10 +139,10 @@
     try { \
         BOOST_TEST_PASSPOINT(); \
         S; \
- BOOST_CHECK_IMPL( false, "exception " BOOST_STRINGIZE( E ) " is expected", TL, CHECK_MSG ); } \
- catch( E const& ex ) { \
+ BOOST_TEST_TOOL_IMPL( 2,false,"exception " BOOST_STRINGIZE(E) " is expected",TL,CHECK_MSG,_); \
+ } catch( E const& ex ) { \
         ::boost::unit_test::ut_detail::ignore_unused_variable_warning( ex ); \
- BOOST_CHECK_IMPL( P, prefix BOOST_STRINGIZE( E ) " is caught", TL, CHECK_MSG ); \
+ BOOST_TEST_TOOL_IMPL( 2, P, prefix BOOST_STRINGIZE( E ) " is caught", TL, CHECK_MSG, _ ); \
     } \
 /**/
 
@@ -148,13 +160,13 @@
 
 //____________________________________________________________________________//
 
-#define BOOST_CHECK_NO_THROW_IMPL( S, TL ) \
- try { \
- S; \
- BOOST_CHECK_IMPL( true, "no exceptions thrown by " BOOST_STRINGIZE( S ), TL, CHECK_MSG ); } \
- catch( ... ) { \
- BOOST_CHECK_IMPL( false, "exception thrown by " BOOST_STRINGIZE( S ), TL, CHECK_MSG ); \
- } \
+#define BOOST_CHECK_NO_THROW_IMPL( S, TL ) \
+ try { \
+ S; \
+ BOOST_TEST_TOOL_IMPL( 2,true,"no exceptions thrown by " BOOST_STRINGIZE( S ),TL,CHECK_MSG,_); \
+ } catch( ... ) { \
+ BOOST_TEST_TOOL_IMPL( 2,false,"exception thrown by " BOOST_STRINGIZE( S ), TL, CHECK_MSG, _ ); \
+ } \
 /**/
 
 #define BOOST_WARN_NO_THROW( S ) BOOST_CHECK_NO_THROW_IMPL( S, WARN )
@@ -163,133 +175,121 @@
 
 //____________________________________________________________________________//
 
-#define BOOST_WARN_EQUAL( L, R ) \
- BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::equal_impl_frwd(), "", WARN, CHECK_EQUAL, (L)(R) )
-#define BOOST_CHECK_EQUAL( L, R ) \
- BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::equal_impl_frwd(), "", CHECK, CHECK_EQUAL, (L)(R) )
-#define BOOST_REQUIRE_EQUAL( L, R ) \
- BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::equal_impl_frwd(), "", REQUIRE, CHECK_EQUAL, (L)(R) )
+#define BOOST_WARN_EQUAL( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
+ ::boost::test_tools::tt_detail::equal_impl_frwd(), "", WARN, CHECK_EQUAL, (L)(R) )
+#define BOOST_CHECK_EQUAL( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
+ ::boost::test_tools::tt_detail::equal_impl_frwd(), "", CHECK, CHECK_EQUAL, (L)(R) )
+#define BOOST_REQUIRE_EQUAL( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
+ ::boost::test_tools::tt_detail::equal_impl_frwd(), "", REQUIRE, CHECK_EQUAL, (L)(R) )
 
 //____________________________________________________________________________//
 
-#define BOOST_WARN_NE( L, R ) \
- BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::ne_impl(), "", WARN, CHECK_NE, (L)(R) )
-#define BOOST_CHECK_NE( L, R ) \
- BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::ne_impl(), "", CHECK, CHECK_NE, (L)(R) )
-#define BOOST_REQUIRE_NE( L, R ) \
- BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::ne_impl(), "", REQUIRE, CHECK_NE, (L)(R) )
+#define BOOST_WARN_NE( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
+ ::boost::test_tools::tt_detail::ne_impl(), "", WARN, CHECK_NE, (L)(R) )
+#define BOOST_CHECK_NE( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
+ ::boost::test_tools::tt_detail::ne_impl(), "", CHECK, CHECK_NE, (L)(R) )
+#define BOOST_REQUIRE_NE( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
+ ::boost::test_tools::tt_detail::ne_impl(), "", REQUIRE, CHECK_NE, (L)(R) )
 
 //____________________________________________________________________________//
 
-#define BOOST_WARN_LT( L, R ) \
- BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::lt_impl(), "", WARN, CHECK_LT, (L)(R) )
-#define BOOST_CHECK_LT( L, R ) \
- BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::lt_impl(), "", CHECK, CHECK_LT, (L)(R) )
-#define BOOST_REQUIRE_LT( L, R ) \
- BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::lt_impl(), "", REQUIRE, CHECK_LT, (L)(R) )
+#define BOOST_WARN_LT( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
+ ::boost::test_tools::tt_detail::lt_impl(), "", WARN, CHECK_LT, (L)(R) )
+#define BOOST_CHECK_LT( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
+ ::boost::test_tools::tt_detail::lt_impl(), "", CHECK, CHECK_LT, (L)(R) )
+#define BOOST_REQUIRE_LT( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
+ ::boost::test_tools::tt_detail::lt_impl(), "", REQUIRE, CHECK_LT, (L)(R) )
 
 //____________________________________________________________________________//
 
-#define BOOST_WARN_LE( L, R ) \
- BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::le_impl(), "", WARN, CHECK_LE, (L)(R) )
-#define BOOST_CHECK_LE( L, R ) \
- BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::le_impl(), "", CHECK, CHECK_LE, (L)(R) )
-#define BOOST_REQUIRE_LE( L, R ) \
- BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::le_impl(), "", REQUIRE, CHECK_LE, (L)(R) )
+#define BOOST_WARN_LE( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
+ ::boost::test_tools::tt_detail::le_impl(), "", WARN, CHECK_LE, (L)(R) )
+#define BOOST_CHECK_LE( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
+ ::boost::test_tools::tt_detail::le_impl(), "", CHECK, CHECK_LE, (L)(R) )
+#define BOOST_REQUIRE_LE( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
+ ::boost::test_tools::tt_detail::le_impl(), "", REQUIRE, CHECK_LE, (L)(R) )
 
 //____________________________________________________________________________//
 
-#define BOOST_WARN_GT( L, R ) \
- BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::gt_impl(), "", WARN, CHECK_GT, (L)(R) )
-#define BOOST_CHECK_GT( L, R ) \
- BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::gt_impl(), "", CHECK, CHECK_GT, (L)(R) )
-#define BOOST_REQUIRE_GT( L, R ) \
- BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::gt_impl(), "", REQUIRE, CHECK_GT, (L)(R) )
+#define BOOST_WARN_GT( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
+ ::boost::test_tools::tt_detail::gt_impl(), "", WARN, CHECK_GT, (L)(R) )
+#define BOOST_CHECK_GT( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
+ ::boost::test_tools::tt_detail::gt_impl(), "", CHECK, CHECK_GT, (L)(R) )
+#define BOOST_REQUIRE_GT( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
+ ::boost::test_tools::tt_detail::gt_impl(), "", REQUIRE, CHECK_GT, (L)(R) )
 
 //____________________________________________________________________________//
 
-#define BOOST_WARN_GE( L, R ) \
- BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::ge_impl(), "", WARN, CHECK_GE, (L)(R) )
-#define BOOST_CHECK_GE( L, R ) \
- BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::ge_impl(), "", CHECK, CHECK_GE, (L)(R) )
-#define BOOST_REQUIRE_GE( L, R ) \
- BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::ge_impl(), "", REQUIRE, CHECK_GE, (L)(R) )
+#define BOOST_WARN_GE( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
+ ::boost::test_tools::tt_detail::ge_impl(), "", WARN, CHECK_GE, (L)(R) )
+#define BOOST_CHECK_GE( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
+ ::boost::test_tools::tt_detail::ge_impl(), "", CHECK, CHECK_GE, (L)(R) )
+#define BOOST_REQUIRE_GE( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
+ ::boost::test_tools::tt_detail::ge_impl(), "", REQUIRE, CHECK_GE, (L)(R) )
 
 //____________________________________________________________________________//
 
-#define BOOST_WARN_CLOSE( L, R, T ) \
- BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::check_is_close, "", WARN, CHECK_CLOSE, \
- (L)(R)(::boost::test_tools::percent_tolerance(T)) )
-#define BOOST_CHECK_CLOSE( L, R, T ) \
- BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::check_is_close, "", CHECK, CHECK_CLOSE, \
- (L)(R)(::boost::test_tools::percent_tolerance(T)) )
-#define BOOST_REQUIRE_CLOSE( L, R, T ) \
- BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::check_is_close, "", REQUIRE, CHECK_CLOSE, \
- (L)(R)(::boost::test_tools::percent_tolerance(T)) )
+#define BOOST_WARN_CLOSE( L, R, T ) BOOST_TEST_TOOL_IMPL( 0, \
+ ::boost::test_tools::check_is_close, "", WARN, CHECK_CLOSE, (L)(R)(::boost::test_tools::percent_tolerance(T)) )
+#define BOOST_CHECK_CLOSE( L, R, T ) BOOST_TEST_TOOL_IMPL( 0, \
+ ::boost::test_tools::check_is_close, "", CHECK, CHECK_CLOSE, (L)(R)(::boost::test_tools::percent_tolerance(T)) )
+#define BOOST_REQUIRE_CLOSE( L, R, T ) BOOST_TEST_TOOL_IMPL( 0, \
+ ::boost::test_tools::check_is_close, "", REQUIRE, CHECK_CLOSE, (L)(R)(::boost::test_tools::percent_tolerance(T)) )
 
 //____________________________________________________________________________//
 
-#define BOOST_WARN_CLOSE_FRACTION( L, R, T ) \
- BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::check_is_close, "", WARN, CHECK_CLOSE_FRACTION, \
- (L)(R)(::boost::test_tools::fraction_tolerance(T)) )
-#define BOOST_CHECK_CLOSE_FRACTION( L, R, T ) \
- BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::check_is_close, "", CHECK, CHECK_CLOSE_FRACTION, \
- (L)(R)(::boost::test_tools::fraction_tolerance(T)) )
-#define BOOST_REQUIRE_CLOSE_FRACTION( L, R, T ) \
- BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::check_is_close, "", REQUIRE, CHECK_CLOSE_FRACTION, \
- (L)(R)(::boost::test_tools::fraction_tolerance(T)) )
+#define BOOST_WARN_CLOSE_FRACTION(L, R, T) BOOST_TEST_TOOL_IMPL( 0, \
+ ::boost::test_tools::check_is_close, "", WARN, CHECK_CLOSE_FRACTION, (L)(R)(::boost::test_tools::fraction_tolerance(T)) )
+#define BOOST_CHECK_CLOSE_FRACTION(L, R, T) BOOST_TEST_TOOL_IMPL( 0, \
+ ::boost::test_tools::check_is_close, "", CHECK, CHECK_CLOSE_FRACTION, (L)(R)(::boost::test_tools::fraction_tolerance(T)) )
+#define BOOST_REQUIRE_CLOSE_FRACTION(L,R,T) BOOST_TEST_TOOL_IMPL( 0, \
+ ::boost::test_tools::check_is_close, "", REQUIRE, CHECK_CLOSE_FRACTION, (L)(R)(::boost::test_tools::fraction_tolerance(T)) )
 
 //____________________________________________________________________________//
 
-#define BOOST_WARN_SMALL( FPV, T ) \
- BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::check_is_small, "", WARN, CHECK_SMALL, (FPV)(T) )
-#define BOOST_CHECK_SMALL( FPV, T ) \
- BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::check_is_small, "", CHECK, CHECK_SMALL, (FPV)(T) )
-#define BOOST_REQUIRE_SMALL( FPV, T ) \
- BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::check_is_small, "", REQUIRE, CHECK_SMALL, (FPV)(T) )
+#define BOOST_WARN_SMALL( FPV, T ) BOOST_TEST_TOOL_IMPL( 0, \
+ ::boost::test_tools::check_is_small, "", WARN, CHECK_SMALL, (FPV)(T) )
+#define BOOST_CHECK_SMALL( FPV, T ) BOOST_TEST_TOOL_IMPL( 0, \
+ ::boost::test_tools::check_is_small, "", CHECK, CHECK_SMALL, (FPV)(T) )
+#define BOOST_REQUIRE_SMALL( FPV, T ) BOOST_TEST_TOOL_IMPL( 0, \
+ ::boost::test_tools::check_is_small, "", REQUIRE, CHECK_SMALL, (FPV)(T) )
 
 //____________________________________________________________________________//
 
-#define BOOST_WARN_PREDICATE( P, ARGS ) \
- BOOST_CHECK_WITH_ARGS_IMPL( P, BOOST_TEST_STRINGIZE( P ), WARN, CHECK_PRED_WITH_ARGS, ARGS )
-#define BOOST_CHECK_PREDICATE( P, ARGS ) \
- BOOST_CHECK_WITH_ARGS_IMPL( P, BOOST_TEST_STRINGIZE( P ), CHECK, CHECK_PRED_WITH_ARGS, ARGS )
-#define BOOST_REQUIRE_PREDICATE( P, ARGS ) \
- BOOST_CHECK_WITH_ARGS_IMPL( P, BOOST_TEST_STRINGIZE( P ), REQUIRE, CHECK_PRED_WITH_ARGS, ARGS )
+#define BOOST_WARN_PREDICATE( P, ARGS ) BOOST_TEST_TOOL_IMPL( 0, \
+ P, BOOST_TEST_TOOLS_STRINGIZE( P ), WARN, CHECK_PRED_WITH_ARGS, ARGS )
+#define BOOST_CHECK_PREDICATE( P, ARGS ) BOOST_TEST_TOOL_IMPL( 0, \
+ P, BOOST_TEST_TOOLS_STRINGIZE( P ), CHECK, CHECK_PRED_WITH_ARGS, ARGS )
+#define BOOST_REQUIRE_PREDICATE( P, ARGS ) BOOST_TEST_TOOL_IMPL( 0, \
+ P, BOOST_TEST_TOOLS_STRINGIZE( P ), REQUIRE, CHECK_PRED_WITH_ARGS, ARGS )
 
 //____________________________________________________________________________//
 
-#define BOOST_EQUAL_COLLECTIONS_IMPL( L_begin, L_end, R_begin, R_end, TL ) \
- BOOST_TEST_TOOL_IMPL( check_impl, ::boost::test_tools::tt_detail::equal_coll_impl( \
- (L_begin), (L_end), (R_begin), (R_end) ), "", TL, CHECK_EQUAL_COLL ), \
- 4, \
- BOOST_STRINGIZE( L_begin ), BOOST_STRINGIZE( L_end ), \
- BOOST_STRINGIZE( R_begin ), BOOST_STRINGIZE( R_end ) ) \
-/**/
-
 #define BOOST_WARN_EQUAL_COLLECTIONS( L_begin, L_end, R_begin, R_end ) \
- BOOST_EQUAL_COLLECTIONS_IMPL( L_begin, L_end, R_begin, R_end, WARN )
+ BOOST_TEST_TOOL_IMPL( 1, ::boost::test_tools::tt_detail::equal_coll_impl(), \
+ "", WARN, CHECK_EQUAL_COLL, (L_begin)(L_end)(R_begin)(R_end) ) \
+/**/
 #define BOOST_CHECK_EQUAL_COLLECTIONS( L_begin, L_end, R_begin, R_end ) \
- BOOST_EQUAL_COLLECTIONS_IMPL( L_begin, L_end, R_begin, R_end, CHECK )
+ BOOST_TEST_TOOL_IMPL( 1, ::boost::test_tools::tt_detail::equal_coll_impl(), \
+ "", CHECK, CHECK_EQUAL_COLL, (L_begin)(L_end)(R_begin)(R_end) ) \
+/**/
 #define BOOST_REQUIRE_EQUAL_COLLECTIONS( L_begin, L_end, R_begin, R_end ) \
- BOOST_EQUAL_COLLECTIONS_IMPL( L_begin, L_end, R_begin, R_end, REQUIRE )
+ BOOST_TEST_TOOL_IMPL( 1, ::boost::test_tools::tt_detail::equal_coll_impl(), \
+ "", REQUIRE, CHECK_EQUAL_COLL, (L_begin)(L_end)(R_begin)(R_end) ) \
+/**/
 
 //____________________________________________________________________________//
 
-#define BOOST_BITWISE_EQUAL_IMPL( L, R, TL ) \
- BOOST_TEST_TOOL_IMPL( check_impl, \
- ::boost::test_tools::tt_detail::bitwise_equal_impl( (L), (R) ), \
- "", TL, CHECK_BITWISE_EQUAL ), \
- 2, BOOST_STRINGIZE( L ), BOOST_STRINGIZE( R ) ) \
-/**/
-
-#define BOOST_WARN_BITWISE_EQUAL( L, R ) BOOST_BITWISE_EQUAL_IMPL( L, R, WARN )
-#define BOOST_CHECK_BITWISE_EQUAL( L, R ) BOOST_BITWISE_EQUAL_IMPL( L, R, CHECK )
-#define BOOST_REQUIRE_BITWISE_EQUAL( L, R ) BOOST_BITWISE_EQUAL_IMPL( L, R, REQUIRE )
+#define BOOST_WARN_BITWISE_EQUAL( L, R ) BOOST_TEST_TOOL_IMPL( 1, \
+ ::boost::test_tools::tt_detail::bitwise_equal_impl(), "", WARN, CHECK_BITWISE_EQUAL, (L)(R) )
+#define BOOST_CHECK_BITWISE_EQUAL( L, R ) BOOST_TEST_TOOL_IMPL( 1, \
+ ::boost::test_tools::tt_detail::bitwise_equal_impl(), "", CHECK, CHECK_BITWISE_EQUAL, (L)(R) )
+#define BOOST_REQUIRE_BITWISE_EQUAL( L, R ) BOOST_TEST_TOOL_IMPL( 1, \
+ ::boost::test_tools::tt_detail::bitwise_equal_impl(), "", REQUIRE, CHECK_BITWISE_EQUAL, (L)(R) )
 
 //____________________________________________________________________________//
 
-#define BOOST_IS_DEFINED( symb ) ::boost::test_tools::tt_detail::is_defined_impl( #symb, BOOST_STRINGIZE(= symb) )
+#define BOOST_IS_DEFINED( symb ) ::boost::test_tools::tt_detail::is_defined_impl( #symb, BOOST_STRINGIZE(= symb) )
 
 //____________________________________________________________________________//
 
@@ -476,14 +476,18 @@
 // ************************************************************************** //
 
 BOOST_TEST_DECL
-bool check_impl( predicate_result const& pr, ::boost::unit_test::lazy_ostream const& check_descr,
+bool check_impl( predicate_result const& pr, ::boost::unit_test::lazy_ostream const& assertion_descr,
                  const_string file_name, std::size_t line_num,
                  tool_level tl, check_type ct,
                  std::size_t num_args, ... );
 
 //____________________________________________________________________________//
+// This function adds level of indirection, but it makes sure we evaluate predicate
+// arguments only once
 
+#ifndef BOOST_TEST_PROD
 #define TEMPL_PARAMS( z, m, dummy ) , typename BOOST_JOIN( Arg, m )
+
 #define FUNC_PARAMS( z, m, dummy ) \
  , BOOST_JOIN( Arg, m ) const& BOOST_JOIN( arg, m ) \
  , char const* BOOST_JOIN( BOOST_JOIN( arg, m ), _descr ) \
@@ -501,7 +505,7 @@
 template<typename Pred \
          BOOST_PP_REPEAT_ ## z( BOOST_PP_ADD( n, 1 ), TEMPL_PARAMS, _ )> \
 inline bool \
-check_frwd( Pred P, unit_test::lazy_ostream const& check_descr, \
+check_frwd( Pred P, unit_test::lazy_ostream const& assertion_descr, \
             const_string file_name, std::size_t line_num, \
             tool_level tl, check_type ct \
             BOOST_PP_REPEAT_ ## z( BOOST_PP_ADD( n, 1 ), FUNC_PARAMS, _ ) \
@@ -509,7 +513,7 @@
 { \
     return \
     check_impl( P( BOOST_PP_REPEAT_ ## z( BOOST_PP_ADD( n, 1 ), PRED_PARAMS, _ ) ), \
- check_descr, file_name, line_num, tl, ct, \
+ assertion_descr, file_name, line_num, tl, ct, \
                 BOOST_PP_ADD( n, 1 ) \
                 BOOST_PP_REPEAT_ ## z( BOOST_PP_ADD( n, 1 ), ARG_INFO, _ ) \
     ); \
@@ -528,6 +532,8 @@
 #undef ARG_INFO
 #undef IMPL_FRWD
 
+#endif
+
 //____________________________________________________________________________//
 
 template <class Left, class Right>
@@ -628,75 +634,77 @@
 
 //____________________________________________________________________________//
 
-template <typename Left, typename Right>
-inline predicate_result
-equal_coll_impl( Left left_begin, Left left_end, Right right_begin, Right right_end )
-{
- predicate_result res( true );
- std::size_t pos = 0;
+struct equal_coll_impl {
+ template <typename Left, typename Right>
+ predicate_result operator()( Left left_begin, Left left_end, Right right_begin, Right right_end )
+ {
+ predicate_result pr( true );
+ std::size_t pos = 0;
 
- for( ; left_begin != left_end && right_begin != right_end; ++left_begin, ++right_begin, ++pos ) {
- if( *left_begin != *right_begin ) {
- res = false;
- res.message() << "\nMismatch in a position " << pos << ": " << *left_begin << " != " << *right_begin;
+ for( ; left_begin != left_end && right_begin != right_end; ++left_begin, ++right_begin, ++pos ) {
+ if( *left_begin != *right_begin ) {
+ pr = false;
+ pr.message() << "\nMismatch in a position " << pos << ": " << *left_begin << " != " << *right_begin;
+ }
         }
- }
 
- if( left_begin != left_end ) {
- std::size_t r_size = pos;
- while( left_begin != left_end ) {
- ++pos;
- ++left_begin;
+ if( left_begin != left_end ) {
+ std::size_t r_size = pos;
+ while( left_begin != left_end ) {
+ ++pos;
+ ++left_begin;
+ }
+
+ pr = false;
+ pr.message() << "\nCollections size mismatch: " << pos << " != " << r_size;
         }
 
- res = false;
- res.message() << "\nCollections size mismatch: " << pos << " != " << r_size;
- }
+ if( right_begin != right_end ) {
+ std::size_t l_size = pos;
+ while( right_begin != right_end ) {
+ ++pos;
+ ++right_begin;
+ }
 
- if( right_begin != right_end ) {
- std::size_t l_size = pos;
- while( right_begin != right_end ) {
- ++pos;
- ++right_begin;
+ pr = false;
+ pr.message() << "\nCollections size mismatch: " << l_size << " != " << pos;
         }
 
- res = false;
- res.message() << "\nCollections size mismatch: " << l_size << " != " << pos;
+ return pr;
     }
-
- return res;
-}
+};
 
 //____________________________________________________________________________//
 
-template <class Left, class Right>
-inline predicate_result
-bitwise_equal_impl( Left const& left, Right const& right )
-{
- predicate_result res( true );
+struct bitwise_equal_impl {
+ template <class Left, class Right>
+ predicate_result operator()( Left const& left, Right const& right )
+ {
+ predicate_result pr( true );
 
- std::size_t left_bit_size = sizeof(Left)*CHAR_BIT;
- std::size_t right_bit_size = sizeof(Right)*CHAR_BIT;
+ std::size_t left_bit_size = sizeof(Left)*CHAR_BIT;
+ std::size_t right_bit_size = sizeof(Right)*CHAR_BIT;
 
- static Left const leftOne( 1 );
- static Right const rightOne( 1 );
+ static Left const leftOne( 1 );
+ static Right const rightOne( 1 );
 
- std::size_t total_bits = left_bit_size < right_bit_size ? left_bit_size : right_bit_size;
+ std::size_t total_bits = left_bit_size < right_bit_size ? left_bit_size : right_bit_size;
 
- for( std::size_t counter = 0; counter < total_bits; ++counter ) {
- if( ( left & ( leftOne << counter ) ) != ( right & ( rightOne << counter ) ) ) {
- res = false;
- res.message() << "\nMismatch in a position " << counter;
+ for( std::size_t counter = 0; counter < total_bits; ++counter ) {
+ if( ( left & ( leftOne << counter ) ) != ( right & ( rightOne << counter ) ) ) {
+ pr = false;
+ pr.message() << "\nMismatch in a position " << counter;
+ }
         }
- }
 
- if( left_bit_size != right_bit_size ) {
- res = false;
- res.message() << "\nOperands bit sizes mismatch: " << left_bit_size << " != " << right_bit_size;
- }
+ if( left_bit_size != right_bit_size ) {
+ pr = false;
+ pr.message() << "\nOperands bit sizes mismatch: " << left_bit_size << " != " << right_bit_size;
+ }
 
- return res;
-}
+ return pr;
+ }
+};
 
 //____________________________________________________________________________//
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk