Error out reporter registration for reporter names with '::'

This commit is contained in:
Martin Hořeňovský 2022-01-09 19:01:14 +01:00
parent 875299cff0
commit b6ff2c3dda
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
19 changed files with 103 additions and 14 deletions

View File

@ -17,6 +17,7 @@
#include <catch2/reporters/catch_reporter_teamcity.hpp>
#include <catch2/reporters/catch_reporter_xml.hpp>
#include <catch2/internal/catch_move_and_forward.hpp>
#include <catch2/internal/catch_enforce.hpp>
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 ) {

View File

@ -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

View File

@ -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

View File

@ -1383,6 +1383,7 @@ Decomposition.tests.cpp:<line number>: failed: truthy(false) for: Hey, its truth
Matchers.tests.cpp:<line number>: 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:<line number>: 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:<line number>: 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:<line number>: passed: registry.registerReporter( "with::doublecolons", Catch::Detail::make_unique<TestReporterFactory>() ), "'::' 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:<line number>: passed: actual, !UnorderedEquals( expected ) for: { 'a', 'b' } not UnorderedEquals: { 'c', 'b' }
Reporters.tests.cpp:<line number>: passed: !(factories.empty()) for: !false
Reporters.tests.cpp:<line number>: passed: listingString, ContainsSubstring("fakeTag"s) for: "All available tags:

View File

@ -1381,6 +1381,7 @@ Decomposition.tests.cpp:<line number>: failed: truthy(false) for: Hey, its truth
Matchers.tests.cpp:<line number>: 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:<line number>: 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:<line number>: 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:<line number>: passed: registry.registerReporter( "with::doublecolons", Catch::Detail::make_unique<TestReporterFactory>() ), "'::' 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:<line number>: passed: actual, !UnorderedEquals( expected ) for: { 'a', 'b' } not UnorderedEquals: { 'c', 'b' }
Reporters.tests.cpp:<line number>: passed: !(factories.empty()) for: !false
Reporters.tests.cpp:<line number>: passed: listingString, ContainsSubstring("fakeTag"s) for: "All available tags:

View File

@ -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

View File

@ -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:<line number>
...............................................................................
Reporters.tests.cpp:<line number>: PASSED:
REQUIRE_THROWS_WITH( registry.registerReporter( "with::doublecolons", Catch::Detail::make_unique<TestReporterFactory>() ), "'::' 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:<line number>
Misc.tests.cpp:<line number>: 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

View File

@ -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:<line number>
...............................................................................
Reporters.tests.cpp:<line number>: PASSED:
REQUIRE_THROWS_WITH( registry.registerReporter( "with::doublecolons", Catch::Detail::make_unique<TestReporterFactory>() ), "'::' 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:<line number>
Misc.tests.cpp:<line number>: 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

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuitesloose text artifact
>
<testsuite name="<exe-name>" errors="17" failures="126" tests="2226" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<testsuite name="<exe-name>" errors="17" failures="126" tests="2227" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<properties>
<property name="random-seed" value="1"/>
<property name="filters" value="~[!nonportable]~[!benchmark]~[approvals] *"/>
@ -1166,6 +1166,7 @@ with expansion:
Matchers.tests.cpp:<line number>
</failure>
</testcase>
<testcase classname="<exe-name>.global" name="Registering reporter with '::' in name fails" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Regression test #1" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Reporter's write listings to provided stream" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Reporter's write listings to provided stream/Automake reporter lists tags" time="{duration}" status="run"/>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="<exe-name>" errors="17" failures="126" tests="2226" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<testsuite name="<exe-name>" errors="17" failures="126" tests="2227" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<properties>
<property name="random-seed" value="1"/>
<property name="filters" value="~[!nonportable]~[!benchmark]~[approvals] *"/>
@ -1165,6 +1165,7 @@ with expansion:
Matchers.tests.cpp:<line number>
</failure>
</testcase>
<testcase classname="<exe-name>.global" name="Registering reporter with '::' in name fails" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Regression test #1" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Reporter's write listings to provided stream" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Reporter's write listings to provided stream/Automake reporter lists tags" time="{duration}" status="run"/>

View File

@ -185,6 +185,7 @@
<testCase name="Multireporter updates ReporterPreferences properly" duration="{duration}"/>
<testCase name="Multireporter updates ReporterPreferences properly/Adding listeners" duration="{duration}"/>
<testCase name="Multireporter updates ReporterPreferences properly/Adding reporters" duration="{duration}"/>
<testCase name="Registering reporter with '::' in name fails" duration="{duration}"/>
<testCase name="Reporter's write listings to provided stream" duration="{duration}"/>
<testCase name="Reporter's write listings to provided stream/Automake reporter lists tags" duration="{duration}"/>
<testCase name="Reporter's write listings to provided stream/Automake reporter lists reporters" duration="{duration}"/>

View File

@ -184,6 +184,7 @@
<testCase name="Multireporter updates ReporterPreferences properly" duration="{duration}"/>
<testCase name="Multireporter updates ReporterPreferences properly/Adding listeners" duration="{duration}"/>
<testCase name="Multireporter updates ReporterPreferences properly/Adding reporters" duration="{duration}"/>
<testCase name="Registering reporter with '::' in name fails" duration="{duration}"/>
<testCase name="Reporter's write listings to provided stream" duration="{duration}"/>
<testCase name="Reporter's write listings to provided stream/Automake reporter lists tags" duration="{duration}"/>
<testCase name="Reporter's write listings to provided stream/Automake reporter lists reporters" duration="{duration}"/>

View File

@ -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<TestReporterFactory>() ), "'::' 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

View File

@ -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<TestReporterFactory>() ), "'::' 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

View File

@ -507,6 +507,8 @@ Matchers.tests.cpp:<line number>|nexpression failed|n CHECK_THAT( testStringFor
Matchers.tests.cpp:<line number>|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:<line number>|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']

View File

@ -507,6 +507,8 @@ Matchers.tests.cpp:<line number>|nexpression failed|n CHECK_THAT( testStringFor
Matchers.tests.cpp:<line number>|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:<line number>|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']

View File

@ -12416,6 +12416,17 @@ Nor would this
</Expression>
<OverallResult success="false"/>
</TestCase>
<TestCase name="Registering reporter with '::' in name fails" tags="[registration][reporters]" filename="tests/<exe-name>/IntrospectiveTests/Reporters.tests.cpp" >
<Expression success="true" type="REQUIRE_THROWS_WITH" filename="tests/<exe-name>/IntrospectiveTests/Reporters.tests.cpp" >
<Original>
registry.registerReporter( "with::doublecolons", Catch::Detail::make_unique&lt;TestReporterFactory>() ), "'::' is not allowed in reporter name: 'with::doublecolons'"
</Original>
<Expanded>
"'::' is not allowed in reporter name: 'with::doublecolons'" equals: "'::' is not allowed in reporter name: 'with::doublecolons'"
</Expanded>
</Expression>
<OverallResult success="true"/>
</TestCase>
<TestCase name="Regression test #1" tags="[matchers][vector]" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
<Expression success="true" type="CHECK_THAT" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
<Original>
@ -20884,6 +20895,6 @@ loose text artifact
</Section>
<OverallResult success="true"/>
</TestCase>
<OverallResults successes="2056" failures="143" expectedFailures="27"/>
<OverallResultsCases successes="292" failures="83" expectedFailures="7"/>
<OverallResults successes="2057" failures="143" expectedFailures="27"/>
<OverallResultsCases successes="293" failures="83" expectedFailures="7"/>
</Catch2TestRun>

View File

@ -12416,6 +12416,17 @@ Nor would this
</Expression>
<OverallResult success="false"/>
</TestCase>
<TestCase name="Registering reporter with '::' in name fails" tags="[registration][reporters]" filename="tests/<exe-name>/IntrospectiveTests/Reporters.tests.cpp" >
<Expression success="true" type="REQUIRE_THROWS_WITH" filename="tests/<exe-name>/IntrospectiveTests/Reporters.tests.cpp" >
<Original>
registry.registerReporter( "with::doublecolons", Catch::Detail::make_unique&lt;TestReporterFactory>() ), "'::' is not allowed in reporter name: 'with::doublecolons'"
</Original>
<Expanded>
"'::' is not allowed in reporter name: 'with::doublecolons'" equals: "'::' is not allowed in reporter name: 'with::doublecolons'"
</Expanded>
</Expression>
<OverallResult success="true"/>
</TestCase>
<TestCase name="Regression test #1" tags="[matchers][vector]" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
<Expression success="true" type="CHECK_THAT" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" >
<Original>
@ -20883,6 +20894,6 @@ There is no extra whitespace here
</Section>
<OverallResult success="true"/>
</TestCase>
<OverallResults successes="2056" failures="143" expectedFailures="27"/>
<OverallResultsCases successes="292" failures="83" expectedFailures="7"/>
<OverallResults successes="2057" failures="143" expectedFailures="27"/>
<OverallResultsCases successes="293" failures="83" expectedFailures="7"/>
</Catch2TestRun>

View File

@ -13,7 +13,9 @@
#include <catch2/interfaces/catch_interfaces_reporter.hpp>
#include <catch2/interfaces/catch_interfaces_reporter_factory.hpp>
#include <catch2/interfaces/catch_interfaces_reporter_registry.hpp>
#include <catch2/internal/catch_enforce.hpp>
#include <catch2/internal/catch_list.hpp>
#include <catch2/internal/catch_reporter_registry.hpp>
#include <catch2/matchers/catch_matchers_string.hpp>
#include <catch2/reporters/catch_reporter_helpers.hpp>
#include <catch2/reporters/catch_reporter_event_listener.hpp>
@ -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<TestReporterFactory>() ),
"'::' is not allowed in reporter name: 'with::doublecolons'" );
}