mirror of https://github.com/catchorg/Catch2.git
Build 34
includes: - SFINAE version of IsStreamable (where available) - new Text class that replaces LineWrapper (internal) - fix for spurious double exception reporting (#164)
This commit is contained in:
parent
2666c96d4e
commit
19279250e8
|
@ -1,6 +1,6 @@
|
||||||
![catch logo](https://raw.github.com/philsquared/Catch/Integration/catch-logo-small.png)
|
![catch logo](https://raw.github.com/philsquared/Catch/Integration/catch-logo-small.png)
|
||||||
|
|
||||||
## CATCH v0.9 build 33 (integration branch)
|
## CATCH v0.9 build 34 (integration branch)
|
||||||
An automated test framework for C, C++ and Objective-C.
|
An automated test framework for C, C++ and Objective-C.
|
||||||
|
|
||||||
This branch may contain code that is experimental or not yet fully tested.
|
This branch may contain code that is experimental or not yet fully tested.
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
// These numbers are maintained by a script
|
// These numbers are maintained by a script
|
||||||
Version libraryVersion( 0, 9, 33, "integration" );
|
Version libraryVersion( 0, 9, 34, "integration" );
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_VERSION_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_VERSION_HPP_INCLUDED
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
CatchSelfTest is a CATCH v0.9 b33 (integration) host application.
|
CatchSelfTest is a CATCH v0.9 b34 (integration) host application.
|
||||||
Run with -? for options
|
Run with -? for options
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
@ -5523,7 +5523,7 @@ with message:
|
||||||
|
|
||||||
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
CatchSelfTest is a CATCH v0.9 b33 (integration) host application.
|
CatchSelfTest is a CATCH v0.9 b34 (integration) host application.
|
||||||
Run with -? for options
|
Run with -? for options
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* CATCH v0.9 build 33 (integration branch)
|
* CATCH v0.9 build 34 (integration branch)
|
||||||
* Generated: 2013-04-11 16:33:19.541792
|
* Generated: 2013-04-20 21:05:02.595019
|
||||||
* ----------------------------------------------------------
|
* ----------------------------------------------------------
|
||||||
* This file has been merged from multiple headers. Please don't edit it directly
|
* This file has been merged from multiple headers. Please don't edit it directly
|
||||||
* Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.
|
* Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
@ -504,6 +504,103 @@ private:
|
||||||
// #included from: catch_tostring.hpp
|
// #included from: catch_tostring.hpp
|
||||||
#define TWOBLUECUBES_CATCH_TOSTRING_HPP_INCLUDED
|
#define TWOBLUECUBES_CATCH_TOSTRING_HPP_INCLUDED
|
||||||
|
|
||||||
|
// #included from: catch_sfinae.hpp
|
||||||
|
#define TWOBLUECUBES_CATCH_SFINAE_HPP_INCLUDED
|
||||||
|
|
||||||
|
// Try to detect if the current compiler supports SFINAE
|
||||||
|
// #included from: catch_compiler_capabilities.h
|
||||||
|
#define TWOBLUECUBES_CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED
|
||||||
|
|
||||||
|
// Much of the following code is based on Boost (1.53)
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Borland
|
||||||
|
#ifdef __BORLANDC__
|
||||||
|
|
||||||
|
#if (__BORLANDC__ > 0x582 )
|
||||||
|
//#define CATCH_SFINAE // Not confirmed
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // __BORLANDC__
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// EDG
|
||||||
|
#ifdef __EDG_VERSION__
|
||||||
|
|
||||||
|
#if (__EDG_VERSION__ > 238 )
|
||||||
|
//#define CATCH_SFINAE // Not confirmed
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // __EDG_VERSION__
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Digital Mars
|
||||||
|
#ifdef __DMC__
|
||||||
|
|
||||||
|
#if (__DMC__ > 0x840 )
|
||||||
|
//#define CATCH_SFINAE // Not confirmed
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // __DMC__
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// GCC
|
||||||
|
#ifdef __GNUC__
|
||||||
|
|
||||||
|
#if __GNUC__ < 3
|
||||||
|
|
||||||
|
#if (__GNUC_MINOR__ >= 96 )
|
||||||
|
#define CATCH_SFINAE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#elif __GNUC__ >= 3
|
||||||
|
|
||||||
|
#define CATCH_SFINAE
|
||||||
|
|
||||||
|
#endif // __GNUC__ < 3
|
||||||
|
|
||||||
|
#endif // __GNUC__
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Visual C++
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
|
||||||
|
#if (_MSC_VER >= 1310 ) // (VC++ 7.0+)
|
||||||
|
//#define CATCH_SFINAE // Not confirmed
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // _MSC_VER
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef CATCH_SFINAE
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
|
||||||
|
struct TrueType {
|
||||||
|
static const bool value = true;
|
||||||
|
typedef void Enable;
|
||||||
|
char sizer[1];
|
||||||
|
};
|
||||||
|
struct FalseType {
|
||||||
|
static const bool value = false;
|
||||||
|
typedef void Disable;
|
||||||
|
char sizer[2];
|
||||||
|
};
|
||||||
|
|
||||||
|
template<bool> struct NotABooleanExpression;
|
||||||
|
|
||||||
|
template<bool c> struct If : NotABooleanExpression<c> {};
|
||||||
|
template<> struct If<true> : TrueType {};
|
||||||
|
template<> struct If<false> : FalseType {};
|
||||||
|
|
||||||
|
template<int size> struct SizedIf;
|
||||||
|
template<> struct SizedIf<sizeof(TrueType)> : TrueType {};
|
||||||
|
template<> struct SizedIf<sizeof(FalseType)> : FalseType {};
|
||||||
|
|
||||||
|
} // end namespace Catch
|
||||||
|
|
||||||
|
#endif // CATCH_SFINAE
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
@ -555,6 +652,49 @@ inline id performOptionalSelector( id obj, SEL sel ) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
|
#ifdef CATCH_SFINAE
|
||||||
|
|
||||||
|
namespace Detail {
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class IsStreamInsertableHelper {
|
||||||
|
template<int N> struct TrueIfSizeable : TrueType {};
|
||||||
|
|
||||||
|
template<typename T2>
|
||||||
|
static TrueIfSizeable<sizeof((*(std::ostream*)0) << *((T2 const*)0))> dummy(T2*);
|
||||||
|
static FalseType dummy(...);
|
||||||
|
|
||||||
|
public:
|
||||||
|
typedef SizedIf<sizeof(dummy((T*)0))> type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct IsStreamInsertable : IsStreamInsertableHelper<T>::type {};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void toStream( std::ostream& os, T const& value, typename IsStreamInsertable<T>::Enable* = 0 ) {
|
||||||
|
os << value;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void toStream( std::ostream& os, T const&, typename IsStreamInsertable<T>::Disable* = 0 ) {
|
||||||
|
os << "{?}";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct StringMaker {
|
||||||
|
static std::string convert( T const& value ) {
|
||||||
|
std::ostringstream oss;
|
||||||
|
Detail::toStream( oss, value );
|
||||||
|
return oss.str();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
namespace Detail {
|
namespace Detail {
|
||||||
|
|
||||||
struct NonStreamable {
|
struct NonStreamable {
|
||||||
|
@ -577,6 +717,9 @@ struct StringMaker {
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct StringMaker<T*> {
|
struct StringMaker<T*> {
|
||||||
static std::string convert( T const* p ) {
|
static std::string convert( T const* p ) {
|
||||||
|
@ -594,7 +737,7 @@ struct StringMaker<std::vector<T> > {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << "{ ";
|
oss << "{ ";
|
||||||
for( std::size_t i = 0; i < v.size(); ++ i ) {
|
for( std::size_t i = 0; i < v.size(); ++ i ) {
|
||||||
oss << v[i];
|
oss << toString( v[i] );
|
||||||
if( i < v.size() - 1 )
|
if( i < v.size() - 1 )
|
||||||
oss << ", ";
|
oss << ", ";
|
||||||
}
|
}
|
||||||
|
@ -620,7 +763,6 @@ namespace Detail {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
std::string toString( const T& value ) {
|
std::string toString( const T& value ) {
|
||||||
return StringMaker<T>::convert( value );
|
return StringMaker<T>::convert( value );
|
||||||
// return Detail::makeString( value );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Built in overloads
|
// Built in overloads
|
||||||
|
@ -2528,7 +2670,6 @@ inline bool isTrue( bool value ){ return value; }
|
||||||
} catch( ... ) { \
|
} catch( ... ) { \
|
||||||
INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionResultBuilder( Catch::ResultWas::ThrewException ) << Catch::translateActiveException(), \
|
INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionResultBuilder( Catch::ResultWas::ThrewException ) << Catch::translateActiveException(), \
|
||||||
resultDisposition | Catch::ResultDisposition::ContinueOnFailure, expr ); \
|
resultDisposition | Catch::ResultDisposition::ContinueOnFailure, expr ); \
|
||||||
throw; \
|
|
||||||
} \
|
} \
|
||||||
} while( Catch::isTrue( false ) )
|
} while( Catch::isTrue( false ) )
|
||||||
|
|
||||||
|
@ -2618,7 +2759,6 @@ inline bool isTrue( bool value ){ return value; }
|
||||||
} catch( ... ) { \
|
} catch( ... ) { \
|
||||||
INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionResultBuilder( Catch::ResultWas::ThrewException ) << Catch::translateActiveException() ), \
|
INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionResultBuilder( Catch::ResultWas::ThrewException ) << Catch::translateActiveException() ), \
|
||||||
resultDisposition | Catch::ResultDisposition::ContinueOnFailure, false ); \
|
resultDisposition | Catch::ResultDisposition::ContinueOnFailure, false ); \
|
||||||
throw; \
|
|
||||||
} \
|
} \
|
||||||
} while( Catch::isTrue( false ) )
|
} while( Catch::isTrue( false ) )
|
||||||
|
|
||||||
|
@ -4085,26 +4225,37 @@ namespace Catch {
|
||||||
// #included from: internal/catch_list.hpp
|
// #included from: internal/catch_list.hpp
|
||||||
#define TWOBLUECUBES_CATCH_LIST_HPP_INCLUDED
|
#define TWOBLUECUBES_CATCH_LIST_HPP_INCLUDED
|
||||||
|
|
||||||
// #included from: catch_line_wrap.h
|
// #included from: catch_text.h
|
||||||
#define TWOBLUECUBES_CATCH_LINE_WRAP_H_INCLUDED
|
#define TWOBLUECUBES_CATCH_TEXT_H_INCLUDED
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
class LineWrapper {
|
struct TextAttributes {
|
||||||
|
TextAttributes()
|
||||||
|
: initialIndent( std::string::npos ),
|
||||||
|
indent( 0 ),
|
||||||
|
width( CATCH_CONFIG_CONSOLE_WIDTH-1 ),
|
||||||
|
tabChar( '\t' )
|
||||||
|
{}
|
||||||
|
|
||||||
|
TextAttributes& setInitialIndent( std::size_t _value ) { initialIndent = _value; return *this; }
|
||||||
|
TextAttributes& setIndent( std::size_t _value ) { indent = _value; return *this; }
|
||||||
|
TextAttributes& setWidth( std::size_t _value ) { width = _value; return *this; }
|
||||||
|
TextAttributes& setTabChar( char _value ) { tabChar = _value; return *this; }
|
||||||
|
|
||||||
|
std::size_t initialIndent; // indent of first line, or npos
|
||||||
|
std::size_t indent; // indent of subsequent lines, or all if initialIndent is npos
|
||||||
|
std::size_t width; // maximum width of text, including indent. Longer text will wrap
|
||||||
|
char tabChar; // If this char is seen the indent is changed to current pos
|
||||||
|
};
|
||||||
|
|
||||||
|
class Text {
|
||||||
public:
|
public:
|
||||||
LineWrapper();
|
Text( std::string const& _str, TextAttributes const& _attr = TextAttributes() );
|
||||||
|
void spliceLine( std::size_t _indent, std::string& _remainder, std::size_t _pos );
|
||||||
LineWrapper& setIndent( std::size_t _indent );
|
|
||||||
LineWrapper& setInitialIndent( std::size_t _initalIndent );
|
|
||||||
LineWrapper& setRight( std::size_t _right );
|
|
||||||
LineWrapper& setTabChar( char _tabChar );
|
|
||||||
|
|
||||||
LineWrapper& wrap( std::string const& _str );
|
|
||||||
|
|
||||||
std::string toString() const;
|
|
||||||
|
|
||||||
typedef std::vector<std::string>::const_iterator const_iterator;
|
typedef std::vector<std::string>::const_iterator const_iterator;
|
||||||
|
|
||||||
|
@ -4113,23 +4264,13 @@ namespace Catch {
|
||||||
std::string const& last() const { return lines.back(); }
|
std::string const& last() const { return lines.back(); }
|
||||||
std::size_t size() const { return lines.size(); }
|
std::size_t size() const { return lines.size(); }
|
||||||
std::string const& operator[]( std::size_t _index ) const { return lines[_index]; }
|
std::string const& operator[]( std::size_t _index ) const { return lines[_index]; }
|
||||||
|
std::string toString() const;
|
||||||
|
|
||||||
friend std::ostream& operator << ( std::ostream& _stream, LineWrapper const& _lineWrapper );
|
friend std::ostream& operator << ( std::ostream& _stream, Text const& _text );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void wrapInternal( std::string const& _str );
|
std::string str;
|
||||||
void addLine( const std::string& _line );
|
TextAttributes attr;
|
||||||
bool isWrapPoint( char c );
|
|
||||||
std::size_t getCurrentIndent() const;
|
|
||||||
|
|
||||||
std::size_t right;
|
|
||||||
std::size_t nextTab;
|
|
||||||
std::size_t tab;
|
|
||||||
std::size_t indent;
|
|
||||||
std::size_t initialIndent;
|
|
||||||
std::string wrappableChars;
|
|
||||||
char tabChar;
|
|
||||||
int recursionCount;
|
|
||||||
std::vector<std::string> lines;
|
std::vector<std::string> lines;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -4236,11 +4377,11 @@ namespace Catch {
|
||||||
if( matchesFilters( config.filters, *it ) ) {
|
if( matchesFilters( config.filters, *it ) ) {
|
||||||
matchedTests++;
|
matchedTests++;
|
||||||
// !TBD: consider listAs()
|
// !TBD: consider listAs()
|
||||||
LineWrapper nameWrapper;
|
Text nameWrapper( it->getTestCaseInfo().name,
|
||||||
nameWrapper.setRight( maxNameLen ).setIndent( 2 ).wrap( it->getTestCaseInfo().name );
|
TextAttributes().setWidth( maxNameLen ).setIndent(2) );
|
||||||
|
|
||||||
LineWrapper tagsWrapper;
|
Text tagsWrapper( it->getTestCaseInfo().tagsAsString,
|
||||||
tagsWrapper.setRight( maxTagLen ).wrap( it->getTestCaseInfo().tagsAsString );
|
TextAttributes().setWidth( maxTagLen ) );
|
||||||
|
|
||||||
for( std::size_t i = 0; i < std::max( nameWrapper.size(), tagsWrapper.size() ); ++i ) {
|
for( std::size_t i = 0; i < std::max( nameWrapper.size(), tagsWrapper.size() ); ++i ) {
|
||||||
Colour::Code colour = Colour::None;
|
Colour::Code colour = Colour::None;
|
||||||
|
@ -4314,9 +4455,9 @@ namespace Catch {
|
||||||
for( std::map<std::string, int>::const_iterator countIt = tagCounts.begin(), countItEnd = tagCounts.end();
|
for( std::map<std::string, int>::const_iterator countIt = tagCounts.begin(), countItEnd = tagCounts.end();
|
||||||
countIt != countItEnd;
|
countIt != countItEnd;
|
||||||
++countIt ) {
|
++countIt ) {
|
||||||
LineWrapper wrapper;
|
Text wrapper( "[" + countIt->first + "]", TextAttributes()
|
||||||
wrapper.setIndent(2).setRight( maxTagLen ).wrap( "[" + countIt->first + "]" );
|
.setIndent(2)
|
||||||
|
.setWidth( maxTagLen ) );
|
||||||
std::cout << wrapper;
|
std::cout << wrapper;
|
||||||
std::size_t dots = 2;
|
std::size_t dots = 2;
|
||||||
if( maxTagLen > wrapper.last().size() )
|
if( maxTagLen > wrapper.last().size() )
|
||||||
|
@ -5049,7 +5190,7 @@ namespace Catch {
|
||||||
displayedSpecificOption = true;
|
displayedSpecificOption = true;
|
||||||
std::cout << "\n" << opt.optionNames() << " " << opt.argsSynopsis() << "\n\n"
|
std::cout << "\n" << opt.optionNames() << " " << opt.argsSynopsis() << "\n\n"
|
||||||
<< opt.optionSummary() << "\n\n"
|
<< opt.optionSummary() << "\n\n"
|
||||||
<< LineWrapper().setIndent( 2 ).wrap( opt.optionDescription() ) << "\n" << std::endl;
|
<< Text( opt.optionDescription(), TextAttributes().setIndent( 2 ) ) << "\n" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6018,112 +6159,89 @@ namespace Catch {
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
// These numbers are maintained by a script
|
// These numbers are maintained by a script
|
||||||
Version libraryVersion( 0, 9, 33, "integration" );
|
Version libraryVersion( 0, 9, 34, "integration" );
|
||||||
}
|
}
|
||||||
|
|
||||||
// #included from: catch_line_wrap.hpp
|
// #included from: catch_text.hpp
|
||||||
#define TWOBLUECUBES_CATCH_LINE_WRAP_HPP_INCLUDED
|
#define TWOBLUECUBES_CATCH_TEXT_HPP_INCLUDED
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
LineWrapper::LineWrapper()
|
Text::Text( std::string const& _str, TextAttributes const& _attr )
|
||||||
: right( CATCH_CONFIG_CONSOLE_WIDTH-1 ),
|
: attr( _attr )
|
||||||
nextTab( 0 ),
|
|
||||||
tab( 0 ),
|
|
||||||
indent( 0 ),
|
|
||||||
initialIndent( (std::size_t)-1 ), // use indent by default
|
|
||||||
wrappableChars( " [({.,/|\\" ),
|
|
||||||
tabChar( '\t' ),
|
|
||||||
recursionCount( 0 )
|
|
||||||
{}
|
|
||||||
|
|
||||||
LineWrapper& LineWrapper::setIndent( std::size_t _indent ) {
|
|
||||||
indent = _indent;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
LineWrapper& LineWrapper::setInitialIndent( std::size_t _initialIndent ) {
|
|
||||||
initialIndent = _initialIndent;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
LineWrapper& LineWrapper::setRight( std::size_t _right ) {
|
|
||||||
right = _right;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
LineWrapper& LineWrapper::wrap( std::string const& _str ) {
|
|
||||||
nextTab = tab = 0;
|
|
||||||
wrapInternal( _str );
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
LineWrapper& LineWrapper::setTabChar( char _tabChar ) {
|
|
||||||
tabChar = _tabChar;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
bool LineWrapper::isWrapPoint( char c ) {
|
|
||||||
return wrappableChars.find( c ) != std::string::npos;
|
|
||||||
}
|
|
||||||
void LineWrapper::wrapInternal( std::string const& _str ) {
|
|
||||||
assert( ++recursionCount < 100 );
|
|
||||||
|
|
||||||
std::size_t width = right - getCurrentIndent();
|
|
||||||
std::size_t wrapPoint = width-tab;
|
|
||||||
for( std::size_t pos = 0; pos < _str.size(); ++pos ) {
|
|
||||||
if( _str[pos] == '\n' )
|
|
||||||
{
|
{
|
||||||
addLine( _str.substr( 0, pos ) );
|
std::string wrappableChars = " [({.,/|\\-";
|
||||||
nextTab = tab = 0;
|
std::size_t indent = _attr.initialIndent != std::string::npos
|
||||||
return wrapInternal( _str.substr( pos+1 ) );
|
? _attr.initialIndent
|
||||||
|
: _attr.indent;
|
||||||
|
std::string remainder = _str;
|
||||||
|
|
||||||
|
while( !remainder.empty() ) {
|
||||||
|
assert( lines.size() < 1000 );
|
||||||
|
std::size_t tabPos = std::string::npos;
|
||||||
|
std::size_t width = (std::min)( remainder.size(), _attr.width - indent );
|
||||||
|
std::size_t pos = remainder.find_first_of( '\n' );
|
||||||
|
if( pos <= width ) {
|
||||||
|
width = pos;
|
||||||
}
|
}
|
||||||
if( pos == width-tab ) {
|
pos = remainder.find_last_of( _attr.tabChar, width );
|
||||||
if( _str[wrapPoint] == ' ' ) {
|
if( pos != std::string::npos ) {
|
||||||
addLine( _str.substr( 0, wrapPoint ) );
|
tabPos = pos;
|
||||||
while( _str[++wrapPoint] == ' ' );
|
if( remainder[width] == '\n' )
|
||||||
|
width--;
|
||||||
|
remainder = remainder.substr( 0, tabPos ) + remainder.substr( tabPos+1 );
|
||||||
}
|
}
|
||||||
else if( isWrapPoint( _str[wrapPoint] ) ) {
|
|
||||||
addLine( _str.substr( 0, wrapPoint ) );
|
if( width == remainder.size() ) {
|
||||||
|
spliceLine( indent, remainder, width );
|
||||||
|
}
|
||||||
|
else if( remainder[width] == '\n' ) {
|
||||||
|
spliceLine( indent, remainder, width );
|
||||||
|
if( width <= 1 || remainder.size() != 1 )
|
||||||
|
remainder = remainder.substr( 1 );
|
||||||
|
indent = _attr.indent;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
addLine( _str.substr( 0, --wrapPoint ) + '-' );
|
pos = remainder.find_last_of( wrappableChars, width );
|
||||||
|
if( pos != std::string::npos && pos > 0 ) {
|
||||||
|
spliceLine( indent, remainder, pos );
|
||||||
|
if( remainder[0] == ' ' )
|
||||||
|
remainder = remainder.substr( 1 );
|
||||||
}
|
}
|
||||||
return wrapInternal( _str.substr( wrapPoint ) );
|
else {
|
||||||
|
spliceLine( indent, remainder, width-1 );
|
||||||
|
lines.back() += "-";
|
||||||
}
|
}
|
||||||
if( _str[pos] == tabChar ) {
|
if( lines.size() == 1 )
|
||||||
nextTab = pos;
|
indent = _attr.indent;
|
||||||
std::string withoutTab = _str.substr( 0, nextTab ) + _str.substr( nextTab+1 );
|
if( tabPos != std::string::npos )
|
||||||
return wrapInternal( withoutTab );
|
indent += tabPos;
|
||||||
}
|
|
||||||
else if( pos > 0 && isWrapPoint( _str[pos] ) ) {
|
|
||||||
wrapPoint = pos;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
addLine( _str );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream& operator << ( std::ostream& _stream, LineWrapper const& _lineWrapper ) {
|
void Text::spliceLine( std::size_t _indent, std::string& _remainder, std::size_t _pos ) {
|
||||||
for( LineWrapper::const_iterator it = _lineWrapper.begin(), itEnd = _lineWrapper.end();
|
lines.push_back( std::string( _indent, ' ' ) + _remainder.substr( 0, _pos ) );
|
||||||
it != itEnd; ++it ) {
|
_remainder = _remainder.substr( _pos );
|
||||||
if( it != _lineWrapper.begin() )
|
|
||||||
_stream << "\n";
|
|
||||||
_stream << *it;
|
|
||||||
}
|
}
|
||||||
return _stream;
|
|
||||||
}
|
std::string Text::toString() const {
|
||||||
std::string LineWrapper::toString() const {
|
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << *this;
|
oss << *this;
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LineWrapper::addLine( const std::string& _line ) {
|
std::ostream& operator << ( std::ostream& _stream, Text const& _text ) {
|
||||||
lines.push_back( std::string( tab + getCurrentIndent(), ' ' ) + _line );
|
for( Text::const_iterator it = _text.begin(), itEnd = _text.end();
|
||||||
if( nextTab > 0 )
|
it != itEnd; ++it ) {
|
||||||
tab = nextTab;
|
if( it != _text.begin() )
|
||||||
|
_stream << "\n";
|
||||||
|
_stream << *it;
|
||||||
}
|
}
|
||||||
|
return _stream;
|
||||||
std::size_t LineWrapper::getCurrentIndent() const
|
|
||||||
{
|
|
||||||
return (initialIndent != (std::size_t)-1 && lines.empty() )
|
|
||||||
? initialIndent
|
|
||||||
: indent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end namespace Catch
|
} // end namespace Catch
|
||||||
|
@ -7450,7 +7568,7 @@ namespace Catch {
|
||||||
if( result.hasExpandedExpression() ) {
|
if( result.hasExpandedExpression() ) {
|
||||||
stream << "with expansion:\n";
|
stream << "with expansion:\n";
|
||||||
Colour colourGuard( Colour::ReconstructedExpression );
|
Colour colourGuard( Colour::ReconstructedExpression );
|
||||||
stream << LineWrapper().setIndent(2).wrap( result.getExpandedExpression() ) << "\n";
|
stream << Text( result.getExpandedExpression(), TextAttributes().setIndent(2) ) << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void printMessage() const {
|
void printMessage() const {
|
||||||
|
@ -7459,7 +7577,7 @@ namespace Catch {
|
||||||
for( std::vector<MessageInfo>::const_iterator it = messages.begin(), itEnd = messages.end();
|
for( std::vector<MessageInfo>::const_iterator it = messages.begin(), itEnd = messages.end();
|
||||||
it != itEnd;
|
it != itEnd;
|
||||||
++it ) {
|
++it ) {
|
||||||
stream << LineWrapper().setIndent(2).wrap( it->message ) << "\n";
|
stream << Text( it->message, TextAttributes().setIndent(2) ) << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void printSourceInfo() const {
|
void printSourceInfo() const {
|
||||||
|
@ -7511,10 +7629,7 @@ namespace Catch {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void printTestCaseAndSectionHeader() {
|
void printTestCaseAndSectionHeader() {
|
||||||
printOpenHeader( unusedTestCaseInfo->name,
|
printOpenHeader( unusedTestCaseInfo->name );
|
||||||
currentSectionInfo
|
|
||||||
? currentSectionInfo->lineInfo
|
|
||||||
: unusedTestCaseInfo->lineInfo );
|
|
||||||
if( currentSectionInfo ) {
|
if( currentSectionInfo ) {
|
||||||
Colour colourGuard( Colour::Headers );
|
Colour colourGuard( Colour::Headers );
|
||||||
std::vector<ThreadedSectionInfo*> sections;
|
std::vector<ThreadedSectionInfo*> sections;
|
||||||
|
@ -7527,10 +7642,19 @@ namespace Catch {
|
||||||
if( !sections.empty() ) {
|
if( !sections.empty() ) {
|
||||||
typedef std::vector<ThreadedSectionInfo*>::const_reverse_iterator It;
|
typedef std::vector<ThreadedSectionInfo*>::const_reverse_iterator It;
|
||||||
for( It it = sections.rbegin(), itEnd = sections.rend(); it != itEnd; ++it )
|
for( It it = sections.rbegin(), itEnd = sections.rend(); it != itEnd; ++it )
|
||||||
printUserString( (*it)->name, 2 );
|
printHeaderString( (*it)->name, 2 );
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
SourceLineInfo lineInfo = currentSectionInfo
|
||||||
|
? currentSectionInfo->lineInfo
|
||||||
|
: unusedTestCaseInfo->lineInfo;
|
||||||
|
|
||||||
|
if( !lineInfo.empty() ){
|
||||||
|
stream << getDashes() << "\n";
|
||||||
|
Colour colourGuard( Colour::FileName );
|
||||||
|
stream << lineInfo << "\n";
|
||||||
|
}
|
||||||
stream << getDots() << "\n" << std::endl;
|
stream << getDots() << "\n" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7538,30 +7662,25 @@ namespace Catch {
|
||||||
printOpenHeader( _name );
|
printOpenHeader( _name );
|
||||||
stream << getDots() << "\n";
|
stream << getDots() << "\n";
|
||||||
}
|
}
|
||||||
void printOpenHeader( std::string const& _name, SourceLineInfo const& _lineInfo = SourceLineInfo() ) {
|
void printOpenHeader( std::string const& _name ) {
|
||||||
stream << getDashes() << "\n";
|
stream << getDashes() << "\n";
|
||||||
if( !_lineInfo.empty() ){
|
|
||||||
Colour colourGuard( Colour::FileName );
|
|
||||||
stream << _lineInfo << "\n\n";
|
|
||||||
}
|
|
||||||
{
|
{
|
||||||
Colour colourGuard( Colour::Headers );
|
Colour colourGuard( Colour::Headers );
|
||||||
printUserString( _name );
|
printHeaderString( _name );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if string has a : in first line will set indent to follow it on
|
// if string has a : in first line will set indent to follow it on
|
||||||
// subsequent lines
|
// subsequent lines
|
||||||
void printUserString( std::string const& _string, std::size_t indent = 0 ) {
|
void printHeaderString( std::string const& _string, std::size_t indent = 0 ) {
|
||||||
std::size_t i = _string.find( ": " );
|
std::size_t i = _string.find( ": " );
|
||||||
if( i != std::string::npos )
|
if( i != std::string::npos )
|
||||||
i+=2;
|
i+=2;
|
||||||
else
|
else
|
||||||
i = 0;
|
i = 0;
|
||||||
stream << LineWrapper()
|
stream << Text( _string, TextAttributes()
|
||||||
.setIndent( indent+i)
|
.setIndent( indent+i)
|
||||||
.setInitialIndent( indent )
|
.setInitialIndent( indent ) ) << "\n";
|
||||||
.wrap( _string ) << "\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void printTotals( const Totals& totals ) {
|
void printTotals( const Totals& totals ) {
|
||||||
|
|
Loading…
Reference in New Issue