diff --git a/src/catch2/internal/catch_reporter_registry.cpp b/src/catch2/internal/catch_reporter_registry.cpp index 26a328f8..67687d1b 100644 --- a/src/catch2/internal/catch_reporter_registry.cpp +++ b/src/catch2/internal/catch_reporter_registry.cpp @@ -17,6 +17,7 @@ #include #include #include +#include namespace Catch { @@ -44,6 +45,8 @@ namespace Catch { } void ReporterRegistry::registerReporter( std::string const& name, IReporterFactoryPtr factory ) { + CATCH_ENFORCE( name.find( "::" ) == name.npos, + "'::' is not allowed in reporter name: '" + name + '\'' ); m_factories.emplace(name, CATCH_MOVE(factory)); } void ReporterRegistry::registerListener( IReporterFactoryPtr factory ) { diff --git a/tests/SelfTest/Baselines/automake.sw.approved.txt b/tests/SelfTest/Baselines/automake.sw.approved.txt index 34a28749..1fff117c 100644 --- a/tests/SelfTest/Baselines/automake.sw.approved.txt +++ b/tests/SelfTest/Baselines/automake.sw.approved.txt @@ -199,6 +199,7 @@ Nor would this :test-result: PASS Range type with sentinel :test-result: FAIL Reconstruction should be based on stringification: #914 :test-result: FAIL Regex string matcher +:test-result: PASS Registering reporter with '::' in name fails :test-result: PASS Regression test #1 :test-result: PASS Reporter's write listings to provided stream :test-result: PASS Reproducer for #2309 - a very long description past 80 chars (default console width) with a late colon : blablabla diff --git a/tests/SelfTest/Baselines/automake.sw.multi.approved.txt b/tests/SelfTest/Baselines/automake.sw.multi.approved.txt index e45cec60..4b75ed64 100644 --- a/tests/SelfTest/Baselines/automake.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/automake.sw.multi.approved.txt @@ -197,6 +197,7 @@ :test-result: PASS Range type with sentinel :test-result: FAIL Reconstruction should be based on stringification: #914 :test-result: FAIL Regex string matcher +:test-result: PASS Registering reporter with '::' in name fails :test-result: PASS Regression test #1 :test-result: PASS Reporter's write listings to provided stream :test-result: PASS Reproducer for #2309 - a very long description past 80 chars (default console width) with a late colon : blablabla diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt index 0babaf7d..f921fc2d 100644 --- a/tests/SelfTest/Baselines/compact.sw.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.approved.txt @@ -1383,6 +1383,7 @@ Decomposition.tests.cpp:: failed: truthy(false) for: Hey, its truth Matchers.tests.cpp:: failed: testStringForMatching(), Matches( "this STRING contains 'abc' as a substring" ) for: "this string contains 'abc' as a substring" matches "this STRING contains 'abc' as a substring" case sensitively Matchers.tests.cpp:: failed: testStringForMatching(), Matches( "contains 'abc' as a substring" ) for: "this string contains 'abc' as a substring" matches "contains 'abc' as a substring" case sensitively Matchers.tests.cpp:: failed: testStringForMatching(), Matches( "this string contains 'abc' as a" ) for: "this string contains 'abc' as a substring" matches "this string contains 'abc' as a" case sensitively +Reporters.tests.cpp:: passed: registry.registerReporter( "with::doublecolons", Catch::Detail::make_unique() ), "'::' is not allowed in reporter name: 'with::doublecolons'" for: "'::' is not allowed in reporter name: 'with::doublecolons'" equals: "'::' is not allowed in reporter name: 'with::doublecolons'" Matchers.tests.cpp:: passed: actual, !UnorderedEquals( expected ) for: { 'a', 'b' } not UnorderedEquals: { 'c', 'b' } Reporters.tests.cpp:: passed: !(factories.empty()) for: !false Reporters.tests.cpp:: passed: listingString, ContainsSubstring("fakeTag"s) for: "All available tags: diff --git a/tests/SelfTest/Baselines/compact.sw.multi.approved.txt b/tests/SelfTest/Baselines/compact.sw.multi.approved.txt index 1966443b..ffd0932a 100644 --- a/tests/SelfTest/Baselines/compact.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.multi.approved.txt @@ -1381,6 +1381,7 @@ Decomposition.tests.cpp:: failed: truthy(false) for: Hey, its truth Matchers.tests.cpp:: failed: testStringForMatching(), Matches( "this STRING contains 'abc' as a substring" ) for: "this string contains 'abc' as a substring" matches "this STRING contains 'abc' as a substring" case sensitively Matchers.tests.cpp:: failed: testStringForMatching(), Matches( "contains 'abc' as a substring" ) for: "this string contains 'abc' as a substring" matches "contains 'abc' as a substring" case sensitively Matchers.tests.cpp:: failed: testStringForMatching(), Matches( "this string contains 'abc' as a" ) for: "this string contains 'abc' as a substring" matches "this string contains 'abc' as a" case sensitively +Reporters.tests.cpp:: passed: registry.registerReporter( "with::doublecolons", Catch::Detail::make_unique() ), "'::' is not allowed in reporter name: 'with::doublecolons'" for: "'::' is not allowed in reporter name: 'with::doublecolons'" equals: "'::' is not allowed in reporter name: 'with::doublecolons'" Matchers.tests.cpp:: passed: actual, !UnorderedEquals( expected ) for: { 'a', 'b' } not UnorderedEquals: { 'c', 'b' } Reporters.tests.cpp:: passed: !(factories.empty()) for: !false Reporters.tests.cpp:: passed: listingString, ContainsSubstring("fakeTag"s) for: "All available tags: diff --git a/tests/SelfTest/Baselines/console.std.approved.txt b/tests/SelfTest/Baselines/console.std.approved.txt index ac979989..ca299535 100644 --- a/tests/SelfTest/Baselines/console.std.approved.txt +++ b/tests/SelfTest/Baselines/console.std.approved.txt @@ -1395,6 +1395,6 @@ due to unexpected exception with message: Why would you throw a std::string? =============================================================================== -test cases: 382 | 306 passed | 69 failed | 7 failed as expected -assertions: 2211 | 2056 passed | 128 failed | 27 failed as expected +test cases: 383 | 307 passed | 69 failed | 7 failed as expected +assertions: 2212 | 2057 passed | 128 failed | 27 failed as expected diff --git a/tests/SelfTest/Baselines/console.sw.approved.txt b/tests/SelfTest/Baselines/console.sw.approved.txt index 5d733c77..11ee162e 100644 --- a/tests/SelfTest/Baselines/console.sw.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.approved.txt @@ -10176,6 +10176,18 @@ with expansion: "this string contains 'abc' as a substring" matches "this string contains 'abc' as a" case sensitively +------------------------------------------------------------------------------- +Registering reporter with '::' in name fails +------------------------------------------------------------------------------- +Reporters.tests.cpp: +............................................................................... + +Reporters.tests.cpp:: PASSED: + REQUIRE_THROWS_WITH( registry.registerReporter( "with::doublecolons", Catch::Detail::make_unique() ), "'::' is not allowed in reporter name: 'with::doublecolons'" ) +with expansion: + "'::' is not allowed in reporter name: 'with::doublecolons'" equals: "'::' is + not allowed in reporter name: 'with::doublecolons'" + ------------------------------------------------------------------------------- Regression test #1 ------------------------------------------------------------------------------- @@ -17772,6 +17784,6 @@ Misc.tests.cpp: Misc.tests.cpp:: PASSED: =============================================================================== -test cases: 382 | 292 passed | 83 failed | 7 failed as expected -assertions: 2226 | 2056 passed | 143 failed | 27 failed as expected +test cases: 383 | 293 passed | 83 failed | 7 failed as expected +assertions: 2227 | 2057 passed | 143 failed | 27 failed as expected diff --git a/tests/SelfTest/Baselines/console.sw.multi.approved.txt b/tests/SelfTest/Baselines/console.sw.multi.approved.txt index ad44370c..9155ad62 100644 --- a/tests/SelfTest/Baselines/console.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.multi.approved.txt @@ -10174,6 +10174,18 @@ with expansion: "this string contains 'abc' as a substring" matches "this string contains 'abc' as a" case sensitively +------------------------------------------------------------------------------- +Registering reporter with '::' in name fails +------------------------------------------------------------------------------- +Reporters.tests.cpp: +............................................................................... + +Reporters.tests.cpp:: PASSED: + REQUIRE_THROWS_WITH( registry.registerReporter( "with::doublecolons", Catch::Detail::make_unique() ), "'::' is not allowed in reporter name: 'with::doublecolons'" ) +with expansion: + "'::' is not allowed in reporter name: 'with::doublecolons'" equals: "'::' is + not allowed in reporter name: 'with::doublecolons'" + ------------------------------------------------------------------------------- Regression test #1 ------------------------------------------------------------------------------- @@ -17764,6 +17776,6 @@ Misc.tests.cpp: Misc.tests.cpp:: PASSED: =============================================================================== -test cases: 382 | 292 passed | 83 failed | 7 failed as expected -assertions: 2226 | 2056 passed | 143 failed | 27 failed as expected +test cases: 383 | 293 passed | 83 failed | 7 failed as expected +assertions: 2227 | 2057 passed | 143 failed | 27 failed as expected diff --git a/tests/SelfTest/Baselines/junit.sw.approved.txt b/tests/SelfTest/Baselines/junit.sw.approved.txt index e3398a6a..459b77ed 100644 --- a/tests/SelfTest/Baselines/junit.sw.approved.txt +++ b/tests/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -1166,6 +1166,7 @@ with expansion: Matchers.tests.cpp: + diff --git a/tests/SelfTest/Baselines/junit.sw.multi.approved.txt b/tests/SelfTest/Baselines/junit.sw.multi.approved.txt index b1ae7efd..8f8eccf2 100644 --- a/tests/SelfTest/Baselines/junit.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/junit.sw.multi.approved.txt @@ -1,6 +1,6 @@ - + @@ -1165,6 +1165,7 @@ with expansion: Matchers.tests.cpp: + diff --git a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt index 081ae969..e597f41a 100644 --- a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt +++ b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt @@ -185,6 +185,7 @@ + diff --git a/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt index cf9c15ce..9637e8a1 100644 --- a/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt @@ -184,6 +184,7 @@ + diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt index e49f387e..6306f579 100644 --- a/tests/SelfTest/Baselines/tap.sw.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.approved.txt @@ -2652,6 +2652,8 @@ not ok {test-number} - testStringForMatching(), Matches( "this STRING contains ' not ok {test-number} - testStringForMatching(), Matches( "contains 'abc' as a substring" ) for: "this string contains 'abc' as a substring" matches "contains 'abc' as a substring" case sensitively # Regex string matcher not ok {test-number} - testStringForMatching(), Matches( "this string contains 'abc' as a" ) for: "this string contains 'abc' as a substring" matches "this string contains 'abc' as a" case sensitively +# Registering reporter with '::' in name fails +ok {test-number} - registry.registerReporter( "with::doublecolons", Catch::Detail::make_unique() ), "'::' is not allowed in reporter name: 'with::doublecolons'" for: "'::' is not allowed in reporter name: 'with::doublecolons'" equals: "'::' is not allowed in reporter name: 'with::doublecolons'" # Regression test #1 ok {test-number} - actual, !UnorderedEquals( expected ) for: { 'a', 'b' } not UnorderedEquals: { 'c', 'b' } # Reporter's write listings to provided stream @@ -4454,5 +4456,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0 ok {test-number} - # xmlentitycheck ok {test-number} - -1..2226 +1..2227 diff --git a/tests/SelfTest/Baselines/tap.sw.multi.approved.txt b/tests/SelfTest/Baselines/tap.sw.multi.approved.txt index f8599833..c6b4a8bd 100644 --- a/tests/SelfTest/Baselines/tap.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.multi.approved.txt @@ -2650,6 +2650,8 @@ not ok {test-number} - testStringForMatching(), Matches( "this STRING contains ' not ok {test-number} - testStringForMatching(), Matches( "contains 'abc' as a substring" ) for: "this string contains 'abc' as a substring" matches "contains 'abc' as a substring" case sensitively # Regex string matcher not ok {test-number} - testStringForMatching(), Matches( "this string contains 'abc' as a" ) for: "this string contains 'abc' as a substring" matches "this string contains 'abc' as a" case sensitively +# Registering reporter with '::' in name fails +ok {test-number} - registry.registerReporter( "with::doublecolons", Catch::Detail::make_unique() ), "'::' is not allowed in reporter name: 'with::doublecolons'" for: "'::' is not allowed in reporter name: 'with::doublecolons'" equals: "'::' is not allowed in reporter name: 'with::doublecolons'" # Regression test #1 ok {test-number} - actual, !UnorderedEquals( expected ) for: { 'a', 'b' } not UnorderedEquals: { 'c', 'b' } # Reporter's write listings to provided stream @@ -4446,5 +4448,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0 ok {test-number} - # xmlentitycheck ok {test-number} - -1..2226 +1..2227 diff --git a/tests/SelfTest/Baselines/teamcity.sw.approved.txt b/tests/SelfTest/Baselines/teamcity.sw.approved.txt index d73f02ae..90e318f1 100644 --- a/tests/SelfTest/Baselines/teamcity.sw.approved.txt +++ b/tests/SelfTest/Baselines/teamcity.sw.approved.txt @@ -507,6 +507,8 @@ Matchers.tests.cpp:|nexpression failed|n CHECK_THAT( testStringFor Matchers.tests.cpp:|nexpression failed|n CHECK_THAT( testStringForMatching(), Matches( "contains |'abc|' as a substring" ) )|nwith expansion:|n "this string contains |'abc|' as a substring" matches "contains |'abc|' as a substring" case sensitively|n'] Matchers.tests.cpp:|nexpression failed|n CHECK_THAT( testStringForMatching(), Matches( "this string contains |'abc|' as a" ) )|nwith expansion:|n "this string contains |'abc|' as a substring" matches "this string contains |'abc|' as a" case sensitively|n'] ##teamcity[testFinished name='Regex string matcher' duration="{duration}"] +##teamcity[testStarted name='Registering reporter with |'::|' in name fails'] +##teamcity[testFinished name='Registering reporter with |'::|' in name fails' duration="{duration}"] ##teamcity[testStarted name='Regression test #1'] ##teamcity[testFinished name='Regression test #1' duration="{duration}"] ##teamcity[testStarted name='Reporter|'s write listings to provided stream'] diff --git a/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt b/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt index 3560775f..dc266f2f 100644 --- a/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt @@ -507,6 +507,8 @@ Matchers.tests.cpp:|nexpression failed|n CHECK_THAT( testStringFor Matchers.tests.cpp:|nexpression failed|n CHECK_THAT( testStringForMatching(), Matches( "contains |'abc|' as a substring" ) )|nwith expansion:|n "this string contains |'abc|' as a substring" matches "contains |'abc|' as a substring" case sensitively|n'] Matchers.tests.cpp:|nexpression failed|n CHECK_THAT( testStringForMatching(), Matches( "this string contains |'abc|' as a" ) )|nwith expansion:|n "this string contains |'abc|' as a substring" matches "this string contains |'abc|' as a" case sensitively|n'] ##teamcity[testFinished name='Regex string matcher' duration="{duration}"] +##teamcity[testStarted name='Registering reporter with |'::|' in name fails'] +##teamcity[testFinished name='Registering reporter with |'::|' in name fails' duration="{duration}"] ##teamcity[testStarted name='Regression test #1'] ##teamcity[testFinished name='Regression test #1' duration="{duration}"] ##teamcity[testStarted name='Reporter|'s write listings to provided stream'] diff --git a/tests/SelfTest/Baselines/xml.sw.approved.txt b/tests/SelfTest/Baselines/xml.sw.approved.txt index b7d5bb15..1305af19 100644 --- a/tests/SelfTest/Baselines/xml.sw.approved.txt +++ b/tests/SelfTest/Baselines/xml.sw.approved.txt @@ -12416,6 +12416,17 @@ Nor would this + + + + registry.registerReporter( "with::doublecolons", Catch::Detail::make_unique<TestReporterFactory>() ), "'::' is not allowed in reporter name: 'with::doublecolons'" + + + "'::' is not allowed in reporter name: 'with::doublecolons'" equals: "'::' is not allowed in reporter name: 'with::doublecolons'" + + + + @@ -20884,6 +20895,6 @@ loose text artifact - - + + diff --git a/tests/SelfTest/Baselines/xml.sw.multi.approved.txt b/tests/SelfTest/Baselines/xml.sw.multi.approved.txt index 9a70d37e..f03c7986 100644 --- a/tests/SelfTest/Baselines/xml.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/xml.sw.multi.approved.txt @@ -12416,6 +12416,17 @@ Nor would this + + + + registry.registerReporter( "with::doublecolons", Catch::Detail::make_unique<TestReporterFactory>() ), "'::' is not allowed in reporter name: 'with::doublecolons'" + + + "'::' is not allowed in reporter name: 'with::doublecolons'" equals: "'::' is not allowed in reporter name: 'with::doublecolons'" + + + + @@ -20883,6 +20894,6 @@ There is no extra whitespace here - - + + diff --git a/tests/SelfTest/IntrospectiveTests/Reporters.tests.cpp b/tests/SelfTest/IntrospectiveTests/Reporters.tests.cpp index 8bb04352..40ae0179 100644 --- a/tests/SelfTest/IntrospectiveTests/Reporters.tests.cpp +++ b/tests/SelfTest/IntrospectiveTests/Reporters.tests.cpp @@ -13,7 +13,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -260,3 +262,25 @@ TEST_CASE("Multireporter updates ReporterPreferences properly", REQUIRE( multiReporter.getPreferences().shouldReportAllAssertions == true ); } } + +namespace { + class TestReporterFactory : public Catch::IReporterFactory { + Catch::IStreamingReporterPtr create( Catch::ReporterConfig const& ) const override { + CATCH_INTERNAL_ERROR( + "This factory should never create a reporter" ); + } + std::string getDescription() const override { + return "Fake test factory"; + } + }; +} + +TEST_CASE("Registering reporter with '::' in name fails", + "[reporters][registration]") { + Catch::ReporterRegistry registry; + + REQUIRE_THROWS_WITH( registry.registerReporter( + "with::doublecolons", + Catch::Detail::make_unique() ), + "'::' is not allowed in reporter name: 'with::doublecolons'" ); +}