lazily stringify expressions

This commit is contained in:
Mickey Rose
2017-01-09 13:23:10 +01:00
committed by Martin Hořeňovský
parent 3b7511e564
commit a1e9b841ff
7 changed files with 223 additions and 110 deletions

View File

@@ -170,6 +170,12 @@ namespace Catch {
assert( !m_sectionStack.empty() );
SectionNode& sectionNode = *m_sectionStack.back();
sectionNode.assertions.push_back( assertionStats );
// AssertionResult holds a pointer to a temporary DecomposedExpression,
// which getExpandedExpression() calls to build the expression string.
// Our section stack copy of the assertionResult will likely outlive the
// temporary, so it must be expanded or discarded now to avoid calling
// a destroyed object later.
prepareExpandedExpression( sectionNode.assertions.back().assertionResult );
return true;
}
virtual void sectionEnded( SectionStats const& sectionStats ) CATCH_OVERRIDE {
@@ -204,6 +210,13 @@ namespace Catch {
virtual void skipTest( TestCaseInfo const& ) CATCH_OVERRIDE {}
virtual void prepareExpandedExpression( AssertionResult& result ) const {
if( result.isOk() )
result.discardDecomposedExpression();
else
result.expandDecomposedExpression();
}
Ptr<IConfig const> m_config;
std::ostream& stream;
std::vector<AssertionStats> m_assertions;