More reformatting

This commit is contained in:
Phil Nash 2012-05-16 08:02:20 +01:00
parent c67a7eef2b
commit 6cd2ac7544
11 changed files with 125 additions and 351 deletions

View File

@ -1,13 +1,9 @@
/* /*
* catch_console_colour_impl.hpp
* Catch
*
* Created by Phil on 25/2/2012. * Created by Phil on 25/2/2012.
* Copyright 2012 Two Blue Cubes Ltd. All rights reserved. * Copyright 2012 Two Blue Cubes Ltd. All rights reserved.
* *
* Distributed under the Boost Software License, Version 1.0. (See accompanying * 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) * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*
*/ */
#ifndef TWOBLUECUBES_CATCH_CONSOLE_COLOUR_IMPL_HPP_INCLUDED #ifndef TWOBLUECUBES_CATCH_CONSOLE_COLOUR_IMPL_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_CONSOLE_COLOUR_IMPL_HPP_INCLUDED #define TWOBLUECUBES_CATCH_CONSOLE_COLOUR_IMPL_HPP_INCLUDED
@ -18,14 +14,12 @@
#include <windows.h> #include <windows.h>
namespace Catch namespace Catch {
{
namespace namespace {
{
WORD mapConsoleColour( TextColour::Colours colour ) WORD mapConsoleColour( TextColour::Colours colour ) {
{ switch( colour ) {
switch( colour )
{
case TextColour::FileName: case TextColour::FileName:
return FOREGROUND_INTENSITY; // greyed out return FOREGROUND_INTENSITY; // greyed out
case TextColour::ResultError: case TextColour::ResultError:
@ -45,8 +39,8 @@ namespace Catch
} }
} }
struct ConsoleColourImpl struct ConsoleColourImpl {
{
ConsoleColourImpl() ConsoleColourImpl()
: hStdout( GetStdHandle(STD_OUTPUT_HANDLE) ), : hStdout( GetStdHandle(STD_OUTPUT_HANDLE) ),
wOldColorAttrs( 0 ) wOldColorAttrs( 0 )
@ -54,12 +48,12 @@ namespace Catch
GetConsoleScreenBufferInfo( hStdout, &csbiInfo ); GetConsoleScreenBufferInfo( hStdout, &csbiInfo );
wOldColorAttrs = csbiInfo.wAttributes; wOldColorAttrs = csbiInfo.wAttributes;
} }
~ConsoleColourImpl()
{ ~ConsoleColourImpl() {
SetConsoleTextAttribute( hStdout, wOldColorAttrs ); SetConsoleTextAttribute( hStdout, wOldColorAttrs );
} }
void set( TextColour::Colours colour )
{ void set( TextColour::Colours colour ) {
WORD consoleColour = mapConsoleColour( colour ); WORD consoleColour = mapConsoleColour( colour );
if( consoleColour > 0 ) if( consoleColour > 0 )
SetConsoleTextAttribute( hStdout, consoleColour ); SetConsoleTextAttribute( hStdout, consoleColour );
@ -70,18 +64,18 @@ namespace Catch
WORD wOldColorAttrs; WORD wOldColorAttrs;
}; };
TextColour::TextColour( Colours colour ) TextColour::TextColour( Colours colour )
: m_impl( new ConsoleColourImpl() ) : m_impl( new ConsoleColourImpl() )
{ {
if( colour ) if( colour )
m_impl->set( colour ); m_impl->set( colour );
} }
TextColour::~TextColour()
{ TextColour::~TextColour() {
delete m_impl; delete m_impl;
} }
void TextColour::set( Colours colour )
{ void TextColour::set( Colours colour ) {
m_impl->set( colour ); m_impl->set( colour );
} }
@ -89,8 +83,7 @@ namespace Catch
#else #else
namespace Catch namespace Catch {
{
TextColour::TextColour( Colours ){} TextColour::TextColour( Colours ){}
TextColour::~TextColour(){} TextColour::~TextColour(){}
void TextColour::set( Colours ){} void TextColour::set( Colours ){}

View File

@ -15,8 +15,8 @@
#include "catch_reporter_registry.hpp" #include "catch_reporter_registry.hpp"
#include "catch_stream.hpp" #include "catch_stream.hpp"
namespace Catch namespace Catch {
{
Context::Context() Context::Context()
: m_reporterRegistry( new ReporterRegistry ), : m_reporterRegistry( new ReporterRegistry ),
m_testCaseRegistry( new TestRegistry ), m_testCaseRegistry( new TestRegistry ),
@ -89,8 +89,7 @@ namespace Catch
GeneratorsForTest& Context::getGeneratorsForCurrentTest() { GeneratorsForTest& Context::getGeneratorsForCurrentTest() {
GeneratorsForTest* generators = findGeneratorsForCurrentTest(); GeneratorsForTest* generators = findGeneratorsForCurrentTest();
if( !generators ) if( !generators ) {
{
std::string testName = getResultCapture().getCurrentTestName(); std::string testName = getResultCapture().getCurrentTestName();
generators = new GeneratorsForTest(); generators = new GeneratorsForTest();
m_generatorsByTestName.insert( std::make_pair( testName, generators ) ); m_generatorsByTestName.insert( std::make_pair( testName, generators ) );
@ -98,8 +97,7 @@ namespace Catch
return *generators; return *generators;
} }
size_t Context::getGeneratorIndex( const std::string& fileInfo, size_t totalSize ) size_t Context::getGeneratorIndex( const std::string& fileInfo, size_t totalSize ) {
{
return me().getGeneratorsForCurrentTest() return me().getGeneratorsForCurrentTest()
.getGeneratorInfo( fileInfo, totalSize ) .getGeneratorInfo( fileInfo, totalSize )
.getCurrentIndex(); .getCurrentIndex();

View File

@ -1,82 +1,53 @@
/* /*
* catch_exception_translator_registry.hpp
* Catch
*
* Created by Phil on 20/04/2011. * Created by Phil on 20/04/2011.
* Copyright 2011 Two Blue Cubes Ltd. All rights reserved. * Copyright 2011 Two Blue Cubes Ltd. All rights reserved.
* *
* Distributed under the Boost Software License, Version 1.0. (See accompanying * 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) * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*
*/ */
#ifndef TWOBLUECUBES_CATCH_EXCEPTION_TRANSLATOR_HPP_INCLUDED #ifndef TWOBLUECUBES_CATCH_EXCEPTION_TRANSLATOR_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_EXCEPTION_TRANSLATOR_HPP_INCLUDED #define TWOBLUECUBES_CATCH_EXCEPTION_TRANSLATOR_HPP_INCLUDED
#include "catch_interfaces_exception.h" #include "catch_interfaces_exception.h"
namespace Catch namespace Catch {
{
class ExceptionTranslatorRegistry : public IExceptionTranslatorRegistry class ExceptionTranslatorRegistry : public IExceptionTranslatorRegistry {
{
/////////////////////////////////////////////////////////////////////// ~ExceptionTranslatorRegistry() {
~ExceptionTranslatorRegistry
()
{
deleteAll( m_translators ); deleteAll( m_translators );
} }
/////////////////////////////////////////////////////////////////////// virtual void registerTranslator( IExceptionTranslator* translator ) {
virtual void registerTranslator
(
IExceptionTranslator* translator
)
{
m_translators.push_back( translator ); m_translators.push_back( translator );
} }
/////////////////////////////////////////////////////////////////////// virtual std::string translateActiveException() const {
virtual std::string translateActiveException try {
()
const
{
try
{
throw; throw;
} }
catch( std::exception& ex ) catch( std::exception& ex ) {
{
return ex.what(); return ex.what();
} }
catch( std::string& msg ) catch( std::string& msg ) {
{
return msg; return msg;
} }
catch( const char* msg ) catch( const char* msg ) {
{
return msg; return msg;
} }
catch(...) catch(...) {
{
return tryTranslators( m_translators.begin() ); return tryTranslators( m_translators.begin() );
} }
} }
/////////////////////////////////////////////////////////////////////// std::string tryTranslators( std::vector<IExceptionTranslator*>::const_iterator it ) const {
std::string tryTranslators
(
std::vector<IExceptionTranslator*>::const_iterator it
)
const
{
if( it == m_translators.end() ) if( it == m_translators.end() )
return "Unknown exception"; return "Unknown exception";
try try {
{
return (*it)->translate(); return (*it)->translate();
} }
catch(...) catch(...) {
{
return tryTranslators( it+1 ); return tryTranslators( it+1 );
} }
} }

View File

@ -1,15 +1,10 @@
/* /*
* catch_generators_impl.hpp
* Catch
*
* Created by Phil on 28/01/2011. * Created by Phil on 28/01/2011.
* Copyright 2011 Two Blue Cubes Ltd. All rights reserved. * Copyright 2011 Two Blue Cubes Ltd. All rights reserved.
* *
* Distributed under the Boost Software License, Version 1.0. (See accompanying * 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) * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*
*/ */
#ifndef TWOBLUECUBES_CATCH_GENERATORS_IMPL_HPP_INCLUDED #ifndef TWOBLUECUBES_CATCH_GENERATORS_IMPL_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_GENERATORS_IMPL_HPP_INCLUDED #define TWOBLUECUBES_CATCH_GENERATORS_IMPL_HPP_INCLUDED
@ -19,37 +14,24 @@
#include <string> #include <string>
#include <map> #include <map>
namespace Catch namespace Catch {
{
struct GeneratorInfo struct GeneratorInfo {
{
/////////////////////////////////////////////////////////////////////// GeneratorInfo( std::size_t size )
GeneratorInfo
(
std::size_t size
)
: m_size( size ), : m_size( size ),
m_currentIndex( 0 ) m_currentIndex( 0 )
{ {}
}
/////////////////////////////////////////////////////////////////////// bool moveNext() {
bool moveNext if( ++m_currentIndex == m_size ) {
()
{
if( ++m_currentIndex == m_size )
{
m_currentIndex = 0; m_currentIndex = 0;
return false; return false;
} }
return true; return true;
} }
/////////////////////////////////////////////////////////////////////// std::size_t getCurrentIndex() const {
std::size_t getCurrentIndex
()
const
{
return m_currentIndex; return m_currentIndex;
} }
@ -57,30 +39,18 @@ namespace Catch
std::size_t m_currentIndex; std::size_t m_currentIndex;
}; };
///////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
class GeneratorsForTest class GeneratorsForTest {
{
public: public:
/////////////////////////////////////////////////////////////////////// ~GeneratorsForTest() {
~GeneratorsForTest
()
{
deleteAll( m_generatorsInOrder ); deleteAll( m_generatorsInOrder );
} }
/////////////////////////////////////////////////////////////////////// GeneratorInfo& getGeneratorInfo( const std::string& fileInfo, std::size_t size ) {
GeneratorInfo& getGeneratorInfo
(
const std::string& fileInfo,
std::size_t size
)
{
std::map<std::string, GeneratorInfo*>::const_iterator it = m_generatorsByName.find( fileInfo ); std::map<std::string, GeneratorInfo*>::const_iterator it = m_generatorsByName.find( fileInfo );
if( it == m_generatorsByName.end() ) if( it == m_generatorsByName.end() ) {
{
GeneratorInfo* info = new GeneratorInfo( size ); GeneratorInfo* info = new GeneratorInfo( size );
m_generatorsByName.insert( std::make_pair( fileInfo, info ) ); m_generatorsByName.insert( std::make_pair( fileInfo, info ) );
m_generatorsInOrder.push_back( info ); m_generatorsInOrder.push_back( info );
@ -89,14 +59,10 @@ namespace Catch
return *it->second; return *it->second;
} }
/////////////////////////////////////////////////////////////////////// bool moveNext() {
bool moveNext
()
{
std::vector<GeneratorInfo*>::const_iterator it = m_generatorsInOrder.begin(); std::vector<GeneratorInfo*>::const_iterator it = m_generatorsInOrder.begin();
std::vector<GeneratorInfo*>::const_iterator itEnd = m_generatorsInOrder.end(); std::vector<GeneratorInfo*>::const_iterator itEnd = m_generatorsInOrder.end();
for(; it != itEnd; ++it ) for(; it != itEnd; ++it ) {
{
if( (*it)->moveNext() ) if( (*it)->moveNext() )
return true; return true;
} }

View File

@ -1,58 +1,39 @@
/* /*
* catch_reporter_registrars.hpp
* Test
*
* Created by Phil on 31/12/2010. * Created by Phil on 31/12/2010.
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved. * Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
* *
* Distributed under the Boost Software License, Version 1.0. (See accompanying * 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) * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*
*/ */
#ifndef TWOBLUECUBES_CATCH_REPORTER_REGISTRARS_HPP_INCLUDED #ifndef TWOBLUECUBES_CATCH_REPORTER_REGISTRARS_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_REPORTER_REGISTRARS_HPP_INCLUDED #define TWOBLUECUBES_CATCH_REPORTER_REGISTRARS_HPP_INCLUDED
#include "catch_context.h" #include "catch_context.h"
namespace Catch namespace Catch {
{
template<typename T> template<typename T>
class ReporterRegistrar class ReporterRegistrar {
{
class ReporterFactory : public IReporterFactory class ReporterFactory : public IReporterFactory {
{
/////////////////////////////////////////////////////////////////// virtual IReporter* create( const IReporterConfig& config ) const {
virtual IReporter* create
(
const IReporterConfig& config
)
const
{
return new T( config ); return new T( config );
} }
///////////////////////////////////////////////////////////////////
virtual std::string getDescription virtual std::string getDescription() const {
()
const
{
return T::getDescription(); return T::getDescription();
} }
}; };
public: public:
/////////////////////////////////////////////////////////////////////// ReporterRegistrar( const std::string& name ) {
ReporterRegistrar
(
const std::string& name
)
{
Context::getReporterRegistry().registerReporter( name, new ReporterFactory() ); Context::getReporterRegistry().registerReporter( name, new ReporterFactory() );
} }
}; };
} }
///////////////////////////////////////////////////////////////////////////////
#define INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType ) \ #define INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType ) \
Catch::ReporterRegistrar<reporterType> catch_internal_RegistrarFor##reporterType( name ); Catch::ReporterRegistrar<reporterType> catch_internal_RegistrarFor##reporterType( name );

View File

@ -1,13 +1,9 @@
/* /*
* catch_reporter_registry.hpp
* Catch
*
* Created by Phil on 29/10/2010. * Created by Phil on 29/10/2010.
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved. * Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
* *
* Distributed under the Boost Software License, Version 1.0. (See accompanying * 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) * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*
*/ */
#ifndef TWOBLUECUBES_CATCH_REPORTER_REGISTRY_HPP_INCLUDED #ifndef TWOBLUECUBES_CATCH_REPORTER_REGISTRY_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_REPORTER_REGISTRY_HPP_INCLUDED #define TWOBLUECUBES_CATCH_REPORTER_REGISTRY_HPP_INCLUDED
@ -16,48 +12,28 @@
#include <map> #include <map>
namespace Catch namespace Catch {
{
class ReporterRegistry : public IReporterRegistry class ReporterRegistry : public IReporterRegistry {
{
public: public:
/////////////////////////////////////////////////////////////////////// ~ReporterRegistry() {
~ReporterRegistry
()
{
deleteAllValues( m_factories ); deleteAllValues( m_factories );
} }
/////////////////////////////////////////////////////////////////////// virtual IReporter* create( const std::string& name, const IReporterConfig& config ) const {
virtual IReporter* create
(
const std::string& name,
const IReporterConfig& config
)
const
{
FactoryMap::const_iterator it = m_factories.find( name ); FactoryMap::const_iterator it = m_factories.find( name );
if( it == m_factories.end() ) if( it == m_factories.end() )
return NULL; return NULL;
return it->second->create( config ); return it->second->create( config );
} }
/////////////////////////////////////////////////////////////////////// void registerReporter( const std::string& name, IReporterFactory* factory ) {
void registerReporter
(
const std::string& name,
IReporterFactory* factory
)
{
m_factories.insert( std::make_pair( name, factory ) ); m_factories.insert( std::make_pair( name, factory ) );
} }
/////////////////////////////////////////////////////////////////////// const FactoryMap& getFactories() const {
const FactoryMap& getFactories
()
const
{
return m_factories; return m_factories;
} }

View File

@ -18,8 +18,8 @@ namespace Catch {
struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison; struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison;
class ResultInfoBuilder : public ResultInfo class ResultInfoBuilder : public ResultInfo {
{
public: public:
ResultInfoBuilder() {} ResultInfoBuilder() {}

View File

@ -21,28 +21,20 @@
#include <set> #include <set>
#include <string> #include <string>
namespace Catch namespace Catch {
{
class StreamRedirect class StreamRedirect {
{
public: public:
/////////////////////////////////////////////////////////////////////// StreamRedirect( std::ostream& stream, std::string& targetString )
StreamRedirect
(
std::ostream& stream,
std::string& targetString
)
: m_stream( stream ), : m_stream( stream ),
m_prevBuf( stream.rdbuf() ), m_prevBuf( stream.rdbuf() ),
m_targetString( targetString ) m_targetString( targetString )
{ {
stream.rdbuf( m_oss.rdbuf() ); stream.rdbuf( m_oss.rdbuf() );
} }
/////////////////////////////////////////////////////////////////////// ~StreamRedirect() {
~StreamRedirect
()
{
m_targetString += m_oss.str(); m_targetString += m_oss.str();
m_stream.rdbuf( m_prevBuf ); m_stream.rdbuf( m_prevBuf );
} }
@ -55,19 +47,15 @@ namespace Catch
}; };
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
class Runner : public IResultCapture, public IRunner class Runner : public IResultCapture, public IRunner {
{
Runner( const Runner& ); Runner( const Runner& );
void operator =( const Runner& ); void operator =( const Runner& );
public: public:
/////////////////////////////////////////////////////////////////////////// explicit Runner( Config& config )
explicit Runner
(
Config& config
)
: m_runningTest( NULL ), : m_runningTest( NULL ),
m_config( config ), m_config( config ),
m_reporter( config.getReporter() ), m_reporter( config.getReporter() ),
@ -79,43 +67,27 @@ namespace Catch
m_reporter->StartTesting(); m_reporter->StartTesting();
} }
/////////////////////////////////////////////////////////////////////////// ~Runner() {
~Runner
()
{
m_reporter->EndTesting( m_totals ); m_reporter->EndTesting( m_totals );
Context::setRunner( m_prevRunner ); Context::setRunner( m_prevRunner );
Context::setResultCapture( m_prevResultCapture ); Context::setResultCapture( m_prevResultCapture );
} }
/////////////////////////////////////////////////////////////////////////// virtual void runAll( bool runHiddenTests = false ) {
virtual void runAll
(
bool runHiddenTests = false
)
{
std::vector<TestCaseInfo> allTests = Context::getTestCaseRegistry().getAllTests(); std::vector<TestCaseInfo> allTests = Context::getTestCaseRegistry().getAllTests();
for( std::size_t i=0; i < allTests.size(); ++i ) for( std::size_t i=0; i < allTests.size(); ++i ) {
{
if( runHiddenTests || !allTests[i].isHidden() ) if( runHiddenTests || !allTests[i].isHidden() )
runTest( allTests[i] ); runTest( allTests[i] );
} }
} }
/////////////////////////////////////////////////////////////////////////// virtual std::size_t runMatching( const std::string& rawTestSpec ) {
virtual std::size_t runMatching
(
const std::string& rawTestSpec
)
{
TestSpec testSpec( rawTestSpec ); TestSpec testSpec( rawTestSpec );
std::vector<TestCaseInfo> allTests = Context::getTestCaseRegistry().getAllTests(); std::vector<TestCaseInfo> allTests = Context::getTestCaseRegistry().getAllTests();
std::size_t testsRun = 0; std::size_t testsRun = 0;
for( std::size_t i=0; i < allTests.size(); ++i ) for( std::size_t i=0; i < allTests.size(); ++i ) {
{ if( testSpec.matches( allTests[i].getName() ) ) {
if( testSpec.matches( allTests[i].getName() ) )
{
runTest( allTests[i] ); runTest( allTests[i] );
testsRun++; testsRun++;
} }
@ -123,12 +95,7 @@ namespace Catch
return testsRun; return testsRun;
} }
/////////////////////////////////////////////////////////////////////////// void runTest( const TestCaseInfo& testInfo ) {
void runTest
(
const TestCaseInfo& testInfo
)
{
Totals prevTotals = m_totals; Totals prevTotals = m_totals;
std::string redirectedCout; std::string redirectedCout;
@ -138,10 +105,8 @@ namespace Catch
m_runningTest = new RunningTest( &testInfo ); m_runningTest = new RunningTest( &testInfo );
do do {
{ do {
do
{
m_reporter->StartGroup( "test case run" ); m_reporter->StartGroup( "test case run" );
m_currentResult.setLineInfo( m_runningTest->getTestCaseInfo().getLineInfo() ); m_currentResult.setLineInfo( m_runningTest->getTestCaseInfo().getLineInfo() );
runCurrentTest( redirectedCout, redirectedCerr ); runCurrentTest( redirectedCout, redirectedCerr );
@ -162,66 +127,35 @@ namespace Catch
m_reporter->EndTestCase( testInfo, m_totals - prevTotals, redirectedCout, redirectedCerr ); m_reporter->EndTestCase( testInfo, m_totals - prevTotals, redirectedCout, redirectedCerr );
} }
/////////////////////////////////////////////////////////////////////////// virtual Totals getTotals() const {
virtual Totals getTotals
()
const
{
return m_totals; return m_totals;
} }
private: // IResultCapture private: // IResultCapture
/////////////////////////////////////////////////////////////////////////// virtual ResultAction::Value acceptResult( bool result ) {
virtual ResultAction::Value acceptResult
(
bool result
)
{
return acceptResult( result ? ResultWas::Ok : ResultWas::ExpressionFailed ); return acceptResult( result ? ResultWas::Ok : ResultWas::ExpressionFailed );
} }
/////////////////////////////////////////////////////////////////////////// virtual ResultAction::Value acceptResult( ResultWas::OfType result ) {
virtual ResultAction::Value acceptResult
(
ResultWas::OfType result
)
{
m_currentResult.setResultType( result ); m_currentResult.setResultType( result );
return actOnCurrentResult(); return actOnCurrentResult();
} }
/////////////////////////////////////////////////////////////////////////// virtual ResultAction::Value acceptExpression( const ResultInfoBuilder& resultInfo ) {
virtual ResultAction::Value acceptExpression
(
const ResultInfoBuilder& resultInfo
)
{
m_currentResult = resultInfo; m_currentResult = resultInfo;
return actOnCurrentResult(); return actOnCurrentResult();
} }
/////////////////////////////////////////////////////////////////////////// virtual void acceptMessage( const std::string& msg ) {
virtual void acceptMessage
(
const std::string& msg
)
{
m_currentResult.setMessage( msg ); m_currentResult.setMessage( msg );
} }
/////////////////////////////////////////////////////////////////////////// virtual void testEnded( const ResultInfo& result ) {
virtual void testEnded if( result.getResultType() == ResultWas::Ok ) {
(
const ResultInfo& result
)
{
if( result.getResultType() == ResultWas::Ok )
{
m_totals.assertions.passed++; m_totals.assertions.passed++;
} }
else if( !result.ok() ) else if( !result.ok() ) {
{
m_totals.assertions.failed++; m_totals.assertions.failed++;
std::vector<ResultInfo>::const_iterator it = m_info.begin(); std::vector<ResultInfo>::const_iterator it = m_info.begin();
@ -237,9 +171,7 @@ namespace Catch
m_reporter->Result( result ); m_reporter->Result( result );
} }
/////////////////////////////////////////////////////////////////////////// virtual bool sectionStarted (
virtual bool sectionStarted
(
const std::string& name, const std::string& name,
const std::string& description, const std::string& description,
const SourceLineInfo& lineInfo, const SourceLineInfo& lineInfo,
@ -259,68 +191,37 @@ namespace Catch
return true; return true;
} }
/////////////////////////////////////////////////////////////////////////// virtual void sectionEnded( const std::string& name, const Counts& prevAssertions ) {
virtual void sectionEnded
(
const std::string& name,
const Counts& prevAssertions
)
{
m_runningTest->endSection( name ); m_runningTest->endSection( name );
m_reporter->EndSection( name, m_totals.assertions - prevAssertions ); m_reporter->EndSection( name, m_totals.assertions - prevAssertions );
} }
/////////////////////////////////////////////////////////////////////////// virtual void pushScopedInfo( ScopedInfo* scopedInfo ) {
virtual void pushScopedInfo
(
ScopedInfo* scopedInfo
)
{
m_scopedInfos.push_back( scopedInfo ); m_scopedInfos.push_back( scopedInfo );
} }
/////////////////////////////////////////////////////////////////////////// virtual void popScopedInfo( ScopedInfo* scopedInfo ) {
virtual void popScopedInfo
(
ScopedInfo* scopedInfo
)
{
if( m_scopedInfos.back() == scopedInfo ) if( m_scopedInfos.back() == scopedInfo )
m_scopedInfos.pop_back(); m_scopedInfos.pop_back();
} }
/////////////////////////////////////////////////////////////////////////// virtual bool shouldDebugBreak() const {
virtual bool shouldDebugBreak
()
const
{
return m_config.shouldDebugBreak(); return m_config.shouldDebugBreak();
} }
/////////////////////////////////////////////////////////////////////////// virtual std::string getCurrentTestName() const {
virtual std::string getCurrentTestName
()
const
{
return m_runningTest return m_runningTest
? m_runningTest->getTestCaseInfo().getName() ? m_runningTest->getTestCaseInfo().getName()
: ""; : "";
} }
/////////////////////////////////////////////////////////////////////////// virtual const ResultInfo* getLastResult() const {
virtual const ResultInfo* getLastResult
()
const
{
return &m_lastResult; return &m_lastResult;
} }
private: private:
/////////////////////////////////////////////////////////////////////////// ResultAction::Value actOnCurrentResult() {
ResultAction::Value actOnCurrentResult
()
{
testEnded( m_currentResult ); testEnded( m_currentResult );
m_lastResult = m_currentResult; m_lastResult = m_currentResult;
@ -333,34 +234,23 @@ namespace Catch
return ResultAction::Failed; return ResultAction::Failed;
} }
/////////////////////////////////////////////////////////////////////////// void runCurrentTest( std::string& redirectedCout, std::string& redirectedCerr ) {
void runCurrentTest try {
(
std::string& redirectedCout,
std::string& redirectedCerr
)
{
try
{
m_runningTest->reset(); m_runningTest->reset();
if( m_reporter->shouldRedirectStdout() ) if( m_reporter->shouldRedirectStdout() ) {
{
StreamRedirect coutRedir( std::cout, redirectedCout ); StreamRedirect coutRedir( std::cout, redirectedCout );
StreamRedirect cerrRedir( std::cerr, redirectedCerr ); StreamRedirect cerrRedir( std::cerr, redirectedCerr );
m_runningTest->getTestCaseInfo().invoke(); m_runningTest->getTestCaseInfo().invoke();
} }
else else {
{
m_runningTest->getTestCaseInfo().invoke(); m_runningTest->getTestCaseInfo().invoke();
} }
m_runningTest->ranToCompletion(); m_runningTest->ranToCompletion();
} }
catch( TestFailureException& ) catch( TestFailureException& ) {
{
// This just means the test was aborted due to failure // This just means the test was aborted due to failure
} }
catch(...) catch(...) {
{
acceptMessage( Catch::Context::getExceptionTranslatorRegistry().translateActiveException() ); acceptMessage( Catch::Context::getExceptionTranslatorRegistry().translateActiveException() );
acceptResult( ResultWas::ThrewException ); acceptResult( ResultWas::ThrewException );
} }

View File

@ -13,7 +13,7 @@
#include <string> #include <string>
namespace Catch{ namespace Catch {
class Section { class Section {
public: public:

View File

@ -14,8 +14,8 @@
#include <sstream> #include <sstream>
#include <iostream> #include <iostream>
namespace Catch namespace Catch {
{
class TestRegistry : public ITestCaseRegistry { class TestRegistry : public ITestCaseRegistry {
public: public:
TestRegistry() : m_unnamedCount( 0 ) {} TestRegistry() : m_unnamedCount( 0 ) {}

View File

@ -11,12 +11,11 @@
#include "catch_common.h" #include "catch_common.h"
#include "catch_interfaces_testcase.h" #include "catch_interfaces_testcase.h"
namespace Catch namespace Catch {
{
template<typename C> template<typename C>
class MethodTestCase : public ITestCase class MethodTestCase : public ITestCase {
{
public: public:
MethodTestCase( void (C::*method)() ) : m_method( method ) {} MethodTestCase( void (C::*method)() ) : m_method( method ) {}
@ -45,8 +44,8 @@ private:
typedef void(*TestFunction)(); typedef void(*TestFunction)();
struct AutoReg struct AutoReg {
{
AutoReg( TestFunction function, AutoReg( TestFunction function,
const char* name, const char* name,
const char* description, const char* description,