From aee31d0620717f3e0f6bde650f4d0e3a5481819c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Fri, 28 May 2021 20:49:05 +0200 Subject: [PATCH] Disallow empty tags in test case specification --- src/catch2/catch_test_case_info.cpp | 1 + .../Baselines/automake.sw.approved.txt | 1 + .../Baselines/compact.sw.approved.txt | 1 + .../Baselines/console.std.approved.txt | 4 ++-- .../Baselines/console.sw.approved.txt | 13 +++++++++++-- .../SelfTest/Baselines/junit.sw.approved.txt | 3 ++- .../Baselines/sonarqube.sw.approved.txt | 1 + tests/SelfTest/Baselines/tap.sw.approved.txt | 4 +++- .../Baselines/teamcity.sw.approved.txt | 2 ++ tests/SelfTest/Baselines/xml.sw.approved.txt | 19 +++++++++++++++---- .../SelfTest/IntrospectiveTests/Tag.tests.cpp | 9 +++++++++ 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:: passed: long_var == unsigned_char_var for: 1 Condition.tests.cpp:: passed: long_var == unsigned_short_var for: 1 == 1 Condition.tests.cpp:: passed: long_var == unsigned_int_var for: 1 == 1 Condition.tests.cpp:: passed: long_var == unsigned_long_var for: 1 == 1 +Tag.tests.cpp:: passed: Catch::TestCaseInfo("", { "test with an empty tag", "[]" }, dummySourceLineInfo) InternalBenchmark.tests.cpp:: passed: erfc_inv(1.103560) == Approx(-0.09203687623843015) for: -0.0920368762 == Approx( -0.0920368762 ) InternalBenchmark.tests.cpp:: passed: erfc_inv(1.067400) == Approx(-0.05980291115763361) for: -0.0598029112 == Approx( -0.0598029112 ) InternalBenchmark.tests.cpp:: 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 @@ -14597,6 +14597,15 @@ Condition.tests.cpp:: PASSED: with expansion: 1 == 1 +------------------------------------------------------------------------------- +empty tags are not allowed +------------------------------------------------------------------------------- +Tag.tests.cpp: +............................................................................... + +Tag.tests.cpp:: PASSED: + REQUIRE_THROWS( Catch::TestCaseInfo("", { "test with an empty tag", "[]" }, dummySourceLineInfo) ) + ------------------------------------------------------------------------------- erfc_inv ------------------------------------------------------------------------------- @@ -16843,6 +16852,6 @@ Misc.tests.cpp: Misc.tests.cpp:: 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 @@ - + @@ -1548,6 +1548,7 @@ Misc.tests.cpp: + 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 @@ + 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:|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 + + + + Catch::TestCaseInfo("", { "test with an empty tag", "[]" }, dummySourceLineInfo) + + + Catch::TestCaseInfo("", { "test with an empty tag", "[]" }, dummySourceLineInfo) + + + + @@ -19815,9 +19826,9 @@ loose text artifact - - + + - - + + 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) + ); +}