mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-17 19:22:25 +01:00
ResultCapture -> RunContext
This commit is contained in:
parent
b77b45a390
commit
73968f29a5
@ -44,12 +44,12 @@
|
|||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
#define INTERNAL_CATCH_IF( expr, resultDisposition, macroName ) \
|
#define INTERNAL_CATCH_IF( expr, resultDisposition, macroName ) \
|
||||||
INTERNAL_CATCH_TEST( expr, resultDisposition, macroName ); \
|
INTERNAL_CATCH_TEST( expr, resultDisposition, macroName ); \
|
||||||
if( Catch::getResultCapture().getLastResult()->succeeded() )
|
if( Catch::getCurrentRunContext().getLastResult()->succeeded() )
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
#define INTERNAL_CATCH_ELSE( expr, resultDisposition, macroName ) \
|
#define INTERNAL_CATCH_ELSE( expr, resultDisposition, macroName ) \
|
||||||
INTERNAL_CATCH_TEST( expr, resultDisposition, macroName ); \
|
INTERNAL_CATCH_TEST( expr, resultDisposition, macroName ); \
|
||||||
if( !Catch::getResultCapture().getLastResult()->succeeded() )
|
if( !Catch::getCurrentRunContext().getLastResult()->succeeded() )
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
#define INTERNAL_CATCH_NO_THROW( expr, resultDisposition, macroName ) \
|
#define INTERNAL_CATCH_NO_THROW( expr, resultDisposition, macroName ) \
|
||||||
|
@ -18,7 +18,7 @@ namespace Catch {
|
|||||||
|
|
||||||
class TestCase;
|
class TestCase;
|
||||||
class Stream;
|
class Stream;
|
||||||
struct IResultCapture;
|
struct IRunContext;
|
||||||
struct IRunner;
|
struct IRunner;
|
||||||
struct IConfig;
|
struct IConfig;
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ namespace Catch {
|
|||||||
{
|
{
|
||||||
virtual ~IContext();
|
virtual ~IContext();
|
||||||
|
|
||||||
virtual IResultCapture* getResultCapture() = 0;
|
virtual IRunContext* getCurrentRunContext() = 0;
|
||||||
virtual IRunner* getRunner() = 0;
|
virtual IRunner* getRunner() = 0;
|
||||||
virtual IConfig const* getConfig() const = 0;
|
virtual IConfig const* getConfig() const = 0;
|
||||||
};
|
};
|
||||||
@ -34,7 +34,7 @@ namespace Catch {
|
|||||||
struct IMutableContext : IContext
|
struct IMutableContext : IContext
|
||||||
{
|
{
|
||||||
virtual ~IMutableContext();
|
virtual ~IMutableContext();
|
||||||
virtual void setResultCapture( IResultCapture* resultCapture ) = 0;
|
virtual void setResultCapture( IRunContext* resultCapture ) = 0;
|
||||||
virtual void setRunner( IRunner* runner ) = 0;
|
virtual void setRunner( IRunner* runner ) = 0;
|
||||||
virtual void setConfig( Ptr<IConfig const> const& config ) = 0;
|
virtual void setConfig( Ptr<IConfig const> const& config ) = 0;
|
||||||
};
|
};
|
||||||
|
@ -22,7 +22,7 @@ namespace Catch {
|
|||||||
void operator=( Context const& );
|
void operator=( Context const& );
|
||||||
|
|
||||||
public: // IContext
|
public: // IContext
|
||||||
virtual IResultCapture* getResultCapture() {
|
virtual IRunContext* getCurrentRunContext() {
|
||||||
return m_resultCapture;
|
return m_resultCapture;
|
||||||
}
|
}
|
||||||
virtual IRunner* getRunner() {
|
virtual IRunner* getRunner() {
|
||||||
@ -33,7 +33,7 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public: // IMutableContext
|
public: // IMutableContext
|
||||||
virtual void setResultCapture( IResultCapture* resultCapture ) {
|
virtual void setResultCapture( IRunContext* resultCapture ) {
|
||||||
m_resultCapture = resultCapture;
|
m_resultCapture = resultCapture;
|
||||||
}
|
}
|
||||||
virtual void setRunner( IRunner* runner ) {
|
virtual void setRunner( IRunner* runner ) {
|
||||||
@ -48,7 +48,7 @@ namespace Catch {
|
|||||||
private:
|
private:
|
||||||
Ptr<IConfig const> m_config;
|
Ptr<IConfig const> m_config;
|
||||||
IRunner* m_runner;
|
IRunner* m_runner;
|
||||||
IResultCapture* m_resultCapture;
|
IRunContext* m_resultCapture;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -15,8 +15,8 @@ namespace Catch {
|
|||||||
// Report the error condition then exit the process
|
// Report the error condition then exit the process
|
||||||
inline void fatal( std::string const& message, int exitCode ) {
|
inline void fatal( std::string const& message, int exitCode ) {
|
||||||
IContext& context = Catch::getCurrentContext();
|
IContext& context = Catch::getCurrentContext();
|
||||||
IResultCapture* resultCapture = context.getResultCapture();
|
IRunContext* runContext = context.getCurrentRunContext();
|
||||||
resultCapture->handleFatalErrorCondition( message );
|
runContext->handleFatalErrorCondition( message );
|
||||||
|
|
||||||
if( Catch::alwaysTrue() ) // avoids "no return" warnings
|
if( Catch::alwaysTrue() ) // avoids "no return" warnings
|
||||||
exit( exitCode );
|
exit( exitCode );
|
||||||
|
@ -53,7 +53,7 @@ namespace Catch {
|
|||||||
DebugOutStream::~DebugOutStream() CATCH_NOEXCEPT {}
|
DebugOutStream::~DebugOutStream() CATCH_NOEXCEPT {}
|
||||||
StreamBufBase::~StreamBufBase() CATCH_NOEXCEPT {}
|
StreamBufBase::~StreamBufBase() CATCH_NOEXCEPT {}
|
||||||
IContext::~IContext() {}
|
IContext::~IContext() {}
|
||||||
IResultCapture::~IResultCapture() {}
|
IRunContext::~IRunContext() {}
|
||||||
ITestCase::~ITestCase() {}
|
ITestCase::~ITestCase() {}
|
||||||
ITestCaseRegistry::~ITestCaseRegistry() {}
|
ITestCaseRegistry::~ITestCaseRegistry() {}
|
||||||
IRegistryHub::~IRegistryHub() {}
|
IRegistryHub::~IRegistryHub() {}
|
||||||
|
@ -23,9 +23,9 @@ namespace Catch {
|
|||||||
class ScopedMessageBuilder;
|
class ScopedMessageBuilder;
|
||||||
struct Counts;
|
struct Counts;
|
||||||
|
|
||||||
struct IResultCapture {
|
struct IRunContext {
|
||||||
|
|
||||||
virtual ~IResultCapture();
|
virtual ~IRunContext();
|
||||||
|
|
||||||
virtual void assertionEnded( AssertionResult const& result ) = 0;
|
virtual void assertionEnded( AssertionResult const& result ) = 0;
|
||||||
virtual bool sectionStarted( SectionInfo const& sectionInfo,
|
virtual bool sectionStarted( SectionInfo const& sectionInfo,
|
||||||
@ -41,7 +41,7 @@ namespace Catch {
|
|||||||
virtual void handleFatalErrorCondition( std::string const& message ) = 0;
|
virtual void handleFatalErrorCondition( std::string const& message ) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
IResultCapture& getResultCapture();
|
IRunContext& getCurrentRunContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_INTERFACES_CAPTURE_H_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_INTERFACES_CAPTURE_H_INCLUDED
|
||||||
|
@ -31,14 +31,14 @@ namespace Catch {
|
|||||||
: m_info( builder.m_info )
|
: m_info( builder.m_info )
|
||||||
{
|
{
|
||||||
m_info.message = builder.m_stream.str();
|
m_info.message = builder.m_stream.str();
|
||||||
getResultCapture().pushScopedMessage( m_info );
|
getCurrentRunContext().pushScopedMessage( m_info );
|
||||||
}
|
}
|
||||||
ScopedMessage::ScopedMessage( ScopedMessage const& other )
|
ScopedMessage::ScopedMessage( ScopedMessage const& other )
|
||||||
: m_info( other.m_info )
|
: m_info( other.m_info )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
ScopedMessage::~ScopedMessage() {
|
ScopedMessage::~ScopedMessage() {
|
||||||
getResultCapture().popScopedMessage( m_info );
|
getCurrentRunContext().popScopedMessage( m_info );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
void ResultBuilder::handleResult( AssertionResult const& result )
|
void ResultBuilder::handleResult( AssertionResult const& result )
|
||||||
{
|
{
|
||||||
getResultCapture().assertionEnded( result );
|
getCurrentRunContext().assertionEnded( result );
|
||||||
|
|
||||||
if( !result.isOk() ) {
|
if( !result.isOk() ) {
|
||||||
if( getCurrentConfig()->shouldDebugBreak() )
|
if( getCurrentConfig()->shouldDebugBreak() )
|
||||||
|
@ -52,7 +52,7 @@ namespace Catch {
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
class RunContext : public IResultCapture, public IRunner {
|
class RunContext : public IRunContext, public IRunner {
|
||||||
|
|
||||||
RunContext( RunContext const& );
|
RunContext( RunContext const& );
|
||||||
void operator =( RunContext const& );
|
void operator =( RunContext const& );
|
||||||
@ -119,7 +119,7 @@ namespace Catch {
|
|||||||
return m_config;
|
return m_config;
|
||||||
}
|
}
|
||||||
|
|
||||||
private: // IResultCapture
|
private: // IRunContext
|
||||||
|
|
||||||
|
|
||||||
virtual void assertionEnded( AssertionResult const& result ) {
|
virtual void assertionEnded( AssertionResult const& result ) {
|
||||||
@ -337,8 +337,8 @@ namespace Catch {
|
|||||||
std::vector<MessageInfo> m_messages;
|
std::vector<MessageInfo> m_messages;
|
||||||
};
|
};
|
||||||
|
|
||||||
IResultCapture& getResultCapture() {
|
IRunContext& getCurrentRunContext() {
|
||||||
if( IResultCapture* capture = getCurrentContext().getResultCapture() )
|
if( IRunContext* capture = getCurrentContext().getCurrentRunContext() )
|
||||||
return *capture;
|
return *capture;
|
||||||
else
|
else
|
||||||
throw std::logic_error( "No result capture instance" );
|
throw std::logic_error( "No result capture instance" );
|
||||||
|
@ -26,7 +26,7 @@ namespace Catch {
|
|||||||
|
|
||||||
Section::Section( SectionInfo const& info )
|
Section::Section( SectionInfo const& info )
|
||||||
: m_info( info ),
|
: m_info( info ),
|
||||||
m_sectionIncluded( getResultCapture().sectionStarted( m_info, m_assertions ) )
|
m_sectionIncluded( getCurrentRunContext().sectionStarted( m_info, m_assertions ) )
|
||||||
{
|
{
|
||||||
m_timer.start();
|
m_timer.start();
|
||||||
}
|
}
|
||||||
@ -35,9 +35,9 @@ namespace Catch {
|
|||||||
if( m_sectionIncluded ) {
|
if( m_sectionIncluded ) {
|
||||||
SectionEndInfo endInfo( m_info, m_assertions, m_timer.getElapsedSeconds() );
|
SectionEndInfo endInfo( m_info, m_assertions, m_timer.getElapsedSeconds() );
|
||||||
if( std::uncaught_exception() )
|
if( std::uncaught_exception() )
|
||||||
getResultCapture().sectionEndedEarly( endInfo );
|
getCurrentRunContext().sectionEndedEarly( endInfo );
|
||||||
else
|
else
|
||||||
getResultCapture().sectionEnded( endInfo );
|
getCurrentRunContext().sectionEnded( endInfo );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user