Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorMartin Hořeňovský2017-06-26 19:08:42 +0200
committerMartin Hořeňovský2017-06-26 19:08:42 +0200
commitc5bac73cadd0441b656242e4b80d3abb8f9d7461 (patch)
tree5234da9c599c9141d85398f40f28610c8c31507d /include
parent1e7000ed559973a44031e21967c56ed7bf29747c (diff)
parent8a14af701e020311f9e7b13a0adba2692b12d5ec (diff)
downloadcatch3-c5bac73cadd0441b656242e4b80d3abb8f9d7461.tar.gz
Merge branch 'master' into dev-modernize
This includes the performance commits done recently
Diffstat (limited to 'include')
-rw-r--r--include/internal/catch_assertionresult.h12
-rw-r--r--include/internal/catch_assertionresult.hpp28
-rw-r--r--include/internal/catch_result_builder.h9
-rw-r--r--include/internal/catch_result_builder.hpp21
-rw-r--r--include/internal/catch_run_context.hpp8
5 files changed, 45 insertions, 33 deletions
diff --git a/include/internal/catch_assertionresult.h b/include/internal/catch_assertionresult.h
index 3f7bc7af..5500707a 100644
--- a/include/internal/catch_assertionresult.h
+++ b/include/internal/catch_assertionresult.h
@@ -40,15 +40,17 @@ namespace Catch {
struct AssertionInfo
{
AssertionInfo() {}
- AssertionInfo( std::string const& _macroName,
+ AssertionInfo( char const * _macroName,
SourceLineInfo const& _lineInfo,
- std::string const& _capturedExpression,
- ResultDisposition::Flags _resultDisposition );
+ char const * _capturedExpression,
+ ResultDisposition::Flags _resultDisposition,
+ char const * _secondArg = "");
- std::string macroName;
+ char const * macroName;
SourceLineInfo lineInfo;
- std::string capturedExpression;
+ char const * capturedExpression;
ResultDisposition::Flags resultDisposition;
+ char const * secondArg;
};
struct AssertionResultData
diff --git a/include/internal/catch_assertionresult.hpp b/include/internal/catch_assertionresult.hpp
index bbabaf1f..81a2dc7c 100644
--- a/include/internal/catch_assertionresult.hpp
+++ b/include/internal/catch_assertionresult.hpp
@@ -13,14 +13,16 @@
namespace Catch {
- AssertionInfo::AssertionInfo( std::string const& _macroName,
+ AssertionInfo::AssertionInfo( char const * _macroName,
SourceLineInfo const& _lineInfo,
- std::string const& _capturedExpression,
- ResultDisposition::Flags _resultDisposition )
+ char const * _capturedExpression,
+ ResultDisposition::Flags _resultDisposition,
+ char const * _secondArg)
: macroName( _macroName ),
lineInfo( _lineInfo ),
capturedExpression( _capturedExpression ),
- resultDisposition( _resultDisposition )
+ resultDisposition( _resultDisposition ),
+ secondArg( _secondArg )
{}
AssertionResult::AssertionResult() {}
@@ -47,24 +49,30 @@ namespace Catch {
}
bool AssertionResult::hasExpression() const {
- return !m_info.capturedExpression.empty();
+ return m_info.capturedExpression[0] != 0;
}
bool AssertionResult::hasMessage() const {
return !m_resultData.message.empty();
}
+ std::string capturedExpressionWithSecondArgument( char const * capturedExpression, char const * secondArg ) {
+ return (secondArg[0] == 0 || secondArg[0] == '"' && secondArg[1] == '"')
+ ? capturedExpression
+ : std::string(capturedExpression) + ", " + secondArg;
+ }
+
std::string AssertionResult::getExpression() const {
if( isFalseTest( m_info.resultDisposition ) )
- return '!' + m_info.capturedExpression;
+ return '!' + capturedExpressionWithSecondArgument(m_info.capturedExpression, m_info.secondArg);
else
- return m_info.capturedExpression;
+ return capturedExpressionWithSecondArgument(m_info.capturedExpression, m_info.secondArg);
}
std::string AssertionResult::getExpressionInMacro() const {
- if( m_info.macroName.empty() )
- return m_info.capturedExpression;
+ if( m_info.macroName[0] == 0 )
+ return capturedExpressionWithSecondArgument(m_info.capturedExpression, m_info.secondArg);
else
- return m_info.macroName + "( " + m_info.capturedExpression + " )";
+ return std::string(m_info.macroName) + "( " + capturedExpressionWithSecondArgument(m_info.capturedExpression, m_info.secondArg) + " )";
}
bool AssertionResult::hasExpandedExpression() const {
diff --git a/include/internal/catch_result_builder.h b/include/internal/catch_result_builder.h
index 65483198..2d17f4d4 100644
--- a/include/internal/catch_result_builder.h
+++ b/include/internal/catch_result_builder.h
@@ -47,7 +47,7 @@ namespace Catch {
template<typename T>
ResultBuilder& operator << ( T const& value ) {
- m_stream.oss << value;
+ m_stream().oss << value;
return *this;
}
@@ -80,7 +80,12 @@ namespace Catch {
private:
AssertionInfo m_assertionInfo;
AssertionResultData m_data;
- CopyableStream m_stream;
+
+ static CopyableStream &m_stream()
+ {
+ static CopyableStream s;
+ return s;
+ }
bool m_shouldDebugBreak = false;
bool m_shouldThrow = false;
diff --git a/include/internal/catch_result_builder.hpp b/include/internal/catch_result_builder.hpp
index 4eea95fe..d477b8af 100644
--- a/include/internal/catch_result_builder.hpp
+++ b/include/internal/catch_result_builder.hpp
@@ -18,23 +18,20 @@
namespace Catch {
- std::string capturedExpressionWithSecondArgument( std::string const& capturedExpression, std::string const& secondArg ) {
- return secondArg.empty() || secondArg == "\"\""
- ? capturedExpression
- : capturedExpression + ", " + secondArg;
- }
ResultBuilder::ResultBuilder( char const* macroName,
SourceLineInfo const& lineInfo,
char const* capturedExpression,
ResultDisposition::Flags resultDisposition,
char const* secondArg )
- : m_assertionInfo( macroName, lineInfo, capturedExpressionWithSecondArgument( capturedExpression, secondArg ), resultDisposition )
- {}
+ : m_assertionInfo( macroName, lineInfo, capturedExpression, resultDisposition, secondArg )
+ {
+ 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";
+ m_stream().oss << "Exception translation was disabled by CATCH_CONFIG_FAST_COMPILE";
captureResult( ResultWas::ThrewException );
getCurrentContext().getResultCapture()->exceptionEarlyReported();
}
@@ -57,7 +54,7 @@ namespace Catch {
void ResultBuilder::useActiveException( ResultDisposition::Flags resultDisposition ) {
m_assertionInfo.resultDisposition = resultDisposition;
- m_stream.oss << Catch::translateActiveException();
+ m_stream().oss << Catch::translateActiveException();
captureResult( ResultWas::ThrewException );
}
@@ -79,7 +76,7 @@ namespace Catch {
assert( !isFalseTest( m_assertionInfo.resultDisposition ) );
AssertionResultData data = m_data;
data.resultType = ResultWas::Ok;
- data.reconstructedExpression = m_assertionInfo.capturedExpression;
+ data.reconstructedExpression = capturedExpressionWithSecondArgument(m_assertionInfo.capturedExpression, m_assertionInfo.secondArg);
std::string actualMessage = Catch::translateActiveException();
if( !matcher.match( actualMessage ) ) {
@@ -145,13 +142,13 @@ namespace Catch {
data.negate( expr.isBinaryExpression() );
}
- data.message = m_stream.oss.str();
+ data.message = m_stream().oss.str();
data.decomposedExpression = &expr; // for lazy reconstruction
return AssertionResult( m_assertionInfo, data );
}
void ResultBuilder::reconstructExpression( std::string& dest ) const {
- dest = m_assertionInfo.capturedExpression;
+ dest = capturedExpressionWithSecondArgument(m_assertionInfo.capturedExpression, m_assertionInfo.secondArg);
}
void ResultBuilder::setExceptionGuard() {
diff --git a/include/internal/catch_run_context.hpp b/include/internal/catch_run_context.hpp
index 375d8cb6..e4ae981b 100644
--- a/include/internal/catch_run_context.hpp
+++ b/include/internal/catch_run_context.hpp
@@ -147,7 +147,7 @@ namespace Catch {
static_cast<void>(m_reporter->assertionEnded(AssertionStats(result, m_messages, m_totals)));
// Reset working state
- m_lastAssertionInfo = AssertionInfo( std::string(), m_lastAssertionInfo.lineInfo, "{Unknown expression after the reported line}" , m_lastAssertionInfo.resultDisposition );
+ m_lastAssertionInfo = AssertionInfo( "", m_lastAssertionInfo.lineInfo, "{Unknown expression after the reported line}" , m_lastAssertionInfo.resultDisposition );
m_lastResult = result;
}
@@ -277,7 +277,7 @@ namespace Catch {
double duration = 0;
m_shouldReportUnexpected = true;
try {
- m_lastAssertionInfo = AssertionInfo( "TEST_CASE", testCaseInfo.lineInfo, std::string(), ResultDisposition::Normal );
+ m_lastAssertionInfo = AssertionInfo( "TEST_CASE", testCaseInfo.lineInfo, "", ResultDisposition::Normal );
seedRng( *m_config );
@@ -329,9 +329,9 @@ namespace Catch {
private:
ResultBuilder makeUnexpectedResultBuilder() const {
- return ResultBuilder( m_lastAssertionInfo.macroName.c_str(),
+ return ResultBuilder( m_lastAssertionInfo.macroName,
m_lastAssertionInfo.lineInfo,
- m_lastAssertionInfo.capturedExpression.c_str(),
+ m_lastAssertionInfo.capturedExpression,
m_lastAssertionInfo.resultDisposition );
}