mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-17 11:12:25 +01:00
Funnel most calls to getCurrentRunContext() through C_A_T_C_H_Context()
This commit is contained in:
parent
f4ba8aaf19
commit
ebb4677089
@ -15,9 +15,6 @@
|
||||
#include "catch_tostring.h"
|
||||
#include "catch_compiler_capabilities.h"
|
||||
|
||||
namespace Catch {
|
||||
AssertionResult const* getLastResult();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// In the event of a failure works out if the debugger needs to be invoked
|
||||
@ -32,7 +29,7 @@ namespace Catch {
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define INTERNAL_CATCH_TEST( expr, resultDisposition, macroName ) \
|
||||
do { \
|
||||
Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition ); \
|
||||
Catch::ResultBuilder __catchResult( C_A_T_C_H_Context(), macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition ); \
|
||||
try { \
|
||||
( __catchResult <= expr ).endExpression(); \
|
||||
} \
|
||||
@ -45,17 +42,17 @@ namespace Catch {
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define INTERNAL_CATCH_IF( expr, resultDisposition, macroName ) \
|
||||
INTERNAL_CATCH_TEST( expr, resultDisposition, macroName ); \
|
||||
if( Catch::getLastResult()->succeeded() )
|
||||
if( C_A_T_C_H_Context().getLastResult()->succeeded() )
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define INTERNAL_CATCH_ELSE( expr, resultDisposition, macroName ) \
|
||||
INTERNAL_CATCH_TEST( expr, resultDisposition, macroName ); \
|
||||
if( !Catch::getLastResult()->succeeded() )
|
||||
if( !C_A_T_C_H_Context().getLastResult()->succeeded() )
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define INTERNAL_CATCH_NO_THROW( expr, resultDisposition, macroName ) \
|
||||
do { \
|
||||
Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition ); \
|
||||
Catch::ResultBuilder __catchResult( C_A_T_C_H_Context(), macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition ); \
|
||||
try { \
|
||||
expr; \
|
||||
__catchResult.captureResult( Catch::ResultWas::Ok ); \
|
||||
@ -69,7 +66,7 @@ namespace Catch {
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define INTERNAL_CATCH_THROWS( expr, resultDisposition, matcher, macroName ) \
|
||||
do { \
|
||||
Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition, #matcher ); \
|
||||
Catch::ResultBuilder __catchResult( C_A_T_C_H_Context(), macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition, #matcher ); \
|
||||
if( __catchResult.allowThrows() ) \
|
||||
try { \
|
||||
expr; \
|
||||
@ -86,7 +83,7 @@ namespace Catch {
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define INTERNAL_CATCH_THROWS_AS( expr, exceptionType, resultDisposition, macroName ) \
|
||||
do { \
|
||||
Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition ); \
|
||||
Catch::ResultBuilder __catchResult( C_A_T_C_H_Context(), macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition ); \
|
||||
if( __catchResult.allowThrows() ) \
|
||||
try { \
|
||||
expr; \
|
||||
@ -108,7 +105,7 @@ namespace Catch {
|
||||
#ifdef CATCH_CONFIG_VARIADIC_MACROS
|
||||
#define INTERNAL_CATCH_MSG( messageType, resultDisposition, macroName, ... ) \
|
||||
do { \
|
||||
Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \
|
||||
Catch::ResultBuilder __catchResult( C_A_T_C_H_Context(), macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \
|
||||
__catchResult << __VA_ARGS__ + ::Catch::StreamEndStop(); \
|
||||
__catchResult.captureResult( messageType ); \
|
||||
INTERNAL_CATCH_REACT( __catchResult ) \
|
||||
@ -116,7 +113,7 @@ namespace Catch {
|
||||
#else
|
||||
#define INTERNAL_CATCH_MSG( messageType, resultDisposition, macroName, log ) \
|
||||
do { \
|
||||
Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \
|
||||
Catch::ResultBuilder __catchResult( C_A_T_C_H_Context(), macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \
|
||||
__catchResult << log + ::Catch::StreamEndStop(); \
|
||||
__catchResult.captureResult( messageType ); \
|
||||
INTERNAL_CATCH_REACT( __catchResult ) \
|
||||
@ -125,12 +122,12 @@ namespace Catch {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define INTERNAL_CATCH_INFO( log, macroName ) \
|
||||
Catch::ScopedMessage INTERNAL_CATCH_UNIQUE_NAME( scopedMessage ) = Catch::MessageBuilder( macroName, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log;
|
||||
Catch::ScopedMessage INTERNAL_CATCH_UNIQUE_NAME( scopedMessage ) = Catch::MessageBuilder( C_A_T_C_H_Context(), macroName, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define INTERNAL_CHECK_THAT( arg, matcher, resultDisposition, macroName ) \
|
||||
do { \
|
||||
Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #arg ", " #matcher, resultDisposition ); \
|
||||
Catch::ResultBuilder __catchResult( C_A_T_C_H_Context(), macroName, CATCH_INTERNAL_LINEINFO, #arg ", " #matcher, resultDisposition ); \
|
||||
try { \
|
||||
std::string matcherAsString = (matcher).toString(); \
|
||||
__catchResult \
|
||||
|
@ -150,7 +150,7 @@ namespace Catch {
|
||||
}
|
||||
ConfigData m_data;
|
||||
|
||||
std::auto_ptr<IStream const> m_stream;
|
||||
CATCH_AUTO_PTR( IStream const ) m_stream;
|
||||
TestSpec m_testSpec;
|
||||
};
|
||||
|
||||
|
@ -16,7 +16,6 @@ namespace Catch {
|
||||
|
||||
class TestCase;
|
||||
class AssertionResult;
|
||||
class ScopedMessageBuilder;
|
||||
|
||||
struct AssertionInfo;
|
||||
struct SectionInfo;
|
||||
@ -48,10 +47,21 @@ namespace Catch {
|
||||
virtual IConfig const& config() const = 0;
|
||||
};
|
||||
|
||||
IRunContext* tryGetCurrentRunContext();
|
||||
IRunContext& getCurrentRunContext();
|
||||
|
||||
IConfig const* getCurrentConfig();
|
||||
|
||||
class LocalContext {
|
||||
|
||||
public:
|
||||
IRunContext& operator()() const {
|
||||
return getCurrentRunContext(); // !TBD
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
inline Catch::IRunContext& C_A_T_C_H_Context() {
|
||||
return Catch::getCurrentRunContext();
|
||||
}
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_INTERFACES_CAPTURE_H_INCLUDED
|
||||
|
@ -91,12 +91,9 @@ namespace Catch
|
||||
{
|
||||
if( assertionResult.hasMessage() ) {
|
||||
// Copy message into messages list.
|
||||
// !TBD This should have been done earlier, somewhere
|
||||
MessageBuilder builder( assertionResult.getTestMacroName(), assertionResult.getSourceInfo(), assertionResult.getResultType() );
|
||||
builder << assertionResult.getMessage();
|
||||
builder.m_info.message = builder.m_stream.str();
|
||||
|
||||
infoMessages.push_back( builder.m_info );
|
||||
MessageInfo info( assertionResult.getTestMacroName(), assertionResult.getSourceInfo(), assertionResult.getResultType() );
|
||||
info.message = assertionResult.getMessage();
|
||||
infoMessages.push_back( info );
|
||||
}
|
||||
}
|
||||
virtual ~AssertionStats();
|
||||
|
@ -46,7 +46,7 @@ namespace Catch
|
||||
it != itEnd;
|
||||
++it ) {
|
||||
if( it->type == ResultWas::Info ) {
|
||||
ResultBuilder rb( it->macroName.c_str(), it->lineInfo, "", ResultDisposition::Normal );
|
||||
ResultBuilder rb( getCurrentRunContext(), it->macroName.c_str(), it->lineInfo, "", ResultDisposition::Normal );
|
||||
rb << it->message;
|
||||
rb.setResultType( ResultWas::Info );
|
||||
AssertionResult result = rb.build();
|
||||
|
@ -38,10 +38,12 @@ namespace Catch {
|
||||
};
|
||||
|
||||
struct MessageBuilder {
|
||||
MessageBuilder( std::string const& macroName,
|
||||
MessageBuilder( IRunContext& runContext,
|
||||
std::string const& macroName,
|
||||
SourceLineInfo const& lineInfo,
|
||||
ResultWas::OfType type )
|
||||
: m_info( macroName, lineInfo, type )
|
||||
: m_runContext( runContext ),
|
||||
m_info( macroName, lineInfo, type )
|
||||
{}
|
||||
|
||||
template<typename T>
|
||||
@ -50,6 +52,7 @@ namespace Catch {
|
||||
return *this;
|
||||
}
|
||||
|
||||
IRunContext& m_runContext;
|
||||
MessageInfo m_info;
|
||||
std::ostringstream m_stream;
|
||||
};
|
||||
|
@ -29,7 +29,7 @@ namespace Catch {
|
||||
|
||||
ScopedMessage::ScopedMessage( MessageBuilder const& builder )
|
||||
: m_info( builder.m_info ),
|
||||
m_runContext( getCurrentRunContext() )
|
||||
m_runContext( builder.m_runContext )
|
||||
{
|
||||
m_info.message = builder.m_stream.str();
|
||||
m_runContext.pushScopedMessage( m_info );
|
||||
|
@ -37,7 +37,9 @@ namespace Catch {
|
||||
|
||||
class ResultBuilder {
|
||||
public:
|
||||
ResultBuilder( char const* macroName,
|
||||
ResultBuilder
|
||||
( IRunContext& runContext,
|
||||
char const* macroName,
|
||||
SourceLineInfo const& lineInfo,
|
||||
char const* capturedExpression,
|
||||
ResultDisposition::Flags resultDisposition,
|
||||
|
@ -21,12 +21,14 @@ namespace Catch {
|
||||
? capturedExpression
|
||||
: capturedExpression + ", " + secondArg;
|
||||
}
|
||||
ResultBuilder::ResultBuilder( char const* macroName,
|
||||
ResultBuilder::ResultBuilder
|
||||
( IRunContext& runContext,
|
||||
char const* macroName,
|
||||
SourceLineInfo const& lineInfo,
|
||||
char const* capturedExpression,
|
||||
ResultDisposition::Flags resultDisposition,
|
||||
char const* secondArg )
|
||||
: m_runContext( getCurrentRunContext() ),
|
||||
: m_runContext( runContext ),
|
||||
m_assertionInfo( macroName, lineInfo, capturedExpressionWithSecondArgument( capturedExpression, secondArg ), resultDisposition ),
|
||||
m_shouldDebugBreak( false ),
|
||||
m_shouldThrow( false )
|
||||
|
@ -75,9 +75,6 @@ namespace Catch {
|
||||
else
|
||||
return CATCH_NULL;
|
||||
}
|
||||
AssertionResult const* getLastResult() {
|
||||
return getCurrentRunContext().getLastResult();
|
||||
}
|
||||
|
||||
class RunContext : public IRunContext {
|
||||
|
||||
@ -243,7 +240,8 @@ namespace Catch {
|
||||
|
||||
// Recreate section for test case (as we will lose the one that was in scope)
|
||||
SectionInfo testCaseSection
|
||||
( m_activeTestCaseInfo->lineInfo,
|
||||
( C_A_T_C_H_Context(),
|
||||
m_activeTestCaseInfo->lineInfo,
|
||||
m_activeTestCaseInfo->name,
|
||||
m_activeTestCaseInfo->description );
|
||||
|
||||
@ -273,7 +271,7 @@ namespace Catch {
|
||||
private:
|
||||
|
||||
void runTest( TestCase const& testCase, std::string& redirectedCout, std::string& redirectedCerr ) {
|
||||
SectionInfo testCaseSection( testCase.lineInfo, testCase.name, testCase.description );
|
||||
SectionInfo testCaseSection( *this, testCase.lineInfo, testCase.name, testCase.description );
|
||||
m_reporter->sectionStarting( testCaseSection );
|
||||
Counts prevAssertions = m_totals.assertions;
|
||||
double duration = 0;
|
||||
@ -325,8 +323,10 @@ namespace Catch {
|
||||
|
||||
private:
|
||||
|
||||
ResultBuilder makeUnexpectedResultBuilder() const {
|
||||
return ResultBuilder( m_lastAssertionInfo.macroName.c_str(),
|
||||
ResultBuilder makeUnexpectedResultBuilder() {
|
||||
return ResultBuilder
|
||||
( *this,
|
||||
m_lastAssertionInfo.macroName.c_str(),
|
||||
m_lastAssertionInfo.lineInfo,
|
||||
m_lastAssertionInfo.capturedExpression.c_str(),
|
||||
m_lastAssertionInfo.resultDisposition );
|
||||
|
@ -40,10 +40,10 @@ namespace Catch {
|
||||
|
||||
#ifdef CATCH_CONFIG_VARIADIC_MACROS
|
||||
#define INTERNAL_CATCH_SECTION( ... ) \
|
||||
if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, __VA_ARGS__ ) )
|
||||
if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( C_A_T_C_H_Context(), CATCH_INTERNAL_LINEINFO, __VA_ARGS__ ) )
|
||||
#else
|
||||
#define INTERNAL_CATCH_SECTION( name, desc ) \
|
||||
if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, name, desc ) )
|
||||
if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( C_A_T_C_H_Context(), CATCH_INTERNAL_LINEINFO, name, desc ) )
|
||||
#endif
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_SECTION_H_INCLUDED
|
||||
|
@ -16,17 +16,19 @@
|
||||
namespace Catch {
|
||||
|
||||
SectionInfo::SectionInfo
|
||||
( SourceLineInfo const& _lineInfo,
|
||||
( IRunContext& _runContext,
|
||||
SourceLineInfo const& _lineInfo,
|
||||
std::string const& _name,
|
||||
std::string const& _description )
|
||||
: name( _name ),
|
||||
: runContext( &_runContext ),
|
||||
name( _name ),
|
||||
description( _description ),
|
||||
lineInfo( _lineInfo )
|
||||
{}
|
||||
|
||||
Section::Section( SectionInfo const& info )
|
||||
: m_info( info ),
|
||||
m_runContext( getCurrentRunContext() ),
|
||||
m_runContext( *info.runContext ),
|
||||
m_sectionIncluded( m_runContext.sectionStarted( m_info, m_assertions ) )
|
||||
{
|
||||
m_timer.start();
|
||||
|
@ -10,15 +10,18 @@
|
||||
|
||||
#include "catch_common.h"
|
||||
#include "catch_totals.hpp"
|
||||
#include "catch_interfaces_capture.h"
|
||||
|
||||
namespace Catch {
|
||||
|
||||
struct SectionInfo {
|
||||
SectionInfo
|
||||
( SourceLineInfo const& _lineInfo,
|
||||
( IRunContext& _runContext,
|
||||
SourceLineInfo const& _lineInfo,
|
||||
std::string const& _name,
|
||||
std::string const& _description = std::string() );
|
||||
|
||||
IRunContext* runContext;
|
||||
std::string name;
|
||||
std::string description;
|
||||
SourceLineInfo lineInfo;
|
||||
|
@ -9,33 +9,10 @@
|
||||
#include "internal/catch_test_case_tracker.hpp"
|
||||
|
||||
|
||||
namespace Catch
|
||||
{
|
||||
class LocalContext {
|
||||
|
||||
public:
|
||||
TrackerContext& operator()() const {
|
||||
return TrackerContext::instance();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Catch
|
||||
|
||||
inline Catch::TrackerContext& C_A_T_C_H_Context() {
|
||||
return Catch::TrackerContext::instance();
|
||||
}
|
||||
|
||||
// -------------------
|
||||
|
||||
#include "catch.hpp"
|
||||
|
||||
using namespace Catch;
|
||||
|
||||
//inline void testCase( Catch::LocalContext const& C_A_T_C_H_Context ) {
|
||||
//
|
||||
// REQUIRE( C_A_T_C_H_Context().i() == 42 );
|
||||
//}
|
||||
|
||||
TEST_CASE( "Tracker", "" ) {
|
||||
|
||||
TrackerContext ctx;
|
||||
|
Loading…
Reference in New Issue
Block a user