mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-30 01:03:30 +01:00
Eliminate some work when results won't be reported.
This commit is contained in:
parent
28741467d5
commit
2212cdfe26
@ -83,12 +83,12 @@
|
|||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
#define INTERNAL_CATCH_IF( macroName, resultDisposition, ... ) \
|
#define INTERNAL_CATCH_IF( macroName, resultDisposition, ... ) \
|
||||||
INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \
|
INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \
|
||||||
if( Catch::getResultCapture().getLastResult()->succeeded() )
|
if( Catch::getResultCapture().lastAssertionPassed() )
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
#define INTERNAL_CATCH_ELSE( macroName, resultDisposition, ... ) \
|
#define INTERNAL_CATCH_ELSE( macroName, resultDisposition, ... ) \
|
||||||
INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \
|
INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \
|
||||||
if( !Catch::getResultCapture().getLastResult()->succeeded() )
|
if( !Catch::getResultCapture().lastAssertionPassed() )
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
#define INTERNAL_CATCH_NO_THROW( macroName, resultDisposition, ... ) \
|
#define INTERNAL_CATCH_NO_THROW( macroName, resultDisposition, ... ) \
|
||||||
|
@ -41,6 +41,10 @@ namespace Catch {
|
|||||||
virtual void exceptionEarlyReported() = 0;
|
virtual void exceptionEarlyReported() = 0;
|
||||||
|
|
||||||
virtual void handleFatalErrorCondition( std::string const& message ) = 0;
|
virtual void handleFatalErrorCondition( std::string const& message ) = 0;
|
||||||
|
|
||||||
|
virtual bool lastAssertionPassed() = 0;
|
||||||
|
virtual void assertionPassed() = 0;
|
||||||
|
virtual void assertionRun() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
IResultCapture& getResultCapture();
|
IResultCapture& getResultCapture();
|
||||||
|
@ -34,14 +34,12 @@ namespace Catch {
|
|||||||
char const* capturedExpression,
|
char const* capturedExpression,
|
||||||
ResultDisposition::Flags resultDisposition )
|
ResultDisposition::Flags resultDisposition )
|
||||||
: m_assertionInfo( macroName, lineInfo, capturedExpression, resultDisposition)
|
: m_assertionInfo( macroName, lineInfo, capturedExpression, resultDisposition)
|
||||||
{
|
{}
|
||||||
m_stream().oss.str("");
|
|
||||||
}
|
|
||||||
|
|
||||||
ResultBuilder::~ResultBuilder() {
|
ResultBuilder::~ResultBuilder() {
|
||||||
#if defined(CATCH_CONFIG_FAST_COMPILE)
|
#if defined(CATCH_CONFIG_FAST_COMPILE)
|
||||||
if ( m_guardException ) {
|
if ( m_guardException ) {
|
||||||
m_stream().oss << "Exception translation was disabled by CATCH_CONFIG_FAST_COMPILE";
|
stream().oss << "Exception translation was disabled by CATCH_CONFIG_FAST_COMPILE";
|
||||||
captureResult( ResultWas::ThrewException );
|
captureResult( ResultWas::ThrewException );
|
||||||
getCurrentContext().getResultCapture()->exceptionEarlyReported();
|
getCurrentContext().getResultCapture()->exceptionEarlyReported();
|
||||||
}
|
}
|
||||||
@ -58,13 +56,25 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ResultBuilder::endExpression( DecomposedExpression const& expr ) {
|
void ResultBuilder::endExpression( DecomposedExpression const& expr ) {
|
||||||
|
// Flip bool results if FalseTest flag is set
|
||||||
|
if( isFalseTest( m_assertionInfo.resultDisposition ) ) {
|
||||||
|
m_data.negate( expr.isBinaryExpression() );
|
||||||
|
}
|
||||||
|
|
||||||
|
getResultCapture().assertionRun();
|
||||||
|
|
||||||
|
if(getCurrentContext().getConfig()->includeSuccessfulResults()
|
||||||
|
|| m_data.resultType != ResultWas::Ok) {
|
||||||
AssertionResult result = build( expr );
|
AssertionResult result = build( expr );
|
||||||
handleResult( result );
|
handleResult( result );
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
getResultCapture().assertionPassed();
|
||||||
|
}
|
||||||
|
|
||||||
void ResultBuilder::useActiveException( ResultDisposition::Flags resultDisposition ) {
|
void ResultBuilder::useActiveException( ResultDisposition::Flags resultDisposition ) {
|
||||||
m_assertionInfo.resultDisposition = resultDisposition;
|
m_assertionInfo.resultDisposition = resultDisposition;
|
||||||
m_stream().oss << Catch::translateActiveException();
|
stream().oss << Catch::translateActiveException();
|
||||||
captureResult( ResultWas::ThrewException );
|
captureResult( ResultWas::ThrewException );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,16 +152,11 @@ namespace Catch {
|
|||||||
// It should immediately be passed to handleResult; if the expression
|
// It should immediately be passed to handleResult; if the expression
|
||||||
// needs to be reported, its string expansion must be composed before
|
// needs to be reported, its string expansion must be composed before
|
||||||
// the temporaries are destroyed.
|
// the temporaries are destroyed.
|
||||||
AssertionResult ResultBuilder::build( DecomposedExpression const& expr ) const
|
AssertionResult ResultBuilder::build( DecomposedExpression const& expr ) const {
|
||||||
{
|
|
||||||
assert( m_data.resultType != ResultWas::Unknown );
|
assert( m_data.resultType != ResultWas::Unknown );
|
||||||
AssertionResultData data = m_data;
|
AssertionResultData data = m_data;
|
||||||
|
|
||||||
// Flip bool results if FalseTest flag is set
|
if(m_usedStream)
|
||||||
if( isFalseTest( m_assertionInfo.resultDisposition ) ) {
|
|
||||||
data.negate( expr.isBinaryExpression() );
|
|
||||||
}
|
|
||||||
|
|
||||||
data.message = m_stream().oss.str();
|
data.message = m_stream().oss.str();
|
||||||
data.decomposedExpression = &expr; // for lazy reconstruction
|
data.decomposedExpression = &expr; // for lazy reconstruction
|
||||||
return AssertionResult( m_assertionInfo, data );
|
return AssertionResult( m_assertionInfo, data );
|
||||||
@ -168,7 +173,15 @@ namespace Catch {
|
|||||||
m_guardException = false;
|
m_guardException = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CopyableStream& ResultBuilder::m_stream() {
|
CopyableStream& ResultBuilder::stream() {
|
||||||
|
if( !m_usedStream ) {
|
||||||
|
m_usedStream = true;
|
||||||
|
s_stream().oss.str("");
|
||||||
|
}
|
||||||
|
return s_stream();
|
||||||
|
}
|
||||||
|
|
||||||
|
CopyableStream& ResultBuilder::s_stream() {
|
||||||
static CopyableStream s;
|
static CopyableStream s;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ namespace Catch {
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
ResultBuilder& operator << ( T const& value ) {
|
ResultBuilder& operator << ( T const& value ) {
|
||||||
m_stream().oss << value;
|
stream().oss << value;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,11 +79,13 @@ namespace Catch {
|
|||||||
AssertionInfo m_assertionInfo;
|
AssertionInfo m_assertionInfo;
|
||||||
AssertionResultData m_data;
|
AssertionResultData m_data;
|
||||||
|
|
||||||
static CopyableStream& m_stream();
|
CopyableStream& stream();
|
||||||
|
static CopyableStream& s_stream();
|
||||||
|
|
||||||
bool m_shouldDebugBreak = false;
|
bool m_shouldDebugBreak = false;
|
||||||
bool m_shouldThrow = false;
|
bool m_shouldThrow = false;
|
||||||
bool m_guardException = false;
|
bool m_guardException = false;
|
||||||
|
bool m_usedStream = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Catch
|
} // namespace Catch
|
||||||
|
@ -213,6 +213,20 @@ namespace Catch {
|
|||||||
m_reporter->testRunEnded(TestRunStats(m_runInfo, m_totals, false));
|
m_reporter->testRunEnded(TestRunStats(m_runInfo, m_totals, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RunContext::lastAssertionPassed() {
|
||||||
|
return m_totals.assertions.passed == (m_prevPassed + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RunContext::assertionPassed() {
|
||||||
|
++m_totals.assertions.passed;
|
||||||
|
m_lastAssertionInfo.capturedExpression = "{Unknown expression after the reported line}";
|
||||||
|
m_lastAssertionInfo.macroName = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
void RunContext::assertionRun() {
|
||||||
|
m_prevPassed = m_totals.assertions.passed;
|
||||||
|
}
|
||||||
|
|
||||||
bool RunContext::aborting() const {
|
bool RunContext::aborting() const {
|
||||||
return m_totals.assertions.failed == static_cast<std::size_t>(m_config->abortAfter());
|
return m_totals.assertions.failed == static_cast<std::size_t>(m_config->abortAfter());
|
||||||
}
|
}
|
||||||
|
@ -84,6 +84,12 @@ namespace Catch {
|
|||||||
|
|
||||||
virtual void handleFatalErrorCondition(std::string const& message) override;
|
virtual void handleFatalErrorCondition(std::string const& message) override;
|
||||||
|
|
||||||
|
virtual bool lastAssertionPassed() override;
|
||||||
|
|
||||||
|
virtual void assertionPassed();
|
||||||
|
|
||||||
|
virtual void assertionRun();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// !TBD We need to do this another way!
|
// !TBD We need to do this another way!
|
||||||
bool aborting() const override;
|
bool aborting() const override;
|
||||||
@ -113,6 +119,7 @@ namespace Catch {
|
|||||||
std::vector<SectionEndInfo> m_unfinishedSections;
|
std::vector<SectionEndInfo> m_unfinishedSections;
|
||||||
std::vector<ITracker*> m_activeSections;
|
std::vector<ITracker*> m_activeSections;
|
||||||
TrackerContext m_trackerContext;
|
TrackerContext m_trackerContext;
|
||||||
|
size_t m_prevPassed = 0;
|
||||||
bool m_shouldReportUnexpected = true;
|
bool m_shouldReportUnexpected = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user