From 4e852672033ac989e303a4a00de607738e64e7e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Thu, 14 Sep 2017 19:57:59 +0200 Subject: [PATCH] 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 --- 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 @@ -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; 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 } );