mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 13:26:10 +01:00
More reformatting
This commit is contained in:
parent
c67a7eef2b
commit
6cd2ac7544
@ -1,13 +1,9 @@
|
||||
/*
|
||||
* catch_console_colour_impl.hpp
|
||||
* Catch
|
||||
*
|
||||
* Created by Phil on 25/2/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_CONSOLE_COLOUR_IMPL_HPP_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_CONSOLE_COLOUR_IMPL_HPP_INCLUDED
|
||||
@ -18,14 +14,12 @@
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
namespace Catch
|
||||
{
|
||||
namespace
|
||||
{
|
||||
WORD mapConsoleColour( TextColour::Colours colour )
|
||||
{
|
||||
switch( colour )
|
||||
{
|
||||
namespace Catch {
|
||||
|
||||
namespace {
|
||||
|
||||
WORD mapConsoleColour( TextColour::Colours colour ) {
|
||||
switch( colour ) {
|
||||
case TextColour::FileName:
|
||||
return FOREGROUND_INTENSITY; // greyed out
|
||||
case TextColour::ResultError:
|
||||
@ -45,8 +39,8 @@ namespace Catch
|
||||
}
|
||||
}
|
||||
|
||||
struct ConsoleColourImpl
|
||||
{
|
||||
struct ConsoleColourImpl {
|
||||
|
||||
ConsoleColourImpl()
|
||||
: hStdout( GetStdHandle(STD_OUTPUT_HANDLE) ),
|
||||
wOldColorAttrs( 0 )
|
||||
@ -54,12 +48,12 @@ namespace Catch
|
||||
GetConsoleScreenBufferInfo( hStdout, &csbiInfo );
|
||||
wOldColorAttrs = csbiInfo.wAttributes;
|
||||
}
|
||||
~ConsoleColourImpl()
|
||||
{
|
||||
|
||||
~ConsoleColourImpl() {
|
||||
SetConsoleTextAttribute( hStdout, wOldColorAttrs );
|
||||
}
|
||||
void set( TextColour::Colours colour )
|
||||
{
|
||||
|
||||
void set( TextColour::Colours colour ) {
|
||||
WORD consoleColour = mapConsoleColour( colour );
|
||||
if( consoleColour > 0 )
|
||||
SetConsoleTextAttribute( hStdout, consoleColour );
|
||||
@ -70,18 +64,18 @@ namespace Catch
|
||||
WORD wOldColorAttrs;
|
||||
};
|
||||
|
||||
TextColour::TextColour( Colours colour )
|
||||
: m_impl( new ConsoleColourImpl() )
|
||||
TextColour::TextColour( Colours colour )
|
||||
: m_impl( new ConsoleColourImpl() )
|
||||
{
|
||||
if( colour )
|
||||
m_impl->set( colour );
|
||||
}
|
||||
TextColour::~TextColour()
|
||||
{
|
||||
|
||||
TextColour::~TextColour() {
|
||||
delete m_impl;
|
||||
}
|
||||
void TextColour::set( Colours colour )
|
||||
{
|
||||
|
||||
void TextColour::set( Colours colour ) {
|
||||
m_impl->set( colour );
|
||||
}
|
||||
|
||||
@ -89,8 +83,7 @@ namespace Catch
|
||||
|
||||
#else
|
||||
|
||||
namespace Catch
|
||||
{
|
||||
namespace Catch {
|
||||
TextColour::TextColour( Colours ){}
|
||||
TextColour::~TextColour(){}
|
||||
void TextColour::set( Colours ){}
|
||||
|
@ -15,8 +15,8 @@
|
||||
#include "catch_reporter_registry.hpp"
|
||||
#include "catch_stream.hpp"
|
||||
|
||||
namespace Catch
|
||||
{
|
||||
namespace Catch {
|
||||
|
||||
Context::Context()
|
||||
: m_reporterRegistry( new ReporterRegistry ),
|
||||
m_testCaseRegistry( new TestRegistry ),
|
||||
@ -89,8 +89,7 @@ namespace Catch
|
||||
|
||||
GeneratorsForTest& Context::getGeneratorsForCurrentTest() {
|
||||
GeneratorsForTest* generators = findGeneratorsForCurrentTest();
|
||||
if( !generators )
|
||||
{
|
||||
if( !generators ) {
|
||||
std::string testName = getResultCapture().getCurrentTestName();
|
||||
generators = new GeneratorsForTest();
|
||||
m_generatorsByTestName.insert( std::make_pair( testName, generators ) );
|
||||
@ -98,8 +97,7 @@ namespace Catch
|
||||
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()
|
||||
.getGeneratorInfo( fileInfo, totalSize )
|
||||
.getCurrentIndex();
|
||||
|
@ -1,82 +1,53 @@
|
||||
/*
|
||||
* catch_exception_translator_registry.hpp
|
||||
* Catch
|
||||
*
|
||||
* Created by Phil on 20/04/2011.
|
||||
* Copyright 2011 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_EXCEPTION_TRANSLATOR_HPP_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_EXCEPTION_TRANSLATOR_HPP_INCLUDED
|
||||
|
||||
#include "catch_interfaces_exception.h"
|
||||
|
||||
namespace Catch
|
||||
{
|
||||
class ExceptionTranslatorRegistry : public IExceptionTranslatorRegistry
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
~ExceptionTranslatorRegistry
|
||||
()
|
||||
{
|
||||
namespace Catch {
|
||||
|
||||
class ExceptionTranslatorRegistry : public IExceptionTranslatorRegistry {
|
||||
|
||||
~ExceptionTranslatorRegistry() {
|
||||
deleteAll( m_translators );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
virtual void registerTranslator
|
||||
(
|
||||
IExceptionTranslator* translator
|
||||
)
|
||||
{
|
||||
|
||||
virtual void registerTranslator( IExceptionTranslator* translator ) {
|
||||
m_translators.push_back( translator );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
virtual std::string translateActiveException
|
||||
()
|
||||
const
|
||||
{
|
||||
try
|
||||
{
|
||||
virtual std::string translateActiveException() const {
|
||||
try {
|
||||
throw;
|
||||
}
|
||||
catch( std::exception& ex )
|
||||
{
|
||||
catch( std::exception& ex ) {
|
||||
return ex.what();
|
||||
}
|
||||
catch( std::string& msg )
|
||||
{
|
||||
catch( std::string& msg ) {
|
||||
return msg;
|
||||
}
|
||||
catch( const char* msg )
|
||||
{
|
||||
catch( const char* msg ) {
|
||||
return msg;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
catch(...) {
|
||||
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() )
|
||||
return "Unknown exception";
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
return (*it)->translate();
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
catch(...) {
|
||||
return tryTranslators( it+1 );
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,10 @@
|
||||
/*
|
||||
* catch_generators_impl.hpp
|
||||
* Catch
|
||||
*
|
||||
* Created by Phil on 28/01/2011.
|
||||
* Copyright 2011 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_GENERATORS_IMPL_HPP_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_GENERATORS_IMPL_HPP_INCLUDED
|
||||
|
||||
@ -19,37 +14,24 @@
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
namespace Catch
|
||||
{
|
||||
struct GeneratorInfo
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
GeneratorInfo
|
||||
(
|
||||
std::size_t size
|
||||
)
|
||||
namespace Catch {
|
||||
|
||||
struct GeneratorInfo {
|
||||
|
||||
GeneratorInfo( std::size_t size )
|
||||
: m_size( size ),
|
||||
m_currentIndex( 0 )
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
bool moveNext
|
||||
()
|
||||
{
|
||||
if( ++m_currentIndex == m_size )
|
||||
{
|
||||
bool moveNext() {
|
||||
if( ++m_currentIndex == m_size ) {
|
||||
m_currentIndex = 0;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
std::size_t getCurrentIndex
|
||||
()
|
||||
const
|
||||
{
|
||||
std::size_t getCurrentIndex() const {
|
||||
return m_currentIndex;
|
||||
}
|
||||
|
||||
@ -57,30 +39,18 @@ namespace Catch
|
||||
std::size_t m_currentIndex;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class GeneratorsForTest
|
||||
{
|
||||
class GeneratorsForTest {
|
||||
|
||||
public:
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
~GeneratorsForTest
|
||||
()
|
||||
{
|
||||
~GeneratorsForTest() {
|
||||
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 );
|
||||
if( it == m_generatorsByName.end() )
|
||||
{
|
||||
if( it == m_generatorsByName.end() ) {
|
||||
GeneratorInfo* info = new GeneratorInfo( size );
|
||||
m_generatorsByName.insert( std::make_pair( fileInfo, info ) );
|
||||
m_generatorsInOrder.push_back( info );
|
||||
@ -89,14 +59,10 @@ namespace Catch
|
||||
return *it->second;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
bool moveNext
|
||||
()
|
||||
{
|
||||
bool moveNext() {
|
||||
std::vector<GeneratorInfo*>::const_iterator it = m_generatorsInOrder.begin();
|
||||
std::vector<GeneratorInfo*>::const_iterator itEnd = m_generatorsInOrder.end();
|
||||
for(; it != itEnd; ++it )
|
||||
{
|
||||
for(; it != itEnd; ++it ) {
|
||||
if( (*it)->moveNext() )
|
||||
return true;
|
||||
}
|
||||
|
@ -1,58 +1,39 @@
|
||||
/*
|
||||
* catch_reporter_registrars.hpp
|
||||
* Test
|
||||
*
|
||||
* 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_REPORTER_REGISTRARS_HPP_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_REPORTER_REGISTRARS_HPP_INCLUDED
|
||||
|
||||
#include "catch_context.h"
|
||||
|
||||
namespace Catch
|
||||
{
|
||||
namespace Catch {
|
||||
|
||||
template<typename T>
|
||||
class ReporterRegistrar
|
||||
{
|
||||
class ReporterFactory : public IReporterFactory
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////
|
||||
virtual IReporter* create
|
||||
(
|
||||
const IReporterConfig& config
|
||||
)
|
||||
const
|
||||
{
|
||||
class ReporterRegistrar {
|
||||
|
||||
class ReporterFactory : public IReporterFactory {
|
||||
|
||||
virtual IReporter* create( const IReporterConfig& config ) const {
|
||||
return new T( config );
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////
|
||||
virtual std::string getDescription
|
||||
()
|
||||
const
|
||||
{
|
||||
|
||||
virtual std::string getDescription() const {
|
||||
return T::getDescription();
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
ReporterRegistrar
|
||||
(
|
||||
const std::string& name
|
||||
)
|
||||
{
|
||||
ReporterRegistrar( const std::string& name ) {
|
||||
Context::getReporterRegistry().registerReporter( name, new ReporterFactory() );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType ) \
|
||||
Catch::ReporterRegistrar<reporterType> catch_internal_RegistrarFor##reporterType( name );
|
||||
|
||||
|
@ -1,13 +1,9 @@
|
||||
/*
|
||||
* catch_reporter_registry.hpp
|
||||
* Catch
|
||||
*
|
||||
* Created by Phil on 29/10/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_REPORTER_REGISTRY_HPP_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_REPORTER_REGISTRY_HPP_INCLUDED
|
||||
@ -16,48 +12,28 @@
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace Catch
|
||||
{
|
||||
class ReporterRegistry : public IReporterRegistry
|
||||
{
|
||||
namespace Catch {
|
||||
|
||||
class ReporterRegistry : public IReporterRegistry {
|
||||
|
||||
public:
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
~ReporterRegistry
|
||||
()
|
||||
{
|
||||
~ReporterRegistry() {
|
||||
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 );
|
||||
if( it == m_factories.end() )
|
||||
return NULL;
|
||||
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 ) );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
const FactoryMap& getFactories
|
||||
()
|
||||
const
|
||||
{
|
||||
const FactoryMap& getFactories() const {
|
||||
return m_factories;
|
||||
}
|
||||
|
||||
|
@ -18,8 +18,8 @@ namespace Catch {
|
||||
|
||||
struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison;
|
||||
|
||||
class ResultInfoBuilder : public ResultInfo
|
||||
{
|
||||
class ResultInfoBuilder : public ResultInfo {
|
||||
|
||||
public:
|
||||
|
||||
ResultInfoBuilder() {}
|
||||
|
@ -21,28 +21,20 @@
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
namespace Catch
|
||||
{
|
||||
class StreamRedirect
|
||||
{
|
||||
namespace Catch {
|
||||
|
||||
class StreamRedirect {
|
||||
|
||||
public:
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
StreamRedirect
|
||||
(
|
||||
std::ostream& stream,
|
||||
std::string& targetString
|
||||
)
|
||||
StreamRedirect( std::ostream& stream, std::string& targetString )
|
||||
: m_stream( stream ),
|
||||
m_prevBuf( stream.rdbuf() ),
|
||||
m_targetString( targetString )
|
||||
m_targetString( targetString )
|
||||
{
|
||||
stream.rdbuf( m_oss.rdbuf() );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
~StreamRedirect
|
||||
()
|
||||
{
|
||||
~StreamRedirect() {
|
||||
m_targetString += m_oss.str();
|
||||
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& );
|
||||
void operator =( const Runner& );
|
||||
|
||||
public:
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
explicit Runner
|
||||
(
|
||||
Config& config
|
||||
)
|
||||
explicit Runner( Config& config )
|
||||
: m_runningTest( NULL ),
|
||||
m_config( config ),
|
||||
m_reporter( config.getReporter() ),
|
||||
@ -79,43 +67,27 @@ namespace Catch
|
||||
m_reporter->StartTesting();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
~Runner
|
||||
()
|
||||
{
|
||||
~Runner() {
|
||||
m_reporter->EndTesting( m_totals );
|
||||
Context::setRunner( m_prevRunner );
|
||||
Context::setResultCapture( m_prevResultCapture );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual void runAll
|
||||
(
|
||||
bool runHiddenTests = false
|
||||
)
|
||||
{
|
||||
virtual void runAll( bool runHiddenTests = false ) {
|
||||
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() )
|
||||
runTest( allTests[i] );
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual std::size_t runMatching
|
||||
(
|
||||
const std::string& rawTestSpec
|
||||
)
|
||||
{
|
||||
virtual std::size_t runMatching( const std::string& rawTestSpec ) {
|
||||
TestSpec testSpec( rawTestSpec );
|
||||
|
||||
std::vector<TestCaseInfo> allTests = Context::getTestCaseRegistry().getAllTests();
|
||||
std::size_t testsRun = 0;
|
||||
for( std::size_t i=0; i < allTests.size(); ++i )
|
||||
{
|
||||
if( testSpec.matches( allTests[i].getName() ) )
|
||||
{
|
||||
for( std::size_t i=0; i < allTests.size(); ++i ) {
|
||||
if( testSpec.matches( allTests[i].getName() ) ) {
|
||||
runTest( allTests[i] );
|
||||
testsRun++;
|
||||
}
|
||||
@ -123,12 +95,7 @@ namespace Catch
|
||||
return testsRun;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
void runTest
|
||||
(
|
||||
const TestCaseInfo& testInfo
|
||||
)
|
||||
{
|
||||
void runTest( const TestCaseInfo& testInfo ) {
|
||||
Totals prevTotals = m_totals;
|
||||
|
||||
std::string redirectedCout;
|
||||
@ -138,10 +105,8 @@ namespace Catch
|
||||
|
||||
m_runningTest = new RunningTest( &testInfo );
|
||||
|
||||
do
|
||||
{
|
||||
do
|
||||
{
|
||||
do {
|
||||
do {
|
||||
m_reporter->StartGroup( "test case run" );
|
||||
m_currentResult.setLineInfo( m_runningTest->getTestCaseInfo().getLineInfo() );
|
||||
runCurrentTest( redirectedCout, redirectedCerr );
|
||||
@ -162,66 +127,35 @@ namespace Catch
|
||||
m_reporter->EndTestCase( testInfo, m_totals - prevTotals, redirectedCout, redirectedCerr );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual Totals getTotals
|
||||
()
|
||||
const
|
||||
{
|
||||
virtual Totals getTotals() const {
|
||||
return m_totals;
|
||||
}
|
||||
|
||||
private: // IResultCapture
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual ResultAction::Value acceptResult
|
||||
(
|
||||
bool result
|
||||
)
|
||||
{
|
||||
virtual ResultAction::Value acceptResult( bool result ) {
|
||||
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 );
|
||||
return actOnCurrentResult();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual ResultAction::Value acceptExpression
|
||||
(
|
||||
const ResultInfoBuilder& resultInfo
|
||||
)
|
||||
{
|
||||
virtual ResultAction::Value acceptExpression( const ResultInfoBuilder& resultInfo ) {
|
||||
m_currentResult = resultInfo;
|
||||
return actOnCurrentResult();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual void acceptMessage
|
||||
(
|
||||
const std::string& msg
|
||||
)
|
||||
{
|
||||
virtual void acceptMessage( const std::string& msg ) {
|
||||
m_currentResult.setMessage( msg );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual void testEnded
|
||||
(
|
||||
const ResultInfo& result
|
||||
)
|
||||
{
|
||||
if( result.getResultType() == ResultWas::Ok )
|
||||
{
|
||||
virtual void testEnded( const ResultInfo& result ) {
|
||||
if( result.getResultType() == ResultWas::Ok ) {
|
||||
m_totals.assertions.passed++;
|
||||
}
|
||||
else if( !result.ok() )
|
||||
{
|
||||
else if( !result.ok() ) {
|
||||
m_totals.assertions.failed++;
|
||||
|
||||
std::vector<ResultInfo>::const_iterator it = m_info.begin();
|
||||
@ -237,9 +171,7 @@ namespace Catch
|
||||
m_reporter->Result( result );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual bool sectionStarted
|
||||
(
|
||||
virtual bool sectionStarted (
|
||||
const std::string& name,
|
||||
const std::string& description,
|
||||
const SourceLineInfo& lineInfo,
|
||||
@ -259,68 +191,37 @@ namespace Catch
|
||||
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_reporter->EndSection( name, m_totals.assertions - prevAssertions );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual void pushScopedInfo
|
||||
(
|
||||
ScopedInfo* scopedInfo
|
||||
)
|
||||
{
|
||||
virtual void pushScopedInfo( ScopedInfo* scopedInfo ) {
|
||||
m_scopedInfos.push_back( scopedInfo );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual void popScopedInfo
|
||||
(
|
||||
ScopedInfo* scopedInfo
|
||||
)
|
||||
{
|
||||
virtual void popScopedInfo( ScopedInfo* scopedInfo ) {
|
||||
if( m_scopedInfos.back() == scopedInfo )
|
||||
m_scopedInfos.pop_back();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual bool shouldDebugBreak
|
||||
()
|
||||
const
|
||||
{
|
||||
virtual bool shouldDebugBreak() const {
|
||||
return m_config.shouldDebugBreak();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual std::string getCurrentTestName
|
||||
()
|
||||
const
|
||||
{
|
||||
virtual std::string getCurrentTestName() const {
|
||||
return m_runningTest
|
||||
? m_runningTest->getTestCaseInfo().getName()
|
||||
: "";
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual const ResultInfo* getLastResult
|
||||
()
|
||||
const
|
||||
{
|
||||
virtual const ResultInfo* getLastResult() const {
|
||||
return &m_lastResult;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
ResultAction::Value actOnCurrentResult
|
||||
()
|
||||
{
|
||||
ResultAction::Value actOnCurrentResult() {
|
||||
testEnded( m_currentResult );
|
||||
m_lastResult = m_currentResult;
|
||||
|
||||
@ -333,34 +234,23 @@ namespace Catch
|
||||
return ResultAction::Failed;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
void runCurrentTest
|
||||
(
|
||||
std::string& redirectedCout,
|
||||
std::string& redirectedCerr
|
||||
)
|
||||
{
|
||||
try
|
||||
{
|
||||
void runCurrentTest( std::string& redirectedCout, std::string& redirectedCerr ) {
|
||||
try {
|
||||
m_runningTest->reset();
|
||||
if( m_reporter->shouldRedirectStdout() )
|
||||
{
|
||||
if( m_reporter->shouldRedirectStdout() ) {
|
||||
StreamRedirect coutRedir( std::cout, redirectedCout );
|
||||
StreamRedirect cerrRedir( std::cerr, redirectedCerr );
|
||||
m_runningTest->getTestCaseInfo().invoke();
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
m_runningTest->getTestCaseInfo().invoke();
|
||||
}
|
||||
m_runningTest->ranToCompletion();
|
||||
}
|
||||
catch( TestFailureException& )
|
||||
{
|
||||
catch( TestFailureException& ) {
|
||||
// This just means the test was aborted due to failure
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
catch(...) {
|
||||
acceptMessage( Catch::Context::getExceptionTranslatorRegistry().translateActiveException() );
|
||||
acceptResult( ResultWas::ThrewException );
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Catch{
|
||||
namespace Catch {
|
||||
|
||||
class Section {
|
||||
public:
|
||||
|
@ -14,8 +14,8 @@
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
namespace Catch
|
||||
{
|
||||
namespace Catch {
|
||||
|
||||
class TestRegistry : public ITestCaseRegistry {
|
||||
public:
|
||||
TestRegistry() : m_unnamedCount( 0 ) {}
|
||||
|
@ -11,12 +11,11 @@
|
||||
#include "catch_common.h"
|
||||
#include "catch_interfaces_testcase.h"
|
||||
|
||||
namespace Catch
|
||||
{
|
||||
namespace Catch {
|
||||
|
||||
template<typename C>
|
||||
class MethodTestCase : public ITestCase
|
||||
{
|
||||
class MethodTestCase : public ITestCase {
|
||||
|
||||
public:
|
||||
MethodTestCase( void (C::*method)() ) : m_method( method ) {}
|
||||
|
||||
@ -45,8 +44,8 @@ private:
|
||||
|
||||
typedef void(*TestFunction)();
|
||||
|
||||
struct AutoReg
|
||||
{
|
||||
struct AutoReg {
|
||||
|
||||
AutoReg( TestFunction function,
|
||||
const char* name,
|
||||
const char* description,
|
||||
|
Loading…
Reference in New Issue
Block a user