mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 07:16:10 +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, ... ) \
|
||||
INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \
|
||||
if( Catch::getResultCapture().getLastResult()->succeeded() )
|
||||
if( Catch::getResultCapture().lastAssertionPassed() )
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define INTERNAL_CATCH_ELSE( macroName, resultDisposition, ... ) \
|
||||
INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \
|
||||
if( !Catch::getResultCapture().getLastResult()->succeeded() )
|
||||
if( !Catch::getResultCapture().lastAssertionPassed() )
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define INTERNAL_CATCH_NO_THROW( macroName, resultDisposition, ... ) \
|
||||
|
@ -41,6 +41,10 @@ namespace Catch {
|
||||
virtual void exceptionEarlyReported() = 0;
|
||||
|
||||
virtual void handleFatalErrorCondition( std::string const& message ) = 0;
|
||||
|
||||
virtual bool lastAssertionPassed() = 0;
|
||||
virtual void assertionPassed() = 0;
|
||||
virtual void assertionRun() = 0;
|
||||
};
|
||||
|
||||
IResultCapture& getResultCapture();
|
||||
|
@ -34,14 +34,12 @@ namespace Catch {
|
||||
char const* capturedExpression,
|
||||
ResultDisposition::Flags resultDisposition )
|
||||
: m_assertionInfo( macroName, lineInfo, capturedExpression, resultDisposition)
|
||||
{
|
||||
m_stream().oss.str("");
|
||||
}
|
||||
{}
|
||||
|
||||
ResultBuilder::~ResultBuilder() {
|
||||
#if defined(CATCH_CONFIG_FAST_COMPILE)
|
||||
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 );
|
||||
getCurrentContext().getResultCapture()->exceptionEarlyReported();
|
||||
}
|
||||
@ -58,13 +56,25 @@ namespace Catch {
|
||||
}
|
||||
|
||||
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 );
|
||||
handleResult( result );
|
||||
}
|
||||
else
|
||||
getResultCapture().assertionPassed();
|
||||
}
|
||||
|
||||
void ResultBuilder::useActiveException( ResultDisposition::Flags resultDisposition ) {
|
||||
m_assertionInfo.resultDisposition = resultDisposition;
|
||||
m_stream().oss << Catch::translateActiveException();
|
||||
stream().oss << Catch::translateActiveException();
|
||||
captureResult( ResultWas::ThrewException );
|
||||
}
|
||||
|
||||
@ -142,16 +152,11 @@ namespace Catch {
|
||||
// It should immediately be passed to handleResult; if the expression
|
||||
// needs to be reported, its string expansion must be composed before
|
||||
// the temporaries are destroyed.
|
||||
AssertionResult ResultBuilder::build( DecomposedExpression const& expr ) const
|
||||
{
|
||||
AssertionResult ResultBuilder::build( DecomposedExpression const& expr ) const {
|
||||
assert( m_data.resultType != ResultWas::Unknown );
|
||||
AssertionResultData data = m_data;
|
||||
|
||||
// Flip bool results if FalseTest flag is set
|
||||
if( isFalseTest( m_assertionInfo.resultDisposition ) ) {
|
||||
data.negate( expr.isBinaryExpression() );
|
||||
}
|
||||
|
||||
if(m_usedStream)
|
||||
data.message = m_stream().oss.str();
|
||||
data.decomposedExpression = &expr; // for lazy reconstruction
|
||||
return AssertionResult( m_assertionInfo, data );
|
||||
@ -168,7 +173,15 @@ namespace Catch {
|
||||
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;
|
||||
return s;
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ namespace Catch {
|
||||
|
||||
template<typename T>
|
||||
ResultBuilder& operator << ( T const& value ) {
|
||||
m_stream().oss << value;
|
||||
stream().oss << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -79,11 +79,13 @@ namespace Catch {
|
||||
AssertionInfo m_assertionInfo;
|
||||
AssertionResultData m_data;
|
||||
|
||||
static CopyableStream& m_stream();
|
||||
CopyableStream& stream();
|
||||
static CopyableStream& s_stream();
|
||||
|
||||
bool m_shouldDebugBreak = false;
|
||||
bool m_shouldThrow = false;
|
||||
bool m_guardException = false;
|
||||
bool m_usedStream = false;
|
||||
};
|
||||
|
||||
} // namespace Catch
|
||||
|
@ -213,6 +213,20 @@ namespace Catch {
|
||||
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 {
|
||||
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 bool lastAssertionPassed() override;
|
||||
|
||||
virtual void assertionPassed();
|
||||
|
||||
virtual void assertionRun();
|
||||
|
||||
public:
|
||||
// !TBD We need to do this another way!
|
||||
bool aborting() const override;
|
||||
@ -113,6 +119,7 @@ namespace Catch {
|
||||
std::vector<SectionEndInfo> m_unfinishedSections;
|
||||
std::vector<ITracker*> m_activeSections;
|
||||
TrackerContext m_trackerContext;
|
||||
size_t m_prevPassed = 0;
|
||||
bool m_shouldReportUnexpected = true;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user