From f00b6e2019a9e5bdbe37dcc0be5756322363909d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Mon, 27 Dec 2021 10:04:48 +0100 Subject: [PATCH] Add more tests for various less common tag-related cases --- docs/test-cases-and-sections.md | 10 +- tests/CMakeLists.txt | 1 + .../Baselines/automake.sw.approved.txt | 5 + .../Baselines/compact.sw.approved.txt | 14 ++ .../Baselines/console.std.approved.txt | 4 +- .../Baselines/console.sw.approved.txt | 120 +++++++++++++- .../SelfTest/Baselines/junit.sw.approved.txt | 7 +- .../Baselines/sonarqube.sw.approved.txt | 7 + tests/SelfTest/Baselines/tap.sw.approved.txt | 30 +++- .../Baselines/teamcity.sw.approved.txt | 10 ++ tests/SelfTest/Baselines/xml.sw.approved.txt | 149 +++++++++++++++++- .../SelfTest/IntrospectiveTests/Tag.tests.cpp | 35 +++- .../TestSpecParser.tests.cpp | 55 +++++++ 13 files changed, 437 insertions(+), 10 deletions(-) create mode 100644 tests/SelfTest/IntrospectiveTests/TestSpecParser.tests.cpp diff --git a/docs/test-cases-and-sections.md b/docs/test-cases-and-sections.md index 06d2f47f..8cfb282b 100644 --- a/docs/test-cases-and-sections.md +++ b/docs/test-cases-and-sections.md @@ -44,7 +44,15 @@ The tag expression, ```"[widget]"``` selects A, B & D. ```"[gadget]"``` selects For more detail on command line selection see [the command line docs](command-line.md#specifying-which-tests-to-run) -Tag names are not case sensitive and can contain any ASCII characters. This means that tags `[tag with spaces]` and `[I said "good day"]` are both allowed tags and can be filtered on. Escapes are not supported however and `[\]]` is not a valid tag. +Tag names are not case sensitive and can contain any ASCII characters. +This means that tags `[tag with spaces]` and `[I said "good day"]` +are both allowed tags and can be filtered on. However, escapes are not +supported however and `[\]]` is not a valid tag. + +The same tag can be specified multiple times for a single test case, +but only one of the instances of identical tags will be kept. Which one +is kept is functionally random. + ### Special Tags diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6857f1bd..02e02747 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -87,6 +87,7 @@ set(TEST_SOURCES ${SELF_TEST_DIR}/IntrospectiveTests/RandomNumberGeneration.tests.cpp ${SELF_TEST_DIR}/IntrospectiveTests/Reporters.tests.cpp ${SELF_TEST_DIR}/IntrospectiveTests/Tag.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/TestSpecParser.tests.cpp ${SELF_TEST_DIR}/IntrospectiveTests/TextFlow.tests.cpp ${SELF_TEST_DIR}/IntrospectiveTests/Sharding.tests.cpp ${SELF_TEST_DIR}/IntrospectiveTests/String.tests.cpp diff --git a/tests/SelfTest/Baselines/automake.sw.approved.txt b/tests/SelfTest/Baselines/automake.sw.approved.txt index ea0e0ce2..05a96c7a 100644 --- a/tests/SelfTest/Baselines/automake.sw.approved.txt +++ b/tests/SelfTest/Baselines/automake.sw.approved.txt @@ -128,6 +128,7 @@ Nor would this :test-result: FAIL Custom std-exceptions can be custom translated :test-result: PASS Default scale is invisible to comparison :test-result: PASS Directly creating an EnumInfo +:test-result: PASS Empty tag is not allowed :test-result: FAIL EndsWith string matcher :test-result: PASS Enums can quickly have stringification enabled using REGISTER_ENUM :test-result: PASS Enums in namespaces can quickly have stringification enabled using REGISTER_ENUM @@ -180,7 +181,9 @@ Nor would this :test-result: FAIL Output from all sections is reported :test-result: PASS Overloaded comma or address-of operators are not used :test-result: PASS Parse test names and tags +:test-result: PASS Parsed tags are matched case insensitive :test-result: PASS Parsing sharding-related cli flags +:test-result: PASS Parsing tags with non-alphabetical characters is pass-through :test-result: PASS Parsing warnings :test-result: PASS Pointers can be compared to null :test-result: PASS Precision of floating point stringification can be set @@ -224,6 +227,7 @@ Message from section two :test-result: PASS Stringifying std::chrono::time_point :test-result: FAIL Tabs and newlines show in output :test-result: PASS Tag alias can be registered against tag patterns +:test-result: PASS Tags with spaces and non-alphanumerical characters are accepted :test-result: PASS Template test case method with test types specified inside std::tuple - MyTypes - 0 :test-result: PASS Template test case method with test types specified inside std::tuple - MyTypes - 1 :test-result: PASS Template test case method with test types specified inside std::tuple - MyTypes - 2 @@ -242,6 +246,7 @@ Message from section two :test-result: PASS TemplateTestSig: vectors can be sized and resized - float,4 :test-result: PASS TemplateTestSig: vectors can be sized and resized - int,5 :test-result: PASS TemplateTestSig: vectors can be sized and resized - std::string,15 +:test-result: PASS Test case with identical tags keeps just one :test-result: PASS Test case with one argument :test-result: PASS Test enum bit values :test-result: PASS Test with special, characters "in name diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt index f58324f4..fab13bf2 100644 --- a/tests/SelfTest/Baselines/compact.sw.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.approved.txt @@ -491,6 +491,7 @@ ToString.tests.cpp:: passed: enumInfo->lookup(1) == "Value2" for: V ToString.tests.cpp:: passed: enumInfo->lookup(3) == "{** unexpected enum value **}" for: {** unexpected enum value **} == "{** unexpected enum value **}" +Tag.tests.cpp:: passed: Catch::TestCaseInfo( "", { "fake test name", "[]" }, dummySourceLineInfo ) Matchers.tests.cpp:: failed: testStringForMatching(), EndsWith( "Substring" ) for: "this string contains 'abc' as a substring" ends with: "Substring" Matchers.tests.cpp:: failed: testStringForMatching(), EndsWith( "this", Catch::CaseSensitive::No ) for: "this string contains 'abc' as a substring" ends with: "this" (case insensitive) EnumToString.tests.cpp:: passed: stringify( EnumClass3::Value1 ) == "Value1" for: "Value1" == "Value1" @@ -1203,6 +1204,9 @@ CmdLine.tests.cpp:: passed: !(spec.matches(*fakeTestCase("hidden an CmdLine.tests.cpp:: passed: !(spec.matches(*fakeTestCase("only foo", "[foo]"))) for: !false CmdLine.tests.cpp:: passed: !(spec.matches(*fakeTestCase("only hidden", "[.]"))) for: !false CmdLine.tests.cpp:: passed: spec.matches(*fakeTestCase("neither foo nor hidden", "[bar]")) for: true +TestSpecParser.tests.cpp:: passed: spec.hasFilters() for: true +TestSpecParser.tests.cpp:: passed: spec.getInvalidSpecs().empty() for: true +TestSpecParser.tests.cpp:: passed: spec.matches( testCase ) for: true CmdLine.tests.cpp:: passed: cli.parse({ "test", "--shard-count=8" }) for: {?} CmdLine.tests.cpp:: passed: config.shardCount == 8 for: 8 == 8 CmdLine.tests.cpp:: passed: !(result) for: !{?} @@ -1215,6 +1219,12 @@ CmdLine.tests.cpp:: passed: !(result) for: !{?} CmdLine.tests.cpp:: passed: result.errorMessage(), ContainsSubstring("Shard index must be a non-negative number") for: "Shard index must be a non-negative number" contains: "Shard index must be a non-negative number" CmdLine.tests.cpp:: passed: cli.parse({ "test", "--shard-index=0" }) for: {?} CmdLine.tests.cpp:: passed: config.shardIndex == 0 for: 0 == 0 +TestSpecParser.tests.cpp:: passed: spec.hasFilters() for: true with 1 message: 'tagString := "[tag with spaces]"' +TestSpecParser.tests.cpp:: passed: spec.getInvalidSpecs().empty() for: true with 1 message: 'tagString := "[tag with spaces]"' +TestSpecParser.tests.cpp:: passed: spec.matches( testCase ) for: true with 1 message: 'tagString := "[tag with spaces]"' +TestSpecParser.tests.cpp:: passed: spec.hasFilters() for: true with 1 message: 'tagString := "[I said "good day" sir!]"' +TestSpecParser.tests.cpp:: passed: spec.getInvalidSpecs().empty() for: true with 1 message: 'tagString := "[I said "good day" sir!]"' +TestSpecParser.tests.cpp:: passed: spec.matches( testCase ) for: true with 1 message: 'tagString := "[I said "good day" sir!]"' CmdLine.tests.cpp:: passed: cli.parse( { "test", "-w", "NoAssertions" } ) for: {?} CmdLine.tests.cpp:: passed: config.warnings == WarnAbout::NoAssertions for: 1 == 1 CmdLine.tests.cpp:: passed: !(cli.parse( { "test", "-w", "NoTests" } )) for: !{?} @@ -1627,6 +1637,8 @@ Tag.tests.cpp:: passed: registry.add( "[no ampersat]", "", Catch::S Tag.tests.cpp:: passed: registry.add( "[the @ is not at the start]", "", Catch::SourceLineInfo( "file", 3 ) ) Tag.tests.cpp:: passed: registry.add( "@no square bracket at start]", "", Catch::SourceLineInfo( "file", 3 ) ) Tag.tests.cpp:: passed: registry.add( "[@no square bracket at end", "", Catch::SourceLineInfo( "file", 3 ) ) +Tag.tests.cpp:: passed: testCase.tags.size() == 2 for: 2 == 2 +Tag.tests.cpp:: passed: testCase.tags, VectorContains( Tag( "tag with spaces" ) ) && VectorContains( Tag( "I said \"good day\" sir!"_catch_sr ) ) for: { {?}, {?} } ( Contains: {?} and Contains: {?} ) Class.tests.cpp:: passed: Template_Fixture::m_a == 1 for: 1 == 1 Class.tests.cpp:: passed: Template_Fixture::m_a == 1 for: 1 == 1 Class.tests.cpp:: passed: Template_Fixture::m_a == 1 for: 1.0 == 1 @@ -1773,6 +1785,8 @@ Misc.tests.cpp:: passed: v.size() == V for: 15 == 15 Misc.tests.cpp:: passed: v.capacity() >= V for: 15 >= 15 Misc.tests.cpp:: passed: v.size() == V for: 15 == 15 Misc.tests.cpp:: passed: v.capacity() >= V for: 15 >= 15 +Tag.tests.cpp:: passed: testCase.tags.size() == 1 for: 1 == 1 +Tag.tests.cpp:: passed: testCase.tags[0] == Tag( "tag1" ) for: {?} == {?} VariadicMacros.tests.cpp:: passed: with 1 message: 'no assertions' Tricky.tests.cpp:: passed: 0x == bit30and31 for: 3221225472 (0x) == 3221225472 CmdLine.tests.cpp:: passed: diff --git a/tests/SelfTest/Baselines/console.std.approved.txt b/tests/SelfTest/Baselines/console.std.approved.txt index be4f8e78..92b8d9d9 100644 --- a/tests/SelfTest/Baselines/console.std.approved.txt +++ b/tests/SelfTest/Baselines/console.std.approved.txt @@ -1426,6 +1426,6 @@ due to unexpected exception with message: Why would you throw a std::string? =============================================================================== -test cases: 379 | 302 passed | 70 failed | 7 failed as expected -assertions: 2169 | 2013 passed | 129 failed | 27 failed as expected +test cases: 384 | 307 passed | 70 failed | 7 failed as expected +assertions: 2183 | 2027 passed | 129 failed | 27 failed as expected diff --git a/tests/SelfTest/Baselines/console.sw.approved.txt b/tests/SelfTest/Baselines/console.sw.approved.txt index 25a85bce..ac9f7eee 100644 --- a/tests/SelfTest/Baselines/console.sw.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.approved.txt @@ -3893,6 +3893,15 @@ with expansion: == "{** unexpected enum value **}" +------------------------------------------------------------------------------- +Empty tag is not allowed +------------------------------------------------------------------------------- +Tag.tests.cpp: +............................................................................... + +Tag.tests.cpp:: PASSED: + REQUIRE_THROWS( Catch::TestCaseInfo( "", { "fake test name", "[]" }, dummySourceLineInfo ) ) + ------------------------------------------------------------------------------- EndsWith string matcher ------------------------------------------------------------------------------- @@ -8782,6 +8791,27 @@ CmdLine.tests.cpp:: PASSED: with expansion: true +------------------------------------------------------------------------------- +Parsed tags are matched case insensitive +------------------------------------------------------------------------------- +TestSpecParser.tests.cpp: +............................................................................... + +TestSpecParser.tests.cpp:: PASSED: + REQUIRE( spec.hasFilters() ) +with expansion: + true + +TestSpecParser.tests.cpp:: PASSED: + REQUIRE( spec.getInvalidSpecs().empty() ) +with expansion: + true + +TestSpecParser.tests.cpp:: PASSED: + REQUIRE( spec.matches( testCase ) ) +with expansion: + true + ------------------------------------------------------------------------------- Parsing sharding-related cli flags shard-count @@ -8887,6 +8917,60 @@ CmdLine.tests.cpp:: PASSED: with expansion: 0 == 0 +------------------------------------------------------------------------------- +Parsing tags with non-alphabetical characters is pass-through +------------------------------------------------------------------------------- +TestSpecParser.tests.cpp: +............................................................................... + +TestSpecParser.tests.cpp:: PASSED: + REQUIRE( spec.hasFilters() ) +with expansion: + true +with message: + tagString := "[tag with spaces]" + +TestSpecParser.tests.cpp:: PASSED: + REQUIRE( spec.getInvalidSpecs().empty() ) +with expansion: + true +with message: + tagString := "[tag with spaces]" + +TestSpecParser.tests.cpp:: PASSED: + REQUIRE( spec.matches( testCase ) ) +with expansion: + true +with message: + tagString := "[tag with spaces]" + +------------------------------------------------------------------------------- +Parsing tags with non-alphabetical characters is pass-through +------------------------------------------------------------------------------- +TestSpecParser.tests.cpp: +............................................................................... + +TestSpecParser.tests.cpp:: PASSED: + REQUIRE( spec.hasFilters() ) +with expansion: + true +with message: + tagString := "[I said "good day" sir!]" + +TestSpecParser.tests.cpp:: PASSED: + REQUIRE( spec.getInvalidSpecs().empty() ) +with expansion: + true +with message: + tagString := "[I said "good day" sir!]" + +TestSpecParser.tests.cpp:: PASSED: + REQUIRE( spec.matches( testCase ) ) +with expansion: + true +with message: + tagString := "[I said "good day" sir!]" + ------------------------------------------------------------------------------- Parsing warnings NoAssertions @@ -11497,6 +11581,22 @@ Tag.tests.cpp:: PASSED: Tag.tests.cpp:: PASSED: CHECK_THROWS( registry.add( "[@no square bracket at end", "", Catch::SourceLineInfo( "file", 3 ) ) ) +------------------------------------------------------------------------------- +Tags with spaces and non-alphanumerical characters are accepted +------------------------------------------------------------------------------- +Tag.tests.cpp: +............................................................................... + +Tag.tests.cpp:: PASSED: + REQUIRE( testCase.tags.size() == 2 ) +with expansion: + 2 == 2 + +Tag.tests.cpp:: PASSED: + REQUIRE_THAT( testCase.tags, VectorContains( Tag( "tag with spaces" ) ) && VectorContains( Tag( "I said \"good day\" sir!"_catch_sr ) ) ) +with expansion: + { {?}, {?} } ( Contains: {?} and Contains: {?} ) + ------------------------------------------------------------------------------- Template test case method with test types specified inside std::tuple - MyTypes - 0 @@ -12774,6 +12874,22 @@ Misc.tests.cpp:: PASSED: with expansion: 15 >= 15 +------------------------------------------------------------------------------- +Test case with identical tags keeps just one +------------------------------------------------------------------------------- +Tag.tests.cpp: +............................................................................... + +Tag.tests.cpp:: PASSED: + REQUIRE( testCase.tags.size() == 1 ) +with expansion: + 1 == 1 + +Tag.tests.cpp:: PASSED: + REQUIRE( testCase.tags[0] == Tag( "tag1" ) ) +with expansion: + {?} == {?} + ------------------------------------------------------------------------------- Test case with one argument ------------------------------------------------------------------------------- @@ -17424,6 +17540,6 @@ Misc.tests.cpp: Misc.tests.cpp:: PASSED: =============================================================================== -test cases: 379 | 286 passed | 86 failed | 7 failed as expected -assertions: 2186 | 2013 passed | 146 failed | 27 failed as expected +test cases: 384 | 291 passed | 86 failed | 7 failed as expected +assertions: 2200 | 2027 passed | 146 failed | 27 failed as expected diff --git a/tests/SelfTest/Baselines/junit.sw.approved.txt b/tests/SelfTest/Baselines/junit.sw.approved.txt index 3181ebbd..a82176bd 100644 --- a/tests/SelfTest/Baselines/junit.sw.approved.txt +++ b/tests/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -451,6 +451,7 @@ Exception.tests.cpp: + FAILED: @@ -1068,12 +1069,14 @@ Message.tests.cpp: + + @@ -1273,6 +1276,7 @@ Misc.tests.cpp: + @@ -1331,6 +1335,7 @@ Misc.tests.cpp: + diff --git a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt index 0762507d..72c2e692 100644 --- a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt +++ b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt @@ -241,12 +241,19 @@ + + + + + + + diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt index 746f2599..e3d75dd8 100644 --- a/tests/SelfTest/Baselines/tap.sw.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.approved.txt @@ -976,6 +976,8 @@ ok {test-number} - enumInfo->lookup(0) == "Value1" for: Value1 == "Value1" ok {test-number} - enumInfo->lookup(1) == "Value2" for: Value2 == "Value2" # Directly creating an EnumInfo ok {test-number} - enumInfo->lookup(3) == "{** unexpected enum value **}" for: {** unexpected enum value **} == "{** unexpected enum value **}" +# Empty tag is not allowed +ok {test-number} - Catch::TestCaseInfo( "", { "fake test name", "[]" }, dummySourceLineInfo ) # EndsWith string matcher not ok {test-number} - testStringForMatching(), EndsWith( "Substring" ) for: "this string contains 'abc' as a substring" ends with: "Substring" # EndsWith string matcher @@ -2328,6 +2330,12 @@ ok {test-number} - !(spec.matches(*fakeTestCase("only foo", "[foo]"))) for: !fal ok {test-number} - !(spec.matches(*fakeTestCase("only hidden", "[.]"))) for: !false # Parse test names and tags ok {test-number} - spec.matches(*fakeTestCase("neither foo nor hidden", "[bar]")) for: true +# Parsed tags are matched case insensitive +ok {test-number} - spec.hasFilters() for: true +# Parsed tags are matched case insensitive +ok {test-number} - spec.getInvalidSpecs().empty() for: true +# Parsed tags are matched case insensitive +ok {test-number} - spec.matches( testCase ) for: true # Parsing sharding-related cli flags ok {test-number} - cli.parse({ "test", "--shard-count=8" }) for: {?} # Parsing sharding-related cli flags @@ -2352,6 +2360,18 @@ ok {test-number} - result.errorMessage(), ContainsSubstring("Shard index must be ok {test-number} - cli.parse({ "test", "--shard-index=0" }) for: {?} # Parsing sharding-related cli flags ok {test-number} - config.shardIndex == 0 for: 0 == 0 +# Parsing tags with non-alphabetical characters is pass-through +ok {test-number} - spec.hasFilters() for: true with 1 message: 'tagString := "[tag with spaces]"' +# Parsing tags with non-alphabetical characters is pass-through +ok {test-number} - spec.getInvalidSpecs().empty() for: true with 1 message: 'tagString := "[tag with spaces]"' +# Parsing tags with non-alphabetical characters is pass-through +ok {test-number} - spec.matches( testCase ) for: true with 1 message: 'tagString := "[tag with spaces]"' +# Parsing tags with non-alphabetical characters is pass-through +ok {test-number} - spec.hasFilters() for: true with 1 message: 'tagString := "[I said "good day" sir!]"' +# Parsing tags with non-alphabetical characters is pass-through +ok {test-number} - spec.getInvalidSpecs().empty() for: true with 1 message: 'tagString := "[I said "good day" sir!]"' +# Parsing tags with non-alphabetical characters is pass-through +ok {test-number} - spec.matches( testCase ) for: true with 1 message: 'tagString := "[I said "good day" sir!]"' # Parsing warnings ok {test-number} - cli.parse( { "test", "-w", "NoAssertions" } ) for: {?} # Parsing warnings @@ -2899,6 +2919,10 @@ ok {test-number} - registry.add( "[the @ is not at the start]", "", Catch::Sourc ok {test-number} - registry.add( "@no square bracket at start]", "", Catch::SourceLineInfo( "file", 3 ) ) # Tag alias can be registered against tag patterns ok {test-number} - registry.add( "[@no square bracket at end", "", Catch::SourceLineInfo( "file", 3 ) ) +# Tags with spaces and non-alphanumerical characters are accepted +ok {test-number} - testCase.tags.size() == 2 for: 2 == 2 +# Tags with spaces and non-alphanumerical characters are accepted +ok {test-number} - testCase.tags, VectorContains( Tag( "tag with spaces" ) ) && VectorContains( Tag( "I said \"good day\" sir!"_catch_sr ) ) for: { {?}, {?} } ( Contains: {?} and Contains: {?} ) # Template test case method with test types specified inside std::tuple - MyTypes - 0 ok {test-number} - Template_Fixture::m_a == 1 for: 1 == 1 # Template test case method with test types specified inside std::tuple - MyTypes - 1 @@ -3191,6 +3215,10 @@ ok {test-number} - v.capacity() >= V for: 15 >= 15 ok {test-number} - v.size() == V for: 15 == 15 # TemplateTestSig: vectors can be sized and resized - std::string,15 ok {test-number} - v.capacity() >= V for: 15 >= 15 +# Test case with identical tags keeps just one +ok {test-number} - testCase.tags.size() == 1 for: 1 == 1 +# Test case with identical tags keeps just one +ok {test-number} - testCase.tags[0] == Tag( "tag1" ) for: {?} == {?} # Test case with one argument ok {test-number} - with 1 message: 'no assertions' # Test enum bit values @@ -4374,5 +4402,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0 ok {test-number} - # xmlentitycheck ok {test-number} - -1..2186 +1..2200 diff --git a/tests/SelfTest/Baselines/teamcity.sw.approved.txt b/tests/SelfTest/Baselines/teamcity.sw.approved.txt index cadec0c4..4f2193fd 100644 --- a/tests/SelfTest/Baselines/teamcity.sw.approved.txt +++ b/tests/SelfTest/Baselines/teamcity.sw.approved.txt @@ -294,6 +294,8 @@ Exception.tests.cpp:|nunexpected exception with message:|n "custom ##teamcity[testFinished name='Default scale is invisible to comparison' duration="{duration}"] ##teamcity[testStarted name='Directly creating an EnumInfo'] ##teamcity[testFinished name='Directly creating an EnumInfo' duration="{duration}"] +##teamcity[testStarted name='Empty tag is not allowed'] +##teamcity[testFinished name='Empty tag is not allowed' duration="{duration}"] ##teamcity[testStarted name='EndsWith string matcher'] Matchers.tests.cpp:|nexpression failed|n CHECK_THAT( testStringForMatching(), EndsWith( "Substring" ) )|nwith expansion:|n "this string contains |'abc|' as a substring" ends with: "Substring"|n'] Matchers.tests.cpp:|nexpression failed|n CHECK_THAT( testStringForMatching(), EndsWith( "this", Catch::CaseSensitive::No ) )|nwith expansion:|n "this string contains |'abc|' as a substring" ends with: "this" (case insensitive)|n'] @@ -465,8 +467,12 @@ Message.tests.cpp:|nexplicit failure with message:|n "Message from ##teamcity[testFinished name='Overloaded comma or address-of operators are not used' duration="{duration}"] ##teamcity[testStarted name='Parse test names and tags'] ##teamcity[testFinished name='Parse test names and tags' duration="{duration}"] +##teamcity[testStarted name='Parsed tags are matched case insensitive'] +##teamcity[testFinished name='Parsed tags are matched case insensitive' duration="{duration}"] ##teamcity[testStarted name='Parsing sharding-related cli flags'] ##teamcity[testFinished name='Parsing sharding-related cli flags' duration="{duration}"] +##teamcity[testStarted name='Parsing tags with non-alphabetical characters is pass-through'] +##teamcity[testFinished name='Parsing tags with non-alphabetical characters is pass-through' duration="{duration}"] ##teamcity[testStarted name='Parsing warnings'] ##teamcity[testFinished name='Parsing warnings' duration="{duration}"] ##teamcity[testStarted name='Pointers can be compared to null'] @@ -553,6 +559,8 @@ Misc.tests.cpp:|nexpression failed|n CHECK( s1 == s2 )|nwith expan ##teamcity[testFinished name='Tabs and newlines show in output' duration="{duration}"] ##teamcity[testStarted name='Tag alias can be registered against tag patterns'] ##teamcity[testFinished name='Tag alias can be registered against tag patterns' duration="{duration}"] +##teamcity[testStarted name='Tags with spaces and non-alphanumerical characters are accepted'] +##teamcity[testFinished name='Tags with spaces and non-alphanumerical characters are accepted' duration="{duration}"] ##teamcity[testStarted name='Template test case method with test types specified inside std::tuple - MyTypes - 0'] ##teamcity[testFinished name='Template test case method with test types specified inside std::tuple - MyTypes - 0' duration="{duration}"] ##teamcity[testStarted name='Template test case method with test types specified inside std::tuple - MyTypes - 1'] @@ -589,6 +597,8 @@ Misc.tests.cpp:|nexpression failed|n CHECK( s1 == s2 )|nwith expan ##teamcity[testFinished name='TemplateTestSig: vectors can be sized and resized - int,5' duration="{duration}"] ##teamcity[testStarted name='TemplateTestSig: vectors can be sized and resized - std::string,15'] ##teamcity[testFinished name='TemplateTestSig: vectors can be sized and resized - std::string,15' duration="{duration}"] +##teamcity[testStarted name='Test case with identical tags keeps just one'] +##teamcity[testFinished name='Test case with identical tags keeps just one' duration="{duration}"] ##teamcity[testStarted name='Test case with one argument'] ##teamcity[testFinished name='Test case with one argument' duration="{duration}"] ##teamcity[testStarted name='Test enum bit values'] diff --git a/tests/SelfTest/Baselines/xml.sw.approved.txt b/tests/SelfTest/Baselines/xml.sw.approved.txt index b9bb761e..2551e03b 100644 --- a/tests/SelfTest/Baselines/xml.sw.approved.txt +++ b/tests/SelfTest/Baselines/xml.sw.approved.txt @@ -4306,6 +4306,17 @@ Nor would this + + + + Catch::TestCaseInfo( "", { "fake test name", "[]" }, dummySourceLineInfo ) + + + Catch::TestCaseInfo( "", { "fake test name", "[]" }, dummySourceLineInfo ) + + + + @@ -10700,6 +10711,33 @@ Nor would this + + + + spec.hasFilters() + + + true + + + + + spec.getInvalidSpecs().empty() + + + true + + + + + spec.matches( testCase ) + + + true + + + +
@@ -10817,6 +10855,75 @@ Nor would this
+ + + tagString := "[tag with spaces]" + + + + spec.hasFilters() + + + true + + + + tagString := "[tag with spaces]" + + + + spec.getInvalidSpecs().empty() + + + true + + + + tagString := "[tag with spaces]" + + + + spec.matches( testCase ) + + + true + + + + tagString := "[I said "good day" sir!]" + + + + spec.hasFilters() + + + true + + + + tagString := "[I said "good day" sir!]" + + + + spec.getInvalidSpecs().empty() + + + true + + + + tagString := "[I said "good day" sir!]" + + + + spec.matches( testCase ) + + + true + + + +
@@ -13640,6 +13747,25 @@ Message from section two
+ + + + testCase.tags.size() == 2 + + + 2 == 2 + + + + + testCase.tags, VectorContains( Tag( "tag with spaces" ) ) && VectorContains( Tag( "I said \"good day\" sir!"_catch_sr ) ) + + + { {?}, {?} } ( Contains: {?} and Contains: {?} ) + + + + @@ -14982,6 +15108,25 @@ Message from section two + + + + testCase.tags.size() == 1 + + + 1 == 1 + + + + + testCase.tags[0] == Tag( "tag1" ) + + + {?} == {?} + + + + @@ -20428,6 +20573,6 @@ loose text artifact
- - + + diff --git a/tests/SelfTest/IntrospectiveTests/Tag.tests.cpp b/tests/SelfTest/IntrospectiveTests/Tag.tests.cpp index 468a6792..b8d751cb 100644 --- a/tests/SelfTest/IntrospectiveTests/Tag.tests.cpp +++ b/tests/SelfTest/IntrospectiveTests/Tag.tests.cpp @@ -40,7 +40,7 @@ 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; +static constexpr Catch::SourceLineInfo dummySourceLineInfo = CATCH_INTERNAL_LINEINFO; TEST_CASE("shortened hide tags are split apart", "[tags]") { using Catch::StringRef; @@ -66,3 +66,36 @@ TEST_CASE( "empty tags are not allowed", "[tags]" ) { Catch::TestCaseInfo("", { "test with an empty tag", "[]" }, dummySourceLineInfo) ); } + +TEST_CASE( "Tags with spaces and non-alphanumerical characters are accepted", + "[tags]" ) { + using Catch::Tag; + using Catch::Matchers::VectorContains; + + Catch::TestCaseInfo testCase( + "", + { "fake test name", "[tag with spaces][I said \"good day\" sir!]" }, + dummySourceLineInfo ); + + REQUIRE( testCase.tags.size() == 2 ); + REQUIRE_THAT( testCase.tags, + VectorContains( Tag( "tag with spaces" ) ) && + VectorContains( Tag( "I said \"good day\" sir!"_catch_sr ) ) ); +} + +TEST_CASE( "Test case with identical tags keeps just one", "[tags]" ) { + using Catch::Tag; + + Catch::TestCaseInfo testCase( + "", + { "fake test name", "[TaG1][tAg1][TAG1][tag1]" }, + dummySourceLineInfo ); + + REQUIRE( testCase.tags.size() == 1 ); + REQUIRE( testCase.tags[0] == Tag( "tag1" ) ); +} + +TEST_CASE( "Empty tag is not allowed" ) { + REQUIRE_THROWS( Catch::TestCaseInfo( + "", { "fake test name", "[]" }, dummySourceLineInfo ) ); +} diff --git a/tests/SelfTest/IntrospectiveTests/TestSpecParser.tests.cpp b/tests/SelfTest/IntrospectiveTests/TestSpecParser.tests.cpp new file mode 100644 index 00000000..c8ac77b2 --- /dev/null +++ b/tests/SelfTest/IntrospectiveTests/TestSpecParser.tests.cpp @@ -0,0 +1,55 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +#include +#include +#include +#include +#include + +namespace { + static constexpr Catch::SourceLineInfo dummySourceLineInfo = CATCH_INTERNAL_LINEINFO; + + static Catch::TestSpec parseAndCreateSpec(std::string const& str) { + Catch::TagAliasRegistry registry; + Catch::TestSpecParser parser( registry ); + + parser.parse( str ); + auto spec = parser.testSpec(); + REQUIRE( spec.hasFilters() ); + REQUIRE( spec.getInvalidSpecs().empty()); + + return spec; + } + +} + +TEST_CASE( "Parsing tags with non-alphabetical characters is pass-through", + "[test-spec][test-spec-parser]" ) { + auto const& tagString = GENERATE( as{}, + "[tag with spaces]", + "[I said \"good day\" sir!]" ); + CAPTURE(tagString); + + auto spec = parseAndCreateSpec( tagString ); + + Catch::TestCaseInfo testCase( + "", { "fake test name", tagString }, dummySourceLineInfo ); + + REQUIRE( spec.matches( testCase ) ); +} + +TEST_CASE("Parsed tags are matched case insensitive", + "[test-spec][test-spec-parser]") { + auto spec = parseAndCreateSpec( "[CASED tag]" ); + + Catch::TestCaseInfo testCase( + "", { "fake test name", "[cased TAG]" }, dummySourceLineInfo ); + + REQUIRE( spec.matches( testCase ) ); +}