mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 13:26:10 +01:00
Made everything used in test case registration noexcept
- this prevents warnings about startup-time exceptions
This commit is contained in:
parent
989222eceb
commit
e01ed48a70
@ -75,18 +75,18 @@ namespace Catch {
|
|||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
SourceLineInfo::SourceLineInfo() : file(""), line( 0 ){}
|
SourceLineInfo::SourceLineInfo() noexcept : file(""), line( 0 ){}
|
||||||
SourceLineInfo::SourceLineInfo( char const* _file, std::size_t _line )
|
SourceLineInfo::SourceLineInfo( char const* _file, std::size_t _line ) noexcept
|
||||||
: file( _file ),
|
: file( _file ),
|
||||||
line( _line )
|
line( _line )
|
||||||
{}
|
{}
|
||||||
bool SourceLineInfo::empty() const {
|
bool SourceLineInfo::empty() const noexcept {
|
||||||
return file[0] == '\0';
|
return file[0] == '\0';
|
||||||
}
|
}
|
||||||
bool SourceLineInfo::operator == ( SourceLineInfo const& other ) const {
|
bool SourceLineInfo::operator == ( SourceLineInfo const& other ) const noexcept {
|
||||||
return line == other.line && (file == other.file || std::strcmp(file, other.file) == 0);
|
return line == other.line && (file == other.file || std::strcmp(file, other.file) == 0);
|
||||||
}
|
}
|
||||||
bool SourceLineInfo::operator < ( SourceLineInfo const& other ) const {
|
bool SourceLineInfo::operator < ( SourceLineInfo const& other ) const noexcept {
|
||||||
return line < other.line || ( line == other.line && (std::strcmp(file, other.file) < 0));
|
return line < other.line || ( line == other.line && (std::strcmp(file, other.file) < 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,17 +77,17 @@ namespace Catch {
|
|||||||
|
|
||||||
struct SourceLineInfo {
|
struct SourceLineInfo {
|
||||||
|
|
||||||
SourceLineInfo();
|
SourceLineInfo() noexcept;
|
||||||
SourceLineInfo( char const* _file, std::size_t _line );
|
SourceLineInfo( char const* _file, std::size_t _line ) noexcept;
|
||||||
|
|
||||||
SourceLineInfo(SourceLineInfo const& other) = default;
|
SourceLineInfo(SourceLineInfo const& other) = default;
|
||||||
SourceLineInfo( SourceLineInfo && ) = default;
|
SourceLineInfo( SourceLineInfo && ) = default;
|
||||||
SourceLineInfo& operator = ( SourceLineInfo const& ) = default;
|
SourceLineInfo& operator = ( SourceLineInfo const& ) = default;
|
||||||
SourceLineInfo& operator = ( SourceLineInfo && ) = default;
|
SourceLineInfo& operator = ( SourceLineInfo && ) = default;
|
||||||
|
|
||||||
bool empty() const;
|
bool empty() const noexcept;
|
||||||
bool operator == ( SourceLineInfo const& other ) const;
|
bool operator == ( SourceLineInfo const& other ) const noexcept;
|
||||||
bool operator < ( SourceLineInfo const& other ) const;
|
bool operator < ( SourceLineInfo const& other ) const noexcept;
|
||||||
|
|
||||||
char const* file;
|
char const* file;
|
||||||
std::size_t line;
|
std::size_t line;
|
||||||
|
@ -46,7 +46,7 @@ namespace Catch {
|
|||||||
virtual void registerTest( TestCase const& testInfo ) = 0;
|
virtual void registerTest( TestCase const& testInfo ) = 0;
|
||||||
virtual void registerTranslator( const IExceptionTranslator* translator ) = 0;
|
virtual void registerTranslator( const IExceptionTranslator* translator ) = 0;
|
||||||
virtual void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) = 0;
|
virtual void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) = 0;
|
||||||
virtual void registerStartupException( std::exception_ptr const& exception ) = 0;
|
virtual void registerStartupException( std::exception_ptr const& exception ) noexcept = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
IRegistryHub& getRegistryHub();
|
IRegistryHub& getRegistryHub();
|
||||||
|
@ -56,7 +56,7 @@ namespace Catch {
|
|||||||
virtual void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) override {
|
virtual void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) override {
|
||||||
m_tagAliasRegistry.add( alias, tag, lineInfo );
|
m_tagAliasRegistry.add( alias, tag, lineInfo );
|
||||||
}
|
}
|
||||||
virtual void registerStartupException( std::exception_ptr const& exception ) override {
|
virtual void registerStartupException( std::exception_ptr const& exception ) noexcept override {
|
||||||
m_exceptionRegistry.add(exception);
|
m_exceptionRegistry.add(exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,11 +9,17 @@
|
|||||||
#include "catch_startup_exception_registry.h"
|
#include "catch_startup_exception_registry.h"
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
void StartupExceptionRegistry::add( std::exception_ptr const& exception ) {
|
void StartupExceptionRegistry::add( std::exception_ptr const& exception ) noexcept {
|
||||||
m_exceptions.push_back(exception);
|
try {
|
||||||
|
m_exceptions.push_back(exception);
|
||||||
|
}
|
||||||
|
catch(...) {
|
||||||
|
// If we run out of memory during start-up there's really not a lot more we can do about it
|
||||||
|
std::terminate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::exception_ptr> const& StartupExceptionRegistry::getExceptions() const {
|
std::vector<std::exception_ptr> const& StartupExceptionRegistry::getExceptions() const noexcept {
|
||||||
return m_exceptions;
|
return m_exceptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,8 +16,8 @@ namespace Catch {
|
|||||||
|
|
||||||
class StartupExceptionRegistry {
|
class StartupExceptionRegistry {
|
||||||
public:
|
public:
|
||||||
void add(std::exception_ptr const& exception);
|
void add(std::exception_ptr const& exception) noexcept;
|
||||||
std::vector<std::exception_ptr> const& getExceptions() const;
|
std::vector<std::exception_ptr> const& getExceptions() const noexcept;
|
||||||
private:
|
private:
|
||||||
std::vector<std::exception_ptr> m_exceptions;
|
std::vector<std::exception_ptr> m_exceptions;
|
||||||
};
|
};
|
||||||
|
@ -46,10 +46,8 @@ namespace Catch {
|
|||||||
std::sort( sorted.begin(), sorted.end() );
|
std::sort( sorted.begin(), sorted.end() );
|
||||||
break;
|
break;
|
||||||
case RunTests::InRandomOrder:
|
case RunTests::InRandomOrder:
|
||||||
{
|
seedRng( config );
|
||||||
seedRng( config );
|
RandomNumberGenerator::shuffle( sorted );
|
||||||
RandomNumberGenerator::shuffle( sorted );
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case RunTests::InDeclarationOrder:
|
case RunTests::InDeclarationOrder:
|
||||||
// already in declaration order
|
// already in declaration order
|
||||||
@ -128,14 +126,14 @@ namespace Catch {
|
|||||||
class TestInvokerAsFunction : public ITestInvoker {
|
class TestInvokerAsFunction : public ITestInvoker {
|
||||||
void(*m_testAsFunction)();
|
void(*m_testAsFunction)();
|
||||||
public:
|
public:
|
||||||
TestInvokerAsFunction( void(*testAsFunction)() ) : m_testAsFunction( testAsFunction ) {}
|
TestInvokerAsFunction( void(*testAsFunction)() ) noexcept : m_testAsFunction( testAsFunction ) {}
|
||||||
|
|
||||||
void invoke() const override {
|
void invoke() const override {
|
||||||
m_testAsFunction();
|
m_testAsFunction();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
auto makeTestInvoker( void(*testAsFunction)() ) -> ITestInvoker* {
|
auto makeTestInvoker( void(*testAsFunction)() ) noexcept -> ITestInvoker* {
|
||||||
return new TestInvokerAsFunction( testAsFunction );
|
return new(std::nothrow) TestInvokerAsFunction( testAsFunction );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -154,7 +152,7 @@ namespace Catch {
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
AutoReg::AutoReg( ITestInvoker* invoker, SourceLineInfo const& lineInfo, StringRef classOrMethod, NameAndTags const& nameAndTags )
|
AutoReg::AutoReg( ITestInvoker* invoker, SourceLineInfo const& lineInfo, StringRef classOrMethod, NameAndTags const& nameAndTags ) noexcept
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
getMutableRegistryHub()
|
getMutableRegistryHub()
|
||||||
|
@ -19,7 +19,7 @@ template<typename C>
|
|||||||
class TestInvokerAsMethod : public ITestInvoker {
|
class TestInvokerAsMethod : public ITestInvoker {
|
||||||
void (C::*m_testAsMethod)();
|
void (C::*m_testAsMethod)();
|
||||||
public:
|
public:
|
||||||
TestInvokerAsMethod( void (C::*testAsMethod)() ) : m_testAsMethod( testAsMethod ) {}
|
TestInvokerAsMethod( void (C::*testAsMethod)() ) noexcept : m_testAsMethod( testAsMethod ) {}
|
||||||
|
|
||||||
void invoke() const override {
|
void invoke() const override {
|
||||||
C obj;
|
C obj;
|
||||||
@ -27,23 +27,23 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
auto makeTestInvoker( void(*testAsFunction)() ) -> ITestInvoker*;
|
auto makeTestInvoker( void(*testAsFunction)() ) noexcept -> ITestInvoker*;
|
||||||
|
|
||||||
template<typename C>
|
template<typename C>
|
||||||
auto makeTestInvoker( void (C::*testAsMethod)() ) -> ITestInvoker* {
|
auto makeTestInvoker( void (C::*testAsMethod)() ) noexcept -> ITestInvoker* {
|
||||||
return new TestInvokerAsMethod<C>( testAsMethod );
|
return new(std::nothrow) TestInvokerAsMethod<C>( testAsMethod );
|
||||||
}
|
}
|
||||||
|
|
||||||
struct NameAndTags {
|
struct NameAndTags {
|
||||||
|
|
||||||
NameAndTags( StringRef name_ = "", StringRef tags_ = "" ) : name( name_ ), tags( tags_ ) {}
|
NameAndTags( StringRef name_ = "", StringRef tags_ = "" ) noexcept : name( name_ ), tags( tags_ ) {}
|
||||||
|
|
||||||
StringRef name;
|
StringRef name;
|
||||||
StringRef tags;
|
StringRef tags;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct AutoReg : NonCopyable {
|
struct AutoReg : NonCopyable {
|
||||||
AutoReg( ITestInvoker* invoker, SourceLineInfo const& lineInfo, StringRef classOrMethod, NameAndTags const& nameAndTags );
|
AutoReg( ITestInvoker* invoker, SourceLineInfo const& lineInfo, StringRef classOrMethod, NameAndTags const& nameAndTags ) noexcept;
|
||||||
~AutoReg();
|
~AutoReg();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user