Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Simplified StringWrapper

- by changing intoStream to << overload
- and removing redundant ctor
Commit
9e8abc33e7a4e8c0d0b69a3fd827ce92c31da951
Author
Phil Nash ·
Parents
b052bd729af9

Files · Download .tar.gz

Changes

 include/catch_runner.hpp                     |  2 +-
 include/internal/catch_line_wrap.h           |  6 +++---
 include/internal/catch_line_wrap.hpp         | 21 +++++++--------------
 include/reporters/catch_reporter_console.hpp |  5 ++---
 4 files changed, 13 insertions(+), 21 deletions(-)

diff --git a/include/catch_runner.hpp b/include/catch_runner.hpp
index 6d63b878..ef9c5975 100644
--- a/include/catch_runner.hpp
+++ b/include/catch_runner.hpp
@@ -161,7 +161,7 @@ namespace Catch {
                 displayedSpecificOption = true;
                 std::cout   << "\n" << opt.optionNames() << " " << opt.argsSynopsis() << "\n\n"
                             << opt.optionSummary() << "\n\n"
-                            << LineWrapper().setIndent( 2 ).wrap( opt.optionDescription() ).toString() << "\n" << std::endl;
+                            << LineWrapper().setIndent( 2 ).wrap( opt.optionDescription() ) << "\n" << std::endl;
             }
         }
 
diff --git a/include/internal/catch_line_wrap.h b/include/internal/catch_line_wrap.h
index e08dada1..ab024bcb 100644
--- a/include/internal/catch_line_wrap.h
+++ b/include/internal/catch_line_wrap.h
@@ -15,7 +15,6 @@ namespace Catch {
     
     class LineWrapper {
     public:
-        LineWrapper( std::size_t _indent, std::size_t _right );
         LineWrapper( std::size_t _right );
         LineWrapper();
 
@@ -23,14 +22,15 @@ namespace Catch {
         LineWrapper& setRight( std::size_t _right );
 
         LineWrapper& wrap( std::string const& _str );
-        
-        std::ostream& intoStream( std::ostream& stream ) const;
+
         std::string toString() const;
 
         typedef std::vector<std::string>::const_iterator const_iterator;
 
         const_iterator begin() const { return lines.begin(); }
         const_iterator end() const { return lines.end(); }
+
+        friend std::ostream& operator << ( std::ostream& _stream, LineWrapper const& _lineWrapper );
         
     private:
         void wrapInternal( std::string const& _str );
diff --git a/include/internal/catch_line_wrap.hpp b/include/internal/catch_line_wrap.hpp
index bb8247d9..1d8bcc75 100644
--- a/include/internal/catch_line_wrap.hpp
+++ b/include/internal/catch_line_wrap.hpp
@@ -12,13 +12,6 @@
 
 namespace Catch {
     
-
-    LineWrapper::LineWrapper( std::size_t _indent, std::size_t _right )
-    :   indent( _indent, ' ' ),
-        right( _right ),
-        nextTab( 0 ),
-        tab( 0 )
-    {}
     LineWrapper::LineWrapper( std::size_t _right )
     :   right( _right ),
         nextTab( 0 ),
@@ -75,18 +68,18 @@ namespace Catch {
         addLine( _str );
     }
 
-    std::ostream& LineWrapper::intoStream( std::ostream& stream ) const {
-        for( const_iterator it = begin(), itEnd = end();
+    std::ostream& operator << ( std::ostream& _stream, LineWrapper const& _lineWrapper ) {
+        for( LineWrapper::const_iterator it = _lineWrapper.begin(), itEnd = _lineWrapper.end();
             it != itEnd; ++it ) {
-            if( it != begin() )
-                stream << "\n";
-            stream << *it;
+            if( it != _lineWrapper.begin() )
+                _stream << "\n";
+            _stream << *it;
         }
-        return stream;
+        return _stream;
     }
     std::string LineWrapper::toString() const {
         std::ostringstream oss;
-        intoStream( oss );
+        oss << *this;
         return oss.str();
     }
     
diff --git a/include/reporters/catch_reporter_console.hpp b/include/reporters/catch_reporter_console.hpp
index b621aa6e..b5ce9ee2 100644
--- a/include/reporters/catch_reporter_console.hpp
+++ b/include/reporters/catch_reporter_console.hpp
@@ -211,7 +211,7 @@ namespace Catch {
                 if( result.hasExpandedExpression() ) {
                     stream << "with expansion:\n";
                     TextColour colourGuard( TextColour::ReconstructedExpression );
-                    stream << LineWrapper().setIndent(2).wrap( result.getExpandedExpression() ).toString() << "\n";
+                    stream << LineWrapper().setIndent(2).wrap( result.getExpandedExpression() ) << "\n";
                 }
             }
             void printMessage() const {
@@ -220,8 +220,7 @@ namespace Catch {
                 for( std::vector<MessageInfo>::const_iterator it = messages.begin(), itEnd = messages.end();
                         it != itEnd;
                         ++it ) {                    
-                    LineWrapper().setIndent(2).wrap( it->message ).intoStream( stream );
-                    stream << "\n";
+                    stream << LineWrapper().setIndent(2).wrap( it->message ) << "\n";
                 }
             }
             void printSourceInfo() const {