Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TEMPLATE_TEST_CASE_n macros #382

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions include/catch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )

Expand Down Expand Up @@ -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 )

Expand Down
113 changes: 113 additions & 0 deletions include/internal/catch_test_registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename T> \
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____ )<Tn>(); \
}

#define INTERNAL_CATCH_TEST_CASE_TEMPLATE_DEFN( T ) \
template<typename T> \
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