From 1d01464730800d03b4b0d1f5de613a3f9c288273 Mon Sep 17 00:00:00 2001 From: Ansel Sermersheim Date: Wed, 23 Sep 2020 09:13:29 -0700 Subject: [PATCH] Support template test cases in ParseAndAddCatchTests * Change regex to allow parentheses inside the test macro for a type list * Append a wildcard to the CTestName if the test case is a template * Also change the regular expression so parentheses are allowed in names (fixes #1848) --- extras/ParseAndAddCatchTests.cmake | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/extras/ParseAndAddCatchTests.cmake b/extras/ParseAndAddCatchTests.cmake index 5e89cb76..9203f163 100644 --- a/extras/ParseAndAddCatchTests.cmake +++ b/extras/ParseAndAddCatchTests.cmake @@ -1,9 +1,11 @@ #==================================================================================================# # supported macros # # - TEST_CASE, # +# - TEMPLATE_TEST_CASE # # - SCENARIO, # # - TEST_CASE_METHOD, # # - CATCH_TEST_CASE, # +# - CATCH_TEMPLATE_TEST_CASE # # - CATCH_SCENARIO, # # - CATCH_TEST_CASE_METHOD. # # # @@ -106,7 +108,7 @@ function(ParseAndAddCatchTests_ParseFile SourceFile TestTarget) ParseAndAddCatchTests_RemoveComments(Contents) # Find definition of test names - string(REGEX MATCHALL "[ \t]*(CATCH_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)[ \t]*\\([^\)]+\\)+[ \t\n]*{+[ \t]*(//[^\n]*[Tt][Ii][Mm][Ee][Oo][Uu][Tt][ \t]*[0-9]+)*" Tests "${Contents}") + string(REGEX MATCHALL "[ \t]*(CATCH_)?(TEMPLATE_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)[ \t]*\\([ \t\n]*\"[^\"]*\"[ \t\n]*,[ \t\n]*\"[^\"]*\"([^\(\)]+(\\([^\)]*\\))*)*\\)+[ \t\n]*{+[ \t]*(//[^\n]*[Tt][Ii][Mm][Ee][Oo][Uu][Tt][ \t]*[0-9]+)*" Tests "${Contents}") if(PARSE_CATCH_TESTS_ADD_TO_CONFIGURE_DEPENDS AND Tests) ParseAndAddCatchTests_PrintDebugMessage("Adding ${SourceFile} to CMAKE_CONFIGURE_DEPENDS property") @@ -122,8 +124,8 @@ function(ParseAndAddCatchTests_ParseFile SourceFile TestTarget) string(REGEX REPLACE "\\\\\n|\n" "" TestName "${TestName}") # Get test type and fixture if applicable - string(REGEX MATCH "(CATCH_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)[ \t]*\\([^,^\"]*" TestTypeAndFixture "${TestName}") - string(REGEX MATCH "(CATCH_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)" TestType "${TestTypeAndFixture}") + string(REGEX MATCH "(CATCH_)?(TEMPLATE_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)[ \t]*\\([^,^\"]*" TestTypeAndFixture "${TestName}") + string(REGEX MATCH "(CATCH_)?(TEMPLATE_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)" TestType "${TestTypeAndFixture}") string(REGEX REPLACE "${TestType}\\([ \t]*" "" TestFixture "${TestTypeAndFixture}") # Get string parts of test definition @@ -194,6 +196,12 @@ function(ParseAndAddCatchTests_ParseFile SourceFile TestTarget) if(NOT ${CMAKE_VERSION} VERSION_EQUAL "3.18") set(CTestName "\"${CTestName}\"") endif() + + # Handle template test cases + if("${TestTypeAndFixture}" MATCHES ".*TEMPLATE_.*") + set(Name "${Name} - *") + endif() + # Add the test and set its properties add_test(NAME "${CTestName}" COMMAND ${OptionalCatchTestLauncher} $ ${Name} ${AdditionalCatchParameters}) # Old CMake versions do not document VERSION_GREATER_EQUAL, so we use VERSION_GREATER with 3.8 instead