id summary reporter owner description type status milestone component version severity resolution keywords cc 12712 BOOST_AUTO_TEST_SUITE: Generate unique names by using __COUNTER__ ki.stfu@… Raffi Enficiaud "There is a problem with non-unique names of _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) 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) 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 +#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 ) ```" Patches closed Boost 1.64.0 test Boost Development Trunk Problem fixed raffi.enficiaud@… ki.stfu@…