Re: [Boost-bugs] [Boost C++ Libraries] #12712: BOOST_AUTO_TEST_SUITE: Generate unique names by using __COUNTER__

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #12712: BOOST_AUTO_TEST_SUITE: Generate unique names by using __COUNTER__
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2016-12-26 08:20:24


#12712: BOOST_AUTO_TEST_SUITE: Generate unique names by using __COUNTER__
-------------------------------+---------------------
  Reporter: ki.stfu@… | Owner: rogeeff
      Type: Patches | Status: new
 Milestone: To Be Determined | Component: test
   Version: Boost 1.62.0 | Severity: Problem
Resolution: | Keywords:
-------------------------------+---------------------

Comment (by ki.stfu@…):

 Oops. I fixed its style:
 ----
 There is a problem with non-unique names of `<test_suite_name>_registrar`
 in `BOOST_AUTO_TEST_SUITE` when joining multiple source files into one
 file using `#include`:

 I have a project with huge number of tests in different files and it takes
 around 10 minutes to compile. The project structure is like:

 `.../test/data/foo.cpp`:
 {{{
 #include "stdafx.h"

 BOOST_AUTO_TEST_SUITE(data)
 BOOST_AUTO_TEST_SUITE(foo)

 <my test cases>

 BOOST_AUTO_TEST_SUITE_END()
 BOOST_AUTO_TEST_SUITE_END()
 }}}

 `.../test/data/bar.cpp`:
 {{{
 #include "stdafx.h"

 BOOST_AUTO_TEST_SUITE(data)
 BOOST_AUTO_TEST_SUITE(bar)

 <my test cases>

 BOOST_AUTO_TEST_SUITE_END()
 BOOST_AUTO_TEST_SUITE_END()
 }}}

 To reduce the compilation time I included all sources into one file and
 after that I need to compile only that file (so it works much faster):

 `.../test/_all.cpp`:
 {{{
 #include "stdafx.h"

 #include "data/foo.cpp"
 #include "data/bar.cpp"
 and so on...

 }}}

 But when I'm compiling this file I get a multiple definitions of
 `data_registrar3` (`3` is a substituted `__LINE__`).

 I think we can use `__COUNTER__` if it's supported (it's not a standard
 feature but most of compilers support it) so that it will fix the problem.

 Here is my patch:
 {{{
 $ diff unit_test_suite.hpp.original unit_test_suite.hpp -uar
 --- unit_test_suite.hpp.original 2016-12-26 11:01:33.272912600
 +0300
 +++ unit_test_suite.hpp 2016-12-26 11:00:37.171138300 +0300
 @@ -24,6 +24,11 @@

  #include <boost/test/detail/pp_variadic.hpp>

 +#if defined(__COUNTER__)
 +#define BOOST_TEST_UNIQUE_NUMBER __COUNTER__
 +#else
 +#define BOOST_TEST_UNIQUE_NUMBER __LINE__
 +#endif

 //____________________________________________________________________________//

 @@ -120,7 +125,7 @@
  //
 **************************************************************************
 //

  #define BOOST_AUTO_TEST_SUITE_END() \
 -BOOST_AUTO_TU_REGISTRAR( BOOST_JOIN( end_suite, __LINE__ ) )( 1 ); \
 +BOOST_AUTO_TU_REGISTRAR( BOOST_JOIN( end_suite, BOOST_TEST_UNIQUE_NUMBER
 ) )( 1 ); \
  } \
  /**/

 @@ -298,7 +303,7 @@

  #define BOOST_TEST_DECORATOR( D ) \
  static boost::unit_test::decorator::collector const& \
 -BOOST_JOIN(decorator_collector,__LINE__) = D; \
 +BOOST_JOIN(decorator_collector,BOOST_TEST_UNIQUE_NUMBER) = D;
 \
  /**/

  //
 **************************************************************************
 //
 @@ -322,7 +327,7 @@

  #define BOOST_AUTO_TU_REGISTRAR( test_name ) \
  static boost::unit_test::ut_detail::auto_test_unit_registrar \
 -BOOST_JOIN( BOOST_JOIN( test_name, _registrar ), __LINE__ ) \
 +BOOST_JOIN( BOOST_JOIN( test_name, _registrar ), BOOST_TEST_UNIQUE_NUMBER
 ) \
  /**/
  #define BOOST_AUTO_TC_INVOKER( test_name ) BOOST_JOIN( test_name,
 _invoker )
  #define BOOST_AUTO_TC_UNIQUE_ID( test_name ) BOOST_JOIN( test_name,
 _id )

 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/12712#comment:1>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:20 UTC