diff --git a/docs/test-cases-and-sections.md b/docs/test-cases-and-sections.md index 8a494b5c..b7f79ef1 100644 --- a/docs/test-cases-and-sections.md +++ b/docs/test-cases-and-sections.md @@ -96,8 +96,8 @@ Other than the additional prefixes and the formatting in the console reporter th ## Type parametrised test cases In addition to `TEST_CASE`s, Catch2 also supports test cases parametrised -by types, in the form of `TEMPLATE_TEST_CASE` and -`TEMPLATE_PRODUCT_TEST_CASE`. +by types, in the form of `TEMPLATE_TEST_CASE`, +`TEMPLATE_PRODUCT_TEST_CASE` and `TEMPLATE_LIST_TEST_CASE`. * **TEMPLATE_TEST_CASE(** _test name_ , _tags_, _type1_, _type2_, ..., _typen_ **)** @@ -192,6 +192,23 @@ _While there is an upper limit on the number of types you can specify in single `TEMPLATE_TEST_CASE` or `TEMPLATE_PRODUCT_TEST_CASE`, the limit is very high and should not be encountered in practice._ +* **TEMPLATE_LIST_TEST_CASE(** _test name_, _tags_, _type list_ **)** + +_type list_ is a generic list of types on which test case should be instantiated. +List can be `std::tuple`, `boost::mpl::list`, `boost::mp11::mp_list` or anything with +`template ` signature. + +This allows you to reuse the _type list_ in multiple test cases. + +Example: +```cpp +using MyTypes = std::tuple; +TEMPLATE_LIST_TEST_CASE("Template test case with test types specified inside std::tuple", "[template][list]", MyTypes) +{ + REQUIRE(sizeof(TestType) > 0); +} +``` + ## Signature based parametrised test cases diff --git a/docs/test-fixtures.md b/docs/test-fixtures.md index 5a2d4df5..5a3f877b 100644 --- a/docs/test-fixtures.md +++ b/docs/test-fixtures.md @@ -111,6 +111,19 @@ TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG(Template_Fixture_2, "A TEMPLATE_PRODUCT_TE } ``` +Catch2 also provides `TEMPLATE_LIST_TEST_CASE_METHOD` to support template fixtures with types specified in +template type lists like `std::tuple`, `boost::mpl::list` or `boost::mp11::mp_list`. This test case works the same as `TEMPLATE_TEST_CASE_METHOD`, +only difference is the source of types. This allows you to reuse the template type list in multiple test cases. + +Example: +```cpp +using MyTypes = std::tuple; +TEMPLATE_LIST_TEST_CASE_METHOD(Template_Fixture, "Template test case method with test types specified inside std::tuple", "[class][template][list]", MyTypes) +{ + REQUIRE( Template_Fixture::m_a == 1 ); +} +``` + --- [Home](Readme.md#top)