mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-10-31 12:17:11 +01:00 
			
		
		
		
	Use correct type name instead of index for TEMPLATE_PRODUCT_TEST_CASE (#1544)
Previously, for a TEMPLATE_PRODUCT_TEST_CASE("Test" ..., T, (P1, P2)),
the generated test case names were
  Test - 0
  Test - 1
With this commit, the correct typename is used:
  Test - T<P1>
  Test - T<P2>
-----------
MSVC needs another indirection to evaluate INTERNAL_CATCH_STRINGIZE
and also inserts a space before theINTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS
parameter, which we can get rid of by pointer arithmetic.
			
			
This commit is contained in:
		 Tobias Ribizel
					Tobias Ribizel
				
			
				
					committed by
					
						 Martin Hořeňovský
						Martin Hořeňovský
					
				
			
			
				
	
			
			
			 Martin Hořeňovský
						Martin Hořeňovský
					
				
			
						parent
						
							359a54b6bd
						
					
				
				
					commit
					c99a346490
				
			| @@ -57,6 +57,16 @@ | ||||
| #define INTERNAL_CATCH_EXPAND2(...) INTERNAL_CATCH_NO## __VA_ARGS__ | ||||
| #define INTERNAL_CATCH_DEF(...) INTERNAL_CATCH_DEF __VA_ARGS__ | ||||
| #define INTERNAL_CATCH_NOINTERNAL_CATCH_DEF | ||||
| #define INTERNAL_CATCH_STRINGIZE(...) INTERNAL_CATCH_STRINGIZE2(__VA_ARGS__) | ||||
| #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR | ||||
| #define INTERNAL_CATCH_STRINGIZE2(...) #__VA_ARGS__ | ||||
| #define INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS(param) INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_REMOVE_PARENS(param)) | ||||
| #else | ||||
| // MSVC is adding extra space and needs another indirection to expand INTERNAL_CATCH_NOINTERNAL_CATCH_DEF | ||||
| #define INTERNAL_CATCH_STRINGIZE2(...) INTERNAL_CATCH_STRINGIZE3(__VA_ARGS__) | ||||
| #define INTERNAL_CATCH_STRINGIZE3(...) #__VA_ARGS__ | ||||
| #define INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS(param) (INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_REMOVE_PARENS(param)) + 1) | ||||
| #endif | ||||
|  | ||||
| #define INTERNAL_CATCH_REMOVE_PARENS(...) INTERNAL_CATCH_EXPAND1(INTERNAL_CATCH_DEF __VA_ARGS__) | ||||
|  | ||||
|   | ||||
| @@ -161,7 +161,10 @@ struct AutoReg : NonCopyable { | ||||
|                     CATCH_INTERNAL_CHECK_UNIQUE_TYPES(Types...)       \ | ||||
|                     int index = 0;                                    \ | ||||
|                     using expander = int[];                           \ | ||||
|                     (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestFuncName<Types> ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ Name " - " + Catch::StringMaker<int>::convert(index++), Tags } ), 0)... };/* NOLINT */ \ | ||||
|                     constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TmplTypes))};\ | ||||
|                     constexpr char const* types_list[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TypesList))};\ | ||||
|                     constexpr auto num_types = sizeof(types_list) / sizeof(types_list[0]);\ | ||||
|                     (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestFuncName<Types> ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index / num_types]) + "<" + std::string(types_list[index % num_types]) + ">", Tags } ), index++, 0)... };/* NOLINT */\ | ||||
|                 }                                                     \ | ||||
|             };                                                        \ | ||||
|             static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){ \ | ||||
| @@ -226,7 +229,10 @@ struct AutoReg : NonCopyable { | ||||
|                     CATCH_INTERNAL_CHECK_UNIQUE_TYPES(Types...)\ | ||||
|                     int index = 0;\ | ||||
|                     using expander = int[];\ | ||||
|                     (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestName<Types>::test ), CATCH_INTERNAL_LINEINFO, #ClassName, Catch::NameAndTags{ Name " - " + Catch::StringMaker<int>::convert(index++), Tags } ), 0)... };/* NOLINT */ \ | ||||
|                     constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TmplTypes))};\ | ||||
|                     constexpr char const* types_list[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TypesList))};\ | ||||
|                     constexpr auto num_types = sizeof(types_list) / sizeof(types_list[0]);\ | ||||
|                     (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestName<Types>::test ), CATCH_INTERNAL_LINEINFO, #ClassName, Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index / num_types]) + "<" + std::string(types_list[index % num_types]) + ">", Tags } ), index++, 0)... };/* NOLINT */ \ | ||||
|                 }\ | ||||
|             };\ | ||||
|             static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user