Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost.Test - how to print the value of a variable in case of error?
From: Attila Feher F (attila.f.feher_at_[hidden])
Date: 2010-06-28 01:08:56


Richard wrote:
[SNIP]
>> If it fails, it tells me this:
>>
>> basics.cpp(61): error in "test_case": check cont.erase(key) == 1u
>> failed [0 != 1]
>
> If you use BOOST_CHECK_MESSAGE(predicate, message), you can create a
> custom failure message that contains additional context:
>
> #define BOOST_TEST_MODULE example
> #include <boost/test/included/unit_test.hpp>
>
> #include <cmath>
>
> BOOST_AUTO_TEST_CASE( test )
> {
> double res = std::sin( 45. );
>
> BOOST_WARN_MESSAGE( res > 1,
> "sin(45){" << res << "} is <= 1. Hmm.. Strange. " ); }

Thanks! I was doing that earlier, but I was hoping there is a "better" solution. With this, I have to do all the things "by hand", so for example the spelling out of the two sides of an EQUAL check. :( It seems that I have to "duplicate" all existing macros and create something like a BOOST_CHECK_..._WITH(...) series.

Eg.:

BOOST_CHECK_EQUAL_WITH(lhs,rhs,v1,v2)

used as:

BOOST_CHECK_EQUAL_WITH(a[i],b[j],i,j)

output:

tests.cpp(99): error in "test_case": check a[i] == b[j] [with i==1, j==42] failed [0 != 1]

BR,
Attila aka WW


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