Boost logo

Boost Users :

Subject: Re: [Boost-users] [Boost.Test] Detail lost when using BOOST_*_NO_THROW
From: Richard (legalize+jeeves_at_[hidden])
Date: 2013-12-29 00:29:30


[Please do not mail me a copy of your followup]

boost-users_at_[hidden] spake the secret code
<20131222101745.6cff920b_at_rid> thusly:

>Unfortunately the Boost.Test framework only provides a terse message
>like this:
>
> test.cpp(123): fatal error in "fnTest": exception thrown by test();
>
>It doesn't tell you which exception was thrown, nor the reason why.

The only place I can find this text is in the implementation of
BOOST_{WARN,CHECK,REQUIRE}_NO_THROW(). Are you really writing a test
about exception handling, or is this a side-effect of your test case?

IMO, unless you are exercising the exception handling properties of a
piece of code, you shouldn't be using BOOST_xxx_NO_THROW -- any test
case will fail if the exercised code throws an exception. So if you
are testing normal functionality of the code, then just let the
unexpected exception be thrown and the test framework should print an
appropriate message.

For instance, this code:

#include <stdexcept>

void foo()
{
        throw std::runtime_error("What the hell?");
}

BOOST_AUTO_TEST_CASE(test_foo)
{
        foo();
        BOOST_REQUIRE(true);
}

fails with this output:

Running 1 test case...
unknown location(0): fatal error in "test_foo": std::runtime_error: What the hell?

-- 
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
     The Computer Graphics Museum <http://computergraphicsmuseum.org>
         The Terminals Wiki <http://terminals.classiccmp.org>
  Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net