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

Added warnings - first one: no assertions

Commit
55764c8d47dfabb1f4530b1880b87c0b134610d0
Author
Phil Nash ·
Parents
78c92e68aa35

Files · Download .tar.gz

Changes

 include/catch_runner.hpp                     |  2 +-
 include/internal/catch_commandline.hpp       | 32 +++++++++++++++++++++++++---
 include/internal/catch_config.hpp            | 14 +++++++++---
 include/internal/catch_context.h             |  3 +--
 include/internal/catch_interfaces_reporter.h | 10 ++++++---
 include/internal/catch_interfaces_testcase.h |  2 ++
 include/internal/catch_test_spec.h           |  3 +++
 include/reporters/catch_reporter_basic.hpp   |  5 +++++
 8 files changed, 59 insertions(+), 12 deletions(-)

diff --git a/include/catch_runner.hpp b/include/catch_runner.hpp
index a927e022..5fec833c 100644
--- a/include/catch_runner.hpp
+++ b/include/catch_runner.hpp
@@ -102,7 +102,7 @@ namespace Catch {
             ? "basic"
             : m_config.reporter;
 
-            ReporterConfig reporterConfig( m_config.name, m_configWrapper.stream(), m_config.includeWhichResults == Include::SuccessfulResults );
+            ReporterConfig reporterConfig( m_config.name, m_configWrapper.stream(), m_config.includeWhichResults == Include::SuccessfulResults, m_config );
 
             m_reporter = getRegistryHub().getReporterRegistry().create( reporterName, reporterConfig );
             if( !m_reporter ) {
diff --git a/include/internal/catch_commandline.hpp b/include/internal/catch_commandline.hpp
index 31ca3748..17a3ea74 100644
--- a/include/internal/catch_commandline.hpp
+++ b/include/internal/catch_commandline.hpp
@@ -401,6 +401,29 @@ namespace Catch {
                 config.allowThrows = false;
             }
         };
+
+        class WarningsOptionParser : public OptionParser {
+        public:
+            WarningsOptionParser() : OptionParser( 1, -1 ) {
+                m_optionNames.push_back( "-w" );
+                m_optionNames.push_back( "--warnings" );
+            }
+            virtual std::string argsSynopsis() const {
+                return "<warning>";
+            }
+            virtual std::string optionSummary() const {
+                return "!TBD";
+            }
+
+            virtual void parseIntoConfig( const Command& cmd, ConfigData& config ) {
+                for( std::size_t i = 0; i < cmd.argsCount(); ++i ) {
+                    if( cmd[i] == "NoAssertions" )
+                        config.warnings = (ConfigData::WarnAbout::What)( config.warnings | ConfigData::WarnAbout::NoAssertions );
+                    else
+                        cmd.raiseError( "Unrecognised warning: " + cmd[i] );
+                }
+            }
+        };
     }
     
     class AllOptions
