Files
Catch2/include/internal/catch_interfaces_reporter.h
T

260 lines
8.9 KiB
C++
Raw Normal View History

/*
* 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)
*/
#ifndef TWOBLUECUBES_CATCH_INTERFACES_REPORTER_H_INCLUDED
#define TWOBLUECUBES_CATCH_INTERFACES_REPORTER_H_INCLUDED
#include "catch_section_info.h"
#include "catch_common.h"
#include "catch_totals.hpp"
2012-08-28 08:20:18 +01:00
#include "catch_config.hpp"
2012-11-22 19:17:20 +00:00
#include "catch_test_case_info.h"
#include "catch_assertionresult.h"
2013-02-02 19:58:04 +00:00
#include "catch_message.h"
#include "catch_option.hpp"
#include <string>
#include <ostream>
#include <map>
2017-04-26 17:04:00 +01:00
#include <memory>
namespace Catch
{
2012-11-29 20:31:17 +00:00
struct ReporterConfig {
explicit ReporterConfig( IConfigPtr const& _fullConfig )
2013-05-28 18:39:32 +01:00
: m_stream( &_fullConfig->stream() ), m_fullConfig( _fullConfig ) {}
ReporterConfig( IConfigPtr const& _fullConfig, std::ostream& _stream )
: m_stream( &_stream ), m_fullConfig( _fullConfig ) {}
2013-05-28 18:39:32 +01:00
std::ostream& stream() const { return *m_stream; }
IConfigPtr fullConfig() const { return m_fullConfig; }
private:
std::ostream* m_stream;
IConfigPtr m_fullConfig;
2012-08-28 08:20:18 +01:00
};
2012-11-22 19:17:20 +00:00
2012-11-29 20:31:17 +00:00
struct ReporterPreferences {
ReporterPreferences()
: shouldRedirectStdOut( false )
{}
bool shouldRedirectStdOut;
};
2013-08-08 08:24:37 +01: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;
};
struct TestRunInfo {
TestRunInfo( std::string const& _name ) : name( _name ) {}
std::string name;
};
struct GroupInfo {
GroupInfo( std::string const& _name,
std::size_t _groupIndex,
std::size_t _groupsCount )
: name( _name ),
groupIndex( _groupIndex ),
groupsCounts( _groupsCount )
{}
std::string name;
std::size_t groupIndex;
std::size_t groupsCounts;
};
struct AssertionStats {
2012-11-29 20:31:17 +00:00
AssertionStats( AssertionResult const& _assertionResult,
2013-02-02 19:58:04 +00:00
std::vector<MessageInfo> const& _infoMessages,
2012-11-29 20:31:17 +00:00
Totals const& _totals )
: assertionResult( _assertionResult ),
2013-02-02 19:58:04 +00:00
infoMessages( _infoMessages ),
totals( _totals )
2013-02-02 19:58:04 +00: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 17:09:57 +01:00
builder.m_info.message = builder.m_stream.str();
infoMessages.push_back( builder.m_info );
2013-02-02 19:58:04 +00:00
}
}
2012-11-30 18:54:06 +00:00
virtual ~AssertionStats();
2013-07-03 19:14:59 +01:00
AssertionStats( AssertionStats const& ) = default;
AssertionStats( AssertionStats && ) = default;
AssertionStats& operator = ( AssertionStats const& ) = default;
AssertionStats& operator = ( AssertionStats && ) = default;
2012-11-22 19:17:20 +00:00
AssertionResult assertionResult;
2013-02-02 19:58:04 +00:00
std::vector<MessageInfo> infoMessages;
2012-11-22 19:17:20 +00:00
Totals totals;
};
struct SectionStats {
SectionStats( SectionInfo const& _sectionInfo,
Counts const& _assertions,
2013-08-07 18:56:35 +01:00
double _durationInSeconds,
bool _missingAssertions )
: sectionInfo( _sectionInfo ),
assertions( _assertions ),
2013-08-07 18:56:35 +01:00
durationInSeconds( _durationInSeconds ),
missingAssertions( _missingAssertions )
{}
2012-11-30 18:54:06 +00:00
virtual ~SectionStats();
SectionStats( SectionStats const& ) = default;
SectionStats( SectionStats && ) = default;
SectionStats& operator = ( SectionStats const& ) = default;
SectionStats& operator = ( SectionStats && ) = default;
2012-11-30 18:54:06 +00:00
2012-11-29 20:31:17 +00:00
SectionInfo sectionInfo;
Counts assertions;
2013-08-07 18:56:35 +01:00
double durationInSeconds;
bool missingAssertions;
2012-11-29 20:31:17 +00:00
};
struct TestCaseStats {
2012-11-29 20:31:17 +00:00
TestCaseStats( TestCaseInfo const& _testInfo,
Totals const& _totals,
std::string const& _stdOut,
std::string const& _stdErr,
bool _aborting )
: testInfo( _testInfo ),
totals( _totals ),
stdOut( _stdOut ),
stdErr( _stdErr ),
aborting( _aborting )
{}
2012-11-30 18:54:06 +00:00
virtual ~TestCaseStats();
TestCaseStats( TestCaseStats const& ) = default;
TestCaseStats( TestCaseStats && ) = default;
TestCaseStats& operator = ( TestCaseStats const& ) = default;
TestCaseStats& operator = ( TestCaseStats && ) = default;
TestCaseInfo testInfo;
2012-11-22 19:17:20 +00:00
Totals totals;
std::string stdOut;
std::string stdErr;
bool aborting;
};
2013-07-03 19:14:59 +01:00
struct TestGroupStats {
TestGroupStats( GroupInfo const& _groupInfo,
2012-11-29 20:31:17 +00:00
Totals const& _totals,
bool _aborting )
: groupInfo( _groupInfo ),
totals( _totals ),
aborting( _aborting )
{}
TestGroupStats( GroupInfo const& _groupInfo )
: groupInfo( _groupInfo ),
aborting( false )
{}
2012-11-30 18:54:06 +00:00
virtual ~TestGroupStats();
TestGroupStats( TestGroupStats const& ) = default;
TestGroupStats( TestGroupStats && ) = default;
TestGroupStats& operator = ( TestGroupStats const& ) = default;
TestGroupStats& operator = ( TestGroupStats && ) = default;
GroupInfo groupInfo;
2012-11-22 19:17:20 +00:00
Totals totals;
bool aborting;
};
2013-07-03 19:14:59 +01:00
struct TestRunStats {
TestRunStats( TestRunInfo const& _runInfo,
2012-11-29 20:31:17 +00:00
Totals const& _totals,
bool _aborting )
: runInfo( _runInfo ),
totals( _totals ),
aborting( _aborting )
{}
virtual ~TestRunStats();
TestRunStats( TestRunStats const& ) = default;
TestRunStats( TestRunStats && ) = default;
TestRunStats& operator = ( TestRunStats const& ) = default;
TestRunStats& operator = ( TestRunStats && ) = default;
TestRunInfo runInfo;
2012-11-22 19:17:20 +00:00
Totals totals;
bool aborting;
};
class MultipleReporters;
2013-08-07 18:56:35 +01:00
struct IStreamingReporter {
virtual ~IStreamingReporter();
// Implementing class must also provide the following static method:
// static std::string getDescription();
virtual ReporterPreferences getPreferences() const = 0;
2013-07-03 19:14:59 +01:00
virtual void noMatchingTestCases( std::string const& spec ) = 0;
virtual void testRunStarting( TestRunInfo const& testRunInfo ) = 0;
virtual void testGroupStarting( GroupInfo const& groupInfo ) = 0;
2012-11-22 19:17:20 +00:00
2012-11-29 20:31:17 +00:00
virtual void testCaseStarting( TestCaseInfo const& testInfo ) = 0;
virtual void sectionStarting( SectionInfo const& sectionInfo ) = 0;
2012-11-29 20:31:17 +00:00
virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0;
2012-11-22 19:17:20 +00:00
// The return value indicates if the messages buffer should be cleared:
2013-06-28 16:25:49 +01:00
virtual bool assertionEnded( AssertionStats const& assertionStats ) = 0;
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;
2014-12-22 20:10:33 +00:00
virtual void skipTest( TestCaseInfo const& testInfo ) = 0;
2017-01-26 23:13:12 +01:00
2017-04-29 19:38:34 +01:00
virtual bool isMulti() const { return false; }
2012-11-22 19:17:20 +00:00
};
2017-04-29 19:38:34 +01:00
using IStreamingReporterPtr = std::unique_ptr<IStreamingReporter>;
2013-07-03 19:14:59 +01:00
struct IReporterFactory {
virtual ~IReporterFactory();
virtual IStreamingReporterPtr create( ReporterConfig const& config ) const = 0;
2012-05-09 08:17:51 +01:00
virtual std::string getDescription() const = 0;
};
using IReporterFactoryPtr = std::shared_ptr<IReporterFactory>;
2012-05-09 08:17:51 +01:00
struct IReporterRegistry {
using FactoryMap = std::map<std::string, IReporterFactoryPtr>;
using Listeners = std::vector<IReporterFactoryPtr>;
virtual ~IReporterRegistry();
virtual IStreamingReporterPtr create( std::string const& name, IConfigPtr const& config ) const = 0;
2013-04-23 18:58:56 +01:00
virtual FactoryMap const& getFactories() const = 0;
virtual Listeners const& getListeners() const = 0;
};
2013-07-03 19:14:59 +01:00
2017-04-29 19:38:34 +01:00
void addReporter( IStreamingReporterPtr& existingReporter, IStreamingReporterPtr&& additionalReporter );
}
#endif // TWOBLUECUBES_CATCH_INTERFACES_REPORTER_H_INCLUDED