Opened 11 years ago

Closed 5 years ago

#5563 closed Bugs (fixed)

using a test macro in a global fixture crashes Boost.Test

Reported by: m.champlon@… Owned by: Raffi Enficiaud
Milestone: Boost 1.65.0 Component: test
Version: Boost 1.42.0 Severity: Problem
Keywords: Cc:

Description

Using a failing macro (such as BOOST_FAIL) from the constructor (or destructor) of a global fixture crashes the test application, for instance (using vc80 and boost 1.42) :

#define BOOST_AUTO_TEST_MAIN #include <boost/test/auto_unit_test.hpp> #define BOOST_LIB_NAME boost_unit_test_framework #include <boost/config/auto_link.hpp>

struct fixture {

fixture() {

BOOST_FAIL( "oups" );

} ~fixture() {

BOOST_FAIL( "oups" );

}

}; BOOST_GLOBAL_FIXTURE( fixture );

BOOST_AUTO_TEST_CASE( some_test ) { }

The problem lies in compiler_log_formatter.ipp around line 40 :

const_string test_phase_identifier() {

return framework::is_initialized()

? const_string( framework::current_test_case().p_name.get() ) : BOOST_TEST_L( "Test setup" );

}

because calling framework::current_test_case() is wrong in this case. Maybe the solution would be to add another state in framework along m_is_initialized and m_test_in_progress ? I would love to provide a patch but I wasn't able to make bjam build and run the tests...

Thanks, MAT.

Change History (15)

comment:1 by Gennadiy Rozental, 11 years ago

Resolution: fixed
Status: newclosed

(In [75035]) avoid crash if testing tool is used in global fixture Fixes #5563

comment:2 by m.champlon@…, 10 years ago

Hi,

As of 26/05/2012 the fix hasn't been merge to the release branch...

MAT.

comment:3 by Raffi Enficiaud, 7 years ago

Milestone: To Be DeterminedBoost 1.59.0

comment:4 by Jim King <jim.king@…>, 7 years ago

Was the solution to this issue to make it impossible to use assertion checks within a global fixture? I find that to be pretty useful, and having moved from boost 1.53 to 1.59 I find I'm having to rewrite a lot of tests so they don't fail with an exception of:

throw std::runtime_error( "can't use testing tools outside of test case implementation" );

these tests never crashed before. Further, the patch that was provided does not provide a test that proves either if the issue existed before or whether it is fixed now.

comment:5 by Raffi Enficiaud, 7 years ago

If I am not mistaken, the solution was to make it possible to use assertions and exceptions in global fixture (obviously not in the fixture dtor). If this is not working, please post the snippet and we will investigate.

comment:6 by Raffi Enficiaud, 7 years ago

Ok, now I think I understand: the fix is to avoid the crash. There is a bug either in the implementation or in the documentation of 1.59.

comment:7 by Raffi Enficiaud, 7 years ago

Resolution: fixed
Status: closedreopened

comment:8 by Raffi Enficiaud, 7 years ago

Owner: changed from Gennadiy Rozental to Raffi Enficiaud
Status: reopenednew

comment:9 by Raffi Enficiaud, 6 years ago

Several major issues appeared while I was digging deeper into this issue:

  • test assertions in fixture dtor that stop the execution of the test crash the application in all case because of an exception in a dtor
  • test assertions in fixture ctor are currently not supported but not mentioned in the documentation. This limitation is mainly due to the order of initialization of the different components of the test framework.

comment:10 by Raffi Enficiaud, 6 years ago

Milestone: Boost 1.59.0To Be Determined

comment:11 by Raffi Enficiaud, 6 years ago

Status: newassigned

comment:12 by Raffi Enficiaud, 5 years ago

Milestone: To Be DeterminedBoost 1.65.0

comment:13 by Raffi Enficiaud, 5 years ago

Fix pushed to develop rev ea9d9b9a8ea3f9aceb71cce41d48c820f05b2fdc

comment:14 by Raffi Enficiaud, 5 years ago

See #11962 for the explanations of the fix.

comment:15 by Raffi Enficiaud, 5 years ago

Resolution: fixed
Status: assignedclosed

In master, rev 3d13638c412ac357f178e99a99bf44dfd756c057

Note: See TracTickets for help on using tickets.