mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 07:16:10 +01:00
Refactored more into Hub
This commit is contained in:
parent
fd58d48665
commit
263c046b84
@ -44,6 +44,9 @@
|
|||||||
4AA7EA9112A438C7005A0B97 /* MiscTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MiscTests.cpp; sourceTree = "<group>"; };
|
4AA7EA9112A438C7005A0B97 /* MiscTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MiscTests.cpp; sourceTree = "<group>"; };
|
||||||
4AD6775912D71DA0005AAF59 /* catch_test_case_registry_impl.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_test_case_registry_impl.hpp; path = ../internal/catch_test_case_registry_impl.hpp; sourceTree = SOURCE_ROOT; };
|
4AD6775912D71DA0005AAF59 /* catch_test_case_registry_impl.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_test_case_registry_impl.hpp; path = ../internal/catch_test_case_registry_impl.hpp; sourceTree = SOURCE_ROOT; };
|
||||||
4AD677B212D7A53E005AAF59 /* catch_interfaces_testcase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = catch_interfaces_testcase.h; path = ../internal/catch_interfaces_testcase.h; sourceTree = SOURCE_ROOT; };
|
4AD677B212D7A53E005AAF59 /* catch_interfaces_testcase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = catch_interfaces_testcase.h; path = ../internal/catch_interfaces_testcase.h; sourceTree = SOURCE_ROOT; };
|
||||||
|
4AD6781D12D7A88E005AAF59 /* catch_interfaces_capture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = catch_interfaces_capture.h; path = ../internal/catch_interfaces_capture.h; sourceTree = SOURCE_ROOT; };
|
||||||
|
4AD6781F12D7A952005AAF59 /* catch_result_type.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = catch_result_type.h; path = ../internal/catch_result_type.h; sourceTree = SOURCE_ROOT; };
|
||||||
|
4AD6783212D7ABB3005AAF59 /* catch_interfaces_runner.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = catch_interfaces_runner.h; path = ../internal/catch_interfaces_runner.h; sourceTree = SOURCE_ROOT; };
|
||||||
4AFC341512809A36003A0C29 /* catch_capture.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_capture.hpp; path = ../internal/catch_capture.hpp; sourceTree = SOURCE_ROOT; };
|
4AFC341512809A36003A0C29 /* catch_capture.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_capture.hpp; path = ../internal/catch_capture.hpp; sourceTree = SOURCE_ROOT; };
|
||||||
4AFC341612809A36003A0C29 /* catch_common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = catch_common.h; path = ../internal/catch_common.h; sourceTree = SOURCE_ROOT; };
|
4AFC341612809A36003A0C29 /* catch_common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = catch_common.h; path = ../internal/catch_common.h; sourceTree = SOURCE_ROOT; };
|
||||||
4AFC341712809A36003A0C29 /* catch_test_registry.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_test_registry.hpp; path = ../internal/catch_test_registry.hpp; sourceTree = SOURCE_ROOT; };
|
4AFC341712809A36003A0C29 /* catch_test_registry.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_test_registry.hpp; path = ../internal/catch_test_registry.hpp; sourceTree = SOURCE_ROOT; };
|
||||||
@ -114,6 +117,8 @@
|
|||||||
4AFC341712809A36003A0C29 /* catch_test_registry.hpp */,
|
4AFC341712809A36003A0C29 /* catch_test_registry.hpp */,
|
||||||
4AFC341B12809A36003A0C29 /* catch_test_case_info.hpp */,
|
4AFC341B12809A36003A0C29 /* catch_test_case_info.hpp */,
|
||||||
4AD677B212D7A53E005AAF59 /* catch_interfaces_testcase.h */,
|
4AD677B212D7A53E005AAF59 /* catch_interfaces_testcase.h */,
|
||||||
|
4AD6781D12D7A88E005AAF59 /* catch_interfaces_capture.h */,
|
||||||
|
4AD6781F12D7A952005AAF59 /* catch_result_type.h */,
|
||||||
);
|
);
|
||||||
name = "TestCase registration";
|
name = "TestCase registration";
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@ -124,6 +129,7 @@
|
|||||||
4A3BFFF0128DD23C005609E3 /* catch_config.hpp */,
|
4A3BFFF0128DD23C005609E3 /* catch_config.hpp */,
|
||||||
4AFC341912809A36003A0C29 /* catch_resultinfo.hpp */,
|
4AFC341912809A36003A0C29 /* catch_resultinfo.hpp */,
|
||||||
4AFC341A12809A36003A0C29 /* catch_runner_impl.hpp */,
|
4AFC341A12809A36003A0C29 /* catch_runner_impl.hpp */,
|
||||||
|
4AD6783212D7ABB3005AAF59 /* catch_interfaces_runner.h */,
|
||||||
);
|
);
|
||||||
name = "Running & Results";
|
name = "Running & Results";
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
#define TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED
|
#define TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED
|
||||||
|
|
||||||
#include "catch_resultinfo.hpp"
|
#include "catch_resultinfo.hpp"
|
||||||
|
#include "catch_result_type.h"
|
||||||
|
#include "catch_interfaces_capture.h"
|
||||||
#include "catch_debugger.hpp"
|
#include "catch_debugger.hpp"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
@ -190,79 +192,17 @@ private:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ResultAction
|
|
||||||
{
|
|
||||||
enum Value
|
|
||||||
{
|
|
||||||
None,
|
|
||||||
Failed = 1, // Failure - but no debug break if Debug bit not set
|
|
||||||
DebugFailed = 3 // Indicates that the debugger should break, if possible
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
class TestCaseInfo;
|
|
||||||
class ScopedInfo;
|
|
||||||
|
|
||||||
struct IResultListener
|
|
||||||
{
|
|
||||||
virtual ~IResultListener(){}
|
|
||||||
virtual void testEnded( const ResultInfo& result ) = 0;
|
|
||||||
virtual bool sectionStarted( const std::string& name, const std::string& description, std::size_t& successes, std::size_t& failures ) = 0;
|
|
||||||
virtual void sectionEnded( const std::string& name, std::size_t successes, std::size_t failures ) = 0;
|
|
||||||
virtual void pushScopedInfo( ScopedInfo* scopedInfo ) = 0;
|
|
||||||
virtual void popScopedInfo( ScopedInfo* scopedInfo ) = 0;
|
|
||||||
virtual bool shouldDebugBreak() const = 0;
|
|
||||||
|
|
||||||
virtual ResultAction::Value acceptResult( bool result ) = 0;
|
|
||||||
virtual ResultAction::Value acceptResult( ResultWas::OfType result ) = 0;
|
|
||||||
virtual void acceptExpression( const MutableResultInfo& resultInfo ) = 0;
|
|
||||||
virtual void acceptMessage( const std::string& msg ) = 0;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class ResultsCapture
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
ResultsCapture()
|
|
||||||
: m_listener( 0 )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static ResultsCapture& instance()
|
|
||||||
{
|
|
||||||
static ResultsCapture instance;
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
static IResultListener* setListener( IResultListener* listener )
|
|
||||||
{
|
|
||||||
IResultListener* prevListener = instance().m_listener;
|
|
||||||
instance().m_listener = listener;
|
|
||||||
return prevListener;
|
|
||||||
}
|
|
||||||
static IResultListener& getListener()
|
|
||||||
{
|
|
||||||
return *instance().m_listener;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
IResultListener* m_listener;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class ScopedInfo
|
class ScopedInfo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ScopedInfo()
|
ScopedInfo()
|
||||||
{
|
{
|
||||||
ResultsCapture::getListener().pushScopedInfo( this );
|
Hub::getResultCapture().pushScopedInfo( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
~ScopedInfo()
|
~ScopedInfo()
|
||||||
{
|
{
|
||||||
ResultsCapture::getListener().popScopedInfo( this );
|
Hub::getResultCapture().popScopedInfo( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopedInfo& operator << ( const char* str )
|
ScopedInfo& operator << ( const char* str )
|
||||||
@ -333,7 +273,7 @@ inline bool isTrue( bool value )
|
|||||||
} // end namespace Catch
|
} // end namespace Catch
|
||||||
|
|
||||||
#define INTERNAL_CATCH_ACCEPT_RESULT( result, stopOnFailure ) \
|
#define INTERNAL_CATCH_ACCEPT_RESULT( result, stopOnFailure ) \
|
||||||
if( Catch::ResultAction::Value action = Catch::ResultsCapture::getListener().acceptResult( result ) ) \
|
if( Catch::ResultAction::Value action = Catch::Hub::getResultCapture().acceptResult( result ) ) \
|
||||||
{ \
|
{ \
|
||||||
if( action == Catch::ResultAction::DebugFailed ) DebugBreak(); \
|
if( action == Catch::ResultAction::DebugFailed ) DebugBreak(); \
|
||||||
if( Catch::isTrue( stopOnFailure ) ) throw Catch::TestFailureException(); \
|
if( Catch::isTrue( stopOnFailure ) ) throw Catch::TestFailureException(); \
|
||||||
@ -341,12 +281,12 @@ inline bool isTrue( bool value )
|
|||||||
|
|
||||||
#define INTERNAL_CATCH_TEST( expr, isNot, stopOnFailure, macroName ) \
|
#define INTERNAL_CATCH_TEST( expr, isNot, stopOnFailure, macroName ) \
|
||||||
{ \
|
{ \
|
||||||
Catch::ResultsCapture::getListener().acceptExpression( Catch::ResultBuilder( #expr, isNot, __FILE__, __LINE__, macroName )->*expr ); \
|
Catch::Hub::getResultCapture().acceptExpression( Catch::ResultBuilder( #expr, isNot, __FILE__, __LINE__, macroName )->*expr ); \
|
||||||
INTERNAL_CATCH_ACCEPT_RESULT( expr, stopOnFailure ) \
|
INTERNAL_CATCH_ACCEPT_RESULT( expr, stopOnFailure ) \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define INTERNAL_CATCH_THROWS( expr, exceptionType, nothrow, stopOnFailure, macroName ) \
|
#define INTERNAL_CATCH_THROWS( expr, exceptionType, nothrow, stopOnFailure, macroName ) \
|
||||||
Catch::ResultsCapture::getListener().acceptExpression( Catch::ResultBuilder( #expr, false, __FILE__, __LINE__, macroName ) ); \
|
Catch::Hub::getResultCapture().acceptExpression( Catch::ResultBuilder( #expr, false, __FILE__, __LINE__, macroName ) ); \
|
||||||
try \
|
try \
|
||||||
{ \
|
{ \
|
||||||
expr; \
|
expr; \
|
||||||
@ -368,8 +308,8 @@ catch( ... ) \
|
|||||||
{ \
|
{ \
|
||||||
std::ostringstream INTERNAL_CATCH_UNIQUE_NAME( strm ); \
|
std::ostringstream INTERNAL_CATCH_UNIQUE_NAME( strm ); \
|
||||||
INTERNAL_CATCH_UNIQUE_NAME( strm ) << reason; \
|
INTERNAL_CATCH_UNIQUE_NAME( strm ) << reason; \
|
||||||
Catch::ResultsCapture::getListener().acceptExpression( Catch::MutableResultInfo( "", false, __FILE__, __LINE__, macroName ) ); \
|
Catch::Hub::getResultCapture().acceptExpression( Catch::MutableResultInfo( "", false, __FILE__, __LINE__, macroName ) ); \
|
||||||
Catch::ResultsCapture::getListener().acceptMessage( INTERNAL_CATCH_UNIQUE_NAME( strm ).str() ); \
|
Catch::Hub::getResultCapture().acceptMessage( INTERNAL_CATCH_UNIQUE_NAME( strm ).str() ); \
|
||||||
INTERNAL_CATCH_ACCEPT_RESULT( resultType, stopOnFailure ) \
|
INTERNAL_CATCH_ACCEPT_RESULT( resultType, stopOnFailure ) \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* catch_hub.h
|
* catch_hub.h
|
||||||
* Test
|
* Catch
|
||||||
*
|
*
|
||||||
* 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.
|
||||||
@ -20,18 +20,9 @@
|
|||||||
namespace Catch
|
namespace Catch
|
||||||
{
|
{
|
||||||
struct TestCaseInfo;
|
struct TestCaseInfo;
|
||||||
struct IResultListener;
|
struct IResultCapture;
|
||||||
struct ITestCaseRegistry
|
struct ITestCaseRegistry;
|
||||||
{
|
struct IRunner;
|
||||||
public:
|
|
||||||
|
|
||||||
virtual void registerTest
|
|
||||||
( const TestCaseInfo& testInfo
|
|
||||||
) = 0;
|
|
||||||
|
|
||||||
virtual const std::vector<TestCaseInfo>& getAllTests
|
|
||||||
() const = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Hub
|
class Hub
|
||||||
{
|
{
|
||||||
@ -40,13 +31,19 @@ namespace Catch
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static IResultListener& getListener();
|
static void setRunner( IRunner* runner );
|
||||||
|
static void setResultCapture( IResultCapture* resultCapture );
|
||||||
|
|
||||||
|
static IResultCapture& getResultCapture();
|
||||||
static IReporterRegistry& getReporterRegistry();
|
static IReporterRegistry& getReporterRegistry();
|
||||||
static ITestCaseRegistry& getTestCaseRegistry();
|
static ITestCaseRegistry& getTestCaseRegistry();
|
||||||
|
static IRunner& getRunner();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::auto_ptr<IReporterRegistry> m_reporterRegistry;
|
std::auto_ptr<IReporterRegistry> m_reporterRegistry;
|
||||||
std::auto_ptr<ITestCaseRegistry> m_testCaseRegistry;
|
std::auto_ptr<ITestCaseRegistry> m_testCaseRegistry;
|
||||||
|
IRunner* m_runner;
|
||||||
|
IResultCapture* m_resultCapture;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* catch_hub_impl.hpp
|
* catch_hub_impl.hpp
|
||||||
* Test
|
* Catch
|
||||||
*
|
*
|
||||||
* 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.
|
||||||
@ -12,6 +12,7 @@
|
|||||||
#include "catch_hub.h"
|
#include "catch_hub.h"
|
||||||
#include "catch_reporter_registry.hpp"
|
#include "catch_reporter_registry.hpp"
|
||||||
#include "catch_test_case_registry_impl.hpp"
|
#include "catch_test_case_registry_impl.hpp"
|
||||||
|
#include "catch_runner_impl.hpp"
|
||||||
|
|
||||||
namespace Catch
|
namespace Catch
|
||||||
{
|
{
|
||||||
@ -22,7 +23,7 @@ namespace Catch
|
|||||||
m_testCaseRegistry( new TestRegistry )
|
m_testCaseRegistry( new TestRegistry )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
Hub& Hub::me
|
Hub& Hub::me
|
||||||
()
|
()
|
||||||
@ -31,6 +32,31 @@ namespace Catch
|
|||||||
return hub;
|
return hub;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
void Hub::setRunner( IRunner* runner )
|
||||||
|
{
|
||||||
|
me().m_runner = runner;
|
||||||
|
}
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
void Hub::setResultCapture( IResultCapture* resultCapture )
|
||||||
|
{
|
||||||
|
me().m_resultCapture = resultCapture;
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
IResultCapture& Hub::getResultCapture
|
||||||
|
()
|
||||||
|
{
|
||||||
|
return *me().m_resultCapture;
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
IRunner& Hub::getRunner
|
||||||
|
()
|
||||||
|
{
|
||||||
|
return *me().m_runner;
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
IReporterRegistry& Hub::getReporterRegistry
|
IReporterRegistry& Hub::getReporterRegistry
|
||||||
()
|
()
|
||||||
|
41
internal/catch_interfaces_capture.h
Normal file
41
internal/catch_interfaces_capture.h
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* catch_interfaces_capture.h
|
||||||
|
* Catch
|
||||||
|
*
|
||||||
|
* Created by Phil on 07/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_INTERFACES_CAPTURE_H_INCLUDED
|
||||||
|
#define TWOBLUECUBES_CATCH_INTERFACES_CAPTURE_H_INCLUDED
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include "catch_result_type.h"
|
||||||
|
|
||||||
|
namespace Catch
|
||||||
|
{
|
||||||
|
class TestCaseInfo;
|
||||||
|
class ScopedInfo;
|
||||||
|
class MutableResultInfo;
|
||||||
|
|
||||||
|
struct IResultCapture
|
||||||
|
{
|
||||||
|
virtual ~IResultCapture(){}
|
||||||
|
virtual void testEnded( const ResultInfo& result ) = 0;
|
||||||
|
virtual bool sectionStarted( const std::string& name, const std::string& description, std::size_t& successes, std::size_t& failures ) = 0;
|
||||||
|
virtual void sectionEnded( const std::string& name, std::size_t successes, std::size_t failures ) = 0;
|
||||||
|
virtual void pushScopedInfo( ScopedInfo* scopedInfo ) = 0;
|
||||||
|
virtual void popScopedInfo( ScopedInfo* scopedInfo ) = 0;
|
||||||
|
virtual bool shouldDebugBreak() const = 0;
|
||||||
|
|
||||||
|
virtual ResultAction::Value acceptResult( bool result ) = 0;
|
||||||
|
virtual ResultAction::Value acceptResult( ResultWas::OfType result ) = 0;
|
||||||
|
virtual void acceptExpression( const MutableResultInfo& resultInfo ) = 0;
|
||||||
|
virtual void acceptMessage( const std::string& msg ) = 0;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // TWOBLUECUBES_CATCH_INTERFACES_CAPTURE_H_INCLUDED
|
29
internal/catch_interfaces_runner.h
Normal file
29
internal/catch_interfaces_runner.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* catch_interfaces_runner.h
|
||||||
|
* Catch
|
||||||
|
*
|
||||||
|
* Created by Phil on 07/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_INTERNAL_CATCH_INTERFACES_RUNNER_H_INCLUDED
|
||||||
|
#define TWOBLUECUBES_INTERNAL_CATCH_INTERFACES_RUNNER_H_INCLUDED
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace Catch
|
||||||
|
{
|
||||||
|
struct IRunner
|
||||||
|
{
|
||||||
|
virtual void runAll() = 0;
|
||||||
|
virtual std::size_t runMatching( const std::string& rawTestSpec ) = 0;
|
||||||
|
virtual std::size_t getSuccessCount() const = 0;
|
||||||
|
virtual std:: size_t getFailureCount() const = 0;
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // TWOBLUECUBES_INTERNAL_CATCH_INTERFACES_RUNNER_H_INCLUDED
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* catch_interfaces_testcase.h
|
* catch_interfaces_testcase.h
|
||||||
* Test
|
* Catch
|
||||||
*
|
*
|
||||||
* Created by Phil on 07/01/2011.
|
* Created by Phil on 07/01/2011.
|
||||||
* Copyright 2011 Two Blue Cubes Ltd. All rights reserved.
|
* Copyright 2011 Two Blue Cubes Ltd. All rights reserved.
|
||||||
@ -13,6 +13,8 @@
|
|||||||
#ifndef TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED
|
#ifndef TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED
|
||||||
#define TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED
|
#define TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace Catch
|
namespace Catch
|
||||||
{
|
{
|
||||||
struct ITestCase
|
struct ITestCase
|
||||||
@ -35,6 +37,16 @@ namespace Catch
|
|||||||
( const ITestCase& other
|
( const ITestCase& other
|
||||||
) const = 0;
|
) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class TestCaseInfo;
|
||||||
|
|
||||||
|
struct ITestCaseRegistry
|
||||||
|
{
|
||||||
|
virtual void registerTest( const TestCaseInfo& testInfo ) = 0;
|
||||||
|
virtual const std::vector<TestCaseInfo>& getAllTests() const = 0;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED
|
51
internal/catch_result_type.h
Normal file
51
internal/catch_result_type.h
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* catch_result_type.h
|
||||||
|
* Catch
|
||||||
|
*
|
||||||
|
* Created by Phil on 07/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_RESULT_TYPE_H_INCLUDED
|
||||||
|
#define TWOBLUECUBES_CATCH_RESULT_TYPE_H_INCLUDED
|
||||||
|
|
||||||
|
namespace Catch
|
||||||
|
{
|
||||||
|
|
||||||
|
struct ResultWas{ enum OfType
|
||||||
|
{
|
||||||
|
Unknown = -1,
|
||||||
|
Ok = 0,
|
||||||
|
Info = 1,
|
||||||
|
Warning = 2,
|
||||||
|
|
||||||
|
FailureBit = 0x10,
|
||||||
|
|
||||||
|
ExpressionFailed = FailureBit | 1,
|
||||||
|
ExplicitFailure = FailureBit | 2,
|
||||||
|
|
||||||
|
Exception = 0x110,
|
||||||
|
|
||||||
|
ThrewException = Exception | 1,
|
||||||
|
DidntThrowException = Exception | 2
|
||||||
|
|
||||||
|
}; };
|
||||||
|
|
||||||
|
struct ResultAction
|
||||||
|
{
|
||||||
|
enum Value
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
Failed = 1, // Failure - but no debug break if Debug bit not set
|
||||||
|
DebugFailed = 3 // Indicates that the debugger should break, if possible
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // TWOBLUECUBES_CATCH_RESULT_TYPE_H_INCLUDED
|
@ -13,28 +13,10 @@
|
|||||||
#define TWOBLUECUBES_CATCH_RESULT_INFO_HPP_INCLUDED
|
#define TWOBLUECUBES_CATCH_RESULT_INFO_HPP_INCLUDED
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "catch_result_type.h"
|
||||||
|
|
||||||
namespace Catch
|
namespace Catch
|
||||||
{
|
{
|
||||||
struct ResultWas{ enum OfType
|
|
||||||
{
|
|
||||||
Unknown = -1,
|
|
||||||
Ok = 0,
|
|
||||||
Info = 1,
|
|
||||||
Warning = 2,
|
|
||||||
|
|
||||||
FailureBit = 0x10,
|
|
||||||
|
|
||||||
ExpressionFailed = FailureBit | 1,
|
|
||||||
ExplicitFailure = FailureBit | 2,
|
|
||||||
|
|
||||||
Exception = 0x110,
|
|
||||||
|
|
||||||
ThrewException = Exception | 1,
|
|
||||||
DidntThrowException = Exception | 2
|
|
||||||
|
|
||||||
}; };
|
|
||||||
|
|
||||||
class ResultInfo
|
class ResultInfo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#ifndef TWOBLUECUBES_INTERNAL_CATCH_RUNNER_HPP_INCLUDED
|
#ifndef TWOBLUECUBES_INTERNAL_CATCH_RUNNER_HPP_INCLUDED
|
||||||
#define TWOBLUECUBES_INTERNAL_CATCH_RUNNER_HPP_INCLUDED
|
#define TWOBLUECUBES_INTERNAL_CATCH_RUNNER_HPP_INCLUDED
|
||||||
|
|
||||||
|
#include "catch_interfaces_runner.h"
|
||||||
#include "catch_interfaces_reporter.h"
|
#include "catch_interfaces_reporter.h"
|
||||||
#include "catch_config.hpp"
|
#include "catch_config.hpp"
|
||||||
#include "catch_test_registry.hpp"
|
#include "catch_test_registry.hpp"
|
||||||
@ -70,7 +71,7 @@ namespace Catch
|
|||||||
std::string& m_targetString;
|
std::string& m_targetString;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Runner : public IResultListener
|
class Runner : public IResultCapture, public IRunner
|
||||||
{
|
{
|
||||||
Runner( const Runner& );
|
Runner( const Runner& );
|
||||||
void operator =( const Runner& );
|
void operator =( const Runner& );
|
||||||
@ -82,15 +83,19 @@ namespace Catch
|
|||||||
m_failures( 0 ),
|
m_failures( 0 ),
|
||||||
m_reporter( m_config.getReporter() )
|
m_reporter( m_config.getReporter() )
|
||||||
{
|
{
|
||||||
|
Hub::setRunner( this );
|
||||||
|
Hub::setResultCapture( this );
|
||||||
m_reporter->StartTesting();
|
m_reporter->StartTesting();
|
||||||
}
|
}
|
||||||
|
|
||||||
~Runner()
|
~Runner()
|
||||||
{
|
{
|
||||||
m_reporter->EndTesting( m_successes, m_failures );
|
m_reporter->EndTesting( m_successes, m_failures );
|
||||||
|
Hub::setRunner( NULL );
|
||||||
|
Hub::setResultCapture( NULL );
|
||||||
}
|
}
|
||||||
|
|
||||||
void runAll()
|
virtual void runAll()
|
||||||
{
|
{
|
||||||
std::vector<TestCaseInfo> allTests = Hub::getTestCaseRegistry().getAllTests();
|
std::vector<TestCaseInfo> allTests = Hub::getTestCaseRegistry().getAllTests();
|
||||||
for( std::size_t i=0; i < allTests.size(); ++i )
|
for( std::size_t i=0; i < allTests.size(); ++i )
|
||||||
@ -99,7 +104,7 @@ namespace Catch
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t runMatching( const std::string& rawTestSpec )
|
virtual std::size_t runMatching( const std::string& rawTestSpec )
|
||||||
{
|
{
|
||||||
TestSpec testSpec( rawTestSpec );
|
TestSpec testSpec( rawTestSpec );
|
||||||
|
|
||||||
@ -118,7 +123,6 @@ namespace Catch
|
|||||||
|
|
||||||
void runTest( const TestCaseInfo& testInfo )
|
void runTest( const TestCaseInfo& testInfo )
|
||||||
{
|
{
|
||||||
IResultListener* prevListener = ResultsCapture::setListener( this );
|
|
||||||
m_reporter->StartTestCase( testInfo );
|
m_reporter->StartTestCase( testInfo );
|
||||||
|
|
||||||
std::string redirectedCout;
|
std::string redirectedCout;
|
||||||
@ -146,19 +150,19 @@ namespace Catch
|
|||||||
}
|
}
|
||||||
m_info.clear();
|
m_info.clear();
|
||||||
m_reporter->EndTestCase( testInfo, redirectedCout, redirectedCerr );
|
m_reporter->EndTestCase( testInfo, redirectedCout, redirectedCerr );
|
||||||
ResultsCapture::setListener( prevListener );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t getSuccessCount() const
|
virtual std::size_t getSuccessCount() const
|
||||||
{
|
{
|
||||||
return m_successes;
|
return m_successes;
|
||||||
}
|
}
|
||||||
std:: size_t getFailureCount() const
|
|
||||||
|
virtual std:: size_t getFailureCount() const
|
||||||
{
|
{
|
||||||
return m_failures;
|
return m_failures;
|
||||||
}
|
}
|
||||||
|
|
||||||
private: // IResultListener
|
private: // IResultCapture
|
||||||
|
|
||||||
virtual ResultAction::Value acceptResult( bool result )
|
virtual ResultAction::Value acceptResult( bool result )
|
||||||
{
|
{
|
||||||
|
@ -24,13 +24,13 @@ namespace Catch
|
|||||||
public:
|
public:
|
||||||
Section( const std::string& name, const std::string& description )
|
Section( const std::string& name, const std::string& description )
|
||||||
: m_name( name ),
|
: m_name( name ),
|
||||||
m_sectionIncluded( ResultsCapture::getListener().sectionStarted( name, description, m_successes, m_failures ) )
|
m_sectionIncluded( Hub::getResultCapture().sectionStarted( name, description, m_successes, m_failures ) )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
~Section()
|
~Section()
|
||||||
{
|
{
|
||||||
ResultsCapture::getListener().sectionEnded( m_name, m_successes, m_failures );
|
Hub::getResultCapture().sectionEnded( m_name, m_successes, m_failures );
|
||||||
}
|
}
|
||||||
|
|
||||||
// This indicates whether the section should be executed or not
|
// This indicates whether the section should be executed or not
|
||||||
|
@ -98,10 +98,10 @@ namespace Catch
|
|||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
void AutoReg::registerTestCase
|
void AutoReg::registerTestCase
|
||||||
(
|
(
|
||||||
ITestCase* testCase,
|
ITestCase* testCase,
|
||||||
const char* name,
|
const char* name,
|
||||||
const char* description
|
const char* description
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
Hub::getTestCaseRegistry().registerTest( TestCaseInfo( testCase, name, description ) );
|
Hub::getTestCaseRegistry().registerTest( TestCaseInfo( testCase, name, description ) );
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user