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

Print warnings if no assertions and not running with -s

Commit
4f57c8c589a1ffffc142960fe79fa6e5b74a1047
Author
Phil Nash ·
Parents
2f086ae25542

Files · Download .tar.gz

Changes

 include/reporters/catch_reporter_console.hpp       | 21 +++++++----
 .../SelfTest/Baselines/console.std.approved.txt    | 42 ++++++++++++++++++++++
 2 files changed, 57 insertions(+), 6 deletions(-)

diff --git a/include/reporters/catch_reporter_console.hpp b/include/reporters/catch_reporter_console.hpp
index 7d9ec684..17b07a7f 100644
--- a/include/reporters/catch_reporter_console.hpp
+++ b/include/reporters/catch_reporter_console.hpp
@@ -41,13 +41,18 @@ namespace Catch {
         virtual bool assertionEnded( AssertionStats const& _assertionStats ) {
             AssertionResult const& result = _assertionStats.assertionResult;
 
+            bool printInfoMessages = true;
+
             // Drop out if result was successful and we're not printing those
-            if( !m_config->includeSuccessfulResults() && result.isOk() )
-                return false;
+            if( !m_config->includeSuccessfulResults() && result.isOk() ) {
+                if( result.getResultType() != ResultWas::Warning )
+                    return false;
+                printInfoMessages = false;
+            }
 
             lazyPrint();
 
-            AssertionPrinter printer( stream, _assertionStats );
+            AssertionPrinter printer( stream, _assertionStats, printInfoMessages );
             printer.print();
             stream << std::endl;
             return true;
@@ -105,13 +110,14 @@ namespace Catch {
         class AssertionPrinter {
             void operator= ( AssertionPrinter const& );
         public:
-            AssertionPrinter( std::ostream& _stream, AssertionStats const& _stats )
+            AssertionPrinter( std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages )
             :   stream( _stream ),
                 stats( _stats ),
                 result( _stats.assertionResult ),
                 colour( Colour::None ),
                 message( result.getMessage() ),
-                messages( _stats.infoMessages )
+                messages( _stats.infoMessages ),
+                printInfoMessages( _printInfoMessages )
             {
                 switch( result.getResultType() ) {
                     case ResultWas::Ok:
@@ -214,7 +220,9 @@ namespace Catch {
                 for( std::vector<MessageInfo>::const_iterator it = messages.begin(), itEnd = messages.end();
                         it != itEnd;
                         ++it ) {
-                    stream << Text( it->message, TextAttributes().setIndent(2) ) << "\n";
+                    // If this assertion is a warning ignore any INFO messages
+                    if( printInfoMessages || it->type != ResultWas::Info )
+                        stream << Text( it->message, TextAttributes().setIndent(2) ) << "\n";
                 }
             }
             void printSourceInfo() const {
@@ -230,6 +238,7 @@ namespace Catch {
             std::string messageLabel;
             std::string message;
             std::vector<MessageInfo> messages;
+            bool printInfoMessages;
         };
 
         void lazyPrint() {
diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt
index feb08934..aaafd844 100644
--- a/projects/SelfTest/Baselines/console.std.approved.txt
+++ b/projects/SelfTest/Baselines/console.std.approved.txt
@@ -373,6 +373,16 @@ ExceptionTests.cpp:<line number>: FAILED:
 due to unexpected exception with message:
   3.14
 
+-------------------------------------------------------------------------------
+./succeeding/message
+-------------------------------------------------------------------------------
+MessageTests.cpp:<line number>
+...............................................................................
+
+MessageTests.cpp:<line number>:
+warning:
+  this is a warning
+
 -------------------------------------------------------------------------------
 ./failing/message/info/1
 -------------------------------------------------------------------------------
@@ -640,6 +650,16 @@ MiscTests.cpp:<line number>: FAILED:
 with expansion:
   "this string contains 'abc' as a substring" equals: "something else"
 
+-------------------------------------------------------------------------------
+Nice descriptive name
+-------------------------------------------------------------------------------
+MiscTests.cpp:<line number>
+...............................................................................
+
+MiscTests.cpp:<line number>:
+warning:
+  This one ran
+
 -------------------------------------------------------------------------------
 ./failing/CatchSectionInfiniteLoop
 -------------------------------------------------------------------------------
@@ -680,6 +700,28 @@ Some information
 An error
 hello
 hello
+-------------------------------------------------------------------------------
+./inprogress/failing/Tricky/trailing expression
+-------------------------------------------------------------------------------
+TrickyTests.cpp:<line number>
+...............................................................................
+
+TrickyTests.cpp:<line number>:
+warning:
+  Uncomment the code in this test to check that it gives a sensible compiler
+  error
+
+-------------------------------------------------------------------------------
+./inprogress/failing/Tricky/compound lhs
+-------------------------------------------------------------------------------
+TrickyTests.cpp:<line number>
+...............................................................................
+
+TrickyTests.cpp:<line number>:
+warning:
+  Uncomment the code in this test to check that it gives a sensible compiler
+  error
+
 -------------------------------------------------------------------------------
 ./failing/Tricky/non streamable type
 -------------------------------------------------------------------------------