Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAnsel Sermersheim2020-09-23 09:13:29 -0700
committerMartin Hořeňovský2020-10-08 11:37:11 +0200
commit1d01464730800d03b4b0d1f5de613a3f9c288273 (patch)
tree43b264da9e6ca7a4b605cec3d046b25443037824
parentc522e88afa04d66004e8d36e3a729fef90e36aaa (diff)
downloadcatch3-1d01464730800d03b4b0d1f5de613a3f9c288273.tar.gz
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)
-rw-r--r--extras/ParseAndAddCatchTests.cmake14
1 files 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} $<TARGET_FILE:${TestTarget}> ${Name} ${AdditionalCatchParameters})
# Old CMake versions do not document VERSION_GREATER_EQUAL, so we use VERSION_GREATER with 3.8 instead