2020-08-30 15:43:45 +02:00
|
|
|
|
|
|
|
|
// 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
|
2020-03-30 10:34:21 +02:00
|
|
|
#include <catch2/interfaces/catch_interfaces_registry_hub.hpp>
|
2012-08-06 08:33:15 +01:00
|
|
|
|
2020-03-30 10:34:21 +02:00
|
|
|
#include <catch2/internal/catch_context.hpp>
|
2020-06-04 11:53:13 +02:00
|
|
|
#include <catch2/internal/catch_enforce.hpp>
|
2020-03-30 10:34:21 +02:00
|
|
|
#include <catch2/internal/catch_test_case_registry_impl.hpp>
|
|
|
|
|
#include <catch2/internal/catch_reporter_registry.hpp>
|
|
|
|
|
#include <catch2/internal/catch_exception_translator_registry.hpp>
|
|
|
|
|
#include <catch2/internal/catch_tag_alias_registry.hpp>
|
|
|
|
|
#include <catch2/internal/catch_startup_exception_registry.hpp>
|
|
|
|
|
#include <catch2/internal/catch_singletons.hpp>
|
|
|
|
|
#include <catch2/internal/catch_enum_values_registry.hpp>
|
2020-07-29 14:30:19 +02:00
|
|
|
#include <catch2/catch_test_case_info.hpp>
|
2020-08-18 11:35:58 +02:00
|
|
|
#include <catch2/internal/catch_noncopyable.hpp>
|
2020-08-23 21:19:26 +02:00
|
|
|
#include <catch2/interfaces/catch_interfaces_reporter_factory.hpp>
|
2021-08-13 14:16:30 +02:00
|
|
|
#include <catch2/internal/catch_move_and_forward.hpp>
|
2012-08-06 08:33:15 +01:00
|
|
|
|
2012-08-06 20:16:53 +01:00
|
|
|
namespace Catch {
|
2012-08-06 08:33:15 +01:00
|
|
|
|
2012-08-06 20:16:53 +01:00
|
|
|
namespace {
|
2013-07-03 19:14:59 +01:00
|
|
|
|
2020-08-18 11:35:58 +02:00
|
|
|
class RegistryHub : public IRegistryHub,
|
|
|
|
|
public IMutableRegistryHub,
|
|
|
|
|
private Detail::NonCopyable {
|
2012-08-06 20:16:53 +01:00
|
|
|
|
2012-08-07 07:58:34 +01:00
|
|
|
public: // IRegistryHub
|
2017-09-07 16:51:33 +02:00
|
|
|
RegistryHub() = default;
|
2017-07-20 15:57:17 +01:00
|
|
|
IReporterRegistry const& getReporterRegistry() const override {
|
2012-08-06 20:16:53 +01:00
|
|
|
return m_reporterRegistry;
|
|
|
|
|
}
|
2017-07-20 15:57:17 +01:00
|
|
|
ITestCaseRegistry const& getTestCaseRegistry() const override {
|
2012-08-06 20:16:53 +01:00
|
|
|
return m_testCaseRegistry;
|
|
|
|
|
}
|
2018-06-15 21:34:38 +01:00
|
|
|
IExceptionTranslatorRegistry const& getExceptionTranslatorRegistry() const override {
|
2012-08-06 20:16:53 +01:00
|
|
|
return m_exceptionTranslatorRegistry;
|
|
|
|
|
}
|
2017-07-20 15:57:17 +01:00
|
|
|
ITagAliasRegistry const& getTagAliasRegistry() const override {
|
2017-03-15 09:45:37 +00:00
|
|
|
return m_tagAliasRegistry;
|
|
|
|
|
}
|
2017-07-20 15:57:17 +01:00
|
|
|
StartupExceptionRegistry const& getStartupExceptionRegistry() const override {
|
2017-06-04 21:39:27 +02:00
|
|
|
return m_exceptionRegistry;
|
|
|
|
|
}
|
2012-08-06 20:16:53 +01:00
|
|
|
|
2012-08-07 07:58:34 +01:00
|
|
|
public: // IMutableRegistryHub
|
2020-01-25 14:07:29 +01:00
|
|
|
void registerReporter( std::string const& name, IReporterFactoryPtr factory ) override {
|
2021-08-13 14:16:30 +02:00
|
|
|
m_reporterRegistry.registerReporter( name, CATCH_MOVE(factory) );
|
2012-08-06 20:16:53 +01:00
|
|
|
}
|
2020-01-25 14:07:29 +01:00
|
|
|
void registerListener( IReporterFactoryPtr factory ) override {
|
2021-08-13 14:16:30 +02:00
|
|
|
m_reporterRegistry.registerListener( CATCH_MOVE(factory) );
|
2015-08-07 08:20:56 +01:00
|
|
|
}
|
2020-05-25 09:45:24 +02:00
|
|
|
void registerTest( Detail::unique_ptr<TestCaseInfo>&& testInfo, Detail::unique_ptr<ITestInvoker>&& invoker ) override {
|
2021-08-13 14:16:30 +02:00
|
|
|
m_testCaseRegistry.registerTest( CATCH_MOVE(testInfo), CATCH_MOVE(invoker) );
|
2012-08-06 20:16:53 +01:00
|
|
|
}
|
2021-06-19 20:57:06 +02:00
|
|
|
void registerTranslator( Detail::unique_ptr<IExceptionTranslator>&& translator ) override {
|
2021-08-13 14:16:30 +02:00
|
|
|
m_exceptionTranslatorRegistry.registerTranslator( CATCH_MOVE(translator) );
|
2012-08-06 20:16:53 +01:00
|
|
|
}
|
2017-07-20 15:57:17 +01:00
|
|
|
void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) override {
|
2017-03-15 09:45:37 +00:00
|
|
|
m_tagAliasRegistry.add( alias, tag, lineInfo );
|
|
|
|
|
}
|
2017-07-27 12:24:52 +02:00
|
|
|
void registerStartupException() noexcept override {
|
2020-06-04 11:53:13 +02:00
|
|
|
#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
|
2017-07-27 12:24:52 +02:00
|
|
|
m_exceptionRegistry.add(std::current_exception());
|
2020-06-04 11:53:13 +02:00
|
|
|
#else
|
|
|
|
|
CATCH_INTERNAL_ERROR("Attempted to register active exception under CATCH_CONFIG_DISABLE_EXCEPTIONS!");
|
|
|
|
|
#endif
|
2017-06-04 21:39:27 +02:00
|
|
|
}
|
2019-04-04 15:55:46 +01:00
|
|
|
IMutableEnumValuesRegistry& getMutableEnumValuesRegistry() override {
|
|
|
|
|
return m_enumValuesRegistry;
|
|
|
|
|
}
|
2012-08-06 20:16:53 +01:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
TestRegistry m_testCaseRegistry;
|
|
|
|
|
ReporterRegistry m_reporterRegistry;
|
|
|
|
|
ExceptionTranslatorRegistry m_exceptionTranslatorRegistry;
|
2017-03-15 09:45:37 +00:00
|
|
|
TagAliasRegistry m_tagAliasRegistry;
|
2017-06-04 21:39:27 +02:00
|
|
|
StartupExceptionRegistry m_exceptionRegistry;
|
2019-04-04 15:55:46 +01:00
|
|
|
Detail::EnumValuesRegistry m_enumValuesRegistry;
|
2012-08-06 20:16:53 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-15 21:34:38 +01:00
|
|
|
using RegistryHubSingleton = Singleton<RegistryHub, IRegistryHub, IMutableRegistryHub>;
|
|
|
|
|
|
|
|
|
|
IRegistryHub const& getRegistryHub() {
|
|
|
|
|
return RegistryHubSingleton::get();
|
2012-08-06 20:16:53 +01:00
|
|
|
}
|
2012-08-07 07:58:34 +01:00
|
|
|
IMutableRegistryHub& getMutableRegistryHub() {
|
2018-06-15 21:34:38 +01:00
|
|
|
return RegistryHubSingleton::getMutable();
|
2012-08-06 20:16:53 +01:00
|
|
|
}
|
|
|
|
|
void cleanUp() {
|
2018-06-15 21:25:04 +01:00
|
|
|
cleanupSingletons();
|
2012-08-08 08:33:54 +01:00
|
|
|
cleanUpContext();
|
2012-08-06 20:16:53 +01:00
|
|
|
}
|
2012-10-17 08:14:22 +01:00
|
|
|
std::string translateActiveException() {
|
|
|
|
|
return getRegistryHub().getExceptionTranslatorRegistry().translateActiveException();
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-06 20:16:53 +01:00
|
|
|
|
|
|
|
|
} // end namespace Catch
|