...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
BOOST_WARN_PREDICATE(predicate, arguments_list); BOOST_CHECK_PREDICATE(predicate, arguments_list); BOOST_REQUIRE_PREDICATE(predicate, arguments_list);
These are generic tools used to validate an arbitrary supplied predicate
functor (there is a compile time limit on predicate arity defined by the
configurable macro BOOST_TEST_MAX_PREDICATE_ARITY
).
To validate zero arity predicate use BOOST_<level>
tools. In other cases prefer theses tools. The advantage of these tools
is that they show arguments values in case of predicate failure.
The first parameter is the predicate itself. The second parameter is the
list of predicate arguments each wrapped in round brackets (BOOST_PP
sequence format).
Code |
---|
#define BOOST_TEST_MODULE example #include <boost/test/included/unit_test.hpp> using namespace boost::unit_test; bool moo( int arg1, int arg2, int mod ) { return ((arg1+arg2) % mod) == 0; } BOOST_AUTO_TEST_CASE( test ) { int i = 17; int j = 15; unit_test_log.set_threshold_level( log_warnings ); BOOST_WARN( moo( 12,i,j ) ); BOOST_WARN_PREDICATE( moo, (12)(i)(j) ); } |
Output |
---|
> example Running 1 test case... test.cpp(14): warning in "test": condition moo( 12,i,j ) is not satisfied test.cpp(15): warning in "test": condition moo( 12, i, j ) is not satisfied for ( 12, 17, 15 ) *** No errors detected |
Note | |
---|---|
Note difference in error log from |
See also: