Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/src/catch2/interfaces
diff options
context:
space:
mode:
authorMartin Hořeňovský2020-07-28 09:24:57 +0200
committerMartin Hořeňovský2020-07-28 09:24:57 +0200
commitd090074da7da0bf8976c6c82cb7ae0bbb61c6af8 (patch)
treed17289fbb02a4e6a0fc7eea905cb494fb2eae705 /src/catch2/interfaces
parentd218d6f9e27afc718cef196fb63d06ca0ce21873 (diff)
downloadcatch3-d090074da7da0bf8976c6c82cb7ae0bbb61c6af8.tar.gz
Devirtualize handling of ReporterPreferences
The new scheme is that there is one protected member instance of `ReporterPreferences` in the `IStreamingReporter` base class, and derived classes can modify it to express their own preferences. Retrieving the preferences is now a non-virtual operation, which makes it much cheaper to read them frequently. Previously, we avoided doing so by caching the preferences in another variable, but we still read them at least once per test case run.
Diffstat (limited to 'src/catch2/interfaces')
-rw-r--r--src/catch2/interfaces/catch_interfaces_reporter.hpp26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/catch2/interfaces/catch_interfaces_reporter.hpp b/src/catch2/interfaces/catch_interfaces_reporter.hpp
index 5f0bcfc6..a411b897 100644
--- a/src/catch2/interfaces/catch_interfaces_reporter.hpp
+++ b/src/catch2/interfaces/catch_interfaces_reporter.hpp
@@ -46,11 +46,6 @@ namespace Catch {
IConfig const* m_fullConfig;
};
- struct ReporterPreferences {
- bool shouldRedirectStdOut = false;
- bool shouldReportAllAssertions = false;
- };
-
template<typename T>
struct LazyStat : Option<T> {
LazyStat& operator=( T const& _value ) {
@@ -178,13 +173,32 @@ namespace Catch {
}
};
+ //! By setting up its preferences, a reporter can modify Catch2's behaviour
+ //! in some regards, e.g. it can request Catch2 to capture writes to
+ //! stdout/stderr during test execution, and pass them to the reporter.
+ struct ReporterPreferences {
+ //! Catch2 should redirect writes to stdout and pass them to the
+ //! reporter
+ bool shouldRedirectStdOut = false;
+ //! Catch2 should call `Reporter::assertionEnded` even for passing
+ //! assertions
+ bool shouldReportAllAssertions = false;
+ };
+
+
struct IStreamingReporter {
+ protected:
+ //! Derived classes can set up their preferences here
+ ReporterPreferences m_preferences;
+ public:
virtual ~IStreamingReporter() = default;
// Implementing class must also provide the following static methods:
// static std::string getDescription();
- virtual ReporterPreferences getPreferences() const = 0;
+ ReporterPreferences const& getPreferences() const {
+ return m_preferences;
+ }
virtual void noMatchingTestCases( std::string const& spec ) = 0;