Split original/ expanded expressions over multiple lines

This commit is contained in:
Phil Nash 2012-12-14 07:49:18 +00:00
parent eac51f38bd
commit 86ad6348d4
3 changed files with 2409 additions and 1055 deletions

View File

@ -121,7 +121,7 @@ inline std::string toString( bool value ) {
inline std::string toString( char value ) { inline std::string toString( char value ) {
return value < ' ' return value < ' '
? toString( (unsigned int)value ) ? toString( static_cast<unsigned int>( value ) )
: Detail::makeString( value ); : Detail::makeString( value );
} }
@ -129,6 +129,10 @@ inline std::string toString( signed char value ) {
return toString( static_cast<char>( value ) ); return toString( static_cast<char>( value ) );
} }
inline std::string toString( unsigned char value ) {
return toString( static_cast<char>( value ) );
}
#ifdef CATCH_CONFIG_CPP11_NULLPTR #ifdef CATCH_CONFIG_CPP11_NULLPTR
inline std::string toString( std::nullptr_t ) { inline std::string toString( std::nullptr_t ) {
return "nullptr"; return "nullptr";

View File

@ -66,6 +66,14 @@ namespace Catch {
static const std::string doubleDashes = "================================================================"; static const std::string doubleDashes = "================================================================";
return doubleDashes; return doubleDashes;
} }
static std::string const& getSpaces() {
static const std::string spaces = " ";
return spaces;
}
static std::string getSpaces( int spaces ) {
return getSpaces().substr( 0, spaces > 0 ? static_cast<std::size_t>( spaces ) : 0 );
}
void printHeader( std::string const& _type, std::string const& _name ) { void printHeader( std::string const& _type, std::string const& _name ) {
std::size_t labelLen = _type.size() + _name.size() + 8; std::size_t labelLen = _type.size() + _name.size() + 8;
std::size_t dashLen = getDashes().size(); std::size_t dashLen = getDashes().size();
@ -97,18 +105,18 @@ namespace Catch {
lazyPrint(); lazyPrint();
printLineInfo( result.getSourceInfo() ); int inset = printLineInfo( result.getSourceInfo() );
if( result.hasExpression() ) { if( result.hasExpression() ) {
TextColour colour( TextColour::OriginalExpression ); TextColour colour( TextColour::OriginalExpression );
stream << result.getExpression(); stream << result.getExpression() << "\n";
if( result.succeeded() ) { if( result.succeeded() ) {
TextColour successColour( TextColour::Success ); TextColour successColour( TextColour::Success );
stream << " succeeded"; stream << "succeeded";
} }
else { else {
TextColour errorColour( TextColour::Error ); TextColour errorColour( TextColour::Error );
stream << " failed"; stream << "failed";
if( result.isOk() ) { if( result.isOk() ) {
TextColour okAnywayColour( TextColour::Success ); TextColour okAnywayColour( TextColour::Success );
stream << " - but was ok"; stream << " - but was ok";
@ -182,17 +190,12 @@ namespace Catch {
} }
if( result.hasExpandedExpression() ) { if( result.hasExpandedExpression() ) {
stream << " for: "; stream << "\nfor: ";
if( result.getExpandedExpression().size() > 40 ) {
stream << "\n";
if( result.getExpandedExpression().size() < 70 )
stream << "\t";
}
TextColour colour( TextColour::ReconstructedExpression ); TextColour colour( TextColour::ReconstructedExpression );
stream << result.getExpandedExpression(); stream << getSpaces( inset-5 ) << result.getExpandedExpression();
} }
stream << std::endl; stream << "\n" << std::endl;
} }
void streamVariableLengthText( std::string const& prefix, std::string const& text ) { void streamVariableLengthText( std::string const& prefix, std::string const& text ) {
@ -319,21 +322,26 @@ namespace Catch {
void printSummarDivider() { void printSummarDivider() {
stream << "----------------------------------------------------------------\n"; stream << "----------------------------------------------------------------\n";
} }
static int countDigits( std::size_t number ) {
int digits = 1;
for( ; number != 0; digits++, number /= 10 );
return digits;
}
void printLineInfo( SourceLineInfo const& lineInfo ) { // Returns number of characters printed
if( !lineInfo.empty() ) { int printLineInfo( SourceLineInfo const& lineInfo ) {
if( m_lastPrintedLine.empty() || if( lineInfo.empty() )
m_lastPrintedLine.file != lineInfo.file || return 0;
abs( static_cast<int>( m_lastPrintedLine.line ) - static_cast<int>( lineInfo.line ) ) > 20 ) { if( m_lastPrintedLine.empty() ||
TextColour colour( TextColour::FileName ); m_lastPrintedLine.file != lineInfo.file ||
stream << lineInfo << "\n"; abs( static_cast<int>( m_lastPrintedLine.line ) - static_cast<int>( lineInfo.line ) ) > 20 ) {
m_lastPrintedLine = lineInfo; TextColour colour( TextColour::FileName );
} stream << lineInfo << "\n";
else if( lineInfo.line != m_lastPrintedLine.line ) {
TextColour colour( TextColour::FileName );
stream << "line " << lineInfo.line << ":\n";
}
} }
TextColour colour( TextColour::FileName );
stream << "[" << lineInfo.line << "] ";
m_lastPrintedLine = lineInfo;
return 3 + countDigits( lineInfo.line );
} }
void resetLastPrintedLine() { void resetLastPrintedLine() {
m_lastPrintedLine = SourceLineInfo(); m_lastPrintedLine = SourceLineInfo();

File diff suppressed because it is too large Load Diff