Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for a snapshot of the master branch, built from commit 6a5a04a711.
PrevUpHomeNext

BOOST_<level>

BOOST_WARN(predicate);
BOOST_CHECK(predicate);
BOOST_REQUIRE(predicate);

These tools are used to validate the predicate value. The only parameter for these tools is a boolean predicate value that gets validated. It could be any expression that could be evaluated and converted to boolean value. The expression gets evaluated only once, so it's safe to pass complex expression for validation.

Example: BOOST_<level> usage

Code

#define BOOST_TEST_MODULE example
#include <boost/test/included/unit_test.hpp>

BOOST_AUTO_TEST_CASE( test )
{
  int i=2;
  BOOST_WARN( sizeof(int) == sizeof(short) );
  BOOST_CHECK( i == 1 );
  BOOST_REQUIRE( i > 5 );
  BOOST_CHECK( i == 6 );  // will never reach this check
}

Output

> example --log_level=warning
Running 1 test case...
test.cpp(9): warning in "test": condition sizeof(int) == sizeof(short) is not satisfied
test.cpp(10): error in "test": check i == 1 has failed
test.cpp(11): fatal error in "test": critical check i > 5 has failed

*** 2 failures are detected in test suite "example"

See also:


PrevUpHomeNext