Boost C++ Libraries: Ticket #5563: using a test macro in a global fixture crashes Boost.Test https://svn.boost.org/trac10/ticket/5563 <p> 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) : </p> <p> #define BOOST_AUTO_TEST_MAIN #include &lt;boost/test/auto_unit_test.hpp&gt; #define BOOST_LIB_NAME boost_unit_test_framework #include &lt;boost/config/auto_link.hpp&gt; </p> <p> struct fixture { </p> <blockquote> <p> fixture() { </p> <blockquote> <p> BOOST_FAIL( "oups" ); </p> </blockquote> <p> } ~fixture() { </p> <blockquote> <p> BOOST_FAIL( "oups" ); </p> </blockquote> <p> } </p> </blockquote> <p> }; BOOST_GLOBAL_FIXTURE( fixture ); </p> <p> BOOST_AUTO_TEST_CASE( some_test ) { } </p> <p> The problem lies in compiler_log_formatter.ipp around line 40 : </p> <p> const_string test_phase_identifier() { </p> <blockquote> <p> return framework::is_initialized() </p> <blockquote> <p> ? const_string( framework::current_test_case().p_name.get() ) : BOOST_TEST_L( "Test setup" ); </p> </blockquote> </blockquote> <p> } </p> <p> 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... </p> <p> Thanks, MAT. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5563 Trac 1.4.3 Gennadiy Rozental Tue, 18 Oct 2011 09:20:22 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/5563#comment:1 https://svn.boost.org/trac10/ticket/5563#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/75035" title="avoid crash if testing tool is used in global fixture Fixes #5563 ">[75035]</a>) avoid crash if testing tool is used in global fixture Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/5563" title="#5563: Bugs: using a test macro in a global fixture crashes Boost.Test (closed: fixed)">#5563</a> </p> Ticket m.champlon@… Sat, 26 May 2012 06:20:30 GMT <link>https://svn.boost.org/trac10/ticket/5563#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5563#comment:2</guid> <description> <p> Hi, </p> <p> As of 26/05/2012 the fix hasn't been merge to the release branch... </p> <p> MAT. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Raffi Enficiaud</dc:creator> <pubDate>Tue, 07 Jul 2015 08:23:20 GMT</pubDate> <title>milestone changed https://svn.boost.org/trac10/ticket/5563#comment:3 https://svn.boost.org/trac10/ticket/5563#comment:3 <ul> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.59.0</span> </li> </ul> Ticket Jim King <jim.king@…> Wed, 23 Sep 2015 14:07:25 GMT <link>https://svn.boost.org/trac10/ticket/5563#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5563#comment:4</guid> <description> <p> 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: </p> <p> throw std::runtime_error( "can't use testing tools outside of test case implementation" ); </p> <p> 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. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Raffi Enficiaud</dc:creator> <pubDate>Wed, 23 Sep 2015 14:22:04 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5563#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5563#comment:5</guid> <description> <p> 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. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Raffi Enficiaud</dc:creator> <pubDate>Wed, 23 Sep 2015 14:26:20 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5563#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5563#comment:6</guid> <description> <p> Ok, now I think I understand: the fix is to <strong>avoid</strong> the crash. There is a bug either in the implementation or in the documentation of 1.59. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Raffi Enficiaud</dc:creator> <pubDate>Wed, 23 Sep 2015 14:26:31 GMT</pubDate> <title>status changed; resolution deleted https://svn.boost.org/trac10/ticket/5563#comment:7 https://svn.boost.org/trac10/ticket/5563#comment:7 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> </ul> Ticket Raffi Enficiaud Wed, 23 Sep 2015 14:26:44 GMT owner, status changed https://svn.boost.org/trac10/ticket/5563#comment:8 https://svn.boost.org/trac10/ticket/5563#comment:8 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Gennadiy Rozental</span> to <span class="trac-author">Raffi Enficiaud</span> </li> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">new</span> </li> </ul> Ticket Raffi Enficiaud Sun, 11 Dec 2016 19:00:54 GMT <link>https://svn.boost.org/trac10/ticket/5563#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5563#comment:9</guid> <description> <p> Several major issues appeared while I was digging deeper into this issue: </p> <ul><li>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 </li><li>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. </li></ul> </description> <category>Ticket</category> </item> <item> <dc:creator>Raffi Enficiaud</dc:creator> <pubDate>Sun, 11 Dec 2016 19:01:17 GMT</pubDate> <title>milestone changed https://svn.boost.org/trac10/ticket/5563#comment:10 https://svn.boost.org/trac10/ticket/5563#comment:10 <ul> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.59.0</span> → <span class="trac-field-new">To Be Determined</span> </li> </ul> Ticket Raffi Enficiaud Sun, 11 Dec 2016 19:01:35 GMT status changed https://svn.boost.org/trac10/ticket/5563#comment:11 https://svn.boost.org/trac10/ticket/5563#comment:11 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket Raffi Enficiaud Thu, 22 Jun 2017 22:53:02 GMT milestone changed https://svn.boost.org/trac10/ticket/5563#comment:12 https://svn.boost.org/trac10/ticket/5563#comment:12 <ul> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.65.0</span> </li> </ul> Ticket Raffi Enficiaud Fri, 23 Jun 2017 15:41:14 GMT <link>https://svn.boost.org/trac10/ticket/5563#comment:13 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5563#comment:13</guid> <description> <p> Fix pushed to develop rev <code>ea9d9b9a8ea3f9aceb71cce41d48c820f05b2fdc</code> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Raffi Enficiaud</dc:creator> <pubDate>Fri, 23 Jun 2017 15:50:57 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5563#comment:14 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5563#comment:14</guid> <description> <p> See <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/11962" title="#11962: Bugs: BOOST_TEST_MESSAGE in fixture constructor - invalid XML (closed: fixed)">#11962</a> for the explanations of the fix. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Raffi Enficiaud</dc:creator> <pubDate>Sun, 16 Jul 2017 08:41:45 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/5563#comment:15 https://svn.boost.org/trac10/ticket/5563#comment:15 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> In master, rev <code>3d13638c412ac357f178e99a99bf44dfd756c057</code> </p> Ticket