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

More console reporter tweaks - mostly newlines

Commit
bb76e477041ac158be62b509d33ab29bc57e3782
Author
Phil Nash ·
Parents
42aef1d99cc2

Files · Download .tar.gz

Changes

 include/reporters/catch_reporter_console.hpp | 73 ++++++++++++++++------------
 1 file changed, 43 insertions(+), 30 deletions(-)

diff --git a/include/reporters/catch_reporter_console.hpp b/include/reporters/catch_reporter_console.hpp
index 999bfdfa..4b7ce2a3 100644
--- a/include/reporters/catch_reporter_console.hpp
+++ b/include/reporters/catch_reporter_console.hpp
@@ -127,16 +127,19 @@ namespace Catch {
                 stream << result.getSourceInfo() << ":\n";
             }
             
+            bool endsWithNewLine = false;
             if( _assertionStats.totals.assertions.total() > 0 ) {
-                printOriginalExpression( result );
-                printResultType( result );
-                printReconstructedExpression( result );
+                endsWithNewLine = printOriginalExpression( result );
+                endsWithNewLine = printResultType( result );
+                endsWithNewLine |= printReconstructedExpression( result );
             }
-            printMessage( result );
+            endsWithNewLine |= printMessage( result );
+            if( !endsWithNewLine )
+                stream << "\n";
             stream << std::endl;
         }
         
-        void printResultType( AssertionResult const& _result ) {
+        bool printResultType( AssertionResult const& _result ) {
             if( _result.succeeded() ) {
                 TextColour successColour( TextColour::Success );
                 stream << "passed";
@@ -149,14 +152,43 @@ namespace Catch {
                 TextColour errorColour( TextColour::Error );
                 stream << "failed";
             }
+            return false;
         }
-        
-        void printMessage( AssertionResult const& _result ) {
+        bool printOriginalExpression( AssertionResult const& _result ) {
+            if( _result.hasExpression() ) {
+                TextColour colour( TextColour::OriginalExpression );
+                stream  << "  ";
+                if( !_result.getTestMacroName().empty() )
+                    stream << _result.getTestMacroName() << "( ";
+                stream << _result.getExpression();
+                if( !_result.getTestMacroName().empty() )
+                    stream << " )";
+                stream << "\n";
+                return true;
+            }
+            return false;
+        }
+        bool printReconstructedExpression( AssertionResult const& _result ) {
+            if( _result.hasExpandedExpression() ) {
+                stream << " with expansion:\n";
+                TextColour colour( TextColour::ReconstructedExpression );
+                stream << wrapLongStrings( _result.getExpandedExpression() ) << "\n";
+                return true;
+            }
+            return false;
+        }        
+        bool printMessage( AssertionResult const& _result ) {
             std::pair<std::string, std::string> message = getMessage( _result );
-            if( !message.first.empty() )
-                stream << " " << message.first << ":\n";
-            if( !message.second.empty() )
-                printWrappableString( message.second );
+            bool endsWithNewLine = false;
+            if( !message.first.empty() ) {
+                stream << " " << message.first << ":" << "\n";
+                endsWithNewLine = true;
+            }
+            if( !message.second.empty() ) {
+                stream << wrapLongStrings( message.second ) << "\n";
+                endsWithNewLine = true;
+            }
+            return endsWithNewLine;
         }
         std::pair<std::string, std::string> getMessage( AssertionResult const& _result ) {
             switch( _result.getResultType() ) {
@@ -182,26 +214,7 @@ namespace Catch {
                         return std::make_pair( "", "" );
             }
         }
-        void printOriginalExpression( AssertionResult const& _result ) {
-            if( _result.hasExpression() ) {
-                TextColour colour( TextColour::OriginalExpression );
-                stream  << "  " << _result.getTestMacroName() << "( "
-                        << _result.getExpression()
-                        << " )\n";
-            }
-        }
-        void printReconstructedExpression( AssertionResult const& _result ) {
-            if( _result.hasExpandedExpression() ) {
-                stream << " with expansion:\n";
-                TextColour colour( TextColour::ReconstructedExpression );
-                printWrappableString( _result.getExpandedExpression() );
-            }
-        }
         
-        void printWrappableString( std::string const& _string ) {
-            stream << wrapLongStrings( _string ) << "\n";
-        }
-
         std::string wrapLongStrings( std::string const& _string ) {
             return Catch::wrapLongStrings( _string, 70, 2 );
         }