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

summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMartin Hořeňovský2021-05-28 20:49:05 +0200
committerMartin Hořeňovský2021-06-01 00:17:13 +0200
commitaee31d0620717f3e0f6bde650f4d0e3a5481819c (patch)
treeaaedb37a723c7e615ed0ce1f84c4a9a9e43682b2
parentc9371865d4e08d6e9907597ca827c295235c0594 (diff)
downloadcatch3-aee31d0620717f3e0f6bde650f4d0e3a5481819c.tar.gz
Disallow empty tags in test case specification
-rw-r--r--src/catch2/catch_test_case_info.cpp1
-rw-r--r--tests/SelfTest/Baselines/automake.sw.approved.txt1
-rw-r--r--tests/SelfTest/Baselines/compact.sw.approved.txt1
-rw-r--r--tests/SelfTest/Baselines/console.std.approved.txt4
-rw-r--r--tests/SelfTest/Baselines/console.sw.approved.txt13
-rw-r--r--tests/SelfTest/Baselines/junit.sw.approved.txt3
-rw-r--r--tests/SelfTest/Baselines/sonarqube.sw.approved.txt1
-rw-r--r--tests/SelfTest/Baselines/tap.sw.approved.txt4
-rw-r--r--tests/SelfTest/Baselines/teamcity.sw.approved.txt2
-rw-r--r--tests/SelfTest/Baselines/xml.sw.approved.txt19
-rw-r--r--tests/SelfTest/IntrospectiveTests/Tag.tests.cpp9
11 files changed, 48 insertions, 10 deletions
diff --git a/src/catch2/catch_test_case_info.cpp b/src/catch2/catch_test_case_info.cpp
index e8029e9c..800c94fa 100644
--- a/src/catch2/catch_test_case_info.cpp
+++ b/src/catch2/catch_test_case_info.cpp
@@ -146,6 +146,7 @@ namespace Catch {
// it over to backing storage and actually reference the
// backing storage in the saved tags
StringRef tagStr = originalTags.substr(tagStart+1, tagEnd - tagStart - 1);
+ CATCH_ENFORCE(!tagStr.empty(), "Empty tags are not allowed");
enforceNotReservedTag(tagStr, lineInfo);
properties |= parseSpecialTag(tagStr);
// When copying a tag to the backing storage, we need to
diff --git a/tests/SelfTest/Baselines/automake.sw.approved.txt b/tests/SelfTest/Baselines/automake.sw.approved.txt
index d6ffeee7..04ba4220 100644
--- a/tests/SelfTest/Baselines/automake.sw.approved.txt
+++ b/tests/SelfTest/Baselines/automake.sw.approved.txt
@@ -282,6 +282,7 @@ Message from section two
:test-result: PASS classify_outliers
:test-result: PASS comparisons between const int variables
:test-result: PASS comparisons between int variables
+:test-result: PASS empty tags are not allowed
:test-result: PASS erfc_inv
:test-result: PASS estimate_clock_resolution
:test-result: PASS even more nested SECTION tests
diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt
index c41b3b34..f3651ac2 100644
--- a/tests/SelfTest/Baselines/compact.sw.approved.txt
+++ b/tests/SelfTest/Baselines/compact.sw.approved.txt
@@ -2065,6 +2065,7 @@ Condition.tests.cpp:<line number>: passed: long_var == unsigned_char_var for: 1
Condition.tests.cpp:<line number>: passed: long_var == unsigned_short_var for: 1 == 1
Condition.tests.cpp:<line number>: passed: long_var == unsigned_int_var for: 1 == 1
Condition.tests.cpp:<line number>: passed: long_var == unsigned_long_var for: 1 == 1
+Tag.tests.cpp:<line number>: passed: Catch::TestCaseInfo("", { "test with an empty tag", "[]" }, dummySourceLineInfo)
InternalBenchmark.tests.cpp:<line number>: passed: erfc_inv(1.103560) == Approx(-0.09203687623843015) for: -0.0920368762 == Approx( -0.0920368762 )
InternalBenchmark.tests.cpp:<line number>: passed: erfc_inv(1.067400) == Approx(-0.05980291115763361) for: -0.0598029112 == Approx( -0.0598029112 )
InternalBenchmark.tests.cpp:<line number>: passed: erfc_inv(0.050000) == Approx(1.38590382434967796) for: 1.3859038243 == Approx( 1.3859038243 )
diff --git a/tests/SelfTest/Baselines/console.std.approved.txt b/tests/SelfTest/Baselines/console.std.approved.txt
index a65f658c..15076a7b 100644
--- a/tests/SelfTest/Baselines/console.std.approved.txt
+++ b/tests/SelfTest/Baselines/console.std.approved.txt
@@ -1386,6 +1386,6 @@ due to unexpected exception with message:
Why would you throw a std::string?
===============================================================================
-test cases: 364 | 288 passed | 70 failed | 6 failed as expected
-assertions: 2091 | 1939 passed | 129 failed | 23 failed as expected
+test cases: 365 | 289 passed | 70 failed | 6 failed as expected
+assertions: 2092 | 1940 passed | 129 failed | 23 failed as expected
diff --git a/tests/SelfTest/Baselines/console.sw.approved.txt b/tests/SelfTest/Baselines/console.sw.approved.txt
index b5045fe1..7ecdf827 100644
--- a/tests/SelfTest/Baselines/console.sw.approved.txt
+++ b/tests/SelfTest/Baselines/console.sw.approved.txt
@@ -14598,6 +14598,15 @@ with expansion:
1 == 1
-------------------------------------------------------------------------------
+empty tags are not allowed
+-------------------------------------------------------------------------------
+Tag.tests.cpp:<line number>
+...............................................................................
+
+Tag.tests.cpp:<line number>: PASSED:
+ REQUIRE_THROWS( Catch::TestCaseInfo("", { "test with an empty tag", "[]" }, dummySourceLineInfo) )
+
+-------------------------------------------------------------------------------
erfc_inv
-------------------------------------------------------------------------------
InternalBenchmark.tests.cpp:<line number>
@@ -16843,6 +16852,6 @@ Misc.tests.cpp:<line number>
Misc.tests.cpp:<line number>: PASSED:
===============================================================================
-test cases: 364 | 272 passed | 86 failed | 6 failed as expected
-assertions: 2108 | 1939 passed | 146 failed | 23 failed as expected
+test cases: 365 | 273 passed | 86 failed | 6 failed as expected
+assertions: 2109 | 1940 passed | 146 failed | 23 failed as expected
diff --git a/tests/SelfTest/Baselines/junit.sw.approved.txt b/tests/SelfTest/Baselines/junit.sw.approved.txt
index 811dab96..98d8a4d0 100644
--- a/tests/SelfTest/Baselines/junit.sw.approved.txt
+++ b/tests/SelfTest/Baselines/junit.sw.approved.txt
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuitesloose text artifact
>
- <testsuite name="<exe-name>" errors="17" failures="130" tests="2109" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
+ <testsuite name="<exe-name>" errors="17" failures="130" tests="2110" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<properties>
<property name="filters" value="~[!nonportable]~[!benchmark]~[approvals] *"/>
<property name="random-seed" value="1"/>
@@ -1548,6 +1548,7 @@ Misc.tests.cpp:<line number>
<testcase classname="<exe-name>.global" name="classify_outliers/mixed" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="comparisons between const int variables" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="comparisons between int variables" time="{duration}" status="run"/>
+ <testcase classname="<exe-name>.global" name="empty tags are not allowed" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="erfc_inv" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="estimate_clock_resolution" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="even more nested SECTION tests/c/d (leaf)" time="{duration}" status="run"/>
diff --git a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt
index 143ed10c..af97d374 100644
--- a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt
+++ b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt
@@ -216,6 +216,7 @@
<file path="tests/<exe-name>/IntrospectiveTests/Tag.tests.cpp">
<testCase name="Tag alias can be registered against tag patterns/The same tag alias can only be registered once" duration="{duration}"/>
<testCase name="Tag alias can be registered against tag patterns/Tag aliases must be of the form [@name]" duration="{duration}"/>
+ <testCase name="empty tags are not allowed" duration="{duration}"/>
<testCase name="shortened hide tags are split apart" duration="{duration}"/>
<testCase name="tags with dots in later positions are not parsed as hidden" duration="{duration}"/>
</file>
diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt
index 17ddd242..311bf419 100644
--- a/tests/SelfTest/Baselines/tap.sw.approved.txt
+++ b/tests/SelfTest/Baselines/tap.sw.approved.txt
@@ -3703,6 +3703,8 @@ ok {test-number} - long_var == unsigned_short_var for: 1 == 1
ok {test-number} - long_var == unsigned_int_var for: 1 == 1
# comparisons between int variables
ok {test-number} - long_var == unsigned_long_var for: 1 == 1
+# empty tags are not allowed
+ok {test-number} - Catch::TestCaseInfo("", { "test with an empty tag", "[]" }, dummySourceLineInfo)
# erfc_inv
ok {test-number} - erfc_inv(1.103560) == Approx(-0.09203687623843015) for: -0.0920368762 == Approx( -0.0920368762 )
# erfc_inv
@@ -4218,5 +4220,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0
ok {test-number} -
# xmlentitycheck
ok {test-number} -
-1..2108
+1..2109
diff --git a/tests/SelfTest/Baselines/teamcity.sw.approved.txt b/tests/SelfTest/Baselines/teamcity.sw.approved.txt
index 1dee018b..369adb62 100644
--- a/tests/SelfTest/Baselines/teamcity.sw.approved.txt
+++ b/tests/SelfTest/Baselines/teamcity.sw.approved.txt
@@ -690,6 +690,8 @@ Misc.tests.cpp:<line number>|nexpression failed|n REQUIRE( testCheckedIf( false
##teamcity[testFinished name='comparisons between const int variables' duration="{duration}"]
##teamcity[testStarted name='comparisons between int variables']
##teamcity[testFinished name='comparisons between int variables' duration="{duration}"]
+##teamcity[testStarted name='empty tags are not allowed']
+##teamcity[testFinished name='empty tags are not allowed' duration="{duration}"]
##teamcity[testStarted name='erfc_inv']
##teamcity[testFinished name='erfc_inv' duration="{duration}"]
##teamcity[testStarted name='estimate_clock_resolution']
diff --git a/tests/SelfTest/Baselines/xml.sw.approved.txt b/tests/SelfTest/Baselines/xml.sw.approved.txt
index c8f413e5..0931e8c3 100644
--- a/tests/SelfTest/Baselines/xml.sw.approved.txt
+++ b/tests/SelfTest/Baselines/xml.sw.approved.txt
@@ -17257,6 +17257,17 @@ There is no extra whitespace here
</Expression>
<OverallResult success="true"/>
</TestCase>
+ <TestCase name="empty tags are not allowed" tags="[tags]" filename="tests/<exe-name>/IntrospectiveTests/Tag.tests.cpp" >
+ <Expression success="true" type="REQUIRE_THROWS" filename="tests/<exe-name>/IntrospectiveTests/Tag.tests.cpp" >
+ <Original>
+ Catch::TestCaseInfo("", { "test with an empty tag", "[]" }, dummySourceLineInfo)
+ </Original>
+ <Expanded>
+ Catch::TestCaseInfo("", { "test with an empty tag", "[]" }, dummySourceLineInfo)
+ </Expanded>
+ </Expression>
+ <OverallResult success="true"/>
+ </TestCase>
<TestCase name="erfc_inv" tags="[benchmark]" filename="tests/<exe-name>/IntrospectiveTests/InternalBenchmark.tests.cpp" >
<Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/InternalBenchmark.tests.cpp" >
<Original>
@@ -19815,9 +19826,9 @@ loose text artifact
</Section>
<OverallResult success="true"/>
</TestCase>
- <OverallResults successes="1939" failures="147" expectedFailures="23"/>
- <OverallResultsCases successes="272" failures="86" expectedFailures="6"/>
+ <OverallResults successes="1940" failures="147" expectedFailures="23"/>
+ <OverallResultsCases successes="273" failures="86" expectedFailures="6"/>
</Group>
- <OverallResults successes="1939" failures="146" expectedFailures="23"/>
- <OverallResultsCases successes="272" failures="86" expectedFailures="6"/>
+ <OverallResults successes="1940" failures="146" expectedFailures="23"/>
+ <OverallResultsCases successes="273" failures="86" expectedFailures="6"/>
</Catch>
diff --git a/tests/SelfTest/IntrospectiveTests/Tag.tests.cpp b/tests/SelfTest/IntrospectiveTests/Tag.tests.cpp
index 44b82c6c..2fe9da23 100644
--- a/tests/SelfTest/IntrospectiveTests/Tag.tests.cpp
+++ b/tests/SelfTest/IntrospectiveTests/Tag.tests.cpp
@@ -39,6 +39,9 @@ TEST_CASE( "Tag alias can be registered against tag patterns" ) {
}
}
+// Dummy line info for creating dummy test cases below
+constexpr Catch::SourceLineInfo dummySourceLineInfo = CATCH_INTERNAL_LINEINFO;
+
TEST_CASE("shortened hide tags are split apart", "[tags]") {
using Catch::StringRef;
using Catch::Matchers::VectorContains;
@@ -60,3 +63,9 @@ TEST_CASE("tags with dots in later positions are not parsed as hidden", "[tags]"
REQUIRE(testcase->tags.size() == 1);
REQUIRE(testcase->tags[0].original == "magic.tag"_catch_sr);
}
+
+TEST_CASE( "empty tags are not allowed", "[tags]" ) {
+ REQUIRE_THROWS(
+ Catch::TestCaseInfo("", { "test with an empty tag", "[]" }, dummySourceLineInfo)
+ );
+}