Boost logo

Boost Users :

Subject: Re: [Boost-users] [Boost.Test] What's the best way to make custom assertions?
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2012-10-23 13:23:30


Le 23/10/12 19:11, Gennadiy Rozental a écrit :
> Richard <legalize+jeeves <at> mail.xmission.com> writes:
>
>> I want to make custom assertion methods that report the failure
>> location as the place where the custom assertion is invoked, not the
>> location where the BOOST_REQUIRE_xxx macros are used in the
>> implementation of the custom assertion.
> Hi Richard,
>
> Frankly I do not follow what you want exactly. BOOST_REQUIRE reports a location
> of that statement. What do you want to report?
>
> It might be that you want something like this:
>
> void check_op1( char const* f, int l )
> {
> BOOST_REQUIRE( expr, f, l );
> }
>
> BOOST_AUTO_TEST_CASE( t1 )
> {
> check_op1( __FILE_, __LINE__ );
> }
>
> BOOST_AUTO_TEST_CASE( t2 )
> {
> check_op1( __FILE_, __LINE__ );
> }
>
> If this is the case, I'd rather you use new BOOST_TEST_CONTEXT facility and
> implement check_op1 like this:
>
> void check_op1( char const* f, int l )
> {
> BOOST_TEST_CONTEXT( "Testing invoked from: " << f << "(" << l << ")" ) {
> BOOST_REQUIRE( expr1 );
> BOOST_REQUIRE( expr2 );
> }
> }
>
>
Would this works as well?

void check_op1()
{
     BOOST_REQUIRE( expr );
}

BOOST_AUTO_TEST_CASE( t1 )
{
     BOOST_TEST_CONTEXT( "Testing invoked from: " << __FILE__ << "(" << __LINE__ << ")" );
     check_op1( );
}

Best,
Vicente


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