mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-01 12:55:40 +02:00
lazily stringify expressions
This commit is contained in:

committed by
Martin Hořeňovský

parent
3b7511e564
commit
a1e9b841ff
@@ -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;
|
||||
|
Reference in New Issue
Block a user