Eliminated objects that hold constant strings. Aids step-debugging in MSVC

This commit is contained in:
Craig Henderson 2013-10-12 10:00:18 +01:00
parent 1fe459572e
commit aef47282ec
6 changed files with 21 additions and 21 deletions

View File

@ -16,14 +16,14 @@ namespace Catch {
struct AssertionInfo struct AssertionInfo
{ {
AssertionInfo() {} AssertionInfo() {}
AssertionInfo( std::string const& _macroName, AssertionInfo( char const * _macroName,
SourceLineInfo const& _lineInfo, SourceLineInfo const& _lineInfo,
std::string const& _capturedExpression, char const * _capturedExpression,
ResultDisposition::Flags _resultDisposition ); ResultDisposition::Flags _resultDisposition );
std::string macroName; char const * macroName;
SourceLineInfo lineInfo; SourceLineInfo lineInfo;
std::string capturedExpression; char const * capturedExpression;
ResultDisposition::Flags resultDisposition; ResultDisposition::Flags resultDisposition;
}; };
@ -53,7 +53,7 @@ namespace Catch {
std::string getExpandedExpression() const; std::string getExpandedExpression() const;
std::string getMessage() const; std::string getMessage() const;
SourceLineInfo getSourceInfo() const; SourceLineInfo getSourceInfo() const;
std::string getTestMacroName() const; char const * getTestMacroName() const;
protected: protected:
AssertionInfo m_info; AssertionInfo m_info;

View File

@ -13,9 +13,9 @@
namespace Catch { namespace Catch {
AssertionInfo::AssertionInfo( std::string const& _macroName, AssertionInfo::AssertionInfo( char const * _macroName,
SourceLineInfo const& _lineInfo, SourceLineInfo const& _lineInfo,
std::string const& _capturedExpression, char const * _capturedExpression,
ResultDisposition::Flags _resultDisposition ) ResultDisposition::Flags _resultDisposition )
: macroName( _macroName ), : macroName( _macroName ),
lineInfo( _lineInfo ), lineInfo( _lineInfo ),
@ -47,7 +47,7 @@ namespace Catch {
} }
bool AssertionResult::hasExpression() const { bool AssertionResult::hasExpression() const {
return !m_info.capturedExpression.empty(); return m_info.capturedExpression != 0 && *m_info.capturedExpression != 0;
} }
bool AssertionResult::hasMessage() const { bool AssertionResult::hasMessage() const {
@ -56,15 +56,15 @@ namespace Catch {
std::string AssertionResult::getExpression() const { std::string AssertionResult::getExpression() const {
if( shouldNegate( m_info.resultDisposition ) ) if( shouldNegate( m_info.resultDisposition ) )
return "!" + m_info.capturedExpression; return std::string("!") + m_info.capturedExpression;
else else
return m_info.capturedExpression; return m_info.capturedExpression;
} }
std::string AssertionResult::getExpressionInMacro() const { std::string AssertionResult::getExpressionInMacro() const {
if( m_info.macroName.empty() ) if( m_info.macroName == 0 || *m_info.macroName == 0)
return m_info.capturedExpression; return m_info.capturedExpression;
else else
return m_info.macroName + "( " + m_info.capturedExpression + " )"; return std::string(m_info.macroName) + "( " + m_info.capturedExpression + " )";
} }
bool AssertionResult::hasExpandedExpression() const { bool AssertionResult::hasExpandedExpression() const {
@ -82,7 +82,7 @@ namespace Catch {
return m_info.lineInfo; return m_info.lineInfo;
} }
std::string AssertionResult::getTestMacroName() const { char const *AssertionResult::getTestMacroName() const {
return m_info.macroName; return m_info.macroName;
} }

View File

@ -105,7 +105,7 @@ namespace Catch {
struct SourceLineInfo { struct SourceLineInfo {
SourceLineInfo() : line( 0 ){} SourceLineInfo() : line( 0 ){}
SourceLineInfo( std::string const& _file, std::size_t _line ) SourceLineInfo( char const * _file, std::size_t _line )
: file( _file ), : file( _file ),
line( _line ) line( _line )
{} {}
@ -114,12 +114,12 @@ namespace Catch {
line( other.line ) line( other.line )
{} {}
bool empty() const { bool empty() const {
return file.empty(); return file == 0 || *file == 0;
} }
bool operator == ( SourceLineInfo const& other ) const { bool operator == ( SourceLineInfo const& other ) const {
return line == other.line && file == other.file; return line == other.line && ((empty() && other.empty()) || strcmp(file, other.file) == 0);
} }
std::string file; char const * file;
std::size_t line; std::size_t line;
}; };

View File

@ -90,7 +90,7 @@ namespace Catch {
return m_exprComponents.lhs + "\n" + m_exprComponents.op + "\n" + m_exprComponents.rhs; return m_exprComponents.lhs + "\n" + m_exprComponents.op + "\n" + m_exprComponents.rhs;
} }
else else
return "{can't expand - use " + info.macroName + "_FALSE( " + info.capturedExpression.substr(1) + " ) instead of " + info.macroName + "( " + info.capturedExpression + " ) for better diagnostics}"; return "{can't expand - use " + std::string(info.macroName) + "_FALSE( " + *(info.capturedExpression+1) + " ) instead of " + info.macroName + "( " + info.capturedExpression + " ) for better diagnostics}";
} }
} // end namespace Catch } // end namespace Catch

View File

@ -15,11 +15,11 @@
namespace Catch { namespace Catch {
struct MessageInfo { struct MessageInfo {
MessageInfo( std::string const& _macroName, MessageInfo( char const * _macroName,
SourceLineInfo const& _lineInfo, SourceLineInfo const& _lineInfo,
ResultWas::OfType _type ); ResultWas::OfType _type );
std::string macroName; char const * macroName;
SourceLineInfo lineInfo; SourceLineInfo lineInfo;
ResultWas::OfType type; ResultWas::OfType type;
std::string message; std::string message;
@ -36,7 +36,7 @@ namespace Catch {
}; };
struct MessageBuilder { struct MessageBuilder {
MessageBuilder( std::string const& macroName, MessageBuilder( char const * macroName,
SourceLineInfo const& lineInfo, SourceLineInfo const& lineInfo,
ResultWas::OfType type ) ResultWas::OfType type )
: m_info( macroName, lineInfo, type ) : m_info( macroName, lineInfo, type )

View File

@ -12,7 +12,7 @@
namespace Catch { namespace Catch {
MessageInfo::MessageInfo( std::string const& _macroName, MessageInfo::MessageInfo( char const * _macroName,
SourceLineInfo const& _lineInfo, SourceLineInfo const& _lineInfo,
ResultWas::OfType _type ) ResultWas::OfType _type )
: macroName( _macroName ), : macroName( _macroName ),