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

summaryrefslogtreecommitdiffhomepage
path: root/src/catch2
diff options
context:
space:
mode:
authorMartin Hořeňovský2022-03-06 16:08:31 +0100
committerMartin Hořeňovský2022-03-06 16:28:22 +0100
commit05d4ec62c8a429752d48c172f368d50c54dc3136 (patch)
tree73ee5758c1c3abb41c7bd1530f29402b57dbd37f /src/catch2
parent4dd5e2eeceaf5c65a7648373b44ef5e68490616b (diff)
downloadcatch3-05d4ec62c8a429752d48c172f368d50c54dc3136.tar.gz
Add common ReporterBase as parent of the helper bases
This is useful as a centralized place for handling common reporter problems like handling output streams, and soon also colour impl handling.
Diffstat (limited to 'src/catch2')
-rw-r--r--src/catch2/reporters/catch_reporter_common_base.cpp30
-rw-r--r--src/catch2/reporters/catch_reporter_common_base.hpp61
-rw-r--r--src/catch2/reporters/catch_reporter_cumulative_base.cpp16
-rw-r--r--src/catch2/reporters/catch_reporter_cumulative_base.hpp14
-rw-r--r--src/catch2/reporters/catch_reporter_streaming_base.cpp16
-rw-r--r--src/catch2/reporters/catch_reporter_streaming_base.hpp14
-rw-r--r--src/catch2/reporters/catch_reporters_all.hpp1
7 files changed, 98 insertions, 54 deletions
diff --git a/src/catch2/reporters/catch_reporter_common_base.cpp b/src/catch2/reporters/catch_reporter_common_base.cpp
new file mode 100644
index 00000000..18a014fc
--- /dev/null
+++ b/src/catch2/reporters/catch_reporter_common_base.cpp
@@ -0,0 +1,30 @@
+
+// Copyright Catch2 Authors
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// https://www.boost.org/LICENSE_1_0.txt)
+
+// SPDX-License-Identifier: BSL-1.0
+
+#include <catch2/reporters/catch_reporter_common_base.hpp>
+
+#include <catch2/reporters/catch_reporter_helpers.hpp>
+
+namespace Catch {
+
+ void ReporterBase::listReporters(std::vector<ReporterDescription> const& descriptions) {
+ defaultListReporters(m_stream, descriptions, m_config->verbosity());
+ }
+
+ void ReporterBase::listTests(std::vector<TestCaseHandle> const& tests) {
+ defaultListTests(m_stream,
+ tests,
+ m_config->hasTestFilters(),
+ m_config->verbosity());
+ }
+
+ void ReporterBase::listTags(std::vector<TagInfo> const& tags) {
+ defaultListTags( m_stream, tags, m_config->hasTestFilters() );
+ }
+
+} // namespace Catch
diff --git a/src/catch2/reporters/catch_reporter_common_base.hpp b/src/catch2/reporters/catch_reporter_common_base.hpp
new file mode 100644
index 00000000..235c2606
--- /dev/null
+++ b/src/catch2/reporters/catch_reporter_common_base.hpp
@@ -0,0 +1,61 @@
+
+// Copyright Catch2 Authors
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// https://www.boost.org/LICENSE_1_0.txt)
+
+// SPDX-License-Identifier: BSL-1.0
+#ifndef CATCH_REPORTER_COMMON_BASE_HPP_INCLUDED
+#define CATCH_REPORTER_COMMON_BASE_HPP_INCLUDED
+
+#include <catch2/interfaces/catch_interfaces_reporter.hpp>
+
+namespace Catch {
+ /**
+ * This is the base class for all reporters.
+ *
+ * If are writing a reporter, you must derive from this type, or one
+ * of the helper reporter bases that are derived from this type.
+ *
+ * ReporterBase centralizes handling of various common tasks in reporters,
+ * like storing the right stream for the reporters to write to, and
+ * providing the default implementation of the different listing events.
+ */
+ class ReporterBase : public IEventListener {
+ protected:
+ //! Stream to write the output to
+ std::ostream& m_stream;
+
+ public:
+ ReporterBase( ReporterConfig const& config ):
+ IEventListener( config.fullConfig() ),
+ m_stream( config.stream() ) {}
+
+
+ /**
+ * Provides a simple default listing of reporters.
+ *
+ * Should look roughly like the reporter listing in v2 and earlier
+ * versions of Catch2.
+ */
+ void listReporters(
+ std::vector<ReporterDescription> const& descriptions ) override;
+ /**
+ * Provides a simple default listing of tests.
+ *
+ * Should look roughly like the test listing in v2 and earlier versions
+ * of Catch2. Especially supports low-verbosity listing that mimics the
+ * old `--list-test-names-only` output.
+ */
+ void listTests( std::vector<TestCaseHandle> const& tests ) override;
+ /**
+ * Provides a simple default listing of tags.
+ *
+ * Should look roughly like the tag listing in v2 and earlier versions
+ * of Catch2.
+ */
+ void listTags( std::vector<TagInfo> const& tags ) override;
+ };
+} // namespace Catch
+
+#endif // CATCH_REPORTER_COMMON_BASE_HPP_INCLUDED
diff --git a/src/catch2/reporters/catch_reporter_cumulative_base.cpp b/src/catch2/reporters/catch_reporter_cumulative_base.cpp
index 9dd1eb78..b52ba7ef 100644
--- a/src/catch2/reporters/catch_reporter_cumulative_base.cpp
+++ b/src/catch2/reporters/catch_reporter_cumulative_base.cpp
@@ -6,7 +6,6 @@
// SPDX-License-Identifier: BSL-1.0
#include <catch2/reporters/catch_reporter_cumulative_base.hpp>
-#include <catch2/reporters/catch_reporter_helpers.hpp>
#include <algorithm>
#include <cassert>
@@ -145,21 +144,6 @@ namespace Catch {
testRunEndedCumulative();
}
- void CumulativeReporterBase::listReporters(std::vector<ReporterDescription> const& descriptions) {
- defaultListReporters(m_stream, descriptions, m_config->verbosity());
- }
-
- void CumulativeReporterBase::listTests(std::vector<TestCaseHandle> const& tests) {
- defaultListTests(m_stream,
- tests,
- m_config->hasTestFilters(),
- m_config->verbosity());
- }
-
- void CumulativeReporterBase::listTags(std::vector<TagInfo> const& tags) {
- defaultListTags( m_stream, tags, m_config->hasTestFilters() );
- }
-
bool CumulativeReporterBase::SectionNode::hasAnyAssertions() const {
return std::any_of(
assertionsAndBenchmarks.begin(),
diff --git a/src/catch2/reporters/catch_reporter_cumulative_base.hpp b/src/catch2/reporters/catch_reporter_cumulative_base.hpp
index 974797c5..fd7a5045 100644
--- a/src/catch2/reporters/catch_reporter_cumulative_base.hpp
+++ b/src/catch2/reporters/catch_reporter_cumulative_base.hpp
@@ -8,7 +8,7 @@
#ifndef CATCH_REPORTER_CUMULATIVE_BASE_HPP_INCLUDED
#define CATCH_REPORTER_CUMULATIVE_BASE_HPP_INCLUDED
-#include <catch2/interfaces/catch_interfaces_reporter.hpp>
+#include <catch2/reporters/catch_reporter_common_base.hpp>
#include <catch2/internal/catch_unique_ptr.hpp>
#include <catch2/internal/catch_optional.hpp>
@@ -59,7 +59,7 @@ namespace Catch {
* performance. **Accessing the assertion expansions if it wasn't stored is
* UB.**
*/
- class CumulativeReporterBase : public IEventListener {
+ class CumulativeReporterBase : public ReporterBase {
public:
template<typename T, typename ChildNodeT>
struct Node {
@@ -90,8 +90,7 @@ namespace Catch {
using TestRunNode = Node<TestRunStats, TestCaseNode>;
CumulativeReporterBase( ReporterConfig const& _config ):
- IEventListener( _config.fullConfig() ),
- m_stream( _config.stream() ) {}
+ ReporterBase( _config ) {}
~CumulativeReporterBase() override;
void benchmarkPreparing( StringRef ) override {}
@@ -121,19 +120,12 @@ namespace Catch {
void skipTest(TestCaseInfo const&) override {}
- void listReporters( std::vector<ReporterDescription> const& descriptions ) override;
- void listTests( std::vector<TestCaseHandle> const& tests ) override;
- void listTags( std::vector<TagInfo> const& tags ) override;
-
protected:
//! Should the cumulative base store the assertion expansion for succesful assertions?
bool m_shouldStoreSuccesfulAssertions = true;
//! Should the cumulative base store the assertion expansion for failed assertions?
bool m_shouldStoreFailedAssertions = true;
- //! Stream to write the output to
- std::ostream& m_stream;
-
// We need lazy construction here. We should probably refactor it
// later, after the events are redone.
//! The root node of the test run tree.
diff --git a/src/catch2/reporters/catch_reporter_streaming_base.cpp b/src/catch2/reporters/catch_reporter_streaming_base.cpp
index 893415fe..a9c898ed 100644
--- a/src/catch2/reporters/catch_reporter_streaming_base.cpp
+++ b/src/catch2/reporters/catch_reporter_streaming_base.cpp
@@ -6,7 +6,6 @@
// SPDX-License-Identifier: BSL-1.0
#include <catch2/reporters/catch_reporter_streaming_base.hpp>
-#include <catch2/reporters/catch_reporter_helpers.hpp>
namespace Catch {
@@ -21,19 +20,4 @@ namespace Catch {
currentTestCaseInfo = nullptr;
}
- void StreamingReporterBase::listReporters(std::vector<ReporterDescription> const& descriptions) {
- defaultListReporters( m_stream, descriptions, m_config->verbosity() );
- }
-
- void StreamingReporterBase::listTests(std::vector<TestCaseHandle> const& tests) {
- defaultListTests(m_stream,
- tests,
- m_config->hasTestFilters(),
- m_config->verbosity());
- }
-
- void StreamingReporterBase::listTags(std::vector<TagInfo> const& tags) {
- defaultListTags( m_stream, tags, m_config->hasTestFilters() );
- }
-
} // end namespace Catch
diff --git a/src/catch2/reporters/catch_reporter_streaming_base.hpp b/src/catch2/reporters/catch_reporter_streaming_base.hpp
index 1ca50f0a..990610fa 100644
--- a/src/catch2/reporters/catch_reporter_streaming_base.hpp
+++ b/src/catch2/reporters/catch_reporter_streaming_base.hpp
@@ -8,7 +8,7 @@
#ifndef CATCH_REPORTER_STREAMING_BASE_HPP_INCLUDED
#define CATCH_REPORTER_STREAMING_BASE_HPP_INCLUDED
-#include <catch2/interfaces/catch_interfaces_reporter.hpp>
+#include <catch2/reporters/catch_reporter_common_base.hpp>
#include <iosfwd>
#include <string>
@@ -16,11 +16,10 @@
namespace Catch {
- class StreamingReporterBase : public IEventListener {
+ class StreamingReporterBase : public ReporterBase {
public:
StreamingReporterBase( ReporterConfig const& _config ):
- IEventListener( _config.fullConfig() ),
- m_stream( _config.stream() ) {}
+ ReporterBase( _config ) {}
~StreamingReporterBase() override;
@@ -61,14 +60,7 @@ namespace Catch {
// It can optionally be overridden in the derived class.
}
- void listReporters( std::vector<ReporterDescription> const& descriptions ) override;
- void listTests( std::vector<TestCaseHandle> const& tests ) override;
- void listTags( std::vector<TagInfo> const& tags ) override;
-
protected:
- //! Stream that the reporter output should be written to
- std::ostream& m_stream;
-
TestRunInfo currentTestRunInfo{ "test run has not started yet"_sr };
TestCaseInfo const* currentTestCaseInfo = nullptr;
diff --git a/src/catch2/reporters/catch_reporters_all.hpp b/src/catch2/reporters/catch_reporters_all.hpp
index 8c6208dc..d3a59eb7 100644
--- a/src/catch2/reporters/catch_reporters_all.hpp
+++ b/src/catch2/reporters/catch_reporters_all.hpp
@@ -22,6 +22,7 @@
#define CATCH_REPORTERS_ALL_HPP_INCLUDED
#include <catch2/reporters/catch_reporter_automake.hpp>
+#include <catch2/reporters/catch_reporter_common_base.hpp>
#include <catch2/reporters/catch_reporter_compact.hpp>
#include <catch2/reporters/catch_reporter_console.hpp>
#include <catch2/reporters/catch_reporter_cumulative_base.hpp>