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

Add tests for tag validation during test registration

Commit
1767d9fad0bc28e2b80744daa93c3430d0c6d238
Author
Martin Hořeňovský ·
Parents
ee4b6eadb7f8

Files · Download .tar.gz

Changes

 tests/ExtraTests/CMakeLists.txt                     | 21 +++++++++++++++++++++
 .../ExtraTests/X37-ReportingInvalidTestCaseTags.cpp | 19 +++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/tests/ExtraTests/CMakeLists.txt b/tests/ExtraTests/CMakeLists.txt
index a7b78748..168b739d 100644
--- a/tests/ExtraTests/CMakeLists.txt
+++ b/tests/ExtraTests/CMakeLists.txt
@@ -461,6 +461,27 @@ set_tests_properties(Reporters::CrashInJunitReporter
 )
 
 
+add_executable(ReportingInvalidTestCaseTags ${TESTS_DIR}/X37-ReportingInvalidTestCaseTags.cpp)
+target_link_libraries(ReportingInvalidTestCaseTags PRIVATE Catch2::Catch2WithMain)
+add_test(
+  NAME Validation::TestCaseTags
+  COMMAND $<TARGET_FILE:ReportingInvalidTestCaseTags>
+)
+# Passing multiple PASS_REGULAR_EXPRESSION does not work, so we join multiple ones with '.*'
+set(regexp
+  "Found an empty tag while registering test case 'Empty tag is not allowed'"
+  "Tag name: \\[!abc\\] is not allowed."
+  "Tag names starting with non-alphanumeric characters are reserved."
+  "Tag name: \\[@def\\] is not allowed."
+  "Tag names starting with non-alphanumeric characters are reserved."
+)
+list(JOIN regexp ".*" regexp)
+set_tests_properties(Validation::TestCaseTags
+  PROPERTIES
+    PASS_REGULAR_EXPRESSION ${regexp}
+)
+
+
 add_executable(QuickExitInTest ${TESTS_DIR}/X40-QuickExit.cpp)
 target_link_libraries(QuickExitInTest PRIVATE Catch2::Catch2WithMain)
 add_test(
diff --git a/tests/ExtraTests/X37-ReportingInvalidTestCaseTags.cpp b/tests/ExtraTests/X37-ReportingInvalidTestCaseTags.cpp
new file mode 100644
index 00000000..d70aa34c
--- /dev/null
+++ b/tests/ExtraTests/X37-ReportingInvalidTestCaseTags.cpp
@@ -0,0 +1,19 @@
+
+//              Copyright Catch2 Authors
+// Distributed under the Boost Software License, Version 1.0.
+//   (See accompanying file LICENSE.txt or copy at
+//        https://www.boost.org/LICENSE_1_0.txt)
+
+// SPDX-License-Identifier: BSL-1.0
+
+/**\file
+ * Checks that TEST_CASE registration validates tags.
+ */
+
+#include <catch2/catch_test_macros.hpp>
+
+TEST_CASE( "Empty tag is not allowed", "[]" ) {}
+
+TEST_CASE( "Exclamation point + unknown followup", "[!abc]" ) {}
+
+TEST_CASE( "At is not allowed either (it is tag-alias in CLI)", "[@def]" ) {}