File indexing completed on 2025-01-18 09:54:07
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef CATCH_REPORTER_CUMULATIVE_BASE_HPP_INCLUDED
0009 #define CATCH_REPORTER_CUMULATIVE_BASE_HPP_INCLUDED
0010
0011 #include <catch2/reporters/catch_reporter_common_base.hpp>
0012 #include <catch2/internal/catch_move_and_forward.hpp>
0013 #include <catch2/internal/catch_unique_ptr.hpp>
0014 #include <catch2/internal/catch_optional.hpp>
0015
0016 #include <string>
0017 #include <vector>
0018
0019 namespace Catch {
0020
0021 namespace Detail {
0022
0023
0024 class AssertionOrBenchmarkResult {
0025
0026
0027
0028 Optional<AssertionStats> m_assertion;
0029 Optional<BenchmarkStats<>> m_benchmark;
0030 public:
0031 AssertionOrBenchmarkResult(AssertionStats const& assertion);
0032 AssertionOrBenchmarkResult(BenchmarkStats<> const& benchmark);
0033
0034 bool isAssertion() const;
0035 bool isBenchmark() const;
0036
0037 AssertionStats const& asAssertion() const;
0038 BenchmarkStats<> const& asBenchmark() const;
0039 };
0040 }
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062 class CumulativeReporterBase : public ReporterBase {
0063 public:
0064 template<typename T, typename ChildNodeT>
0065 struct Node {
0066 explicit Node( T const& _value ) : value( _value ) {}
0067
0068 using ChildNodes = std::vector<Detail::unique_ptr<ChildNodeT>>;
0069 T value;
0070 ChildNodes children;
0071 };
0072 struct SectionNode {
0073 explicit SectionNode(SectionStats const& _stats) : stats(_stats) {}
0074
0075 bool operator == (SectionNode const& other) const {
0076 return stats.sectionInfo.lineInfo == other.stats.sectionInfo.lineInfo;
0077 }
0078
0079 bool hasAnyAssertions() const;
0080
0081 SectionStats stats;
0082 std::vector<Detail::unique_ptr<SectionNode>> childSections;
0083 std::vector<Detail::AssertionOrBenchmarkResult> assertionsAndBenchmarks;
0084 std::string stdOut;
0085 std::string stdErr;
0086 };
0087
0088
0089 using TestCaseNode = Node<TestCaseStats, SectionNode>;
0090 using TestRunNode = Node<TestRunStats, TestCaseNode>;
0091
0092
0093
0094 CumulativeReporterBase(ReporterConfig&& _config):
0095 ReporterBase(CATCH_MOVE(_config))
0096 {}
0097 ~CumulativeReporterBase() override;
0098
0099 void benchmarkPreparing( StringRef ) override {}
0100 void benchmarkStarting( BenchmarkInfo const& ) override {}
0101 void benchmarkEnded( BenchmarkStats<> const& benchmarkStats ) override;
0102 void benchmarkFailed( StringRef ) override {}
0103
0104 void noMatchingTestCases( StringRef ) override {}
0105 void reportInvalidTestSpec( StringRef ) override {}
0106 void fatalErrorEncountered( StringRef ) override {}
0107
0108 void testRunStarting( TestRunInfo const& ) override {}
0109
0110 void testCaseStarting( TestCaseInfo const& ) override {}
0111 void testCasePartialStarting( TestCaseInfo const&, uint64_t ) override {}
0112 void sectionStarting( SectionInfo const& sectionInfo ) override;
0113
0114 void assertionStarting( AssertionInfo const& ) override {}
0115
0116 void assertionEnded( AssertionStats const& assertionStats ) override;
0117 void sectionEnded( SectionStats const& sectionStats ) override;
0118 void testCasePartialEnded( TestCaseStats const&, uint64_t ) override {}
0119 void testCaseEnded( TestCaseStats const& testCaseStats ) override;
0120 void testRunEnded( TestRunStats const& testRunStats ) override;
0121
0122 virtual void testRunEndedCumulative() = 0;
0123
0124 void skipTest(TestCaseInfo const&) override {}
0125
0126 protected:
0127
0128 bool m_shouldStoreSuccesfulAssertions = true;
0129
0130 bool m_shouldStoreFailedAssertions = true;
0131
0132
0133
0134
0135 Detail::unique_ptr<TestRunNode> m_testRun;
0136
0137 private:
0138
0139
0140 std::vector<Detail::unique_ptr<TestCaseNode>> m_testCases;
0141
0142 Detail::unique_ptr<SectionNode> m_rootSection;
0143
0144 SectionNode* m_deepestSection = nullptr;
0145
0146 std::vector<SectionNode*> m_sectionStack;
0147 };
0148
0149 }
0150
0151 #endif