Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-14 08:50:29

0001 
0002 //              Copyright Catch2 Authors
0003 // Distributed under the Boost Software License, Version 1.0.
0004 //   (See accompanying file LICENSE.txt or copy at
0005 //        https://www.boost.org/LICENSE_1_0.txt)
0006 
0007 // SPDX-License-Identifier: BSL-1.0
0008 
0009 #ifndef CATCH_REPORTER_JSON_HPP_INCLUDED
0010 #define CATCH_REPORTER_JSON_HPP_INCLUDED
0011 
0012 #include <catch2/catch_timer.hpp>
0013 #include <catch2/internal/catch_jsonwriter.hpp>
0014 #include <catch2/reporters/catch_reporter_streaming_base.hpp>
0015 
0016 #include <stack>
0017 
0018 namespace Catch {
0019     class JsonReporter : public StreamingReporterBase {
0020     public:
0021         JsonReporter( ReporterConfig&& config );
0022 
0023         ~JsonReporter() override;
0024 
0025         static std::string getDescription();
0026 
0027     public: // StreamingReporterBase
0028         void testRunStarting( TestRunInfo const& runInfo ) override;
0029         void testRunEnded( TestRunStats const& runStats ) override;
0030 
0031         void testCaseStarting( TestCaseInfo const& tcInfo ) override;
0032         void testCaseEnded( TestCaseStats const& tcStats ) override;
0033 
0034         void testCasePartialStarting( TestCaseInfo const& tcInfo,
0035                                       uint64_t index ) override;
0036         void testCasePartialEnded( TestCaseStats const& tcStats,
0037                                    uint64_t index ) override;
0038 
0039         void sectionStarting( SectionInfo const& sectionInfo ) override;
0040         void sectionEnded( SectionStats const& sectionStats ) override;
0041 
0042         void assertionStarting( AssertionInfo const& assertionInfo ) override;
0043         void assertionEnded( AssertionStats const& assertionStats ) override;
0044 
0045         //void testRunEndedCumulative() override;
0046 
0047         void benchmarkPreparing( StringRef name ) override;
0048         void benchmarkStarting( BenchmarkInfo const& ) override;
0049         void benchmarkEnded( BenchmarkStats<> const& ) override;
0050         void benchmarkFailed( StringRef error ) override;
0051 
0052         void listReporters(
0053             std::vector<ReporterDescription> const& descriptions ) override;
0054         void listListeners(
0055             std::vector<ListenerDescription> const& descriptions ) override;
0056         void listTests( std::vector<TestCaseHandle> const& tests ) override;
0057         void listTags( std::vector<TagInfo> const& tags ) override;
0058 
0059     private:
0060         Timer m_testCaseTimer;
0061         enum class Writer {
0062             Object,
0063             Array
0064         };
0065 
0066         JsonArrayWriter& startArray();
0067         JsonArrayWriter& startArray( StringRef key );
0068 
0069         JsonObjectWriter& startObject();
0070         JsonObjectWriter& startObject( StringRef key );
0071 
0072         void endObject();
0073         void endArray();
0074 
0075         bool isInside( Writer writer );
0076 
0077         void startListing();
0078         void endListing();
0079 
0080         // Invariant:
0081         // When m_writers is not empty and its top element is
0082         // - Writer::Object, then m_objectWriters is not be empty
0083         // - Writer::Array,  then m_arrayWriters shall not be empty
0084         std::stack<JsonObjectWriter> m_objectWriters{};
0085         std::stack<JsonArrayWriter> m_arrayWriters{};
0086         std::stack<Writer> m_writers{};
0087 
0088         bool m_startedListing = false;
0089 
0090         // std::size_t m_sectionDepth = 0;
0091         // std::size_t m_sectionStarted = 0;
0092     };
0093 } // namespace Catch
0094 
0095 #endif // CATCH_REPORTER_JSON_HPP_INCLUDED