2010-12-31 23:07:47 +01:00
|
|
|
/*
|
|
|
|
* Created by Phil on 31/12/2010.
|
|
|
|
* Copyright 2010 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)
|
|
|
|
*/
|
2012-09-17 07:42:29 +02:00
|
|
|
#ifndef TWOBLUECUBES_CATCH_INTERFACES_REPORTER_H_INCLUDED
|
|
|
|
#define TWOBLUECUBES_CATCH_INTERFACES_REPORTER_H_INCLUDED
|
2010-12-31 23:07:47 +01:00
|
|
|
|
|
|
|
#include "catch_common.h"
|
2012-02-24 09:59:35 +01:00
|
|
|
#include "catch_totals.hpp"
|
2012-05-04 08:55:11 +02:00
|
|
|
#include "catch_ptr.hpp"
|
2012-08-28 09:20:18 +02:00
|
|
|
#include "catch_config.hpp"
|
2012-11-22 20:17:20 +01:00
|
|
|
#include "catch_test_case_info.h"
|
|
|
|
#include "catch_assertionresult.h"
|
2013-02-02 20:58:04 +01:00
|
|
|
#include "catch_message.h"
|
2012-12-05 09:40:53 +01:00
|
|
|
#include "catch_option.hpp"
|
2010-12-31 23:07:47 +01:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <ostream>
|
2010-12-31 23:21:36 +01:00
|
|
|
#include <map>
|
2013-08-16 09:01:16 +02:00
|
|
|
#include <assert.h>
|
2010-12-31 23:07:47 +01:00
|
|
|
|
|
|
|
namespace Catch
|
|
|
|
{
|
2012-11-29 21:31:17 +01:00
|
|
|
struct ReporterConfig {
|
2013-05-28 19:39:32 +02:00
|
|
|
explicit ReporterConfig( Ptr<IConfig> const& _fullConfig )
|
|
|
|
: m_stream( &_fullConfig->stream() ), m_fullConfig( _fullConfig ) {}
|
|
|
|
|
|
|
|
ReporterConfig( Ptr<IConfig> const& _fullConfig, std::ostream& _stream )
|
2012-11-27 00:28:00 +01:00
|
|
|
: m_stream( &_stream ), m_fullConfig( _fullConfig ) {}
|
2012-09-20 09:17:52 +02:00
|
|
|
|
2013-05-28 19:39:32 +02:00
|
|
|
std::ostream& stream() const { return *m_stream; }
|
|
|
|
Ptr<IConfig> fullConfig() const { return m_fullConfig; }
|
2012-09-20 09:17:52 +02:00
|
|
|
|
|
|
|
private:
|
2012-11-27 00:28:00 +01:00
|
|
|
std::ostream* m_stream;
|
2013-05-28 19:39:32 +02:00
|
|
|
Ptr<IConfig> m_fullConfig;
|
2012-08-28 09:20:18 +02:00
|
|
|
};
|
2012-11-22 20:17:20 +01:00
|
|
|
|
2012-11-29 21:31:17 +01:00
|
|
|
struct ReporterPreferences {
|
2012-11-29 10:05:51 +01:00
|
|
|
ReporterPreferences()
|
|
|
|
: shouldRedirectStdOut( false )
|
|
|
|
{}
|
|
|
|
|
|
|
|
bool shouldRedirectStdOut;
|
|
|
|
};
|
|
|
|
|
2013-08-08 09:24:37 +02:00
|
|
|
template<typename T>
|
|
|
|
struct LazyStat : Option<T> {
|
|
|
|
LazyStat() : used( false ) {}
|
|
|
|
LazyStat& operator=( T const& _value ) {
|
|
|
|
Option<T>::operator=( _value );
|
|
|
|
used = false;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
void reset() {
|
|
|
|
Option<T>::reset();
|
|
|
|
used = false;
|
|
|
|
}
|
|
|
|
bool used;
|
|
|
|
};
|
|
|
|
|
2012-12-02 00:49:57 +01:00
|
|
|
struct TestRunInfo {
|
|
|
|
TestRunInfo( std::string const& _name ) : name( _name ) {}
|
|
|
|
std::string name;
|
|
|
|
};
|
|
|
|
struct GroupInfo {
|
2013-01-13 22:51:44 +01:00
|
|
|
GroupInfo( std::string const& _name,
|
|
|
|
std::size_t _groupIndex,
|
|
|
|
std::size_t _groupsCount )
|
|
|
|
: name( _name ),
|
|
|
|
groupIndex( _groupIndex ),
|
|
|
|
groupsCounts( _groupsCount )
|
|
|
|
{}
|
|
|
|
|
2012-12-02 00:49:57 +01:00
|
|
|
std::string name;
|
2013-01-13 22:51:44 +01:00
|
|
|
std::size_t groupIndex;
|
|
|
|
std::size_t groupsCounts;
|
2012-12-02 00:49:57 +01:00
|
|
|
};
|
|
|
|
|
2012-11-29 21:31:17 +01:00
|
|
|
struct SectionInfo {
|
|
|
|
SectionInfo( std::string const& _name,
|
|
|
|
std::string const& _description,
|
|
|
|
SourceLineInfo const& _lineInfo )
|
|
|
|
: name( _name ),
|
|
|
|
description( _description ),
|
2012-11-30 09:58:46 +01:00
|
|
|
lineInfo( _lineInfo )
|
2012-11-29 21:31:17 +01:00
|
|
|
{}
|
|
|
|
|
|
|
|
std::string name;
|
|
|
|
std::string description;
|
2012-11-30 09:58:46 +01:00
|
|
|
SourceLineInfo lineInfo;
|
2012-11-29 21:31:17 +01:00
|
|
|
};
|
|
|
|
|
2013-01-03 10:04:46 +01:00
|
|
|
struct AssertionStats {
|
2012-11-29 21:31:17 +01:00
|
|
|
AssertionStats( AssertionResult const& _assertionResult,
|
2013-02-02 20:58:04 +01:00
|
|
|
std::vector<MessageInfo> const& _infoMessages,
|
2012-11-29 21:31:17 +01:00
|
|
|
Totals const& _totals )
|
2012-11-25 22:43:36 +01:00
|
|
|
: assertionResult( _assertionResult ),
|
2013-02-02 20:58:04 +01:00
|
|
|
infoMessages( _infoMessages ),
|
2012-11-25 22:43:36 +01:00
|
|
|
totals( _totals )
|
2013-02-02 20:58:04 +01:00
|
|
|
{
|
|
|
|
if( assertionResult.hasMessage() ) {
|
|
|
|
// Copy message into messages list.
|
|
|
|
// !TBD This should have been done earlier, somewhere
|
|
|
|
MessageBuilder builder( assertionResult.getTestMacroName(), assertionResult.getSourceInfo(), assertionResult.getResultType() );
|
|
|
|
builder << assertionResult.getMessage();
|
2013-06-28 18:09:57 +02:00
|
|
|
builder.m_info.message = builder.m_stream.str();
|
|
|
|
|
|
|
|
infoMessages.push_back( builder.m_info );
|
2013-02-02 20:58:04 +01:00
|
|
|
}
|
|
|
|
}
|
2012-11-30 19:54:06 +01:00
|
|
|
virtual ~AssertionStats();
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2012-11-22 20:17:20 +01:00
|
|
|
AssertionResult assertionResult;
|
2013-02-02 20:58:04 +01:00
|
|
|
std::vector<MessageInfo> infoMessages;
|
2012-11-22 20:17:20 +01:00
|
|
|
Totals totals;
|
|
|
|
};
|
|
|
|
|
2013-01-03 10:04:46 +01:00
|
|
|
struct SectionStats {
|
2012-11-30 09:58:46 +01:00
|
|
|
SectionStats( SectionInfo const& _sectionInfo,
|
|
|
|
Counts const& _assertions,
|
2013-08-07 19:56:35 +02:00
|
|
|
double _durationInSeconds,
|
2012-11-30 09:58:46 +01:00
|
|
|
bool _missingAssertions )
|
|
|
|
: sectionInfo( _sectionInfo ),
|
|
|
|
assertions( _assertions ),
|
2013-08-07 19:56:35 +02:00
|
|
|
durationInSeconds( _durationInSeconds ),
|
2012-11-30 09:58:46 +01:00
|
|
|
missingAssertions( _missingAssertions )
|
|
|
|
{}
|
2012-11-30 19:54:06 +01:00
|
|
|
virtual ~SectionStats();
|
|
|
|
|
2012-11-29 21:31:17 +01:00
|
|
|
SectionInfo sectionInfo;
|
2012-11-30 09:58:46 +01:00
|
|
|
Counts assertions;
|
2013-08-07 19:56:35 +02:00
|
|
|
double durationInSeconds;
|
2012-11-30 09:58:46 +01:00
|
|
|
bool missingAssertions;
|
2012-11-29 21:31:17 +01:00
|
|
|
};
|
|
|
|
|
2013-01-03 10:04:46 +01:00
|
|
|
struct TestCaseStats {
|
2012-11-29 21:31:17 +01:00
|
|
|
TestCaseStats( TestCaseInfo const& _testInfo,
|
|
|
|
Totals const& _totals,
|
|
|
|
std::string const& _stdOut,
|
|
|
|
std::string const& _stdErr,
|
2012-11-25 22:43:36 +01:00
|
|
|
bool _aborting )
|
|
|
|
: testInfo( _testInfo ),
|
|
|
|
totals( _totals ),
|
|
|
|
stdOut( _stdOut ),
|
|
|
|
stdErr( _stdErr ),
|
|
|
|
aborting( _aborting )
|
|
|
|
{}
|
2012-11-30 19:54:06 +01:00
|
|
|
virtual ~TestCaseStats();
|
2012-11-25 22:43:36 +01:00
|
|
|
|
|
|
|
TestCaseInfo testInfo;
|
2012-11-22 20:17:20 +01:00
|
|
|
Totals totals;
|
|
|
|
std::string stdOut;
|
|
|
|
std::string stdErr;
|
|
|
|
bool aborting;
|
|
|
|
};
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2013-01-03 10:04:46 +01:00
|
|
|
struct TestGroupStats {
|
2012-12-02 00:49:57 +01:00
|
|
|
TestGroupStats( GroupInfo const& _groupInfo,
|
2012-11-29 21:31:17 +01:00
|
|
|
Totals const& _totals,
|
2012-11-25 22:43:36 +01:00
|
|
|
bool _aborting )
|
2012-12-02 00:49:57 +01:00
|
|
|
: groupInfo( _groupInfo ),
|
2012-11-25 22:43:36 +01:00
|
|
|
totals( _totals ),
|
|
|
|
aborting( _aborting )
|
|
|
|
{}
|
2013-01-03 10:04:46 +01:00
|
|
|
TestGroupStats( GroupInfo const& _groupInfo )
|
|
|
|
: groupInfo( _groupInfo ),
|
|
|
|
aborting( false )
|
|
|
|
{}
|
2012-11-30 19:54:06 +01:00
|
|
|
virtual ~TestGroupStats();
|
2012-11-25 22:43:36 +01:00
|
|
|
|
2012-12-02 00:49:57 +01:00
|
|
|
GroupInfo groupInfo;
|
2012-11-22 20:17:20 +01:00
|
|
|
Totals totals;
|
|
|
|
bool aborting;
|
|
|
|
};
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2013-01-03 10:04:46 +01:00
|
|
|
struct TestRunStats {
|
2012-12-02 00:49:57 +01:00
|
|
|
TestRunStats( TestRunInfo const& _runInfo,
|
2012-11-29 21:31:17 +01:00
|
|
|
Totals const& _totals,
|
2012-11-25 22:43:36 +01:00
|
|
|
bool _aborting )
|
2012-12-02 00:49:57 +01:00
|
|
|
: runInfo( _runInfo ),
|
2012-11-25 22:43:36 +01:00
|
|
|
totals( _totals ),
|
|
|
|
aborting( _aborting )
|
|
|
|
{}
|
2013-01-03 10:04:46 +01:00
|
|
|
TestRunStats( TestRunStats const& _other )
|
|
|
|
: runInfo( _other.runInfo ),
|
|
|
|
totals( _other.totals ),
|
|
|
|
aborting( _other.aborting )
|
|
|
|
{}
|
2012-11-30 19:54:06 +01:00
|
|
|
virtual ~TestRunStats();
|
2013-01-03 10:04:46 +01:00
|
|
|
|
2012-12-02 00:49:57 +01:00
|
|
|
TestRunInfo runInfo;
|
2012-11-22 20:17:20 +01:00
|
|
|
Totals totals;
|
|
|
|
bool aborting;
|
|
|
|
};
|
|
|
|
|
2013-08-07 19:56:35 +02:00
|
|
|
|
2012-11-22 20:17:20 +01:00
|
|
|
struct IStreamingReporter : IShared {
|
2012-11-25 22:43:36 +01:00
|
|
|
virtual ~IStreamingReporter();
|
2012-12-05 09:40:53 +01:00
|
|
|
|
2013-01-13 22:51:44 +01:00
|
|
|
// Implementing class must also provide the following static method:
|
2012-12-05 09:40:53 +01:00
|
|
|
// static std::string getDescription();
|
|
|
|
|
2012-11-29 10:05:51 +01:00
|
|
|
virtual ReporterPreferences getPreferences() const = 0;
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2013-03-12 20:06:40 +01:00
|
|
|
virtual void noMatchingTestCases( std::string const& spec ) = 0;
|
2012-11-29 10:05:51 +01:00
|
|
|
|
2012-12-02 00:49:57 +01:00
|
|
|
virtual void testRunStarting( TestRunInfo const& testRunInfo ) = 0;
|
|
|
|
virtual void testGroupStarting( GroupInfo const& groupInfo ) = 0;
|
2012-11-22 20:17:20 +01:00
|
|
|
|
2012-11-29 21:31:17 +01:00
|
|
|
virtual void testCaseStarting( TestCaseInfo const& testInfo ) = 0;
|
2012-11-30 09:58:46 +01:00
|
|
|
virtual void sectionStarting( SectionInfo const& sectionInfo ) = 0;
|
|
|
|
|
2012-11-29 21:31:17 +01:00
|
|
|
virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0;
|
2012-11-22 20:17:20 +01:00
|
|
|
|
2013-06-28 17:25:49 +02:00
|
|
|
virtual bool assertionEnded( AssertionStats const& assertionStats ) = 0;
|
2013-01-03 10:04:46 +01:00
|
|
|
virtual void sectionEnded( SectionStats const& sectionStats ) = 0;
|
|
|
|
virtual void testCaseEnded( TestCaseStats const& testCaseStats ) = 0;
|
|
|
|
virtual void testGroupEnded( TestGroupStats const& testGroupStats ) = 0;
|
|
|
|
virtual void testRunEnded( TestRunStats const& testRunStats ) = 0;
|
2012-11-22 20:17:20 +01:00
|
|
|
};
|
2012-12-05 09:40:53 +01:00
|
|
|
|
2013-01-03 10:04:46 +01:00
|
|
|
struct StreamingReporterBase : SharedImpl<IStreamingReporter> {
|
|
|
|
|
|
|
|
StreamingReporterBase( ReporterConfig const& _config )
|
2013-05-28 19:39:32 +02:00
|
|
|
: m_config( _config.fullConfig() ),
|
2012-12-09 12:20:46 +01:00
|
|
|
stream( _config.stream() )
|
2012-12-05 09:40:53 +01:00
|
|
|
{}
|
|
|
|
|
2013-01-03 10:04:46 +01:00
|
|
|
virtual ~StreamingReporterBase();
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2013-03-12 20:06:40 +01:00
|
|
|
virtual void noMatchingTestCases( std::string const& ) {}
|
2012-12-05 09:40:53 +01:00
|
|
|
|
|
|
|
virtual void testRunStarting( TestRunInfo const& _testRunInfo ) {
|
2013-08-08 09:24:37 +02:00
|
|
|
currentTestRunInfo = _testRunInfo;
|
2012-12-05 09:40:53 +01:00
|
|
|
}
|
|
|
|
virtual void testGroupStarting( GroupInfo const& _groupInfo ) {
|
2013-08-08 09:24:37 +02:00
|
|
|
currentGroupInfo = _groupInfo;
|
2012-12-05 09:40:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void testCaseStarting( TestCaseInfo const& _testInfo ) {
|
2013-08-08 09:24:37 +02:00
|
|
|
currentTestCaseInfo = _testInfo;
|
2012-12-05 09:40:53 +01:00
|
|
|
}
|
|
|
|
virtual void sectionStarting( SectionInfo const& _sectionInfo ) {
|
2013-08-15 19:39:55 +02:00
|
|
|
m_sectionStack.push_back( _sectionInfo );
|
2012-12-05 09:40:53 +01:00
|
|
|
}
|
|
|
|
|
2013-01-03 10:04:46 +01:00
|
|
|
virtual void sectionEnded( SectionStats const& /* _sectionStats */ ) {
|
2013-08-08 09:05:19 +02:00
|
|
|
m_sectionStack.pop_back();
|
2012-12-05 09:40:53 +01:00
|
|
|
}
|
2013-01-03 10:04:46 +01:00
|
|
|
virtual void testCaseEnded( TestCaseStats const& /* _testCaseStats */ ) {
|
2013-08-08 09:24:37 +02:00
|
|
|
currentTestCaseInfo.reset();
|
2013-08-08 09:05:19 +02:00
|
|
|
assert( m_sectionStack.empty() );
|
2012-12-05 09:40:53 +01:00
|
|
|
}
|
2013-01-03 10:04:46 +01:00
|
|
|
virtual void testGroupEnded( TestGroupStats const& /* _testGroupStats */ ) {
|
2013-08-08 09:24:37 +02:00
|
|
|
currentGroupInfo.reset();
|
2012-12-05 09:40:53 +01:00
|
|
|
}
|
2013-01-03 10:04:46 +01:00
|
|
|
virtual void testRunEnded( TestRunStats const& /* _testRunStats */ ) {
|
2013-08-08 09:24:37 +02:00
|
|
|
currentTestCaseInfo.reset();
|
|
|
|
currentGroupInfo.reset();
|
|
|
|
currentTestRunInfo.reset();
|
2012-12-05 09:40:53 +01:00
|
|
|
}
|
|
|
|
|
2013-05-28 19:39:32 +02:00
|
|
|
Ptr<IConfig> m_config;
|
2013-08-15 19:39:55 +02:00
|
|
|
std::ostream& stream;
|
|
|
|
|
2013-08-08 09:24:37 +02:00
|
|
|
LazyStat<TestRunInfo> currentTestRunInfo;
|
|
|
|
LazyStat<GroupInfo> currentGroupInfo;
|
|
|
|
LazyStat<TestCaseInfo> currentTestCaseInfo;
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2013-08-15 19:39:55 +02:00
|
|
|
std::vector<SectionInfo> m_sectionStack;
|
2012-12-05 09:40:53 +01:00
|
|
|
};
|
|
|
|
|
2013-08-15 19:39:55 +02:00
|
|
|
struct CumulativeReporterBase : SharedImpl<IStreamingReporter> {
|
|
|
|
template<typename T, typename ChildNodeT>
|
|
|
|
struct Node : SharedImpl<> {
|
|
|
|
explicit Node( T const& _value ) : value( _value ) {}
|
|
|
|
virtual ~Node() {}
|
|
|
|
|
|
|
|
typedef std::vector<Ptr<ChildNodeT> > ChildNodes;
|
|
|
|
T value;
|
|
|
|
ChildNodes children;
|
|
|
|
};
|
|
|
|
struct SectionNode : SharedImpl<> {
|
|
|
|
explicit SectionNode( SectionStats const& _stats ) : stats( _stats ) {}
|
|
|
|
virtual ~SectionNode();
|
|
|
|
|
|
|
|
bool operator == ( SectionNode const& other ) const {
|
|
|
|
return stats.sectionInfo.lineInfo == other.stats.sectionInfo.lineInfo;
|
|
|
|
}
|
|
|
|
bool operator == ( Ptr<SectionNode> const& other ) const {
|
|
|
|
return operator==( *other );
|
|
|
|
}
|
2013-01-03 10:04:46 +01:00
|
|
|
|
2013-08-15 19:39:55 +02:00
|
|
|
SectionStats stats;
|
|
|
|
typedef std::vector<Ptr<SectionNode> > ChildSections;
|
|
|
|
typedef std::vector<AssertionStats> Assertions;
|
|
|
|
ChildSections childSections;
|
|
|
|
Assertions assertions;
|
|
|
|
std::string stdOut;
|
|
|
|
std::string stdErr;
|
|
|
|
};
|
|
|
|
friend bool operator == ( Ptr<SectionNode> const& node, SectionInfo const& other ) {
|
|
|
|
return node->stats.sectionInfo.lineInfo == other.lineInfo;
|
|
|
|
}
|
2013-01-03 10:04:46 +01:00
|
|
|
|
2013-08-15 19:39:55 +02:00
|
|
|
typedef Node<TestCaseStats, SectionNode> TestCaseNode;
|
|
|
|
typedef Node<TestGroupStats, TestCaseNode> TestGroupNode;
|
|
|
|
typedef Node<TestRunStats, TestGroupNode> TestRunNode;
|
2013-01-03 10:04:46 +01:00
|
|
|
|
2013-08-15 19:39:55 +02:00
|
|
|
CumulativeReporterBase( ReporterConfig const& _config )
|
|
|
|
: m_config( _config.fullConfig() ),
|
|
|
|
stream( _config.stream() )
|
|
|
|
{}
|
|
|
|
~CumulativeReporterBase();
|
|
|
|
|
|
|
|
virtual void testRunStarting( TestRunInfo const& ) {}
|
|
|
|
virtual void testGroupStarting( GroupInfo const& ) {}
|
|
|
|
|
|
|
|
virtual void testCaseStarting( TestCaseInfo const& ) {}
|
|
|
|
|
|
|
|
virtual void sectionStarting( SectionInfo const& sectionInfo ) {
|
|
|
|
SectionStats incompleteStats( sectionInfo, Counts(), 0, false );
|
|
|
|
Ptr<SectionNode> node;
|
|
|
|
if( m_sectionStack.empty() ) {
|
|
|
|
if( !m_rootSection )
|
|
|
|
m_rootSection = new SectionNode( incompleteStats );
|
|
|
|
node = m_rootSection;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
SectionNode& parentNode = *m_sectionStack.back();
|
|
|
|
SectionNode::ChildSections::const_iterator it =
|
|
|
|
std::find( parentNode.childSections.begin(), parentNode.childSections.end(), sectionInfo );
|
|
|
|
if( it == parentNode.childSections.end() ) {
|
|
|
|
node = new SectionNode( incompleteStats );
|
|
|
|
parentNode.childSections.push_back( node );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
node = *it;
|
|
|
|
}
|
|
|
|
m_sectionStack.push_back( node );
|
|
|
|
m_deepestSection = node;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void assertionStarting( AssertionInfo const& ) {}
|
|
|
|
|
|
|
|
virtual bool assertionEnded( AssertionStats const& assertionStats ) {
|
|
|
|
assert( !m_sectionStack.empty() );
|
|
|
|
SectionNode& sectionNode = *m_sectionStack.back();
|
|
|
|
sectionNode.assertions.push_back( assertionStats );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
virtual void sectionEnded( SectionStats const& sectionStats ) {
|
|
|
|
assert( !m_sectionStack.empty() );
|
|
|
|
SectionNode& node = *m_sectionStack.back();
|
|
|
|
node.stats = sectionStats;
|
|
|
|
m_sectionStack.pop_back();
|
|
|
|
}
|
|
|
|
virtual void testCaseEnded( TestCaseStats const& testCaseStats ) {
|
|
|
|
Ptr<TestCaseNode> node = new TestCaseNode( testCaseStats );
|
|
|
|
assert( m_sectionStack.size() == 0 );
|
|
|
|
node->children.push_back( m_rootSection );
|
|
|
|
m_testCases.push_back( node );
|
|
|
|
m_rootSection.reset();
|
|
|
|
|
|
|
|
assert( m_deepestSection );
|
|
|
|
m_deepestSection->stdOut = testCaseStats.stdOut;
|
|
|
|
m_deepestSection->stdErr = testCaseStats.stdErr;
|
|
|
|
}
|
|
|
|
virtual void testGroupEnded( TestGroupStats const& testGroupStats ) {
|
|
|
|
Ptr<TestGroupNode> node = new TestGroupNode( testGroupStats );
|
|
|
|
node->children.swap( m_testCases );
|
|
|
|
m_testGroups.push_back( node );
|
|
|
|
}
|
|
|
|
virtual void testRunEnded( TestRunStats const& testRunStats ) {
|
|
|
|
Ptr<TestRunNode> node = new TestRunNode( testRunStats );
|
|
|
|
node->children.swap( m_testGroups );
|
|
|
|
m_testRuns.push_back( node );
|
|
|
|
testRunEnded();
|
|
|
|
}
|
|
|
|
virtual void testRunEnded() = 0;
|
|
|
|
|
|
|
|
Ptr<IConfig> m_config;
|
|
|
|
std::ostream& stream;
|
|
|
|
std::vector<AssertionStats> m_assertions;
|
|
|
|
std::vector<std::vector<Ptr<SectionNode> > > m_sections;
|
|
|
|
std::vector<Ptr<TestCaseNode> > m_testCases;
|
|
|
|
std::vector<Ptr<TestGroupNode> > m_testGroups;
|
|
|
|
|
|
|
|
std::vector<Ptr<TestRunNode> > m_testRuns;
|
|
|
|
|
|
|
|
Ptr<SectionNode> m_rootSection;
|
|
|
|
Ptr<SectionNode> m_deepestSection;
|
|
|
|
std::vector<Ptr<SectionNode> > m_sectionStack;
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2013-01-03 10:04:46 +01:00
|
|
|
};
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2012-11-30 19:54:06 +01:00
|
|
|
// Deprecated
|
2012-05-09 09:17:51 +02:00
|
|
|
struct IReporter : IShared {
|
2012-08-13 08:46:10 +02:00
|
|
|
virtual ~IReporter();
|
2012-10-16 09:27:21 +02:00
|
|
|
|
|
|
|
virtual bool shouldRedirectStdout() const = 0;
|
|
|
|
|
2013-07-03 20:14:59 +02:00
|
|
|
virtual void StartTesting() = 0;
|
2012-11-30 19:54:06 +01:00
|
|
|
virtual void EndTesting( Totals const& totals ) = 0;
|
2012-11-29 21:31:17 +01:00
|
|
|
virtual void StartGroup( std::string const& groupName ) = 0;
|
2012-11-30 19:54:06 +01:00
|
|
|
virtual void EndGroup( std::string const& groupName, Totals const& totals ) = 0;
|
2012-11-29 21:31:17 +01:00
|
|
|
virtual void StartTestCase( TestCaseInfo const& testInfo ) = 0;
|
|
|
|
virtual void EndTestCase( TestCaseInfo const& testInfo, Totals const& totals, std::string const& stdOut, std::string const& stdErr ) = 0;
|
|
|
|
virtual void StartSection( std::string const& sectionName, std::string const& description ) = 0;
|
2013-04-23 19:58:56 +02:00
|
|
|
virtual void EndSection( std::string const& sectionName, Counts const& assertions ) = 0;
|
2012-11-29 21:31:17 +01:00
|
|
|
virtual void NoAssertionsInSection( std::string const& sectionName ) = 0;
|
|
|
|
virtual void NoAssertionsInTestCase( std::string const& testName ) = 0;
|
2012-06-01 20:40:27 +02:00
|
|
|
virtual void Aborted() = 0;
|
2013-04-23 19:58:56 +02:00
|
|
|
virtual void Result( AssertionResult const& result ) = 0;
|
2010-12-31 23:07:47 +01:00
|
|
|
};
|
2012-11-25 22:43:36 +01:00
|
|
|
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2012-05-09 09:17:51 +02:00
|
|
|
struct IReporterFactory {
|
2012-08-13 08:46:10 +02:00
|
|
|
virtual ~IReporterFactory();
|
2012-11-30 20:15:23 +01:00
|
|
|
virtual IStreamingReporter* create( ReporterConfig const& config ) const = 0;
|
2012-05-09 09:17:51 +02:00
|
|
|
virtual std::string getDescription() const = 0;
|
2010-12-31 23:07:47 +01:00
|
|
|
};
|
|
|
|
|
2012-05-09 09:17:51 +02:00
|
|
|
struct IReporterRegistry {
|
2010-12-31 23:21:36 +01:00
|
|
|
typedef std::map<std::string, IReporterFactory*> FactoryMap;
|
|
|
|
|
2012-08-13 08:46:10 +02:00
|
|
|
virtual ~IReporterRegistry();
|
2013-07-03 20:14:59 +02:00
|
|
|
virtual IStreamingReporter* create( std::string const& name, Ptr<IConfig> const& config ) const = 0;
|
2013-04-23 19:58:56 +02:00
|
|
|
virtual FactoryMap const& getFactories() const = 0;
|
2010-12-31 23:07:47 +01:00
|
|
|
};
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2012-11-29 21:31:17 +01:00
|
|
|
inline std::string trim( std::string const& str ) {
|
2013-08-08 09:05:19 +02:00
|
|
|
static char const* whitespaceChars = "\n\r\t ";
|
|
|
|
std::string::size_type start = str.find_first_not_of( whitespaceChars );
|
|
|
|
std::string::size_type end = str.find_last_not_of( whitespaceChars );
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2012-02-28 21:04:25 +01:00
|
|
|
return start != std::string::npos ? str.substr( start, 1+end-start ) : "";
|
2010-12-31 23:07:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-17 07:42:29 +02:00
|
|
|
#endif // TWOBLUECUBES_CATCH_INTERFACES_REPORTER_H_INCLUDED
|