mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-01 12:55:40 +02:00
Added self-test for section ordering
Added MockReporter for tracking test runs. Added intrusive smart pointer. Config holds reporter by smart pointer, so we can route the mock reporter through multiple test runs
This commit is contained in:
@@ -56,8 +56,7 @@ namespace Catch
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
Config()
|
||||
: m_reporter( NULL ),
|
||||
m_listSpec( List::None ),
|
||||
: m_listSpec( List::None ),
|
||||
m_shouldDebugBreak( false ),
|
||||
m_showHelp( false ),
|
||||
m_streambuf( NULL ),
|
||||
@@ -137,15 +136,15 @@ namespace Catch
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
void setReporter( IReporter* reporter )
|
||||
{
|
||||
m_reporter = std::auto_ptr<IReporter>( reporter );
|
||||
m_reporter = reporter;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
IReporter* getReporter() const
|
||||
Ptr<IReporter> getReporter()
|
||||
{
|
||||
if( !m_reporter.get() )
|
||||
const_cast<Config*>( this )->setReporter( Hub::getReporterRegistry().create( "basic", *this ) );
|
||||
return m_reporter.get();
|
||||
return m_reporter;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
@@ -221,7 +220,7 @@ namespace Catch
|
||||
setStreamBuf( newBuf );
|
||||
delete m_streambuf;
|
||||
m_streambuf = newBuf;
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual bool includeSuccessfulResults() const
|
||||
@@ -230,7 +229,7 @@ namespace Catch
|
||||
}
|
||||
|
||||
private:
|
||||
std::auto_ptr<IReporter> m_reporter;
|
||||
Ptr<IReporter> m_reporter;
|
||||
std::string m_filename;
|
||||
std::string m_message;
|
||||
List::What m_listSpec;
|
||||
|
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "catch_common.h"
|
||||
#include "catch_totals.hpp"
|
||||
#include "catch_ptr.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <ostream>
|
||||
@@ -43,7 +44,7 @@ namespace Catch
|
||||
class ResultInfo;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
struct IReporter : NonCopyable
|
||||
struct IReporter : IShared
|
||||
{
|
||||
virtual ~IReporter
|
||||
(){}
|
||||
|
@@ -21,7 +21,7 @@ namespace Catch
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
inline int List
|
||||
(
|
||||
const Config& config
|
||||
Config& config
|
||||
)
|
||||
{
|
||||
if( config.listWhat() & Config::List::Reports )
|
||||
@@ -54,7 +54,7 @@ namespace Catch
|
||||
return (std::numeric_limits<int>::max)();
|
||||
}
|
||||
|
||||
if( config.getReporter() )
|
||||
if( config.getReporter().get() )
|
||||
{
|
||||
std::cerr << "Reporters ignored when listing" << std::endl;
|
||||
}
|
||||
|
100
include/internal/catch_ptr.hpp
Normal file
100
include/internal/catch_ptr.hpp
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* catch_ptr.hpp
|
||||
* Catch
|
||||
*
|
||||
* Created by Phil on 02/05/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_PTR_HPP_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_PTR_HPP_INCLUDED
|
||||
|
||||
#include "catch_common.h"
|
||||
|
||||
namespace Catch
|
||||
{
|
||||
// An intrusive reference counting smart pointer.
|
||||
// T must implement addRef() and release() methods
|
||||
// typically implementing the IShared interface
|
||||
template<typename T>
|
||||
class Ptr
|
||||
{
|
||||
public:
|
||||
Ptr() : m_p( NULL ){}
|
||||
Ptr( T* p ) : m_p( p ){
|
||||
m_p->addRef();
|
||||
}
|
||||
Ptr( const Ptr& other ) : m_p( other.m_p ){
|
||||
m_p->addRef();
|
||||
}
|
||||
~Ptr(){
|
||||
if( m_p )
|
||||
m_p->release();
|
||||
}
|
||||
Ptr& operator = ( T* p ){
|
||||
Ptr temp( p );
|
||||
swap( temp );
|
||||
return *this;
|
||||
}
|
||||
Ptr& operator = ( Ptr& other ){
|
||||
Ptr temp( other );
|
||||
swap( temp );
|
||||
return *this;
|
||||
}
|
||||
void swap( Ptr& other ){
|
||||
std::swap( m_p, other.m_p );
|
||||
}
|
||||
|
||||
T* get(){
|
||||
return m_p;
|
||||
}
|
||||
const T* get() const{
|
||||
return m_p;
|
||||
}
|
||||
|
||||
T& operator*(){
|
||||
return *m_p;
|
||||
}
|
||||
const T& operator*() const{
|
||||
return *m_p;
|
||||
}
|
||||
|
||||
T* operator->(){
|
||||
return m_p;
|
||||
}
|
||||
const T* operator->() const{
|
||||
return m_p;
|
||||
}
|
||||
|
||||
private:
|
||||
T* m_p;
|
||||
};
|
||||
|
||||
struct IShared : NonCopyable {
|
||||
virtual ~IShared(){}
|
||||
virtual void addRef() = 0;
|
||||
virtual void release() = 0;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct SharedImpl : T {
|
||||
|
||||
SharedImpl() : m_rc( 0 ){}
|
||||
|
||||
virtual void addRef(){
|
||||
++m_rc;
|
||||
}
|
||||
virtual void release(){
|
||||
if( --m_rc == 0 )
|
||||
delete this;
|
||||
}
|
||||
|
||||
int m_rc;
|
||||
};
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_PTR_HPP_INCLUDED
|
@@ -108,6 +108,14 @@ namespace Catch
|
||||
return m_expr;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
bool hasExpandedExpression
|
||||
()
|
||||
const
|
||||
{
|
||||
return hasExpression() && getExpandedExpressionInternal() != m_expr;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
std::string getExpandedExpression
|
||||
()
|
||||
@@ -162,7 +170,7 @@ namespace Catch
|
||||
else if( m_op != "!" )
|
||||
return m_lhs + " " + m_op + " " + m_rhs;
|
||||
else
|
||||
return "{can't expand - use " + m_macroName + "_NOT( " + m_expr.substr(1) + " ) instead of " + m_macroName + "( " + m_expr + " ) for better diagnostics}";
|
||||
return "{can't expand - use " + m_macroName + "_FALSE( " + m_expr.substr(1) + " ) instead of " + m_macroName + "( " + m_expr + " ) for better diagnostics}";
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
@@ -300,11 +300,11 @@ namespace Catch
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
explicit Runner
|
||||
(
|
||||
const Config& config
|
||||
Config& config
|
||||
)
|
||||
: m_runningTest( NULL ),
|
||||
m_config( config ),
|
||||
m_reporter( m_config.getReporter() ),
|
||||
m_reporter( config.getReporter() ),
|
||||
m_prevRunner( &Hub::getRunner() ),
|
||||
m_prevResultCapture( &Hub::getResultCapture() )
|
||||
{
|
||||
@@ -376,9 +376,11 @@ namespace Catch
|
||||
{
|
||||
do
|
||||
{
|
||||
m_reporter->StartGroup( "test case run" );
|
||||
m_currentResult.setFileAndLine( m_runningTest->getTestCaseInfo().getFilename(),
|
||||
m_runningTest->getTestCaseInfo().getLine() );
|
||||
runCurrentTest( redirectedCout, redirectedCerr );
|
||||
m_reporter->EndGroup( "test case run", m_totals - prevTotals );
|
||||
}
|
||||
while( m_runningTest->hasUntestedSections() );
|
||||
}
|
||||
@@ -608,7 +610,7 @@ namespace Catch
|
||||
|
||||
const Config& m_config;
|
||||
Totals m_totals;
|
||||
IReporter* m_reporter;
|
||||
Ptr<IReporter> m_reporter;
|
||||
std::vector<ScopedInfo*> m_scopedInfos;
|
||||
std::vector<ResultInfo> m_info;
|
||||
IRunner* m_prevRunner;
|
||||
|
@@ -38,7 +38,7 @@ namespace Catch
|
||||
std::string m_label;
|
||||
};
|
||||
|
||||
class BasicReporter : public IReporter
|
||||
class BasicReporter : public SharedImpl<IReporter>
|
||||
{
|
||||
struct SpanInfo
|
||||
{
|
||||
@@ -311,7 +311,7 @@ namespace Catch
|
||||
break;
|
||||
}
|
||||
|
||||
if( resultInfo.hasExpression() && resultInfo.getExpression() != resultInfo.getExpandedExpression() )
|
||||
if( resultInfo.hasExpandedExpression() )
|
||||
{
|
||||
m_config.stream() << " for: ";
|
||||
TextColour colour( TextColour::ReconstructedExpression );
|
||||
|
@@ -19,7 +19,7 @@
|
||||
|
||||
namespace Catch
|
||||
{
|
||||
class JunitReporter : public Catch::IReporter
|
||||
class JunitReporter : public SharedImpl<IReporter>
|
||||
{
|
||||
struct TestStats
|
||||
{
|
||||
|
@@ -19,7 +19,7 @@
|
||||
|
||||
namespace Catch
|
||||
{
|
||||
class XmlReporter : public Catch::IReporter
|
||||
class XmlReporter : public SharedImpl<IReporter>
|
||||
{
|
||||
public:
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
@@ -29,7 +29,7 @@ namespace Catch
|
||||
)
|
||||
: m_config( config )
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
static std::string getDescription
|
||||
|
Reference in New Issue
Block a user