Use unique_ptr for passing around exception translators

This commit is contained in:
Martin Hořeňovský 2021-06-19 20:57:06 +02:00
parent 28a33497be
commit a7533707ff
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
5 changed files with 13 additions and 8 deletions

View File

@ -56,8 +56,8 @@ namespace Catch {
void registerTest( Detail::unique_ptr<TestCaseInfo>&& testInfo, Detail::unique_ptr<ITestInvoker>&& invoker ) override {
m_testCaseRegistry.registerTest( std::move(testInfo), std::move(invoker) );
}
void registerTranslator( const IExceptionTranslator* translator ) override {
m_exceptionTranslatorRegistry.registerTranslator( translator );
void registerTranslator( Detail::unique_ptr<IExceptionTranslator>&& translator ) override {
m_exceptionTranslatorRegistry.registerTranslator( std::move(translator) );
}
void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) override {
m_tagAliasRegistry.add( alias, tag, lineInfo );

View File

@ -48,8 +48,11 @@ namespace Catch {
public:
template<typename T>
ExceptionTranslatorRegistrar( std::string(*translateFunction)( T const& ) ) {
getMutableRegistryHub().registerTranslator
( new ExceptionTranslator<T>( translateFunction ) );
getMutableRegistryHub().registerTranslator(
Detail::unique_ptr<IExceptionTranslator>(
new ExceptionTranslator<T>( translateFunction )
)
);
}
};

View File

@ -47,7 +47,7 @@ namespace Catch {
virtual void registerReporter( std::string const& name, IReporterFactoryPtr factory ) = 0;
virtual void registerListener( IReporterFactoryPtr factory ) = 0;
virtual void registerTest(Detail::unique_ptr<TestCaseInfo>&& testInfo, Detail::unique_ptr<ITestInvoker>&& invoker) = 0;
virtual void registerTranslator( const IExceptionTranslator* translator ) = 0;
virtual void registerTranslator( Detail::unique_ptr<IExceptionTranslator>&& translator ) = 0;
virtual void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) = 0;
virtual void registerStartupException() noexcept = 0;
virtual IMutableEnumValuesRegistry& getMutableEnumValuesRegistry() = 0;

View File

@ -15,8 +15,8 @@ namespace Catch {
ExceptionTranslatorRegistry::~ExceptionTranslatorRegistry() {
}
void ExceptionTranslatorRegistry::registerTranslator( const IExceptionTranslator* translator ) {
m_translators.push_back( Detail::unique_ptr<const IExceptionTranslator>( translator ) );
void ExceptionTranslatorRegistry::registerTranslator( Detail::unique_ptr<IExceptionTranslator>&& translator ) {
m_translators.push_back( std::move( translator ) );
}
#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)

View File

@ -9,6 +9,8 @@
#define CATCH_EXCEPTION_TRANSLATOR_REGISTRY_HPP_INCLUDED
#include <catch2/interfaces/catch_interfaces_exception.hpp>
#include <catch2/internal/catch_unique_ptr.hpp>
#include <vector>
#include <string>
@ -17,7 +19,7 @@ namespace Catch {
class ExceptionTranslatorRegistry : public IExceptionTranslatorRegistry {
public:
~ExceptionTranslatorRegistry() override;
void registerTranslator( const IExceptionTranslator* translator );
void registerTranslator( Detail::unique_ptr<IExceptionTranslator>&& translator );
std::string translateActiveException() const override;
std::string tryTranslators() const;