From 37cbf4a4fe7a2963f8ae6d6fe998f8ac9360cbc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Fri, 17 Apr 2020 21:16:18 +0200 Subject: [PATCH] Add more tests for test spec parser Originally the tests were from #1912, but as it turned out, the issue was somewhere else. Still, the inputs provided were interesting, so they are now part of our test suite. --- .../Baselines/compact.sw.approved.txt | 4 ++ .../Baselines/console.std.approved.txt | 4 +- .../Baselines/console.sw.approved.txt | 38 +++++++++++++++- .../Baselines/console.swa4.approved.txt | 38 +++++++++++++++- .../SelfTest/Baselines/junit.sw.approved.txt | 4 +- .../Baselines/sonarqube.sw.approved.txt | 2 + .../SelfTest/Baselines/xml.sw.approved.txt | 45 ++++++++++++++++++- .../IntrospectiveTests/CmdLine.tests.cpp | 18 ++++++++ 8 files changed, 144 insertions(+), 9 deletions(-) diff --git a/projects/SelfTest/Baselines/compact.sw.approved.txt b/projects/SelfTest/Baselines/compact.sw.approved.txt index 280f697a..41d38556 100644 --- a/projects/SelfTest/Baselines/compact.sw.approved.txt +++ b/projects/SelfTest/Baselines/compact.sw.approved.txt @@ -26,6 +26,10 @@ Compilation.tests.cpp:: passed: std::is_same, TypeLis CmdLine.tests.cpp:: passed: spec.matches(fakeTestCase("spec . char")) for: true CmdLine.tests.cpp:: passed: spec.matches(fakeTestCase("spec , char")) for: true CmdLine.tests.cpp:: passed: !(spec.matches(fakeTestCase(R"(spec \, char)"))) for: !false +CmdLine.tests.cpp:: passed: spec.matches(fakeTestCase(R"(spec {a} char)")) for: true +CmdLine.tests.cpp:: passed: spec.matches(fakeTestCase(R"(spec [a] char)")) for: true +CmdLine.tests.cpp:: passed: !(spec.matches(fakeTestCase("differs but has similar tag", "[a]"))) for: !false +CmdLine.tests.cpp:: passed: spec.matches(fakeTestCase(R"(spec \ char)")) for: true Exception.tests.cpp:: failed: unexpected exception with message: 'answer := 42' with 1 message: 'expected exception' Exception.tests.cpp:: failed: unexpected exception with message: 'answer := 42'; expression was: thisThrows() with 1 message: 'expected exception' Exception.tests.cpp:: passed: thisThrows() with 1 message: 'answer := 42' diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index 6b29a98c..8e11339e 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -1380,6 +1380,6 @@ due to unexpected exception with message: Why would you throw a std::string? =============================================================================== -test cases: 308 | 234 passed | 70 failed | 4 failed as expected -assertions: 1688 | 1536 passed | 131 failed | 21 failed as expected +test cases: 309 | 235 passed | 70 failed | 4 failed as expected +assertions: 1692 | 1540 passed | 131 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index fcb7a802..ae96fe75 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -209,6 +209,40 @@ CmdLine.tests.cpp:: PASSED: with expansion: !false +------------------------------------------------------------------------------- +#1912 -- test spec parser handles escaping + Various parentheses +------------------------------------------------------------------------------- +CmdLine.tests.cpp: +............................................................................... + +CmdLine.tests.cpp:: PASSED: + REQUIRE( spec.matches(fakeTestCase(R"(spec {a} char)")) ) +with expansion: + true + +CmdLine.tests.cpp:: PASSED: + REQUIRE( spec.matches(fakeTestCase(R"(spec [a] char)")) ) +with expansion: + true + +CmdLine.tests.cpp:: PASSED: + REQUIRE_FALSE( spec.matches(fakeTestCase("differs but has similar tag", "[a]")) ) +with expansion: + !false + +------------------------------------------------------------------------------- +#1912 -- test spec parser handles escaping + backslash in test name +------------------------------------------------------------------------------- +CmdLine.tests.cpp: +............................................................................... + +CmdLine.tests.cpp:: PASSED: + REQUIRE( spec.matches(fakeTestCase(R"(spec \ char)")) ) +with expansion: + true + ------------------------------------------------------------------------------- #748 - captures with unexpected exceptions outside assertions @@ -13488,6 +13522,6 @@ Misc.tests.cpp: Misc.tests.cpp:: PASSED: =============================================================================== -test cases: 308 | 218 passed | 86 failed | 4 failed as expected -assertions: 1705 | 1536 passed | 148 failed | 21 failed as expected +test cases: 309 | 219 passed | 86 failed | 4 failed as expected +assertions: 1709 | 1540 passed | 148 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/console.swa4.approved.txt b/projects/SelfTest/Baselines/console.swa4.approved.txt index e32fd88f..4a5b4864 100644 --- a/projects/SelfTest/Baselines/console.swa4.approved.txt +++ b/projects/SelfTest/Baselines/console.swa4.approved.txt @@ -209,6 +209,40 @@ CmdLine.tests.cpp:: PASSED: with expansion: !false +------------------------------------------------------------------------------- +#1912 -- test spec parser handles escaping + Various parentheses +------------------------------------------------------------------------------- +CmdLine.tests.cpp: +............................................................................... + +CmdLine.tests.cpp:: PASSED: + REQUIRE( spec.matches(fakeTestCase(R"(spec {a} char)")) ) +with expansion: + true + +CmdLine.tests.cpp:: PASSED: + REQUIRE( spec.matches(fakeTestCase(R"(spec [a] char)")) ) +with expansion: + true + +CmdLine.tests.cpp:: PASSED: + REQUIRE_FALSE( spec.matches(fakeTestCase("differs but has similar tag", "[a]")) ) +with expansion: + !false + +------------------------------------------------------------------------------- +#1912 -- test spec parser handles escaping + backslash in test name +------------------------------------------------------------------------------- +CmdLine.tests.cpp: +............................................................................... + +CmdLine.tests.cpp:: PASSED: + REQUIRE( spec.matches(fakeTestCase(R"(spec \ char)")) ) +with expansion: + true + ------------------------------------------------------------------------------- #748 - captures with unexpected exceptions outside assertions @@ -389,6 +423,6 @@ Condition.tests.cpp:: FAILED: CHECK( true != true ) =============================================================================== -test cases: 20 | 15 passed | 3 failed | 2 failed as expected -assertions: 45 | 38 passed | 4 failed | 3 failed as expected +test cases: 21 | 16 passed | 3 failed | 2 failed as expected +assertions: 49 | 42 passed | 4 failed | 3 failed as expected diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index 76284a2f..d47ca8ac 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -31,6 +31,8 @@ Nor would this + + FAILED: diff --git a/projects/SelfTest/Baselines/sonarqube.sw.approved.txt b/projects/SelfTest/Baselines/sonarqube.sw.approved.txt index 72fdd780..59e4512f 100644 --- a/projects/SelfTest/Baselines/sonarqube.sw.approved.txt +++ b/projects/SelfTest/Baselines/sonarqube.sw.approved.txt @@ -3,6 +3,8 @@ > + + diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index 807a946e..3f610208 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -223,6 +223,47 @@ Nor would this + +
+ + + spec.matches(fakeTestCase(R"(spec {a} char)")) + + + true + + + + + spec.matches(fakeTestCase(R"(spec [a] char)")) + + + true + + + + + !(spec.matches(fakeTestCase("differs but has similar tag", "[a]"))) + + + !false + + + +
+
+ + + spec.matches(fakeTestCase(R"(spec \ char)")) + + + true + + + +
+ +
@@ -16139,7 +16180,7 @@ loose text artifact
- + - + diff --git a/projects/SelfTest/IntrospectiveTests/CmdLine.tests.cpp b/projects/SelfTest/IntrospectiveTests/CmdLine.tests.cpp index 0d8232e0..48895717 100644 --- a/projects/SelfTest/IntrospectiveTests/CmdLine.tests.cpp +++ b/projects/SelfTest/IntrospectiveTests/CmdLine.tests.cpp @@ -303,6 +303,24 @@ TEST_CASE("#1905 -- test spec parser properly clears internal state between comp REQUIRE_FALSE(spec.matches(fakeTestCase(R"(spec \, char)"))); } +TEST_CASE("#1912 -- test spec parser handles escaping", "[command-line][test-spec]") { + using Catch::parseTestSpec; + using Catch::TestSpec; + + SECTION("Various parentheses") { + TestSpec spec = parseTestSpec(R"(spec {a} char,spec \[a] char)"); + + REQUIRE(spec.matches(fakeTestCase(R"(spec {a} char)"))); + REQUIRE(spec.matches(fakeTestCase(R"(spec [a] char)"))); + REQUIRE_FALSE(spec.matches(fakeTestCase("differs but has similar tag", "[a]"))); + } + SECTION("backslash in test name") { + TestSpec spec = parseTestSpec(R"(spec \\ char)"); + + REQUIRE(spec.matches(fakeTestCase(R"(spec \ char)"))); + } +} + TEST_CASE( "Process can be configured on command line", "[config][command-line]" ) { #ifndef CATCH_CONFIG_DISABLE_MATCHERS