Add check for registering multiple reporters under same name

This commit is contained in:
Martin Hořeňovský 2022-05-15 09:54:27 +02:00
parent fc3d11b1d1
commit 33aeb603fe
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
2 changed files with 17 additions and 1 deletions

View File

@ -47,7 +47,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));
auto ret = m_factories.emplace(name, CATCH_MOVE(factory));
CATCH_ENFORCE( ret.second, "reporter using '" + name + "' as name was already registered" );
}
void ReporterRegistry::registerListener(
Detail::unique_ptr<EventListenerFactory> factory ) {

View File

@ -312,3 +312,18 @@ TEST_CASE("Registering reporter with '::' in name fails",
Catch::Detail::make_unique<TestReporterFactory>() ),
"'::' is not allowed in reporter name: 'with::doublecolons'" );
}
TEST_CASE("Registering multiple reporters with the same name fails",
"[reporters][registration][approvals]") {
Catch::ReporterRegistry registry;
registry.registerReporter(
"some-reporter-name",
Catch::Detail::make_unique<TestReporterFactory>() );
REQUIRE_THROWS_WITH(
registry.registerReporter(
"some-reporter-name",
Catch::Detail::make_unique<TestReporterFactory>() ),
"reporter using 'some-reporter-name' as name was already registered" );
}