Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

CatchAddTests now adds tags as labels for ctest

- `ctest --print-labels` now will show list of available labels
- `ctest -L <regex>` will allow to run tests with given labels(tags)
Commit
d4eec016a9df54a560d82e5ee12aef42822525e7
Author
Maciej Patro ·
Committer
Martin Hořeňovský
Parents
36fb8561633c

Files · Download .tar.gz

Changes

 contrib/CatchAddTests.cmake | 66 ++++++++++++++++++++++++++++++++-------------
 1 file changed, 47 insertions(+), 19 deletions(-)

diff --git a/contrib/CatchAddTests.cmake b/contrib/CatchAddTests.cmake
index 2220ce3a..ca5ebc17 100644
--- a/contrib/CatchAddTests.cmake
+++ b/contrib/CatchAddTests.cmake
@@ -22,6 +22,39 @@ function(add_command NAME)
   set(script "${script}${NAME}(${_args})\n" PARENT_SCOPE)
 endfunction()
 
+macro(_add_catch_test_labels LINE)
+  # convert to list of tags
+  string(REPLACE "][" "]\\;[" tags ${line})
+
+  add_command(
+    set_tests_properties "${prefix}${test}${suffix}"
+      PROPERTIES
+        LABELS "${tags}"
+  )
+endmacro()
+
+macro(_add_catch_test LINE)
+  set(test ${line})
+  # use escape commas to handle properly test cases with commans inside the name
+  string(REPLACE "," "\\," test_name ${test})
+  # ...and add to script
+  add_command(
+    add_test "${prefix}${test}${suffix}"
+      ${TEST_EXECUTOR}
+       "${TEST_EXECUTABLE}"
+       "${test_name}"
+       ${extra_args}
+     )
+
+  add_command(
+    set_tests_properties "${prefix}${test}${suffix}"
+      PROPERTIES
+        WORKING_DIRECTORY "${TEST_WORKING_DIR}"
+        ${properties}
+  )
+  list(APPEND tests "${prefix}${test}${suffix}")
+endmacro()
+
 # Run test executable to get list of available tests
 if(NOT EXISTS "${TEST_EXECUTABLE}")
   message(FATAL_ERROR
@@ -29,7 +62,7 @@ if(NOT EXISTS "${TEST_EXECUTABLE}")
   )
 endif()
 execute_process(
-  COMMAND ${TEST_EXECUTOR} "${TEST_EXECUTABLE}" ${spec} --list-test-names-only
+  COMMAND ${TEST_EXECUTOR} "${TEST_EXECUTABLE}" ${spec} --list-tests
   OUTPUT_VARIABLE output
   RESULT_VARIABLE result
 )
@@ -47,27 +80,22 @@ elseif(${result} LESS 0)
 endif()
 
 string(REPLACE "\n" ";" output "${output}")
+set(test)
+set(tags_regex "(\\[([^\\[]*)\\])+$")
 
 # Parse output
 foreach(line ${output})
-  set(test ${line})
-  # use escape commas to handle properly test cases with commans inside the name
-  string(REPLACE "," "\\," test_name ${test})
-  # ...and add to script
-  add_command(add_test
-    "${prefix}${test}${suffix}"
-    ${TEST_EXECUTOR}
-    "${TEST_EXECUTABLE}"
-    "${test_name}"
-    ${extra_args}
-  )
-  add_command(set_tests_properties
-    "${prefix}${test}${suffix}"
-    PROPERTIES
-    WORKING_DIRECTORY "${TEST_WORKING_DIR}"
-    ${properties}
-  )
-  list(APPEND tests "${prefix}${test}${suffix}")
+  # lines without leading whitespaces are catch output not tests
+  if(${line} MATCHES "^[ \t]+")
+    # strip leading spaces and tabs
+    string(REGEX REPLACE "^[ \t]+" "" line ${line})
+
+    if(${line} MATCHES "${tags_regex}")
+      _add_catch_test_labels(${line})
+    else()
+      _add_catch_test(${line})
+    endif()
+  endif()
 endforeach()
 
 # Create a list of all discovered tests, which users may use to e.g. set