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

Add fatalErrorEncountered method to Reporter/Listener interface

An empty default implementation is provided to keep backward compatibility.
Called when signal or Structured Exception is encountered.

Related to #1005
Commit
4e852672033ac989e303a4a00de607738e64e7e5
Author
Martin Hořeňovský ·
Parents
eaf850cd0c2c

Files · Download .tar.gz

Changes

 include/internal/catch_interfaces_reporter.cpp | 2 +-
 include/internal/catch_interfaces_reporter.h   | 4 ++++
 include/internal/catch_run_context.cpp         | 3 +++
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/include/internal/catch_interfaces_reporter.cpp b/include/internal/catch_interfaces_reporter.cpp
index 06e409ae..3859c546 100644
--- a/include/internal/catch_interfaces_reporter.cpp
+++ b/include/internal/catch_interfaces_reporter.cpp
@@ -105,7 +105,7 @@ namespace Catch {
 
     TestRunStats::~TestRunStats() = default;
 
-
+    void IStreamingReporter::fatalErrorEncountered( StringRef name ) {}
     bool IStreamingReporter::isMulti() const { return false; }
 
     IReporterFactory::~IReporterFactory() = default;
diff --git a/include/internal/catch_interfaces_reporter.h b/include/internal/catch_interfaces_reporter.h
index 43beca68..318ce669 100644
--- a/include/internal/catch_interfaces_reporter.h
+++ b/include/internal/catch_interfaces_reporter.h
@@ -16,6 +16,7 @@
 #include "catch_assertionresult.h"
 #include "catch_message.h"
 #include "catch_option.hpp"
+#include "catch_stringref.h"
 
 
 #include <string>
@@ -201,6 +202,9 @@ namespace Catch {
 
         virtual void skipTest( TestCaseInfo const& testInfo ) = 0;
 
+        // Default empty implementation provided
+        virtual void fatalErrorEncountered( StringRef name );
+
         virtual bool isMulti() const;
     };
     using IStreamingReporterPtr = std::unique_ptr<IStreamingReporter>;
diff --git a/include/internal/catch_run_context.cpp b/include/internal/catch_run_context.cpp
index 60f133a0..b034ec62 100644
--- a/include/internal/catch_run_context.cpp
+++ b/include/internal/catch_run_context.cpp
@@ -209,6 +209,9 @@ namespace Catch {
     }
 
     void RunContext::handleFatalErrorCondition(std::string const & message) {
+        // First notify reporter that bad things happened
+        m_reporter->fatalErrorEncountered(message);
+
         // Don't rebuild the result -- the stringification itself can cause more fatal errors
         // Instead, fake a result data.
         AssertionResultData tempResult( ResultWas::FatalErrorCondition, { false } );