Made everything used in test case registration noexcept

- this prevents warnings about startup-time exceptions
This commit is contained in:
Phil Nash 2017-07-13 08:25:47 +01:00
parent 989222eceb
commit e01ed48a70
8 changed files with 35 additions and 31 deletions

View File

@ -75,18 +75,18 @@ namespace Catch {
return os;
}
SourceLineInfo::SourceLineInfo() : file(""), line( 0 ){}
SourceLineInfo::SourceLineInfo( char const* _file, std::size_t _line )
SourceLineInfo::SourceLineInfo() noexcept : file(""), line( 0 ){}
SourceLineInfo::SourceLineInfo( char const* _file, std::size_t _line ) noexcept
: file( _file ),
line( _line )
{}
bool SourceLineInfo::empty() const {
bool SourceLineInfo::empty() const noexcept {
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);
}
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));
}

View File

@ -77,17 +77,17 @@ namespace Catch {
struct SourceLineInfo {
SourceLineInfo();
SourceLineInfo( char const* _file, std::size_t _line );
SourceLineInfo() noexcept;
SourceLineInfo( char const* _file, std::size_t _line ) noexcept;
SourceLineInfo(SourceLineInfo const& other) = default;
SourceLineInfo( SourceLineInfo && ) = default;
SourceLineInfo& operator = ( SourceLineInfo const& ) = default;
SourceLineInfo& operator = ( SourceLineInfo && ) = default;
bool empty() const;
bool operator == ( SourceLineInfo const& other ) const;
bool operator < ( SourceLineInfo const& other ) const;
bool empty() const noexcept;
bool operator == ( SourceLineInfo const& other ) const noexcept;
bool operator < ( SourceLineInfo const& other ) const noexcept;
char const* file;
std::size_t line;

View File

@ -46,7 +46,7 @@ namespace Catch {
virtual void registerTest( TestCase const& testInfo ) = 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 registerStartupException( std::exception_ptr const& exception ) = 0;
virtual void registerStartupException( std::exception_ptr const& exception ) noexcept = 0;
};
IRegistryHub& getRegistryHub();

View File

@ -56,7 +56,7 @@ namespace Catch {
virtual void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) override {
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);
}

View File

@ -9,11 +9,17 @@
#include "catch_startup_exception_registry.h"
namespace Catch {
void StartupExceptionRegistry::add( std::exception_ptr const& exception ) {
void StartupExceptionRegistry::add( std::exception_ptr const& exception ) noexcept {
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;
}

View File

@ -16,8 +16,8 @@ namespace Catch {
class StartupExceptionRegistry {
public:
void add(std::exception_ptr const& exception);
std::vector<std::exception_ptr> const& getExceptions() const;
void add(std::exception_ptr const& exception) noexcept;
std::vector<std::exception_ptr> const& getExceptions() const noexcept;
private:
std::vector<std::exception_ptr> m_exceptions;
};

View File

@ -46,10 +46,8 @@ namespace Catch {
std::sort( sorted.begin(), sorted.end() );
break;
case RunTests::InRandomOrder:
{
seedRng( config );
RandomNumberGenerator::shuffle( sorted );
}
break;
case RunTests::InDeclarationOrder:
// already in declaration order
@ -128,14 +126,14 @@ namespace Catch {
class TestInvokerAsFunction : public ITestInvoker {
void(*m_testAsFunction)();
public:
TestInvokerAsFunction( void(*testAsFunction)() ) : m_testAsFunction( testAsFunction ) {}
TestInvokerAsFunction( void(*testAsFunction)() ) noexcept : m_testAsFunction( testAsFunction ) {}
void invoke() const override {
m_testAsFunction();
}
};
auto makeTestInvoker( void(*testAsFunction)() ) -> ITestInvoker* {
return new TestInvokerAsFunction( testAsFunction );
auto makeTestInvoker( void(*testAsFunction)() ) noexcept -> ITestInvoker* {
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 {
getMutableRegistryHub()

View File

@ -19,7 +19,7 @@ template<typename C>
class TestInvokerAsMethod : public ITestInvoker {
void (C::*m_testAsMethod)();
public:
TestInvokerAsMethod( void (C::*testAsMethod)() ) : m_testAsMethod( testAsMethod ) {}
TestInvokerAsMethod( void (C::*testAsMethod)() ) noexcept : m_testAsMethod( testAsMethod ) {}
void invoke() const override {
C obj;
@ -27,23 +27,23 @@ public:
}
};
auto makeTestInvoker( void(*testAsFunction)() ) -> ITestInvoker*;
auto makeTestInvoker( void(*testAsFunction)() ) noexcept -> ITestInvoker*;
template<typename C>
auto makeTestInvoker( void (C::*testAsMethod)() ) -> ITestInvoker* {
return new TestInvokerAsMethod<C>( testAsMethod );
auto makeTestInvoker( void (C::*testAsMethod)() ) noexcept -> ITestInvoker* {
return new(std::nothrow) TestInvokerAsMethod<C>( testAsMethod );
}
struct NameAndTags {
NameAndTags( StringRef name_ = "", StringRef tags_ = "" ) : name( name_ ), tags( tags_ ) {}
NameAndTags( StringRef name_ = "", StringRef tags_ = "" ) noexcept : name( name_ ), tags( tags_ ) {}
StringRef name;
StringRef tags;
};
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();
};