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 3f974608da.
PrevUpHomeNext

BOOST_<level>_MESSAGE

BOOST_WARN_MESSAGE(predicate, message);
BOOST_CHECK_MESSAGE(predicate, message);
BOOST_REQUIRE_MESSAGE(predicate, message);

These tools perform exactly the same check as BOOST_<level> tools. The only difference is that instead of generating an error/confirm message these use the supplied one.

The first parameter is the boolean expression. The second parameter is the message reported in case of check failure. The message argument can be constructed of components of any type supporting the std::ostream& operator<<(std::ostream&).

Example: BOOST_<level>_MESSAGE usage

Code

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

#include <cmath>

BOOST_AUTO_TEST_CASE( test )
{
  // sin 45 radians is actually ~ 0.85, sin 45 degrees is ~0.707
  double res = std::sin( 45. );

  BOOST_WARN_MESSAGE( res < 0.71,
                      "sin(45){" << res << "} is > 0.71. Arg is not in radian?" );
}

Output

> example --log_level=warning
Running 1 test case...
test.cpp(12): warning in "test": sin(45){0.850904} is > 0.71. Arg is not in radian?

*** No errors detected

See also:


PrevUpHomeNext