@@ -410,8 +433,9 @@ namespace Catch {
         typedef Parsers::const_iterator const_iterator;
         typedef Parsers::const_iterator iterator;
 
-        AllOptions() {            
-            add<Options::TestCaseOptionParser>();
+        AllOptions() {
+            add<Options::TestCaseOptionParser>();   // Keep this one first
+
             add<Options::ListOptionParser>();
             add<Options::ReporterOptionParser>();
             add<Options::OutputOptionParser>();
@@ -420,7 +444,9 @@ namespace Catch {
             add<Options::NameOptionParser>();
             add<Options::AbortOptionParser>();
             add<Options::NoThrowOptionParser>();
-            add<Options::HelpOptionParser>();
+            add<Options::WarningsOptionParser>();
+
+            add<Options::HelpOptionParser>();       // Keep this one last
         }
 
         void parseIntoConfig( const CommandParser& parser, ConfigData& config ) {
diff --git a/include/internal/catch_config.hpp b/include/internal/catch_config.hpp
index f859f004..c2b989b0 100644
--- a/include/internal/catch_config.hpp
+++ b/include/internal/catch_config.hpp
@@ -9,8 +9,8 @@
 #define TWOBLUECUBES_CATCH_RUNNERCONFIG_HPP_INCLUDED
 
 #include "catch_test_spec.h"
-#include "catch_interfaces_reporter.h"
 #include "catch_context.h"
+#include "catch_interfaces_config.h"
 
 #include <memory>
 #include <vector>
@@ -36,18 +36,25 @@ namespace Catch {
         WhatMask = 0xf,
         
         AsText = 0x10,
-        AsXml = 0x11,
+        AsXml = 0x20,
         
         AsMask = 0xf0
     }; };
     
     struct ConfigData {
+
+        struct WarnAbout { enum What {
+            Nothing = 0x00,
+            NoAssertions = 0x01
+        }; };
+
         ConfigData()
         :   listSpec( List::None ),
             shouldDebugBreak( false ),
             includeWhichResults( Include::FailedOnly ),
             cutoff( -1 ),
-            allowThrows( true )
+            allowThrows( true ),
+            warnings( WarnAbout::Nothing )
         {}
         
         std::string reporter;
@@ -60,6 +67,7 @@ namespace Catch {
         std::string name;
         int cutoff;
         bool allowThrows;
+        WarnAbout::What warnings;
     };
     
     
diff --git a/include/internal/catch_context.h b/include/internal/catch_context.h
index c3460e3d..7ddd1f53 100644
--- a/include/internal/catch_context.h
+++ b/include/internal/catch_context.h
@@ -8,8 +8,6 @@
 #ifndef TWOBLUECUBES_CATCH_CONTEXT_H_INCLUDED
 #define TWOBLUECUBES_CATCH_CONTEXT_H_INCLUDED
 
-#include "catch_interfaces_reporter.h"
-#include "catch_interfaces_config.h"
 #include "catch_interfaces_generators.h"
 
 #include <memory>
@@ -22,6 +20,7 @@ namespace Catch {
     struct IResultCapture;
     struct IRunner;
     struct IGeneratorsForTest;
+    struct IConfig;
 
     class StreamBufBase : public std::streambuf {
     public:
diff --git a/include/internal/catch_interfaces_reporter.h b/include/internal/catch_interfaces_reporter.h
index f6b90872..792d6ff3 100644
--- a/include/internal/catch_interfaces_reporter.h
+++ b/include/internal/catch_interfaces_reporter.h
@@ -11,6 +11,7 @@
 #include "catch_common.h"
 #include "catch_totals.hpp"
 #include "catch_ptr.hpp"
+#include "catch_config.hpp"
 
 #include <string>
 #include <ostream>
@@ -22,16 +23,19 @@ namespace Catch
     {
         ReporterConfig( const std::string& _name,
                         std::ostream& _stream,
-                        bool _includeSuccessfulResults = false )
+                        bool _includeSuccessfulResults,
+                        const ConfigData& _fullConfig )
         :   name( _name ),
             stream( _stream ),
-            includeSuccessfulResults( _includeSuccessfulResults )
+            includeSuccessfulResults( _includeSuccessfulResults ),
+            fullConfig( _fullConfig )
         {}
         
         std::string name;
         std::ostream& stream;
         bool includeSuccessfulResults;
-    };    
+        ConfigData fullConfig;
+    };
     
     class TestCaseInfo;
     class ResultInfo;
diff --git a/include/internal/catch_interfaces_testcase.h b/include/internal/catch_interfaces_testcase.h
index 7d5192aa..94ddf6f7 100644
--- a/include/internal/catch_interfaces_testcase.h
+++ b/include/internal/catch_interfaces_testcase.h
@@ -8,6 +8,8 @@
 #ifndef TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED
 #define TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED
 
+#include "catch_ptr.hpp"
+
 #include <vector>
 
 namespace Catch {
diff --git a/include/internal/catch_test_spec.h b/include/internal/catch_test_spec.h
index 4aa03855..69a76b82 100644
--- a/include/internal/catch_test_spec.h
+++ b/include/internal/catch_test_spec.h
@@ -8,7 +8,10 @@
 #ifndef TWOBLUECUBES_CATCH_TESTSPEC_H_INCLUDED
 #define TWOBLUECUBES_CATCH_TESTSPEC_H_INCLUDED
 
+#include "catch_test_case_info.h"
+
 #include <string>
+#include <vector>
 
 namespace Catch {
     
diff --git a/include/reporters/catch_reporter_basic.hpp b/include/reporters/catch_reporter_basic.hpp
index 4cff4729..28304d73 100644
--- a/include/reporters/catch_reporter_basic.hpp
+++ b/include/reporters/catch_reporter_basic.hpp
@@ -129,6 +129,11 @@ namespace Catch {
         }
         
         virtual void EndSection( const std::string& sectionName, const Counts& assertions ) {
+            if( ( m_config.fullConfig.warnings & ConfigData::WarnAbout::NoAssertions ) && assertions.total() == 0 ) {
+                StartSpansLazily();
+                m_config.stream << "** No assertions in section **" << std::endl;
+            }
+
             SpanInfo& sectionSpan = m_sectionSpans.back();
             if( sectionSpan.emitted && !sectionSpan.name.empty() ) {
                 m_config.stream << "[End of section: '" << sectionName << "' ";