mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-30 01:03:30 +01:00
Fixed dereferenced null issue
This commit is contained in:
parent
59d556907d
commit
5daa22dcc3
@ -25,7 +25,10 @@
|
|||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
inline IResultCapture& getResultCapture() {
|
inline IResultCapture& getResultCapture() {
|
||||||
return getCurrentContext().getResultCapture();
|
if( IResultCapture* capture = getCurrentContext().getResultCapture() )
|
||||||
|
return *capture;
|
||||||
|
else
|
||||||
|
throw std::logic_error( "No result capture instance" );
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename MatcherT>
|
template<typename MatcherT>
|
||||||
|
@ -28,8 +28,8 @@ namespace Catch {
|
|||||||
{
|
{
|
||||||
virtual ~IContext();
|
virtual ~IContext();
|
||||||
|
|
||||||
virtual IResultCapture& getResultCapture() = 0;
|
virtual IResultCapture* getResultCapture() = 0;
|
||||||
virtual IRunner& getRunner() = 0;
|
virtual IRunner* getRunner() = 0;
|
||||||
virtual size_t getGeneratorIndex( std::string const& fileInfo, size_t totalSize ) = 0;
|
virtual size_t getGeneratorIndex( std::string const& fileInfo, size_t totalSize ) = 0;
|
||||||
virtual bool advanceGeneratorsForCurrentTest() = 0;
|
virtual bool advanceGeneratorsForCurrentTest() = 0;
|
||||||
virtual Ptr<IConfig const> getConfig() const = 0;
|
virtual Ptr<IConfig const> getConfig() const = 0;
|
||||||
|
@ -22,17 +22,11 @@ namespace Catch {
|
|||||||
void operator=( Context const& );
|
void operator=( Context const& );
|
||||||
|
|
||||||
public: // IContext
|
public: // IContext
|
||||||
virtual IResultCapture& getResultCapture() {
|
virtual IResultCapture* getResultCapture() {
|
||||||
if( m_resultCapture )
|
return m_resultCapture;
|
||||||
return *m_resultCapture;
|
|
||||||
else
|
|
||||||
throw std::logic_error( "No result capture instance" );
|
|
||||||
}
|
}
|
||||||
virtual IRunner& getRunner() {
|
virtual IRunner* getRunner() {
|
||||||
if( m_runner )
|
return m_runner;
|
||||||
return *m_runner;
|
|
||||||
else
|
|
||||||
throw std::logic_error( "No runner instance" );
|
|
||||||
}
|
}
|
||||||
virtual size_t getGeneratorIndex( std::string const& fileInfo, size_t totalSize ) {
|
virtual size_t getGeneratorIndex( std::string const& fileInfo, size_t totalSize ) {
|
||||||
return getGeneratorsForCurrentTest()
|
return getGeneratorsForCurrentTest()
|
||||||
@ -63,7 +57,7 @@ namespace Catch {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
IGeneratorsForTest* findGeneratorsForCurrentTest() {
|
IGeneratorsForTest* findGeneratorsForCurrentTest() {
|
||||||
std::string testName = getResultCapture().getCurrentTestName();
|
std::string testName = getResultCapture()->getCurrentTestName();
|
||||||
|
|
||||||
std::map<std::string, IGeneratorsForTest*>::const_iterator it =
|
std::map<std::string, IGeneratorsForTest*>::const_iterator it =
|
||||||
m_generatorsByTestName.find( testName );
|
m_generatorsByTestName.find( testName );
|
||||||
@ -75,7 +69,7 @@ namespace Catch {
|
|||||||
IGeneratorsForTest& getGeneratorsForCurrentTest() {
|
IGeneratorsForTest& getGeneratorsForCurrentTest() {
|
||||||
IGeneratorsForTest* generators = findGeneratorsForCurrentTest();
|
IGeneratorsForTest* generators = findGeneratorsForCurrentTest();
|
||||||
if( !generators ) {
|
if( !generators ) {
|
||||||
std::string testName = getResultCapture().getCurrentTestName();
|
std::string testName = getResultCapture()->getCurrentTestName();
|
||||||
generators = createGeneratorsForTest();
|
generators = createGeneratorsForTest();
|
||||||
m_generatorsByTestName.insert( std::make_pair( testName, generators ) );
|
m_generatorsByTestName.insert( std::make_pair( testName, generators ) );
|
||||||
}
|
}
|
||||||
|
@ -63,8 +63,8 @@ namespace Catch {
|
|||||||
m_activeTestCase( NULL ),
|
m_activeTestCase( NULL ),
|
||||||
m_config( config ),
|
m_config( config ),
|
||||||
m_reporter( reporter ),
|
m_reporter( reporter ),
|
||||||
m_prevRunner( &m_context.getRunner() ),
|
m_prevRunner( m_context.getRunner() ),
|
||||||
m_prevResultCapture( &m_context.getResultCapture() ),
|
m_prevResultCapture( m_context.getResultCapture() ),
|
||||||
m_prevConfig( m_context.getConfig() )
|
m_prevConfig( m_context.getConfig() )
|
||||||
{
|
{
|
||||||
m_context.setRunner( this );
|
m_context.setRunner( this );
|
||||||
|
@ -19,14 +19,14 @@ namespace Catch {
|
|||||||
std::string const& name,
|
std::string const& name,
|
||||||
std::string const& description )
|
std::string const& description )
|
||||||
: m_info( name, description, lineInfo ),
|
: m_info( name, description, lineInfo ),
|
||||||
m_sectionIncluded( getCurrentContext().getResultCapture().sectionStarted( m_info, m_assertions ) )
|
m_sectionIncluded( getResultCapture().sectionStarted( m_info, m_assertions ) )
|
||||||
{
|
{
|
||||||
m_timer.start();
|
m_timer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
Section::~Section() {
|
Section::~Section() {
|
||||||
if( m_sectionIncluded )
|
if( m_sectionIncluded )
|
||||||
getCurrentContext().getResultCapture().sectionEnded( m_info, m_assertions, m_timer.getElapsedSeconds() );
|
getResultCapture().sectionEnded( m_info, m_assertions, m_timer.getElapsedSeconds() );
|
||||||
}
|
}
|
||||||
|
|
||||||
// This indicates whether the section should be executed or not
|
// This indicates whether the section should be executed or not
|
||||||
|
Loading…
Reference in New Issue
Block a user