- Fixed endianness when converting numbers to hex strings
- Added option to show invisibles (/t, /n) in printed strings with -i
- moved toString() impls to impl file
- avoid allocations for static strings used in reporter
This commit is contained in:
Phil Nash 2014-04-23 07:10:10 +01:00
parent 31caba4f73
commit aef6cd5332
3 changed files with 186 additions and 122 deletions

View File

@ -1,6 +1,6 @@
![catch logo](catch-logo-small.png)
*v1.0 build 39 (master branch)*
*v1.0 build 40 (master branch)*
Build status (on Travis CI) [![Build Status](https://travis-ci.org/philsquared/Catch.png)](https://travis-ci.org/philsquared/Catch)

View File

@ -13,7 +13,7 @@
namespace Catch {
// These numbers are maintained by a script
Version libraryVersion( 1, 0, 39, "master" );
Version libraryVersion( 1, 0, 40, "master" );
}
#endif // TWOBLUECUBES_CATCH_VERSION_HPP_INCLUDED

View File

@ -1,6 +1,6 @@
/*
* CATCH v1.0 build 39 (master branch)
* Generated: 2014-04-21 18:50:19.658444
* CATCH v1.0 build 40 (master branch)
* Generated: 2014-04-23 07:07:39.268798
* ----------------------------------------------------------
* This file has been merged from multiple headers. Please don't edit it directly
* Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.
@ -576,8 +576,8 @@ private:
// #included from: catch_expressionresult_builder.h
#define TWOBLUECUBES_CATCH_ASSERTIONRESULT_BUILDER_H_INCLUDED
// #included from: catch_tostring.hpp
#define TWOBLUECUBES_CATCH_TOSTRING_HPP_INCLUDED
// #included from: catch_tostring.h
#define TWOBLUECUBES_CATCH_TOSTRING_H_INCLUDED
// #included from: catch_sfinae.hpp
#define TWOBLUECUBES_CATCH_SFINAE_HPP_INCLUDED
@ -723,8 +723,21 @@ namespace Detail {
}
};
// For display purposes only.
// Does not consider endian-ness
struct Endianness {
enum Arch { Big, Little };
static Arch which() {
union {
int asInt;
char asChar[sizeof (int)];
};
asInt = 1;
return ( asChar[sizeof(int)-1] == 1 ) ? Big : Little;
}
};
// Writes the raw memory into a string, considering endianness
template<typename T>
std::string rawMemoryToString( T value ) {
union {
@ -736,8 +749,14 @@ namespace Detail {
std::ostringstream oss;
oss << "0x";
for( unsigned char* cp = bytes; cp < bytes+sizeof(T); ++cp )
oss << std::hex << std::setw(2) << std::setfill('0') << (unsigned int)*cp;
int i = 0, end = sizeof(T), inc = 1;
if( Endianness::which() == Endianness::Little ) {
i = end-1;
end = inc = -1;
}
for( ; i != end; i += inc )
oss << std::hex << std::setw(2) << std::setfill('0') << (unsigned int)bytes[i];
return oss.str();
}
@ -785,7 +804,7 @@ struct StringMaker<std::vector<T, Allocator> > {
namespace Detail {
template<typename T>
inline std::string makeString( T const& value ) {
std::string makeString( T const& value ) {
return StringMaker<T>::convert( value );
}
} // end namespace Detail
@ -804,99 +823,27 @@ std::string toString( T const& value ) {
// Built in overloads
inline std::string toString( std::string const& value ) {
return "\"" + value + "\"";
}
inline std::string toString( std::wstring const& value ) {
std::ostringstream oss;
oss << "\"";
for(size_t i = 0; i < value.size(); ++i )
oss << static_cast<char>( value[i] <= 0xff ? value[i] : '?');
oss << "\"";
return oss.str();
}
inline std::string toString( const char* const value ) {
return value ? Catch::toString( std::string( value ) ) : std::string( "{null string}" );
}
inline std::string toString( char* const value ) {
return Catch::toString( static_cast<const char*>( value ) );
}
inline std::string toString( int value ) {
std::ostringstream oss;
oss << value;
return oss.str();
}
inline std::string toString( unsigned long value ) {
std::ostringstream oss;
if( value > 8192 )
oss << "0x" << std::hex << value;
else
oss << value;
return oss.str();
}
inline std::string toString( unsigned int value ) {
return toString( static_cast<unsigned long>( value ) );
}
inline std::string toString( const double value ) {
std::ostringstream oss;
oss << std::setprecision( 10 )
<< std::fixed
<< value;
std::string d = oss.str();
std::size_t i = d.find_last_not_of( '0' );
if( i != std::string::npos && i != d.size()-1 ) {
if( d[i] == '.' )
i++;
d = d.substr( 0, i+1 );
}
return d;
}
inline std::string toString( bool value ) {
return value ? "true" : "false";
}
inline std::string toString( char value ) {
return value < ' '
? toString( static_cast<unsigned int>( value ) )
: Detail::makeString( value );
}
inline std::string toString( signed char value ) {
return toString( static_cast<char>( value ) );
}
inline std::string toString( unsigned char value ) {
return toString( static_cast<char>( value ) );
}
std::string toString( std::string const& value );
std::string toString( std::wstring const& value );
std::string toString( const char* const value );
std::string toString( char* const value );
std::string toString( int value );
std::string toString( unsigned long value );
std::string toString( unsigned int value );
std::string toString( const double value );
std::string toString( bool value );
std::string toString( char value );
std::string toString( signed char value );
std::string toString( unsigned char value );
#ifdef CATCH_CONFIG_CPP11_NULLPTR
inline std::string toString( std::nullptr_t ) {
return "nullptr";
}
std::string toString( std::nullptr_t );
#endif
#ifdef __OBJC__
inline std::string toString( NSString const * const& nsstring ) {
if( !nsstring )
return "nil";
return std::string( "@\"" ) + [nsstring UTF8String] + "\"";
}
inline std::string toString( NSString * CATCH_ARC_STRONG const& nsstring ) {
if( !nsstring )
return "nil";
return std::string( "@\"" ) + [nsstring UTF8String] + "\"";
}
inline std::string toString( NSObject* const& nsObject ) {
return toString( [nsObject description] );
}
std::string toString( NSString const * const& nsstring );
std::string toString( NSString * CATCH_ARC_STRONG const& nsstring );
std::string toString( NSObject* const& nsObject );
#endif
namespace Detail {
@ -1575,6 +1522,7 @@ namespace Catch {
virtual bool shouldDebugBreak() const = 0;
virtual bool warnAboutMissingAssertions() const = 0;
virtual int abortAfter() const = 0;
virtual bool showInvisibles() const = 0;
virtual ShowDurations::OrNot showDurations() const = 0;
virtual std::vector<TestCaseFilters> const& filters() const = 0;
};
@ -2925,6 +2873,7 @@ namespace Catch {
shouldDebugBreak( false ),
noThrow( false ),
showHelp( false ),
showInvisibles( false ),
abortAfter( -1 ),
verbosity( Verbosity::Normal ),
warnings( WarnAbout::Nothing ),
@ -2940,6 +2889,7 @@ namespace Catch {
bool shouldDebugBreak;
bool noThrow;
bool showHelp;
bool showInvisibles;
int abortAfter;
@ -3043,6 +2993,7 @@ namespace Catch {
}
bool showHelp() const { return m_data.showHelp; }
bool showInvisibles() const { return m_data.showInvisibles; }
// IConfig interface
virtual bool allowThrows() const { return !m_data.noThrow; }
@ -4002,6 +3953,10 @@ namespace Catch {
.describe( "skip exception tests" )
.bind( &ConfigData::noThrow );
cli["-i"]["--invisibles"]
.describe( "show invisibles (tabs, newlines)" )
.bind( &ConfigData::showInvisibles );
cli["-o"]["--out"]
.describe( "output filename" )
.bind( &ConfigData::outputFilename, "filename" );
@ -6697,7 +6652,7 @@ namespace Catch {
namespace Catch {
// These numbers are maintained by a script
Version libraryVersion( 1, 0, 39, "master" );
Version libraryVersion( 1, 0, 40, "master" );
}
// #included from: catch_message.hpp
@ -7096,6 +7051,122 @@ namespace Catch {
}
#endif // Platform
// #included from: catch_tostring.hpp
#define TWOBLUECUBES_CATCH_TOSTRING_HPP_INCLUDED
namespace Catch {
std::string toString( std::string const& value ) {
std::string s = value;
if( getCurrentContext().getConfig()->showInvisibles() ) {
for(size_t i = 0; i < s.size(); ++i ) {
std::string subs;
switch( s[i] ) {
case '\n': subs = "\\n"; break;
case '\t': subs = "\\t"; break;
default: break;
}
if( !subs.empty() ) {
s = s.substr( 0, i ) + subs + s.substr( i+1 );
++i;
}
}
}
return "\"" + s + "\"";
}
std::string toString( std::wstring const& value ) {
std::string s;
s.reserve( value.size() );
for(size_t i = 0; i < value.size(); ++i )
s += value[i] <= 0xff ? static_cast<char>( value[i] ) : '?';
return toString( s );
}
std::string toString( const char* const value ) {
return value ? Catch::toString( std::string( value ) ) : std::string( "{null string}" );
}
std::string toString( char* const value ) {
return Catch::toString( static_cast<const char*>( value ) );
}
std::string toString( int value ) {
std::ostringstream oss;
oss << value;
return oss.str();
}
std::string toString( unsigned long value ) {
std::ostringstream oss;
if( value > 8192 )
oss << "0x" << std::hex << value;
else
oss << value;
return oss.str();
}
std::string toString( unsigned int value ) {
return toString( static_cast<unsigned long>( value ) );
}
std::string toString( const double value ) {
std::ostringstream oss;
oss << std::setprecision( 10 )
<< std::fixed
<< value;
std::string d = oss.str();
std::size_t i = d.find_last_not_of( '0' );
if( i != std::string::npos && i != d.size()-1 ) {
if( d[i] == '.' )
i++;
d = d.substr( 0, i+1 );
}
return d;
}
std::string toString( bool value ) {
return value ? "true" : "false";
}
std::string toString( char value ) {
return value < ' '
? toString( static_cast<unsigned int>( value ) )
: Detail::makeString( value );
}
std::string toString( signed char value ) {
return toString( static_cast<char>( value ) );
}
std::string toString( unsigned char value ) {
return toString( static_cast<char>( value ) );
}
#ifdef CATCH_CONFIG_CPP11_NULLPTR
std::string toString( std::nullptr_t ) {
return "nullptr";
}
#endif
#ifdef __OBJC__
std::string toString( NSString const * const& nsstring ) {
if( !nsstring )
return "nil";
return std::string( "@\"" ) + [nsstring UTF8String] + "\"";
}
std::string toString( NSString * CATCH_ARC_STRONG const& nsstring ) {
if( !nsstring )
return "nil";
return std::string( "@\"" ) + [nsstring UTF8String] + "\"";
}
std::string toString( NSObject* const& nsObject ) {
return toString( [nsObject description] );
}
#endif
} // end namespace Catch
// #included from: ../reporters/catch_reporter_xml.hpp
#define TWOBLUECUBES_CATCH_REPORTER_XML_HPP_INCLUDED
@ -8156,7 +8227,7 @@ namespace Catch {
m_atLeastOneTestCasePrinted = true;
}
void lazyPrintRunInfo() {
stream << "\n" << getTildes() << "\n";
stream << "\n" << getLineOfChars<'~'>() << "\n";
Colour colour( Colour::SecondaryText );
stream << currentTestRunInfo->name
<< " is a Catch v" << libraryVersion.majorVersion << "."
@ -8192,19 +8263,19 @@ namespace Catch {
SourceLineInfo lineInfo = m_sectionStack.front().lineInfo;
if( !lineInfo.empty() ){
stream << getDashes() << "\n";
stream << getLineOfChars<'-'>() << "\n";
Colour colourGuard( Colour::FileName );
stream << lineInfo << "\n";
}
stream << getDots() << "\n" << std::endl;
stream << getLineOfChars<'.'>() << "\n" << std::endl;
}
void printClosedHeader( std::string const& _name ) {
printOpenHeader( _name );
stream << getDots() << "\n";
stream << getLineOfChars<'.'>() << "\n";
}
void printOpenHeader( std::string const& _name ) {
stream << getDashes() << "\n";
stream << getLineOfChars<'-'>() << "\n";
{
Colour colourGuard( Colour::Headers );
printHeaderString( _name );
@ -8277,26 +8348,19 @@ namespace Catch {
}
void printTotalsDivider() {
stream << getDoubleDashes() << "\n";
stream << getLineOfChars<'='>() << "\n";
}
void printSummaryDivider() {
stream << getDashes() << "\n";
stream << getLineOfChars<'-'>() << "\n";
}
static std::string const& getDashes() {
static const std::string dashes( CATCH_CONFIG_CONSOLE_WIDTH-1, '-' );
return dashes;
template<char C>
static char const* getLineOfChars() {
static char line[CATCH_CONFIG_CONSOLE_WIDTH] = {0};
if( !*line ) {
memset( line, C, CATCH_CONFIG_CONSOLE_WIDTH-1 );
line[CATCH_CONFIG_CONSOLE_WIDTH-1] = 0;
}
static std::string const& getDots() {
static const std::string dots( CATCH_CONFIG_CONSOLE_WIDTH-1, '.' );
return dots;
}
static std::string const& getDoubleDashes() {
static const std::string doubleDashes( CATCH_CONFIG_CONSOLE_WIDTH-1, '=' );
return doubleDashes;
}
static std::string const& getTildes() {
static const std::string dots( CATCH_CONFIG_CONSOLE_WIDTH-1, '~' );
return dots;
return line;
}
private: