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