Disallow empty tags in test case specification

This commit is contained in:
Martin Hořeňovský 2021-05-28 20:49:05 +02:00
parent c9371865d4
commit aee31d0620
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
11 changed files with 48 additions and 10 deletions

View File

@ -146,6 +146,7 @@ namespace Catch {
// it over to backing storage and actually reference the // it over to backing storage and actually reference the
// backing storage in the saved tags // backing storage in the saved tags
StringRef tagStr = originalTags.substr(tagStart+1, tagEnd - tagStart - 1); StringRef tagStr = originalTags.substr(tagStart+1, tagEnd - tagStart - 1);
CATCH_ENFORCE(!tagStr.empty(), "Empty tags are not allowed");
enforceNotReservedTag(tagStr, lineInfo); enforceNotReservedTag(tagStr, lineInfo);
properties |= parseSpecialTag(tagStr); properties |= parseSpecialTag(tagStr);
// When copying a tag to the backing storage, we need to // When copying a tag to the backing storage, we need to

View File

@ -282,6 +282,7 @@ Message from section two
:test-result: PASS classify_outliers :test-result: PASS classify_outliers
:test-result: PASS comparisons between const int variables :test-result: PASS comparisons between const int variables
:test-result: PASS comparisons between 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 erfc_inv
:test-result: PASS estimate_clock_resolution :test-result: PASS estimate_clock_resolution
:test-result: PASS even more nested SECTION tests :test-result: PASS even more nested SECTION tests

View File

@ -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_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_int_var for: 1 == 1
Condition.tests.cpp:<line number>: passed: long_var == unsigned_long_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.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(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 ) InternalBenchmark.tests.cpp:<line number>: passed: erfc_inv(0.050000) == Approx(1.38590382434967796) for: 1.3859038243 == Approx( 1.3859038243 )

View File

@ -1386,6 +1386,6 @@ due to unexpected exception with message:
Why would you throw a std::string? Why would you throw a std::string?
=============================================================================== ===============================================================================
test cases: 364 | 288 passed | 70 failed | 6 failed as expected test cases: 365 | 289 passed | 70 failed | 6 failed as expected
assertions: 2091 | 1939 passed | 129 failed | 23 failed as expected assertions: 2092 | 1940 passed | 129 failed | 23 failed as expected

View File

@ -14597,6 +14597,15 @@ Condition.tests.cpp:<line number>: PASSED:
with expansion: with expansion:
1 == 1 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 erfc_inv
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
@ -16843,6 +16852,6 @@ Misc.tests.cpp:<line number>
Misc.tests.cpp:<line number>: PASSED: Misc.tests.cpp:<line number>: PASSED:
=============================================================================== ===============================================================================
test cases: 364 | 272 passed | 86 failed | 6 failed as expected test cases: 365 | 273 passed | 86 failed | 6 failed as expected
assertions: 2108 | 1939 passed | 146 failed | 23 failed as expected assertions: 2109 | 1940 passed | 146 failed | 23 failed as expected

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<testsuitesloose text artifact <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> <properties>
<property name="filters" value="~[!nonportable]~[!benchmark]~[approvals] *"/> <property name="filters" value="~[!nonportable]~[!benchmark]~[approvals] *"/>
<property name="random-seed" value="1"/> <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="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 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="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="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="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"/> <testcase classname="<exe-name>.global" name="even more nested SECTION tests/c/d (leaf)" time="{duration}" status="run"/>

View File

@ -216,6 +216,7 @@
<file path="tests/<exe-name>/IntrospectiveTests/Tag.tests.cpp"> <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/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="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="shortened hide tags are split apart" duration="{duration}"/>
<testCase name="tags with dots in later positions are not parsed as hidden" duration="{duration}"/> <testCase name="tags with dots in later positions are not parsed as hidden" duration="{duration}"/>
</file> </file>

View File

@ -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 ok {test-number} - long_var == unsigned_int_var for: 1 == 1
# comparisons between int variables # comparisons between int variables
ok {test-number} - long_var == unsigned_long_var for: 1 == 1 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 # erfc_inv
ok {test-number} - erfc_inv(1.103560) == Approx(-0.09203687623843015) for: -0.0920368762 == Approx( -0.0920368762 ) ok {test-number} - erfc_inv(1.103560) == Approx(-0.09203687623843015) for: -0.0920368762 == Approx( -0.0920368762 )
# erfc_inv # erfc_inv
@ -4218,5 +4220,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0
ok {test-number} - ok {test-number} -
# xmlentitycheck # xmlentitycheck
ok {test-number} - ok {test-number} -
1..2108 1..2109

View File

@ -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[testFinished name='comparisons between const int variables' duration="{duration}"]
##teamcity[testStarted name='comparisons between int variables'] ##teamcity[testStarted name='comparisons between int variables']
##teamcity[testFinished name='comparisons between int variables' duration="{duration}"] ##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[testStarted name='erfc_inv']
##teamcity[testFinished name='erfc_inv' duration="{duration}"] ##teamcity[testFinished name='erfc_inv' duration="{duration}"]
##teamcity[testStarted name='estimate_clock_resolution'] ##teamcity[testStarted name='estimate_clock_resolution']

View File

@ -17257,6 +17257,17 @@ There is no extra whitespace here
</Expression> </Expression>
<OverallResult success="true"/> <OverallResult success="true"/>
</TestCase> </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" > <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" > <Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/InternalBenchmark.tests.cpp" >
<Original> <Original>
@ -19815,9 +19826,9 @@ loose text artifact
</Section> </Section>
<OverallResult success="true"/> <OverallResult success="true"/>
</TestCase> </TestCase>
<OverallResults successes="1939" failures="147" expectedFailures="23"/> <OverallResults successes="1940" failures="147" expectedFailures="23"/>
<OverallResultsCases successes="272" failures="86" expectedFailures="6"/> <OverallResultsCases successes="273" failures="86" expectedFailures="6"/>
</Group> </Group>
<OverallResults successes="1939" failures="146" expectedFailures="23"/> <OverallResults successes="1940" failures="146" expectedFailures="23"/>
<OverallResultsCases successes="272" failures="86" expectedFailures="6"/> <OverallResultsCases successes="273" failures="86" expectedFailures="6"/>
</Catch> </Catch>

View File

@ -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]") { TEST_CASE("shortened hide tags are split apart", "[tags]") {
using Catch::StringRef; using Catch::StringRef;
using Catch::Matchers::VectorContains; 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.size() == 1);
REQUIRE(testcase->tags[0].original == "magic.tag"_catch_sr); 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)
);
}