/* * Created by Phil on 27/11/2013. * Copyright 2013 Two Blue Cubes Ltd. All rights reserved. * * Distributed under the Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ #ifndef TWOBLUECUBES_CATCH_REPORTER_BASES_HPP_INCLUDED #define TWOBLUECUBES_CATCH_REPORTER_BASES_HPP_INCLUDED #include "../internal/catch_interfaces_reporter.h" #include #include #include #include #include namespace Catch { // Returns double formatted as %.3f (format expected on output) std::string getFormattedDuration( double duration ); struct StreamingReporterBase : IStreamingReporter { StreamingReporterBase(ReporterConfig const& _config); virtual ReporterPreferences getPreferences() const override; virtual ~StreamingReporterBase() override; virtual void noMatchingTestCases(std::string const&) override; virtual void testRunStarting(TestRunInfo const& _testRunInfo) override; virtual void testGroupStarting(GroupInfo const& _groupInfo) override; virtual void testCaseStarting(TestCaseInfo const& _testInfo) override; virtual void sectionStarting(SectionInfo const& _sectionInfo) override; virtual void sectionEnded(SectionStats const& /* _sectionStats */) override; virtual void testCaseEnded(TestCaseStats const& /* _testCaseStats */) override; virtual void testGroupEnded(TestGroupStats const& /* _testGroupStats */) override; virtual void testRunEnded(TestRunStats const& /* _testRunStats */) override; virtual void skipTest(TestCaseInfo const&) override; IConfigPtr m_config; std::ostream& stream; LazyStat currentTestRunInfo; LazyStat currentGroupInfo; LazyStat currentTestCaseInfo; std::vector m_sectionStack; ReporterPreferences m_reporterPrefs; }; struct CumulativeReporterBase : IStreamingReporter { template struct Node { explicit Node( T const& _value ) : value( _value ) {} virtual ~Node() {} using ChildNodes = std::vector>; T value; ChildNodes children; }; struct SectionNode { explicit SectionNode(SectionStats const& _stats); virtual ~SectionNode(); bool operator == (SectionNode const& other) const; bool operator == (std::shared_ptr const& other) const; SectionStats stats; using ChildSections = std::vector>; using Assertions = std::vector; ChildSections childSections; Assertions assertions; std::string stdOut; std::string stdErr; }; struct BySectionInfo { BySectionInfo(SectionInfo const& other); BySectionInfo(BySectionInfo const& other); bool operator() (std::shared_ptr const& node) const; void operator=(BySectionInfo const&) = delete; private: SectionInfo const& m_other; }; using TestCaseNode = Node; using TestGroupNode = Node; using TestRunNode = Node; CumulativeReporterBase(ReporterConfig const& _config); ~CumulativeReporterBase(); virtual ReporterPreferences getPreferences() const override; virtual void testRunStarting(TestRunInfo const&) override; virtual void testGroupStarting(GroupInfo const&) override; virtual void testCaseStarting(TestCaseInfo const&) override; virtual void sectionStarting(SectionInfo const& sectionInfo) override; virtual void assertionStarting(AssertionInfo const&) override; virtual bool assertionEnded(AssertionStats const& assertionStats) override; virtual void sectionEnded(SectionStats const& sectionStats) override; virtual void testCaseEnded(TestCaseStats const& testCaseStats) override; virtual void testGroupEnded(TestGroupStats const& testGroupStats) override; virtual void testRunEnded(TestRunStats const& testRunStats) override; virtual void testRunEndedCumulative() = 0; virtual void skipTest(TestCaseInfo const&) override; virtual void prepareExpandedExpression(AssertionResult& result) const; IConfigPtr m_config; std::ostream& stream; std::vector m_assertions; std::vector>> m_sections; std::vector> m_testCases; std::vector> m_testGroups; std::vector> m_testRuns; std::shared_ptr m_rootSection; std::shared_ptr m_deepestSection; std::vector> m_sectionStack; ReporterPreferences m_reporterPrefs; }; template char const* getLineOfChars() { static char line[CATCH_CONFIG_CONSOLE_WIDTH] = {0}; if( !*line ) { std::memset( line, C, CATCH_CONFIG_CONSOLE_WIDTH-1 ); line[CATCH_CONFIG_CONSOLE_WIDTH-1] = 0; } return line; } struct TestEventListenerBase : StreamingReporterBase { TestEventListenerBase(ReporterConfig const& _config); virtual void assertionStarting(AssertionInfo const&) override; virtual bool assertionEnded(AssertionStats const&) override; }; } // end namespace Catch #endif // TWOBLUECUBES_CATCH_REPORTER_BASES_HPP_INCLUDED