mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-01 12:55:40 +02:00
Started new reporter, "console", which will replace "basic" when done.
Introduced Option template as part of this.
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
#include "../reporters/catch_reporter_basic.hpp"
|
||||
#include "../reporters/catch_reporter_xml.hpp"
|
||||
#include "../reporters/catch_reporter_junit.hpp"
|
||||
#include "../reporters/catch_reporter_console.hpp"
|
||||
|
||||
namespace Catch {
|
||||
NonCopyable::~NonCopyable() {}
|
||||
@@ -54,8 +55,11 @@ namespace Catch {
|
||||
TestCaseStats::~TestCaseStats() {}
|
||||
TestGroupStats::~TestGroupStats() {}
|
||||
TestRunStats::~TestRunStats() {}
|
||||
ThreadedSectionInfo::~ThreadedSectionInfo() {}
|
||||
|
||||
BasicReporter::~BasicReporter() {}
|
||||
AccumulatingReporter::~AccumulatingReporter() {}
|
||||
ConsoleReporter::~ConsoleReporter() {}
|
||||
IRunner::~IRunner() {}
|
||||
IMutableContext::~IMutableContext() {}
|
||||
IConfig::~IConfig() {}
|
||||
|
@@ -14,6 +14,7 @@
|
||||
#include "catch_config.hpp"
|
||||
#include "catch_test_case_info.h"
|
||||
#include "catch_assertionresult.h"
|
||||
#include "catch_option.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <ostream>
|
||||
@@ -25,7 +26,7 @@ namespace Catch
|
||||
ReporterConfig( std::ostream& _stream, ConfigData const& _fullConfig )
|
||||
: m_stream( &_stream ), m_fullConfig( _fullConfig ) {}
|
||||
|
||||
std::ostream& stream() { return *m_stream; }
|
||||
std::ostream& stream() const { return *m_stream; }
|
||||
std::string name() const { return m_fullConfig.name; }
|
||||
bool includeSuccessfulResults() const { return m_fullConfig.includeWhichResults == Include::SuccessfulResults; }
|
||||
bool warnAboutMissingAssertions() const { return m_fullConfig.warnings & ConfigData::WarnAbout::NoAssertions; }
|
||||
@@ -66,6 +67,17 @@ namespace Catch
|
||||
SourceLineInfo lineInfo;
|
||||
};
|
||||
|
||||
struct ThreadedSectionInfo : SectionInfo, SharedImpl<> {
|
||||
ThreadedSectionInfo( SectionInfo const& _sectionInfo, Ptr<ThreadedSectionInfo> const& _parent = Ptr<ThreadedSectionInfo>() )
|
||||
: SectionInfo( _sectionInfo ),
|
||||
parent( _parent )
|
||||
{}
|
||||
virtual ~ThreadedSectionInfo();
|
||||
|
||||
std::vector<Ptr<ThreadedSectionInfo> > children;
|
||||
Ptr<ThreadedSectionInfo> parent;
|
||||
};
|
||||
|
||||
struct AssertionStats : SharedImpl<> {
|
||||
AssertionStats( AssertionResult const& _assertionResult,
|
||||
Totals const& _totals )
|
||||
@@ -150,6 +162,10 @@ namespace Catch
|
||||
// !Work In progress
|
||||
struct IStreamingReporter : IShared {
|
||||
virtual ~IStreamingReporter();
|
||||
|
||||
// Implementing class must also provide the following static methid:
|
||||
// static std::string getDescription();
|
||||
|
||||
virtual ReporterPreferences getPreferences() const = 0;
|
||||
|
||||
virtual void testRunStarting( TestRunInfo const& testRunInfo ) = 0;
|
||||
@@ -171,6 +187,59 @@ namespace Catch
|
||||
// - this would be used by the JUnit reporter, for example.
|
||||
// - it may be used by the basic reporter, too, but that would clear down the stack
|
||||
// as it goes
|
||||
struct AccumulatingReporter : SharedImpl<IStreamingReporter> {
|
||||
|
||||
AccumulatingReporter( ReporterConfig const& _config )
|
||||
: stream( _config.stream() )
|
||||
{}
|
||||
|
||||
virtual ~AccumulatingReporter();
|
||||
|
||||
virtual void testRunStarting( TestRunInfo const& _testRunInfo ) {
|
||||
testRunInfo = _testRunInfo;
|
||||
}
|
||||
virtual void testGroupStarting( GroupInfo const& _groupInfo ) {
|
||||
unusedGroupInfo = _groupInfo;
|
||||
}
|
||||
|
||||
virtual void testCaseStarting( TestCaseInfo const& _testInfo ) {
|
||||
unusedTestCaseInfo = _testInfo;
|
||||
}
|
||||
virtual void sectionStarting( SectionInfo const& _sectionInfo ) {
|
||||
Ptr<ThreadedSectionInfo> sectionInfo = new ThreadedSectionInfo( _sectionInfo );
|
||||
unusedSectionInfo = sectionInfo;
|
||||
if( !currentSectionInfo ) {
|
||||
currentSectionInfo = sectionInfo;
|
||||
}
|
||||
else {
|
||||
currentSectionInfo->children.push_back( sectionInfo );
|
||||
sectionInfo->parent = currentSectionInfo;
|
||||
currentSectionInfo = sectionInfo;
|
||||
}
|
||||
}
|
||||
|
||||
virtual void sectionEnded( Ptr<SectionStats const> const& /* _sectionStats */ ) {
|
||||
currentSectionInfo = currentSectionInfo->parent;
|
||||
unusedSectionInfo = currentSectionInfo;
|
||||
}
|
||||
virtual void testCaseEnded( Ptr<TestCaseStats const> const& /* _testCaseStats */ ) {
|
||||
unusedTestCaseInfo.reset();
|
||||
}
|
||||
virtual void testGroupEnded( Ptr<TestGroupStats const> const& /* _testGroupStats */ ) {
|
||||
unusedGroupInfo.reset();
|
||||
}
|
||||
virtual void testRunEnded( Ptr<TestRunStats const> const& /* _testRunStats */ ) {
|
||||
}
|
||||
|
||||
Option<TestRunInfo> testRunInfo;
|
||||
Option<GroupInfo> unusedGroupInfo;
|
||||
Option<TestCaseInfo> unusedTestCaseInfo;
|
||||
Ptr<ThreadedSectionInfo> unusedSectionInfo;
|
||||
Ptr<ThreadedSectionInfo> currentSectionInfo;
|
||||
bool currentSectionOpen;
|
||||
std::ostream& stream;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Deprecated
|
||||
|
64
include/internal/catch_option.hpp
Normal file
64
include/internal/catch_option.hpp
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Created by Phil on 02/12/2012.
|
||||
* Copyright 2012 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_OPTION_HPP_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_OPTION_HPP_INCLUDED
|
||||
|
||||
#include "catch_common.h"
|
||||
|
||||
namespace Catch {
|
||||
|
||||
// An optional type
|
||||
template<typename T>
|
||||
class Option {
|
||||
public:
|
||||
Option() : nullableValue( NULL ) {}
|
||||
Option( T const& _value )
|
||||
: nullableValue( new( storage ) T( _value ) )
|
||||
{}
|
||||
Option( Option const& _other )
|
||||
: nullableValue( _other ? new( storage ) T( *_other ) : NULL )
|
||||
{}
|
||||
|
||||
~Option() {
|
||||
reset();
|
||||
}
|
||||
|
||||
Option& operator= ( Option const& _other ) {
|
||||
reset();
|
||||
if( _other )
|
||||
nullableValue = new( storage ) T( *_other );
|
||||
return *this;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
if( nullableValue )
|
||||
nullableValue->~T();
|
||||
nullableValue = NULL;
|
||||
}
|
||||
T& operator*() { return *nullableValue; }
|
||||
const T& operator*() const { return *nullableValue; }
|
||||
T* operator->() { return nullableValue; }
|
||||
const T* operator->() const { return nullableValue; }
|
||||
|
||||
bool some() const { return nullableValue != NULL; }
|
||||
bool none() const { return nullableValue == NULL; }
|
||||
|
||||
bool operator !() const { return nullableValue == NULL; }
|
||||
operator SafeBool::type() const {
|
||||
return SafeBool::makeSafe( some() );
|
||||
}
|
||||
|
||||
private:
|
||||
T* nullableValue;
|
||||
char storage[sizeof(T)];
|
||||
};
|
||||
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_OPTION_HPP_INCLUDED
|
@@ -31,6 +31,11 @@ namespace Catch {
|
||||
if( m_p )
|
||||
m_p->release();
|
||||
}
|
||||
void reset() {
|
||||
if( m_p )
|
||||
m_p->release();
|
||||
m_p = NULL;
|
||||
}
|
||||
Ptr& operator = ( T* p ){
|
||||
Ptr temp( p );
|
||||
swap( temp );
|
||||
@@ -47,6 +52,7 @@ namespace Catch {
|
||||
T& operator*() const { return *m_p; }
|
||||
T* operator->() const { return m_p; }
|
||||
bool operator !() const { return m_p == NULL; }
|
||||
operator SafeBool::type() const { return SafeBool::makeSafe( m_p != NULL ); }
|
||||
|
||||
private:
|
||||
T* m_p;
|
||||
|
@@ -31,8 +31,8 @@ namespace Catch {
|
||||
std::string className;
|
||||
std::string description;
|
||||
std::set<std::string> tags;
|
||||
bool isHidden;
|
||||
SourceLineInfo lineInfo;
|
||||
bool isHidden;
|
||||
};
|
||||
|
||||
class TestCase : protected TestCaseInfo {
|
||||
|
@@ -41,8 +41,8 @@ namespace Catch {
|
||||
className( _className ),
|
||||
description( _description ),
|
||||
tags( _tags ),
|
||||
isHidden( _isHidden ),
|
||||
lineInfo( _lineInfo )
|
||||
lineInfo( _lineInfo ),
|
||||
isHidden( _isHidden )
|
||||
{}
|
||||
|
||||
TestCaseInfo::TestCaseInfo( const TestCaseInfo& other )
|
||||
@@ -50,8 +50,8 @@ namespace Catch {
|
||||
className( other.className ),
|
||||
description( other.description ),
|
||||
tags( other.tags ),
|
||||
isHidden( other.isHidden ),
|
||||
lineInfo( other.lineInfo )
|
||||
lineInfo( other.lineInfo ),
|
||||
isHidden( other.isHidden )
|
||||
{}
|
||||
|
||||
TestCase::TestCase( ITestCase* testCase, const TestCaseInfo& info ) : TestCaseInfo( info ), test( testCase ) {}
|
||||
|
Reference in New Issue
Block a user