From 4554155e3dea5e21cb1bc5b9d89f571060e5d33e Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Mon, 10 Feb 2014 17:20:30 +0000 Subject: [PATCH 01/11] =?UTF-8?q?Made=20Clara=20a=20=E2=80=9CCliche?= =?UTF-8?q?=E2=80=9D=20header,=20which=20will=20be=20usable=20independentl?= =?UTF-8?q?y=20of=20Catch.=20-=20This=20is=20just=20a=20first=20step.=20It?= =?UTF-8?q?=20still=20has=20a=20dependency=20on=20catch=5Ftext.h,=20which?= =?UTF-8?q?=20also=20needs=20to=20be=20made=20a=20Cliche=20header.=20-=20T?= =?UTF-8?q?hese=20then=20need=20their=20own=20homes=20on=20GitHub.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/internal/catch_clara.h | 16 ++++++++++++++++ include/internal/catch_commandline.hpp | 2 +- include/internal/clara.h | 19 +++++++++++++++++-- projects/SelfTest/TestMain.cpp | 2 +- .../CatchSelfTest.xcodeproj/project.pbxproj | 2 ++ 5 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 include/internal/catch_clara.h diff --git a/include/internal/catch_clara.h b/include/internal/catch_clara.h new file mode 100644 index 00000000..636be471 --- /dev/null +++ b/include/internal/catch_clara.h @@ -0,0 +1,16 @@ +/* + * Created by Phil on 10/2/2014. + * Copyright 2014 Two Blue Cubes Ltd. All rights reserved. + * + * Distributed under the Boost Software License, Version 1.0. (See accompanying + * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + * + */ +#ifndef TWOBLUECUBES_CATCH_CLARA_H_INCLUDED +#define TWOBLUECUBES_CATCH_CLARA_H_INCLUDED + +#define CLICHE_CLARA_EMBEDDED_NAMESPACE Catch +#include "clara.h" +#undef CLICHE_CLARA_EMBEDDED_NAMESPACE + +#endif // TWOBLUECUBES_CATCH_CLARA_H_INCLUDED diff --git a/include/internal/catch_commandline.hpp b/include/internal/catch_commandline.hpp index 5b80761f..ee19de85 100644 --- a/include/internal/catch_commandline.hpp +++ b/include/internal/catch_commandline.hpp @@ -10,7 +10,7 @@ #include "catch_config.hpp" #include "catch_common.h" -#include "clara.h" +#include "catch_clara.h" #include diff --git a/include/internal/clara.h b/include/internal/clara.h index b44d129a..494b959a 100644 --- a/include/internal/clara.h +++ b/include/internal/clara.h @@ -5,11 +5,22 @@ * Distributed under the Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ -#ifndef TWOBLUECUBES_CLARA_H_INCLUDED +#ifndef CLICHE_CLARA_EMBEDDED_NAMESPACE +#ifdef TWOBLUECUBES_CLARA_H_INCLUDED +#define TWOBLUECUBES_CLARA_H_ALREADY_INCLUDED +#else #define TWOBLUECUBES_CLARA_H_INCLUDED +#endif +#endif + +#ifndef TWOBLUECUBES_CLARA_H_ALREADY_INCLUDED #include "catch_text.h" // This will get moved out too +#ifdef CLICHE_CLARA_EMBEDDED_NAMESPACE +namespace CLICHE_CLARA_EMBEDDED_NAMESPACE { +#endif + namespace Clara { namespace Detail { template struct RemoveConstRef{ typedef T type; }; @@ -582,5 +593,9 @@ namespace Clara { } // end namespace Clara +#ifdef CLICHE_CLARA_EMBEDDED_NAMESPACE +} // end embedded namespace +#endif + +#endif // TWOBLUECUBES_CLARA_H_ALREAD_INCLUDED -#endif // TWOBLUECUBES_CLARA_H_INCLUDED diff --git a/projects/SelfTest/TestMain.cpp b/projects/SelfTest/TestMain.cpp index 575a456a..b1468cbc 100644 --- a/projects/SelfTest/TestMain.cpp +++ b/projects/SelfTest/TestMain.cpp @@ -16,7 +16,7 @@ template void parseIntoConfig( const char * (&argv)[size], Catch::ConfigData& config ) { - Clara::CommandLine parser = Catch::makeCommandLineParser(); + Catch::Clara::CommandLine parser = Catch::makeCommandLineParser(); parser.parseInto( size, argv, config ); } diff --git a/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj b/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj index e61b82de..20d58a9f 100644 --- a/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj +++ b/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj @@ -77,6 +77,7 @@ 26847E5B16BBAB790043B9C1 /* catch_message.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = catch_message.h; sourceTree = ""; }; 26847E5C16BBACB60043B9C1 /* catch_message.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_message.hpp; sourceTree = ""; }; 26847E5D16BBADB40043B9C1 /* catch_message.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = catch_message.cpp; path = ../../../SelfTest/SurrogateCpps/catch_message.cpp; sourceTree = ""; }; + 268F47B018A93F7800D8C14F /* catch_clara.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = catch_clara.h; sourceTree = ""; }; 26948284179A9AB900ED166E /* SectionTrackerTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SectionTrackerTests.cpp; path = ../../../SelfTest/SectionTrackerTests.cpp; sourceTree = ""; }; 26948287179EF7F900ED166E /* catch_test_case_tracker.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_test_case_tracker.hpp; sourceTree = ""; }; 2694A1FB16A0000E004816E3 /* catch_text.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = catch_text.cpp; sourceTree = ""; }; @@ -438,6 +439,7 @@ 26AEAF1617BEA18E009E32C9 /* catch_platform.h */, 262E739A1846759000CAC268 /* catch_common.hpp */, 261488FC184D1DC10041FBEB /* catch_stream.h */, + 268F47B018A93F7800D8C14F /* catch_clara.h */, ); name = Infrastructure; sourceTree = ""; From c98a97cf90eaf95fedd540f29a0ba8015c925eae Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Mon, 10 Feb 2014 17:30:12 +0000 Subject: [PATCH 02/11] Tweaked Cliche macros/ names --- include/internal/catch_clara.h | 4 ++-- include/internal/clara.h | 24 ++++++++++++++---------- projects/SelfTest/CmdLineTests.cpp | 2 +- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/include/internal/catch_clara.h b/include/internal/catch_clara.h index 636be471..0f9dfa62 100644 --- a/include/internal/catch_clara.h +++ b/include/internal/catch_clara.h @@ -9,8 +9,8 @@ #ifndef TWOBLUECUBES_CATCH_CLARA_H_INCLUDED #define TWOBLUECUBES_CATCH_CLARA_H_INCLUDED -#define CLICHE_CLARA_EMBEDDED_NAMESPACE Catch +#define CLICHE_CLARA_OUTER_NAMESPACE Catch #include "clara.h" -#undef CLICHE_CLARA_EMBEDDED_NAMESPACE +#undef CLICHE_CLARA_OUTER_NAMESPACE #endif // TWOBLUECUBES_CATCH_CLARA_H_INCLUDED diff --git a/include/internal/clara.h b/include/internal/clara.h index 494b959a..7ae8c334 100644 --- a/include/internal/clara.h +++ b/include/internal/clara.h @@ -5,20 +5,24 @@ * Distributed under the Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ -#ifndef CLICHE_CLARA_EMBEDDED_NAMESPACE -#ifdef TWOBLUECUBES_CLARA_H_INCLUDED -#define TWOBLUECUBES_CLARA_H_ALREADY_INCLUDED -#else -#define TWOBLUECUBES_CLARA_H_INCLUDED -#endif -#endif +// Only use header guard if we are not using an outer namespace +#ifndef CLICHE_CLARA_OUTER_NAMESPACE +# ifdef TWOBLUECUBES_CLARA_H_INCLUDED +# ifndef TWOBLUECUBES_CLARA_H_ALREADY_INCLUDED +# define TWOBLUECUBES_CLARA_H_ALREADY_INCLUDED +# endif +# else +# define TWOBLUECUBES_CLARA_H_INCLUDED +# endif +#endif #ifndef TWOBLUECUBES_CLARA_H_ALREADY_INCLUDED #include "catch_text.h" // This will get moved out too -#ifdef CLICHE_CLARA_EMBEDDED_NAMESPACE -namespace CLICHE_CLARA_EMBEDDED_NAMESPACE { +// Use optional outer namespace +#ifdef CLICHE_CLARA_OUTER_NAMESPACE +namespace CLICHE_CLARA_OUTER_NAMESPACE { #endif namespace Clara { @@ -593,7 +597,7 @@ namespace Clara { } // end namespace Clara -#ifdef CLICHE_CLARA_EMBEDDED_NAMESPACE +#ifdef CLICHE_CLARA_OUTER_NAMESPACE } // end embedded namespace #endif diff --git a/projects/SelfTest/CmdLineTests.cpp b/projects/SelfTest/CmdLineTests.cpp index 3eb54d2f..8d003fed 100644 --- a/projects/SelfTest/CmdLineTests.cpp +++ b/projects/SelfTest/CmdLineTests.cpp @@ -9,7 +9,7 @@ #pragma clang diagnostic ignored "-Wpadded" #endif -#include "internal/clara.h" +#include "internal/clara.h" // This will does not declare Clara within the Catch namespace #include "catch.hpp" From b75624393567a861f6b2f85dfffb3f4b7fbaf793 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Mon, 10 Feb 2014 17:31:31 +0000 Subject: [PATCH 03/11] Fixed some comments --- include/internal/catch_clara.h | 1 + include/internal/clara.h | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/internal/catch_clara.h b/include/internal/catch_clara.h index 0f9dfa62..a30c0fd2 100644 --- a/include/internal/catch_clara.h +++ b/include/internal/catch_clara.h @@ -9,6 +9,7 @@ #ifndef TWOBLUECUBES_CATCH_CLARA_H_INCLUDED #define TWOBLUECUBES_CATCH_CLARA_H_INCLUDED +// Declare Clara inside the Catch namespace #define CLICHE_CLARA_OUTER_NAMESPACE Catch #include "clara.h" #undef CLICHE_CLARA_OUTER_NAMESPACE diff --git a/include/internal/clara.h b/include/internal/clara.h index 7ae8c334..5a207139 100644 --- a/include/internal/clara.h +++ b/include/internal/clara.h @@ -598,8 +598,8 @@ namespace Clara { } // end namespace Clara #ifdef CLICHE_CLARA_OUTER_NAMESPACE -} // end embedded namespace +} // end outer namespace #endif -#endif // TWOBLUECUBES_CLARA_H_ALREAD_INCLUDED +#endif // TWOBLUECUBES_CLARA_H_ALREADY_INCLUDED From 0dc49d1b5785209c6d8e6b03f02f103b3305fbc4 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Tue, 11 Feb 2014 06:32:56 +0000 Subject: [PATCH 04/11] Extracted stand-alone micro-library, tbc_text_format.h, from catch_text.h. - use this version in clara.h so clara can stand alone. --- include/internal/catch_clara.h | 3 + include/internal/catch_impl.hpp | 1 - include/internal/catch_text.h | 57 ++----- include/internal/catch_text.hpp | 95 ----------- include/internal/clara.h | 23 ++- include/internal/tbc_text_format.h | 153 ++++++++++++++++++ .../CatchSelfTest.xcodeproj/project.pbxproj | 2 + 7 files changed, 187 insertions(+), 147 deletions(-) delete mode 100644 include/internal/catch_text.hpp create mode 100644 include/internal/tbc_text_format.h diff --git a/include/internal/catch_clara.h b/include/internal/catch_clara.h index a30c0fd2..d9ecbed1 100644 --- a/include/internal/catch_clara.h +++ b/include/internal/catch_clara.h @@ -9,6 +9,9 @@ #ifndef TWOBLUECUBES_CATCH_CLARA_H_INCLUDED #define TWOBLUECUBES_CATCH_CLARA_H_INCLUDED +#define CLARA_CONFIG_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH + + // Declare Clara inside the Catch namespace #define CLICHE_CLARA_OUTER_NAMESPACE Catch #include "clara.h" diff --git a/include/internal/catch_impl.hpp b/include/internal/catch_impl.hpp index 01522355..e19c159f 100644 --- a/include/internal/catch_impl.hpp +++ b/include/internal/catch_impl.hpp @@ -28,7 +28,6 @@ #include "catch_tags.hpp" #include "catch_test_spec.hpp" #include "catch_version.hpp" -#include "catch_text.hpp" #include "catch_message.hpp" #include "catch_legacy_reporter_adapter.hpp" #include "catch_timer.hpp" diff --git a/include/internal/catch_text.h b/include/internal/catch_text.h index e713f7b7..4657f744 100644 --- a/include/internal/catch_text.h +++ b/include/internal/catch_text.h @@ -1,6 +1,6 @@ /* - * Created by Phil on 18/4/2013. - * Copyright 2013 Two Blue Cubes Ltd. All rights reserved. + * Created by Phil on 10/2/2014. + * Copyright 2014 Two Blue Cubes Ltd. All rights reserved. * * Distributed under the Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -10,52 +10,15 @@ #include "catch_config.hpp" -#include -#include +#define TBC_TEXT_FORMAT_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH + +#define CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE Catch +#include "tbc_text_format.h" +#undef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE namespace Catch { - - 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: - Text( std::string const& _str, TextAttributes const& _attr = TextAttributes() ); - void spliceLine( std::size_t _indent, std::string& _remainder, std::size_t _pos ); - - typedef std::vector::const_iterator const_iterator; - - const_iterator begin() const { return lines.begin(); } - const_iterator end() const { return lines.end(); } - std::string const& last() const { return lines.back(); } - std::size_t size() const { return lines.size(); } - std::string const& operator[]( std::size_t _index ) const { return lines[_index]; } - std::string toString() const; - - friend std::ostream& operator << ( std::ostream& _stream, Text const& _text ); - - private: - std::string str; - TextAttributes attr; - std::vector lines; - }; - -} // end namespace Catch + using Tbc::Text; + using Tbc::TextAttributes; +} #endif // TWOBLUECUBES_CATCH_TEXT_H_INCLUDED diff --git a/include/internal/catch_text.hpp b/include/internal/catch_text.hpp deleted file mode 100644 index f1f884dd..00000000 --- a/include/internal/catch_text.hpp +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Created by Phil on 20/4/2013. - * Copyright 2013 Two Blue Cubes Ltd. All rights reserved. - * - * Distributed under the Boost Software License, Version 1.0. (See accompanying - * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - */ -#ifndef TWOBLUECUBES_CATCH_TEXT_HPP_INCLUDED -#define TWOBLUECUBES_CATCH_TEXT_HPP_INCLUDED - -#include -#include - -namespace Catch { - - Text::Text( std::string const& _str, TextAttributes const& _attr ) - : attr( _attr ) - { - std::string wrappableChars = " [({.,/|\\-"; - std::size_t indent = _attr.initialIndent != std::string::npos - ? _attr.initialIndent - : _attr.indent; - std::string remainder = _str; - - while( !remainder.empty() ) { - if( lines.size() >= 1000 ) { - lines.push_back( "... message truncated due to excessive size" ); - return; - } - 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; - } - pos = remainder.find_last_of( _attr.tabChar, width ); - if( pos != std::string::npos ) { - tabPos = pos; - if( remainder[width] == '\n' ) - width--; - remainder = remainder.substr( 0, tabPos ) + remainder.substr( tabPos+1 ); - } - - 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 { - 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 ); - } - else { - spliceLine( indent, remainder, width-1 ); - lines.back() += "-"; - } - if( lines.size() == 1 ) - indent = _attr.indent; - if( tabPos != std::string::npos ) - indent += tabPos; - } - } - } - - void Text::spliceLine( std::size_t _indent, std::string& _remainder, std::size_t _pos ) { - lines.push_back( std::string( _indent, ' ' ) + _remainder.substr( 0, _pos ) ); - _remainder = _remainder.substr( _pos ); - } - - std::string Text::toString() const { - std::ostringstream oss; - oss << *this; - return oss.str(); - } - - std::ostream& operator << ( std::ostream& _stream, Text const& _text ) { - for( Text::const_iterator it = _text.begin(), itEnd = _text.end(); - it != itEnd; ++it ) { - if( it != _text.begin() ) - _stream << "\n"; - _stream << *it; - } - return _stream; - } - -} // end namespace Catch - -#endif // TWOBLUECUBES_CATCH_TEXT_HPP_INCLUDED diff --git a/include/internal/clara.h b/include/internal/clara.h index 5a207139..b2ffc586 100644 --- a/include/internal/clara.h +++ b/include/internal/clara.h @@ -18,7 +18,13 @@ #endif #ifndef TWOBLUECUBES_CLARA_H_ALREADY_INCLUDED -#include "catch_text.h" // This will get moved out too +#define CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE Clara +#include "tbc_text_format.h" +#undef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE + +#include +#include +#include // Use optional outer namespace #ifdef CLICHE_CLARA_OUTER_NAMESPACE @@ -27,6 +33,15 @@ namespace CLICHE_CLARA_OUTER_NAMESPACE { namespace Clara { namespace Detail { + +#ifdef CLARA_CONSOLE_WIDTH + const unsigned int consoleWidth = CLARA_CONFIG_CONSOLE_WIDTH; +#else + const unsigned int consoleWidth = 80; +#endif + + using namespace ::Clara::Tbc; + template struct RemoveConstRef{ typedef T type; }; template struct RemoveConstRef{ typedef T type; }; template struct RemoveConstRef{ typedef T type; }; @@ -416,18 +431,18 @@ namespace Clara { m_boundProcessName = Detail::makeBoundField( f ); } - void optUsage( std::ostream& os, std::size_t indent = 0, std::size_t width = CATCH_CONFIG_CONSOLE_WIDTH ) const { + void optUsage( std::ostream& os, std::size_t indent = 0, std::size_t width = Detail::consoleWidth ) const { typename std::vector::const_iterator itBegin = m_options.begin(), itEnd = m_options.end(), it; std::size_t maxWidth = 0; for( it = itBegin; it != itEnd; ++it ) maxWidth = (std::max)( maxWidth, it->commands().size() ); for( it = itBegin; it != itEnd; ++it ) { - Catch::Text usage( it->commands(), Catch::TextAttributes() + Detail::Text usage( it->commands(), Detail::TextAttributes() .setWidth( maxWidth+indent ) .setIndent( indent ) ); // !TBD handle longer usage strings - Catch::Text desc( it->description, Catch::TextAttributes() + Detail::Text desc( it->description, Detail::TextAttributes() .setWidth( width - maxWidth -3 ) ); for( std::size_t i = 0; i < (std::max)( usage.size(), desc.size() ); ++i ) { diff --git a/include/internal/tbc_text_format.h b/include/internal/tbc_text_format.h new file mode 100644 index 00000000..a63d6a14 --- /dev/null +++ b/include/internal/tbc_text_format.h @@ -0,0 +1,153 @@ +/* + * Created by Phil on 18/4/2013. + * Copyright 2013 Two Blue Cubes Ltd. All rights reserved. + * + * Distributed under the Boost Software License, Version 1.0. (See accompanying + * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + */ +// Only use header guard if we are not using an outer namespace +#ifndef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE +# ifdef TWOBLUECUBES_TEXT_FORMAT_H_INCLUDED +# ifndef TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED +# define TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED +# endif +# else +# define TWOBLUECUBES_TEXT_FORMAT_H_INCLUDED +# endif +#endif +#ifndef TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED +#include +#include +#include + +// Use optional outer namespace +#ifdef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE +namespace CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE { +#endif + +namespace Tbc { + +#ifdef TBC_TEXT_FORMAT_CONSOLE_WIDTH + const unsigned int consoleWidth = TBC_TEXT_FORMAT_CONSOLE_WIDTH; +#else + const unsigned int consoleWidth = 80; +#endif + + struct TextAttributes { + TextAttributes() + : initialIndent( std::string::npos ), + indent( 0 ), + width( consoleWidth-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: + Text( std::string const& _str, TextAttributes const& _attr = TextAttributes() ) + : attr( _attr ) + { + std::string wrappableChars = " [({.,/|\\-"; + std::size_t indent = _attr.initialIndent != std::string::npos + ? _attr.initialIndent + : _attr.indent; + std::string remainder = _str; + + while( !remainder.empty() ) { + if( lines.size() >= 1000 ) { + lines.push_back( "... message truncated due to excessive size" ); + return; + } + 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; + } + pos = remainder.find_last_of( _attr.tabChar, width ); + if( pos != std::string::npos ) { + tabPos = pos; + if( remainder[width] == '\n' ) + width--; + remainder = remainder.substr( 0, tabPos ) + remainder.substr( tabPos+1 ); + } + + 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 { + 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 ); + } + else { + spliceLine( indent, remainder, width-1 ); + lines.back() += "-"; + } + if( lines.size() == 1 ) + indent = _attr.indent; + if( tabPos != std::string::npos ) + indent += tabPos; + } + } + } + + void spliceLine( std::size_t _indent, std::string& _remainder, std::size_t _pos ) { + lines.push_back( std::string( _indent, ' ' ) + _remainder.substr( 0, _pos ) ); + _remainder = _remainder.substr( _pos ); + } + + typedef std::vector::const_iterator const_iterator; + + const_iterator begin() const { return lines.begin(); } + const_iterator end() const { return lines.end(); } + std::string const& last() const { return lines.back(); } + std::size_t size() const { return lines.size(); } + std::string const& operator[]( std::size_t _index ) const { return lines[_index]; } + std::string toString() const { + std::ostringstream oss; + oss << *this; + return oss.str(); + } + + inline friend std::ostream& operator << ( std::ostream& _stream, Text const& _text ) { + for( Text::const_iterator it = _text.begin(), itEnd = _text.end(); + it != itEnd; ++it ) { + if( it != _text.begin() ) + _stream << "\n"; + _stream << *it; + } + return _stream; + } + + private: + std::string str; + TextAttributes attr; + std::vector lines; + }; + +} // end namespace Tbc + +#ifdef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE +} // end outer namespace +#endif + +#endif // TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED diff --git a/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj b/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj index 20d58a9f..4c3d6af2 100644 --- a/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj +++ b/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj @@ -78,6 +78,7 @@ 26847E5C16BBACB60043B9C1 /* catch_message.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_message.hpp; sourceTree = ""; }; 26847E5D16BBADB40043B9C1 /* catch_message.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = catch_message.cpp; path = ../../../SelfTest/SurrogateCpps/catch_message.cpp; sourceTree = ""; }; 268F47B018A93F7800D8C14F /* catch_clara.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = catch_clara.h; sourceTree = ""; }; + 268F47B118A944DB00D8C14F /* tbc_text_format.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = tbc_text_format.h; path = ../../../../include/internal/tbc_text_format.h; sourceTree = ""; }; 26948284179A9AB900ED166E /* SectionTrackerTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SectionTrackerTests.cpp; path = ../../../SelfTest/SectionTrackerTests.cpp; sourceTree = ""; }; 26948287179EF7F900ED166E /* catch_test_case_tracker.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_test_case_tracker.hpp; sourceTree = ""; }; 2694A1FB16A0000E004816E3 /* catch_text.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = catch_text.cpp; sourceTree = ""; }; @@ -202,6 +203,7 @@ isa = PBXGroup; children = ( 26C5F3EC17514B970056FB3C /* clara.h */, + 268F47B118A944DB00D8C14F /* tbc_text_format.h */, ); name = External; sourceTree = ""; From 633feaa4a60323004d113ef03ca0e719de9bd396 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Tue, 11 Feb 2014 17:40:11 +0000 Subject: [PATCH 05/11] Added #include to clara.h - thanks Martin --- include/internal/clara.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/internal/clara.h b/include/internal/clara.h index b2ffc586..c7c5052f 100644 --- a/include/internal/clara.h +++ b/include/internal/clara.h @@ -25,6 +25,7 @@ #include #include #include +#include // Use optional outer namespace #ifdef CLICHE_CLARA_OUTER_NAMESPACE From 160b74d6c711f5a02678a44806cdf01524837d12 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Tue, 11 Feb 2014 17:41:11 +0000 Subject: [PATCH 06/11] =?UTF-8?q?=E2=80=A6=20and=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/internal/clara.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/internal/clara.h b/include/internal/clara.h index c7c5052f..6493e01b 100644 --- a/include/internal/clara.h +++ b/include/internal/clara.h @@ -26,6 +26,7 @@ #include #include #include +#include // Use optional outer namespace #ifdef CLICHE_CLARA_OUTER_NAMESPACE From b15726beba79852b4d60270cd42eb395f89ddf3a Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Tue, 11 Feb 2014 17:45:15 +0000 Subject: [PATCH 07/11] Added #include for to Clara - thanks again, Martin --- include/internal/clara.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/internal/clara.h b/include/internal/clara.h index 6493e01b..25544e7c 100644 --- a/include/internal/clara.h +++ b/include/internal/clara.h @@ -27,6 +27,7 @@ #include #include #include +#include // Use optional outer namespace #ifdef CLICHE_CLARA_OUTER_NAMESPACE From 5845ae94aad65cbbde26b87a49b81dba411e84a7 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Tue, 11 Feb 2014 18:11:06 +0000 Subject: [PATCH 08/11] Added private assignment operator to fix VS2010 issue - thanks to Kosta (#239) --- include/reporters/catch_reporter_bases.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/reporters/catch_reporter_bases.hpp b/include/reporters/catch_reporter_bases.hpp index 21e70980..ee255406 100644 --- a/include/reporters/catch_reporter_bases.hpp +++ b/include/reporters/catch_reporter_bases.hpp @@ -99,6 +99,8 @@ namespace Catch { return node->stats.sectionInfo.lineInfo == m_other.lineInfo; } private: + BySectionInfo& operator=( BySectionInfo const& other ); // = delete; + SectionInfo const& m_other; }; From d29cbecfa5c5e535dad5d91e2a0b5f1c810bc0d8 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Tue, 11 Feb 2014 18:11:37 +0000 Subject: [PATCH 09/11] Updated single include generator to allow for embedded micro-libraries --- scripts/generateSingleHeader.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/generateSingleHeader.py b/scripts/generateSingleHeader.py index 839c72cc..b1f9ae88 100644 --- a/scripts/generateSingleHeader.py +++ b/scripts/generateSingleHeader.py @@ -8,10 +8,10 @@ from scriptCommon import catchPath versionParser = re.compile( r'(\s*Version\slibraryVersion)\s*\(\s*(.*)\s*,\s*(.*)\s*,\s*(.*)\s*,\s*\"(.*)\"\s*\).*' ) includesParser = re.compile( r'\s*#include\s*"(.*)"' ) -guardParser = re.compile( r'\s*#.*_INCLUDED') +guardParser = re.compile( r'\s*#.*TWOBLUECUBES_CATCH_.*_INCLUDED') defineParser = re.compile( r'\s*#define') -ifParser = re.compile( r'\s*#if') -endIfParser = re.compile( r'\s*#endif') +ifParser = re.compile( r'\s*#ifndef TWOBLUECUBES_CATCH_.*_INCLUDED') +endIfParser = re.compile( r'\s*#endif // TWOBLUECUBES_CATCH_.*_INCLUDED') ifImplParser = re.compile( r'\s*#if.*(CATCH_CONFIG_MAIN|CATCH_CONFIG_RUNNER)') commentParser1 = re.compile( r'^\s*/\*') commentParser2 = re.compile( r'^\s*\*') @@ -62,7 +62,8 @@ def parseFile( path, filename ): header = m.group(1) headerPath, sep, headerFile = header.rpartition( "/" ) if not headerFile in seenHeaders: - seenHeaders.add( headerFile ) + if headerFile != "tbc_text_format.h" and headerFile != "clara.h": + seenHeaders.add( headerFile ) write( "// #included from: {0}\n".format( header ) ) if( headerPath == "internal" and path.endswith( "internal/" ) ): headerPath = "" From f899552d52c3eb756c7d9823c5fc8c3656878b34 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Tue, 11 Feb 2014 18:12:31 +0000 Subject: [PATCH 10/11] updated single include test project --- .../CatchSelfTestSingle.xcodeproj/project.pbxproj | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/projects/XCode4/CatchSelfTest/CatchSelfTestSingle.xcodeproj/project.pbxproj b/projects/XCode4/CatchSelfTest/CatchSelfTestSingle.xcodeproj/project.pbxproj index 209296a4..1eee6eb6 100644 --- a/projects/XCode4/CatchSelfTest/CatchSelfTestSingle.xcodeproj/project.pbxproj +++ b/projects/XCode4/CatchSelfTest/CatchSelfTestSingle.xcodeproj/project.pbxproj @@ -128,7 +128,7 @@ 4A90B5CD15D2E3E900EF71BC /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0440; + LastUpgradeCheck = 0500; ORGANIZATIONNAME = "Phil Nash"; }; buildConfigurationList = 4A90B5D015D2E3E900EF71BC /* Build configuration list for PBXProject "CatchSelfTestSingle" */; @@ -172,7 +172,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_64_BIT)"; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; @@ -199,7 +198,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_64_BIT)"; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = YES; From 1c2fbe146b9d86ee174f08f3b9af6a6437c44c39 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Tue, 11 Feb 2014 18:12:41 +0000 Subject: [PATCH 11/11] build 26 --- README.md | 2 +- include/internal/catch_version.hpp | 2 +- single_include/catch.hpp | 427 ++++++++++++++++++++++------- 3 files changed, 326 insertions(+), 105 deletions(-) diff --git a/README.md b/README.md index 14a391d0..a621a74c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ![catch logo](catch-logo-small.png) -*v1.0 build 25 (master branch)* +*v1.0 build 26 (master branch)* Build status (on Travis CI) [![Build Status](https://travis-ci.org/philsquared/Catch.png)](https://travis-ci.org/philsquared/Catch) diff --git a/include/internal/catch_version.hpp b/include/internal/catch_version.hpp index 2fcf72d1..90c54ce0 100644 --- a/include/internal/catch_version.hpp +++ b/include/internal/catch_version.hpp @@ -13,7 +13,7 @@ namespace Catch { // These numbers are maintained by a script - Version libraryVersion( 1, 0, 25, "master" ); + Version libraryVersion( 1, 0, 26, "master" ); } #endif // TWOBLUECUBES_CATCH_VERSION_HPP_INCLUDED diff --git a/single_include/catch.hpp b/single_include/catch.hpp index 746e9f4e..6b335058 100644 --- a/single_include/catch.hpp +++ b/single_include/catch.hpp @@ -1,6 +1,6 @@ /* - * CATCH v1.0 build 25 (master branch) - * Generated: 2014-01-08 17:16:38.496390 + * CATCH v1.0 build 26 (master branch) + * Generated: 2014-02-11 18:09:37.990814 * ---------------------------------------------------------- * This file has been merged from multiple headers. Please don't edit it directly * Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved. @@ -3002,22 +3002,62 @@ namespace Catch { } // end namespace Catch +// #included from: catch_clara.h +#define TWOBLUECUBES_CATCH_CLARA_H_INCLUDED + +#define CLARA_CONFIG_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH + +// Declare Clara inside the Catch namespace +#define CLICHE_CLARA_OUTER_NAMESPACE Catch // #included from: clara.h -#define TWOBLUECUBES_CLARA_H_INCLUDED -// #included from: catch_text.h -#define TWOBLUECUBES_CATCH_TEXT_H_INCLUDED +// Only use header guard if we are not using an outer namespace +#ifndef CLICHE_CLARA_OUTER_NAMESPACE +# ifdef TWOBLUECUBES_CLARA_H_INCLUDED +# ifndef TWOBLUECUBES_CLARA_H_ALREADY_INCLUDED +# define TWOBLUECUBES_CLARA_H_ALREADY_INCLUDED +# endif +# else +# define TWOBLUECUBES_CLARA_H_INCLUDED +# endif +#endif +#ifndef TWOBLUECUBES_CLARA_H_ALREADY_INCLUDED +#define CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE Clara +// #included from: tbc_text_format.h +// Only use header guard if we are not using an outer namespace +#ifndef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE +# ifdef TWOBLUECUBES_TEXT_FORMAT_H_INCLUDED +# ifndef TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED +# define TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED +# endif +# else +# define TWOBLUECUBES_TEXT_FORMAT_H_INCLUDED +# endif +#endif +#ifndef TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED #include #include +#include -namespace Catch { +// Use optional outer namespace +#ifdef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE +namespace CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE { +#endif + +namespace Tbc { + +#ifdef TBC_TEXT_FORMAT_CONSOLE_WIDTH + const unsigned int consoleWidth = TBC_TEXT_FORMAT_CONSOLE_WIDTH; +#else + const unsigned int consoleWidth = 80; +#endif struct TextAttributes { TextAttributes() : initialIndent( std::string::npos ), indent( 0 ), - width( CATCH_CONFIG_CONSOLE_WIDTH-1 ), + width( consoleWidth-1 ), tabChar( '\t' ) {} @@ -3034,8 +3074,66 @@ namespace Catch { class Text { public: - Text( std::string const& _str, TextAttributes const& _attr = TextAttributes() ); - void spliceLine( std::size_t _indent, std::string& _remainder, std::size_t _pos ); + Text( std::string const& _str, TextAttributes const& _attr = TextAttributes() ) + : attr( _attr ) + { + std::string wrappableChars = " [({.,/|\\-"; + std::size_t indent = _attr.initialIndent != std::string::npos + ? _attr.initialIndent + : _attr.indent; + std::string remainder = _str; + + while( !remainder.empty() ) { + if( lines.size() >= 1000 ) { + lines.push_back( "... message truncated due to excessive size" ); + return; + } + 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; + } + pos = remainder.find_last_of( _attr.tabChar, width ); + if( pos != std::string::npos ) { + tabPos = pos; + if( remainder[width] == '\n' ) + width--; + remainder = remainder.substr( 0, tabPos ) + remainder.substr( tabPos+1 ); + } + + 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 { + 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 ); + } + else { + spliceLine( indent, remainder, width-1 ); + lines.back() += "-"; + } + if( lines.size() == 1 ) + indent = _attr.indent; + if( tabPos != std::string::npos ) + indent += tabPos; + } + } + } + + void spliceLine( std::size_t _indent, std::string& _remainder, std::size_t _pos ) { + lines.push_back( std::string( _indent, ' ' ) + _remainder.substr( 0, _pos ) ); + _remainder = _remainder.substr( _pos ); + } typedef std::vector::const_iterator const_iterator; @@ -3044,9 +3142,21 @@ namespace Catch { std::string const& last() const { return lines.back(); } std::size_t size() const { return lines.size(); } std::string const& operator[]( std::size_t _index ) const { return lines[_index]; } - std::string toString() const; + std::string toString() const { + std::ostringstream oss; + oss << *this; + return oss.str(); + } - friend std::ostream& operator << ( std::ostream& _stream, Text const& _text ); + inline friend std::ostream& operator << ( std::ostream& _stream, Text const& _text ) { + for( Text::const_iterator it = _text.begin(), itEnd = _text.end(); + it != itEnd; ++it ) { + if( it != _text.begin() ) + _stream << "\n"; + _stream << *it; + } + return _stream; + } private: std::string str; @@ -3054,10 +3164,38 @@ namespace Catch { std::vector lines; }; -} // end namespace Catch +} // end namespace Tbc + +#ifdef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE +} // end outer namespace +#endif + +#endif // TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED +#undef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE + +#include +#include +#include +#include +#include +#include + +// Use optional outer namespace +#ifdef CLICHE_CLARA_OUTER_NAMESPACE +namespace CLICHE_CLARA_OUTER_NAMESPACE { +#endif namespace Clara { namespace Detail { + +#ifdef CLARA_CONSOLE_WIDTH + const unsigned int consoleWidth = CLARA_CONFIG_CONSOLE_WIDTH; +#else + const unsigned int consoleWidth = 80; +#endif + + using namespace ::Clara::Tbc; + template struct RemoveConstRef{ typedef T type; }; template struct RemoveConstRef{ typedef T type; }; template struct RemoveConstRef{ typedef T type; }; @@ -3446,18 +3584,18 @@ namespace Clara { m_boundProcessName = Detail::makeBoundField( f ); } - void optUsage( std::ostream& os, std::size_t indent = 0, std::size_t width = CATCH_CONFIG_CONSOLE_WIDTH ) const { + void optUsage( std::ostream& os, std::size_t indent = 0, std::size_t width = Detail::consoleWidth ) const { typename std::vector::const_iterator itBegin = m_options.begin(), itEnd = m_options.end(), it; std::size_t maxWidth = 0; for( it = itBegin; it != itEnd; ++it ) maxWidth = (std::max)( maxWidth, it->commands().size() ); for( it = itBegin; it != itEnd; ++it ) { - Catch::Text usage( it->commands(), Catch::TextAttributes() + Detail::Text usage( it->commands(), Detail::TextAttributes() .setWidth( maxWidth+indent ) .setIndent( indent ) ); // !TBD handle longer usage strings - Catch::Text desc( it->description, Catch::TextAttributes() + Detail::Text desc( it->description, Detail::TextAttributes() .setWidth( width - maxWidth -3 ) ); for( std::size_t i = 0; i < (std::max)( usage.size(), desc.size() ); ++i ) { @@ -3627,6 +3765,14 @@ namespace Clara { } // end namespace Clara +#ifdef CLICHE_CLARA_OUTER_NAMESPACE +} // end outer namespace +#endif + +#endif // TWOBLUECUBES_CLARA_H_ALREADY_INCLUDED + +#undef CLICHE_CLARA_OUTER_NAMESPACE + #include namespace Catch { @@ -3780,6 +3926,166 @@ namespace Catch { // #included from: internal/catch_list.hpp #define TWOBLUECUBES_CATCH_LIST_HPP_INCLUDED +// #included from: catch_text.h +#define TWOBLUECUBES_CATCH_TEXT_H_INCLUDED + +#define TBC_TEXT_FORMAT_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH + +#define CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE Catch +// #included from: tbc_text_format.h +// Only use header guard if we are not using an outer namespace +#ifndef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE +# ifdef TWOBLUECUBES_TEXT_FORMAT_H_INCLUDED +# ifndef TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED +# define TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED +# endif +# else +# define TWOBLUECUBES_TEXT_FORMAT_H_INCLUDED +# endif +#endif +#ifndef TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED +#include +#include +#include + +// Use optional outer namespace +#ifdef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE +namespace CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE { +#endif + +namespace Tbc { + +#ifdef TBC_TEXT_FORMAT_CONSOLE_WIDTH + const unsigned int consoleWidth = TBC_TEXT_FORMAT_CONSOLE_WIDTH; +#else + const unsigned int consoleWidth = 80; +#endif + + struct TextAttributes { + TextAttributes() + : initialIndent( std::string::npos ), + indent( 0 ), + width( consoleWidth-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: + Text( std::string const& _str, TextAttributes const& _attr = TextAttributes() ) + : attr( _attr ) + { + std::string wrappableChars = " [({.,/|\\-"; + std::size_t indent = _attr.initialIndent != std::string::npos + ? _attr.initialIndent + : _attr.indent; + std::string remainder = _str; + + while( !remainder.empty() ) { + if( lines.size() >= 1000 ) { + lines.push_back( "... message truncated due to excessive size" ); + return; + } + 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; + } + pos = remainder.find_last_of( _attr.tabChar, width ); + if( pos != std::string::npos ) { + tabPos = pos; + if( remainder[width] == '\n' ) + width--; + remainder = remainder.substr( 0, tabPos ) + remainder.substr( tabPos+1 ); + } + + 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 { + 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 ); + } + else { + spliceLine( indent, remainder, width-1 ); + lines.back() += "-"; + } + if( lines.size() == 1 ) + indent = _attr.indent; + if( tabPos != std::string::npos ) + indent += tabPos; + } + } + } + + void spliceLine( std::size_t _indent, std::string& _remainder, std::size_t _pos ) { + lines.push_back( std::string( _indent, ' ' ) + _remainder.substr( 0, _pos ) ); + _remainder = _remainder.substr( _pos ); + } + + typedef std::vector::const_iterator const_iterator; + + const_iterator begin() const { return lines.begin(); } + const_iterator end() const { return lines.end(); } + std::string const& last() const { return lines.back(); } + std::size_t size() const { return lines.size(); } + std::string const& operator[]( std::size_t _index ) const { return lines[_index]; } + std::string toString() const { + std::ostringstream oss; + oss << *this; + return oss.str(); + } + + inline friend std::ostream& operator << ( std::ostream& _stream, Text const& _text ) { + for( Text::const_iterator it = _text.begin(), itEnd = _text.end(); + it != itEnd; ++it ) { + if( it != _text.begin() ) + _stream << "\n"; + _stream << *it; + } + return _stream; + } + + private: + std::string str; + TextAttributes attr; + std::vector lines; + }; + +} // end namespace Tbc + +#ifdef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE +} // end outer namespace +#endif + +#endif // TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED +#undef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE + +namespace Catch { + using Tbc::Text; + using Tbc::TextAttributes; +} + // #included from: catch_console_colour.hpp #define TWOBLUECUBES_CATCH_CONSOLE_COLOUR_HPP_INCLUDED @@ -6206,96 +6512,9 @@ namespace Catch { namespace Catch { // These numbers are maintained by a script - Version libraryVersion( 1, 0, 25, "master" ); + Version libraryVersion( 1, 0, 26, "master" ); } -// #included from: catch_text.hpp -#define TWOBLUECUBES_CATCH_TEXT_HPP_INCLUDED - -#include -#include - -namespace Catch { - - Text::Text( std::string const& _str, TextAttributes const& _attr ) - : attr( _attr ) - { - std::string wrappableChars = " [({.,/|\\-"; - std::size_t indent = _attr.initialIndent != std::string::npos - ? _attr.initialIndent - : _attr.indent; - std::string remainder = _str; - - while( !remainder.empty() ) { - if( lines.size() >= 1000 ) { - lines.push_back( "... message truncated due to excessive size" ); - return; - } - 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; - } - pos = remainder.find_last_of( _attr.tabChar, width ); - if( pos != std::string::npos ) { - tabPos = pos; - if( remainder[width] == '\n' ) - width--; - remainder = remainder.substr( 0, tabPos ) + remainder.substr( tabPos+1 ); - } - - 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 { - 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 ); - } - else { - spliceLine( indent, remainder, width-1 ); - lines.back() += "-"; - } - if( lines.size() == 1 ) - indent = _attr.indent; - if( tabPos != std::string::npos ) - indent += tabPos; - } - } - } - - void Text::spliceLine( std::size_t _indent, std::string& _remainder, std::size_t _pos ) { - lines.push_back( std::string( _indent, ' ' ) + _remainder.substr( 0, _pos ) ); - _remainder = _remainder.substr( _pos ); - } - - std::string Text::toString() const { - std::ostringstream oss; - oss << *this; - return oss.str(); - } - - std::ostream& operator << ( std::ostream& _stream, Text const& _text ) { - for( Text::const_iterator it = _text.begin(), itEnd = _text.end(); - it != itEnd; ++it ) { - if( it != _text.begin() ) - _stream << "\n"; - _stream << *it; - } - return _stream; - } - -} // end namespace Catch - // #included from: catch_message.hpp #define TWOBLUECUBES_CATCH_MESSAGE_HPP_INCLUDED @@ -6787,6 +7006,8 @@ namespace Catch { return node->stats.sectionInfo.lineInfo == m_other.lineInfo; } private: + BySectionInfo& operator=( BySectionInfo const& other ); // = delete; + SectionInfo const& m_other; };