From 6926b39c503983943f383bf6494410aeee96109d Mon Sep 17 00:00:00 2001 From: gbsylveg Date: Wed, 18 Mar 2015 11:18:11 +0000 Subject: [PATCH] Add TEMPLATE_TEST_CASE_n macros to meet the requirements of type-parameterised tests via test case templates (#46, #357) --- include/catch.hpp | 18 ++++ include/internal/catch_test_registry.hpp | 113 +++++++++++++++++++++++ 2 files changed, 131 insertions(+) diff --git a/include/catch.hpp b/include/catch.hpp index 4251cd0841..a87c549a31 100644 --- a/include/catch.hpp +++ b/include/catch.hpp @@ -104,6 +104,15 @@ #endif #define CATCH_ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE( "", "" ) +#define CATCH_TEMPLATE_TEST_CASE_1(name, description, T, T1) INTERNAL_CATCH_TEMPLATE_TEST_CASE_1(name, description, T, T1) +#define CATCH_TEMPLATE_TEST_CASE_2(name, description, T, T1, T2) INTERNAL_CATCH_TEMPLATE_TEST_CASE_2(name, description, T, T1, T2) +#define CATCH_TEMPLATE_TEST_CASE_3(name, description, T, T1, T2, T3) INTERNAL_CATCH_TEMPLATE_TEST_CASE_3(name, description, T, T1, T2, T3) +#define CATCH_TEMPLATE_TEST_CASE_4(name, description, T, T1, T2, T3, T4) INTERNAL_CATCH_TEMPLATE_TEST_CASE_4(name, description, T, T1, T2, T3, T4) +#define CATCH_TEMPLATE_TEST_CASE_5(name, description, T, T1, T2, T3, T4, T5) INTERNAL_CATCH_TEMPLATE_TEST_CASE_5(name, description, T, T1, T2, T3, T4, T5) +#define CATCH_TEMPLATE_TEST_CASE_6(name, description, T, T1, T2, T3, T4, T5, T6) INTERNAL_CATCH_TEMPLATE_TEST_CASE_6(name, description, T, T1, T2, T3, T4, T5, T6) +#define CATCH_TEMPLATE_TEST_CASE_7(name, description, T, T1, T2, T3, T4, T5, T6, T7) INTERNAL_CATCH_TEMPLATE_TEST_CASE_7(name, description, T, T1, T2, T3, T4, T5, T6, T7) +#define CATCH_TEMPLATE_TEST_CASE_8(name, description, T, T1, T2, T3, T4, T5, T6, T7, T8) INTERNAL_CATCH_TEMPLATE_TEST_CASE_8(name, description, T, T1, T2, T3, T4, T5, T6, T7, T8) + #define CATCH_REGISTER_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType ) #define CATCH_REGISTER_LEGACY_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_LEGACY_REPORTER( name, reporterType ) @@ -169,6 +178,15 @@ #endif #define ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE( "", "" ) +#define TEMPLATE_TEST_CASE_1(name, description, T, T1) INTERNAL_CATCH_TEMPLATE_TEST_CASE_1(name, description, T, T1) +#define TEMPLATE_TEST_CASE_2(name, description, T, T1, T2) INTERNAL_CATCH_TEMPLATE_TEST_CASE_2(name, description, T, T1, T2) +#define TEMPLATE_TEST_CASE_3(name, description, T, T1, T2, T3) INTERNAL_CATCH_TEMPLATE_TEST_CASE_3(name, description, T, T1, T2, T3) +#define TEMPLATE_TEST_CASE_4(name, description, T, T1, T2, T3, T4) INTERNAL_CATCH_TEMPLATE_TEST_CASE_4(name, description, T, T1, T2, T3, T4) +#define TEMPLATE_TEST_CASE_5(name, description, T, T1, T2, T3, T4, T5) INTERNAL_CATCH_TEMPLATE_TEST_CASE_5(name, description, T, T1, T2, T3, T4, T5) +#define TEMPLATE_TEST_CASE_6(name, description, T, T1, T2, T3, T4, T5, T6) INTERNAL_CATCH_TEMPLATE_TEST_CASE_6(name, description, T, T1, T2, T3, T4, T5, T6) +#define TEMPLATE_TEST_CASE_7(name, description, T, T1, T2, T3, T4, T5, T6, T7) INTERNAL_CATCH_TEMPLATE_TEST_CASE_7(name, description, T, T1, T2, T3, T4, T5, T6, T7) +#define TEMPLATE_TEST_CASE_8(name, description, T, T1, T2, T3, T4, T5, T6, T7, T8) INTERNAL_CATCH_TEMPLATE_TEST_CASE_8(name, description, T, T1, T2, T3, T4, T5, T6, T7, T8) + #define REGISTER_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType ) #define REGISTER_LEGACY_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_LEGACY_REPORTER( name, reporterType ) diff --git a/include/internal/catch_test_registry.hpp b/include/internal/catch_test_registry.hpp index 73de60b415..ee59a4310b 100644 --- a/include/internal/catch_test_registry.hpp +++ b/include/internal/catch_test_registry.hpp @@ -117,4 +117,117 @@ struct AutoReg { #endif +/////////////////////////////////////////////////////////////////////////////// +// Type-parameterised tests via test case templates +// See https://github.com/philsquared/Catch/issues/46 +// and https://github.com/philsquared/Catch/issues/357 + +#define INTERNAL_CATCH_TEST_CASE_TEMPLATE_DECL( T ) \ + template \ + static void INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_TE____T_E_S_T____ )(); + +#define INTERNAL_CATCH_TEMPLATE_TEST_CASE_SECTION( Tn ) \ + INTERNAL_CATCH_SECTION( #Tn, "" ) \ + { \ + INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_TE____T_E_S_T____ )(); \ + } + +#define INTERNAL_CATCH_TEST_CASE_TEMPLATE_DEFN( T ) \ + template \ + static void INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_TE____T_E_S_T____ )() + +// Simple repetition, which could be accomplished more tersely with some extra preprocessor magic + +#define INTERNAL_CATCH_TEMPLATE_TEST_CASE_1( name, description, T, T1 ) \ + INTERNAL_CATCH_TEST_CASE_TEMPLATE_DECL( T ) \ + INTERNAL_CATCH_TESTCASE( name, description ) \ + { \ + INTERNAL_CATCH_TEMPLATE_TEST_CASE_SECTION( T1 ) \ + } \ + INTERNAL_CATCH_TEST_CASE_TEMPLATE_DEFN( T ) + +#define INTERNAL_CATCH_TEMPLATE_TEST_CASE_2( name, description, T, T1, T2 ) \ + INTERNAL_CATCH_TEST_CASE_TEMPLATE_DECL( T ) \ + INTERNAL_CATCH_TESTCASE( name, description ) \ + { \ + INTERNAL_CATCH_TEMPLATE_TEST_CASE_SECTION( T1 ) \ + INTERNAL_CATCH_TEMPLATE_TEST_CASE_SECTION( T2 ) \ + } \ + INTERNAL_CATCH_TEST_CASE_TEMPLATE_DEFN( T ) + +#define INTERNAL_CATCH_TEMPLATE_TEST_CASE_3( name, description, T, T1, T2, T3 ) \ + INTERNAL_CATCH_TEST_CASE_TEMPLATE_DECL( T ) \ + INTERNAL_CATCH_TESTCASE( name, description ) \ + { \ + INTERNAL_CATCH_TEMPLATE_TEST_CASE_SECTION( T1 ) \ + INTERNAL_CATCH_TEMPLATE_TEST_CASE_SECTION( T2 ) \ + INTERNAL_CATCH_TEMPLATE_TEST_CASE_SECTION( T3 ) \ + } \ + INTERNAL_CATCH_TEST_CASE_TEMPLATE_DEFN( T ) + +#define INTERNAL_CATCH_TEMPLATE_TEST_CASE_4( name, description, T, T1, T2, T3, T4 ) \ + INTERNAL_CATCH_TEST_CASE_TEMPLATE_DECL( T ) \ + INTERNAL_CATCH_TESTCASE( name, description ) \ + { \ + INTERNAL_CATCH_TEMPLATE_TEST_CASE_SECTION( T1 ) \ + INTERNAL_CATCH_TEMPLATE_TEST_CASE_SECTION( T2 ) \ + INTERNAL_CATCH_TEMPLATE_TEST_CASE_SECTION( T3 ) \ + INTERNAL_CATCH_TEMPLATE_TEST_CASE_SECTION( T4 ) \ + } \ + INTERNAL_CATCH_TEST_CASE_TEMPLATE_DEFN( T ) + +#define INTERNAL_CATCH_TEMPLATE_TEST_CASE_5( name, description, T, T1, T2, T3, T4, T5 ) \ + INTERNAL_CATCH_TEST_CASE_TEMPLATE_DECL( T ) \ + INTERNAL_CATCH_TESTCASE( name, description ) \ + { \ + INTERNAL_CATCH_TEMPLATE_TEST_CASE_SECTION( T1 ) \ + INTERNAL_CATCH_TEMPLATE_TEST_CASE_SECTION( T2 ) \ + INTERNAL_CATCH_TEMPLATE_TEST_CASE_SECTION( T3 ) \ + INTERNAL_CATCH_TEMPLATE_TEST_CASE_SECTION( T4 ) \ + INTERNAL_CATCH_TEMPLATE_TEST_CASE_SECTION( T5 ) \ + } \ + INTERNAL_CATCH_TEST_CASE_TEMPLATE_DEFN( T ) + +#define INTERNAL_CATCH_TEMPLATE_TEST_CASE_6( name, description, T, T1, T2, T3, T4, T5, T6 ) \ + INTERNAL_CATCH_TEST_CASE_TEMPLATE_DECL( T ) \ + INTERNAL_CATCH_TESTCASE( name, description ) \ + { \ + INTERNAL_CATCH_TEMPLATE_TEST_CASE_SECTION( T1 ) \ + INTERNAL_CATCH_TEMPLATE_TEST_CASE_SECTION( T2 ) \ + INTERNAL_CATCH_TEMPLATE_TEST_CASE_SECTION( T3 ) \ + INTERNAL_CATCH_TEMPLATE_TEST_CASE_SECTION( T4 ) \ + INTERNAL_CATCH_TEMPLATE_TEST_CASE_SECTION( T5 ) \ + INTERNAL_CATCH_TEMPLATE_TEST_CASE_SECTION( T6 ) \ + } \ + INTERNAL_CATCH_TEST_CASE_TEMPLATE_DEFN( T ) + +#define INTERNAL_CATCH_TEMPLATE_TEST_CASE_7( name, description, T, T1, T2, T3, T4, T5, T6, T7 ) \ + INTERNAL_CATCH_TEST_CASE_TEMPLATE_DECL( T ) \ + INTERNAL_CATCH_TESTCASE( name, description ) \ + { \ + INTERNAL_CATCH_TEMPLATE_TEST_CASE_SECTION( T1 ) \ + INTERNAL_CATCH_TEMPLATE_TEST_CASE_SECTION( T2 ) \ + INTERNAL_CATCH_TEMPLATE_TEST_CASE_SECTION( T3 ) \ + INTERNAL_CATCH_TEMPLATE_TEST_CASE_SECTION( T4 ) \ + INTERNAL_CATCH_TEMPLATE_TEST_CASE_SECTION( T5 ) \ + INTERNAL_CATCH_TEMPLATE_TEST_CASE_SECTION( T6 ) \ + INTERNAL_CATCH_TEMPLATE_TEST_CASE_SECTION( T7 ) \ + } \ + INTERNAL_CATCH_TEST_CASE_TEMPLATE_DEFN( T ) + +#define INTERNAL_CATCH_TEMPLATE_TEST_CASE_8( name, description, T, T1, T2, T3, T4, T5, T6, T7, T8 ) \ + INTERNAL_CATCH_TEST_CASE_TEMPLATE_DECL( T ) \ + INTERNAL_CATCH_TESTCASE( name, description ) \ + { \ + INTERNAL_CATCH_TEMPLATE_TEST_CASE_SECTION( T1 ) \ + INTERNAL_CATCH_TEMPLATE_TEST_CASE_SECTION( T2 ) \ + INTERNAL_CATCH_TEMPLATE_TEST_CASE_SECTION( T3 ) \ + INTERNAL_CATCH_TEMPLATE_TEST_CASE_SECTION( T4 ) \ + INTERNAL_CATCH_TEMPLATE_TEST_CASE_SECTION( T5 ) \ + INTERNAL_CATCH_TEMPLATE_TEST_CASE_SECTION( T6 ) \ + INTERNAL_CATCH_TEMPLATE_TEST_CASE_SECTION( T7 ) \ + INTERNAL_CATCH_TEMPLATE_TEST_CASE_SECTION( T8 ) \ + } \ + INTERNAL_CATCH_TEST_CASE_TEMPLATE_DEFN( T ) + #endif // TWOBLUECUBES_CATCH_TEST_REGISTRY_HPP_INCLUDED