2013-12-03 19:52:41 +01:00
|
|
|
/*
|
|
|
|
* 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"
|
|
|
|
|
2014-12-22 08:42:25 +01:00
|
|
|
#include <cstring>
|
2017-03-02 16:16:17 +01:00
|
|
|
#include <cfloat>
|
|
|
|
#include <cstdio>
|
2017-02-22 13:31:51 +01:00
|
|
|
#include <assert.h>
|
2017-04-26 18:04:00 +02:00
|
|
|
#include <memory>
|
2014-12-22 08:42:25 +01:00
|
|
|
|
2013-12-03 19:52:41 +01:00
|
|
|
namespace Catch {
|
|
|
|
|
2017-07-10 11:33:18 +02:00
|
|
|
// Returns double formatted as %.3f (format expected on output)
|
|
|
|
std::string getFormattedDuration( double duration );
|
2017-03-02 16:16:17 +01:00
|
|
|
|
2017-04-25 22:51:44 +02:00
|
|
|
struct StreamingReporterBase : IStreamingReporter {
|
2013-12-03 19:52:41 +01:00
|
|
|
|
2017-07-10 11:33:18 +02:00
|
|
|
StreamingReporterBase(ReporterConfig const& _config);
|
2015-08-07 09:20:56 +02:00
|
|
|
|
2017-07-10 11:33:18 +02:00
|
|
|
virtual ReporterPreferences getPreferences() const override;
|
2013-12-03 19:52:41 +01:00
|
|
|
|
2017-04-25 12:41:30 +02:00
|
|
|
virtual ~StreamingReporterBase() override;
|
2013-12-03 19:52:41 +01:00
|
|
|
|
2017-07-10 11:33:18 +02:00
|
|
|
virtual void noMatchingTestCases(std::string const&) override;
|
2013-12-03 19:52:41 +01:00
|
|
|
|
2017-07-10 11:33:18 +02:00
|
|
|
virtual void testRunStarting(TestRunInfo const& _testRunInfo) override;
|
|
|
|
virtual void testGroupStarting(GroupInfo const& _groupInfo) override;
|
2013-12-03 19:52:41 +01:00
|
|
|
|
2017-07-10 11:33:18 +02:00
|
|
|
virtual void testCaseStarting(TestCaseInfo const& _testInfo) override;
|
|
|
|
virtual void sectionStarting(SectionInfo const& _sectionInfo) override;
|
2013-12-03 19:52:41 +01:00
|
|
|
|
2017-07-10 11:33:18 +02:00
|
|
|
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;
|
2013-12-03 19:52:41 +01:00
|
|
|
|
2017-07-10 11:33:18 +02:00
|
|
|
virtual void skipTest(TestCaseInfo const&) override;
|
2014-12-22 21:10:33 +01:00
|
|
|
|
2017-04-25 21:18:02 +02:00
|
|
|
IConfigPtr m_config;
|
2013-12-03 19:52:41 +01:00
|
|
|
std::ostream& stream;
|
|
|
|
|
|
|
|
LazyStat<TestRunInfo> currentTestRunInfo;
|
|
|
|
LazyStat<GroupInfo> currentGroupInfo;
|
|
|
|
LazyStat<TestCaseInfo> currentTestCaseInfo;
|
|
|
|
|
|
|
|
std::vector<SectionInfo> m_sectionStack;
|
2015-08-07 09:20:56 +02:00
|
|
|
ReporterPreferences m_reporterPrefs;
|
2013-12-03 19:52:41 +01:00
|
|
|
};
|
|
|
|
|
2017-04-25 22:51:44 +02:00
|
|
|
struct CumulativeReporterBase : IStreamingReporter {
|
2013-12-03 19:52:41 +01:00
|
|
|
template<typename T, typename ChildNodeT>
|
2017-04-25 22:08:41 +02:00
|
|
|
struct Node {
|
2013-12-03 19:52:41 +01:00
|
|
|
explicit Node( T const& _value ) : value( _value ) {}
|
|
|
|
virtual ~Node() {}
|
|
|
|
|
2017-04-25 22:08:41 +02:00
|
|
|
using ChildNodes = std::vector<std::shared_ptr<ChildNodeT>>;
|
2013-12-03 19:52:41 +01:00
|
|
|
T value;
|
|
|
|
ChildNodes children;
|
|
|
|
};
|
2017-04-25 22:08:41 +02:00
|
|
|
struct SectionNode {
|
2017-07-10 11:33:18 +02:00
|
|
|
explicit SectionNode(SectionStats const& _stats);
|
2013-12-03 19:52:41 +01:00
|
|
|
virtual ~SectionNode();
|
|
|
|
|
2017-07-10 11:33:18 +02:00
|
|
|
bool operator == (SectionNode const& other) const;
|
|
|
|
bool operator == (std::shared_ptr<SectionNode> const& other) const;
|
2013-12-03 19:52:41 +01:00
|
|
|
|
|
|
|
SectionStats stats;
|
2017-04-25 22:08:41 +02:00
|
|
|
using ChildSections = std::vector<std::shared_ptr<SectionNode>>;
|
|
|
|
using Assertions = std::vector<AssertionStats>;
|
2013-12-03 19:52:41 +01:00
|
|
|
ChildSections childSections;
|
|
|
|
Assertions assertions;
|
|
|
|
std::string stdOut;
|
|
|
|
std::string stdErr;
|
|
|
|
};
|
2013-12-18 09:37:23 +01:00
|
|
|
|
|
|
|
struct BySectionInfo {
|
2017-07-10 11:33:18 +02:00
|
|
|
BySectionInfo(SectionInfo const& other);
|
|
|
|
BySectionInfo(BySectionInfo const& other);
|
|
|
|
bool operator() (std::shared_ptr<SectionNode> const& node) const;
|
|
|
|
void operator=(BySectionInfo const&) = delete;
|
|
|
|
|
2013-12-18 09:37:23 +01:00
|
|
|
private:
|
|
|
|
SectionInfo const& m_other;
|
|
|
|
};
|
|
|
|
|
2013-12-03 19:52:41 +01:00
|
|
|
|
2017-04-25 22:08:41 +02:00
|
|
|
using TestCaseNode = Node<TestCaseStats, SectionNode>;
|
|
|
|
using TestGroupNode = Node<TestGroupStats, TestCaseNode>;
|
|
|
|
using TestRunNode = Node<TestRunStats, TestGroupNode>;
|
2013-12-03 19:52:41 +01:00
|
|
|
|
2017-07-10 11:33:18 +02:00
|
|
|
CumulativeReporterBase(ReporterConfig const& _config);
|
2013-12-03 19:52:41 +01:00
|
|
|
~CumulativeReporterBase();
|
|
|
|
|
2017-07-10 11:33:18 +02:00
|
|
|
virtual ReporterPreferences getPreferences() const override;
|
2015-08-07 09:20:56 +02:00
|
|
|
|
2017-07-10 11:33:18 +02:00
|
|
|
virtual void testRunStarting(TestRunInfo const&) override;
|
|
|
|
virtual void testGroupStarting(GroupInfo const&) override;
|
2013-12-03 19:52:41 +01:00
|
|
|
|
2017-07-10 11:33:18 +02:00
|
|
|
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;
|
2013-12-07 10:08:01 +01:00
|
|
|
virtual void testRunEndedCumulative() = 0;
|
2013-12-03 19:52:41 +01:00
|
|
|
|
2017-07-10 11:33:18 +02:00
|
|
|
virtual void skipTest(TestCaseInfo const&) override;
|
2014-12-22 21:10:33 +01:00
|
|
|
|
2017-07-10 11:33:18 +02:00
|
|
|
virtual void prepareExpandedExpression(AssertionResult& result) const;
|
2017-01-09 13:23:10 +01:00
|
|
|
|
2017-04-25 21:18:02 +02:00
|
|
|
IConfigPtr m_config;
|
2013-12-03 19:52:41 +01:00
|
|
|
std::ostream& stream;
|
|
|
|
std::vector<AssertionStats> m_assertions;
|
2017-04-25 22:08:41 +02:00
|
|
|
std::vector<std::vector<std::shared_ptr<SectionNode>>> m_sections;
|
|
|
|
std::vector<std::shared_ptr<TestCaseNode>> m_testCases;
|
|
|
|
std::vector<std::shared_ptr<TestGroupNode>> m_testGroups;
|
2013-12-03 19:52:41 +01:00
|
|
|
|
2017-04-25 22:08:41 +02:00
|
|
|
std::vector<std::shared_ptr<TestRunNode>> m_testRuns;
|
2013-12-03 19:52:41 +01:00
|
|
|
|
2017-04-25 22:08:41 +02:00
|
|
|
std::shared_ptr<SectionNode> m_rootSection;
|
|
|
|
std::shared_ptr<SectionNode> m_deepestSection;
|
|
|
|
std::vector<std::shared_ptr<SectionNode>> m_sectionStack;
|
2015-08-07 09:20:56 +02:00
|
|
|
ReporterPreferences m_reporterPrefs;
|
2013-12-03 19:52:41 +01:00
|
|
|
};
|
|
|
|
|
2014-12-20 01:46:02 +01:00
|
|
|
template<char C>
|
|
|
|
char const* getLineOfChars() {
|
|
|
|
static char line[CATCH_CONFIG_CONSOLE_WIDTH] = {0};
|
|
|
|
if( !*line ) {
|
2017-01-26 19:11:20 +01:00
|
|
|
std::memset( line, C, CATCH_CONFIG_CONSOLE_WIDTH-1 );
|
2014-12-20 01:46:02 +01:00
|
|
|
line[CATCH_CONFIG_CONSOLE_WIDTH-1] = 0;
|
|
|
|
}
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2015-08-07 09:20:56 +02:00
|
|
|
struct TestEventListenerBase : StreamingReporterBase {
|
2017-07-10 11:33:18 +02:00
|
|
|
TestEventListenerBase(ReporterConfig const& _config);
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2017-07-10 11:33:18 +02:00
|
|
|
virtual void assertionStarting(AssertionInfo const&) override;
|
|
|
|
virtual bool assertionEnded(AssertionStats const&) override;
|
2015-08-07 09:20:56 +02:00
|
|
|
};
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2013-12-03 19:52:41 +01:00
|
|
|
} // end namespace Catch
|
|
|
|
|
|
|
|
#endif // TWOBLUECUBES_CATCH_REPORTER_BASES_HPP_INCLUDED
|