mirror of
https://github.com/catchorg/Catch2.git
synced 2025-09-15 09:55:39 +02:00
First cut of ThreadContext (not plumbed in anywhere yet)
This commit is contained in:
@@ -87,8 +87,8 @@ namespace Catch {
|
||||
std::srand( config.rngSeed() );
|
||||
}
|
||||
unsigned int rngSeed() {
|
||||
return getCurrentConfig()
|
||||
? getCurrentConfig()->rngSeed()
|
||||
return getGlobalConfig()
|
||||
? getGlobalConfig()->rngSeed()
|
||||
: 0;
|
||||
}
|
||||
|
||||
|
@@ -145,7 +145,7 @@ namespace {
|
||||
};
|
||||
|
||||
IColourImpl* platformColourInstance() {
|
||||
IConfig const* config = getCurrentConfig();
|
||||
IConfig const* config = getGlobalConfig();
|
||||
return (config && config->forceColour()) || isatty(STDOUT_FILENO)
|
||||
? PosixColourImpl::instance()
|
||||
: NoColourImpl::instance();
|
||||
|
@@ -14,7 +14,7 @@ namespace Catch {
|
||||
|
||||
// Report the error condition then exit the process
|
||||
inline void fatal( std::string const& message, int exitCode ) {
|
||||
IRunContext& runContext = getCurrentRunContext();
|
||||
IRunContext& runContext = getGlobalRunContext();
|
||||
runContext.handleFatalErrorCondition( message );
|
||||
|
||||
if( Catch::alwaysTrue() ) // avoids "no return" warnings
|
||||
|
@@ -33,6 +33,7 @@
|
||||
#include "catch_result_builder.hpp"
|
||||
#include "catch_tag_alias_registry.hpp"
|
||||
#include "catch_test_case_tracker.hpp"
|
||||
#include "catch_thread_context.hpp"
|
||||
#include "catch_stream.hpp"
|
||||
|
||||
#include "../reporters/catch_reporter_multi.hpp"
|
||||
@@ -68,6 +69,7 @@ namespace Catch {
|
||||
TestRunStats::~TestRunStats() {}
|
||||
CumulativeReporterBase::SectionNode::~SectionNode() {}
|
||||
CumulativeReporterBase::~CumulativeReporterBase() {}
|
||||
ThreadContext::~ThreadContext() {}
|
||||
|
||||
StreamingReporterBase::~StreamingReporterBase() {}
|
||||
ConsoleReporter::~ConsoleReporter() {}
|
||||
|
@@ -47,21 +47,21 @@ namespace Catch {
|
||||
virtual IConfig const& config() const = 0;
|
||||
};
|
||||
|
||||
IRunContext& getCurrentRunContext();
|
||||
|
||||
IConfig const* getCurrentConfig();
|
||||
IRunContext& getGlobalRunContext();
|
||||
|
||||
IConfig const* getGlobalConfig();
|
||||
|
||||
class LocalContext {
|
||||
|
||||
public:
|
||||
IRunContext& operator()() const {
|
||||
return getCurrentRunContext(); // !TBD
|
||||
return getGlobalRunContext(); // !TBD
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
inline Catch::IRunContext& C_A_T_C_H_Context() {
|
||||
return Catch::getCurrentRunContext();
|
||||
return Catch::getGlobalRunContext();
|
||||
}
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_INTERFACES_CAPTURE_H_INCLUDED
|
||||
|
@@ -8,6 +8,8 @@
|
||||
#ifndef TWOBLUECUBES_CATCH_RUNNER_IMPL_HPP_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_RUNNER_IMPL_HPP_INCLUDED
|
||||
|
||||
#include "catch_thread_context.hpp"
|
||||
|
||||
#include "catch_interfaces_capture.h"
|
||||
#include "catch_interfaces_reporter.h"
|
||||
#include "catch_interfaces_exception.h"
|
||||
@@ -53,24 +55,25 @@ namespace Catch {
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace {
|
||||
IRunContext* s_currentRunContext = CATCH_NULL;
|
||||
IRunContext* g_globalRunContext = CATCH_NULL;
|
||||
|
||||
void setCurrentRunContext( IRunContext* context ) {
|
||||
s_currentRunContext = context;
|
||||
void setGlobalRunContext( IRunContext* context ) {
|
||||
assert( g_globalRunContext == CATCH_NULL || context == CATCH_NULL );
|
||||
g_globalRunContext = context;
|
||||
}
|
||||
}
|
||||
|
||||
IRunContext* tryGetCurrentRunContext() {
|
||||
return s_currentRunContext;
|
||||
IRunContext* tryGetGlobalRunContext() {
|
||||
return g_globalRunContext;
|
||||
}
|
||||
IRunContext& getCurrentRunContext() {
|
||||
if( IRunContext* capture = tryGetCurrentRunContext() )
|
||||
IRunContext& getGlobalRunContext() {
|
||||
if( IRunContext* capture = tryGetGlobalRunContext() )
|
||||
return *capture;
|
||||
else
|
||||
throw std::logic_error( "No current test runner" );
|
||||
}
|
||||
IConfig const* getCurrentConfig() {
|
||||
if( IRunContext* capture = tryGetCurrentRunContext() )
|
||||
IConfig const* getGlobalConfig() {
|
||||
if( IRunContext* capture = tryGetGlobalRunContext() )
|
||||
return &capture->config();
|
||||
else
|
||||
return CATCH_NULL;
|
||||
@@ -89,13 +92,13 @@ namespace Catch {
|
||||
m_reporter( reporter ),
|
||||
m_activeTestCaseInfo( CATCH_NULL )
|
||||
{
|
||||
setCurrentRunContext( this );
|
||||
setGlobalRunContext( this );
|
||||
m_reporter->testRunStarting( m_runInfo );
|
||||
}
|
||||
|
||||
virtual ~RunContext() {
|
||||
m_reporter->testRunEnded( TestRunStats( m_runInfo, m_totals, isAborting() ) );
|
||||
setCurrentRunContext( CATCH_NULL );
|
||||
setGlobalRunContext( CATCH_NULL );
|
||||
}
|
||||
|
||||
void testGroupStarting( std::string const& testSpec, std::size_t groupIndex, std::size_t groupsCount ) {
|
||||
|
85
include/internal/catch_thread_context.hpp
Normal file
85
include/internal/catch_thread_context.hpp
Normal file
@@ -0,0 +1,85 @@
|
||||
//
|
||||
/*
|
||||
* Created by Phil on 24/11/2015.
|
||||
* Copyright 2015 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_THREAD_CONTEXT_HPP_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_THREAD_CONTEXT_HPP_INCLUDED
|
||||
|
||||
#include "catch_interfaces_capture.h"
|
||||
#include "catch_notimplemented_exception.h"
|
||||
|
||||
namespace Catch {
|
||||
|
||||
class ThreadContext : public IRunContext {
|
||||
|
||||
IRunContext& m_parentContext;
|
||||
std::vector<MessageInfo> m_messages;
|
||||
std::vector<AssertionResult> m_assertions;
|
||||
|
||||
ThreadContext( ThreadContext const& );
|
||||
void operator =( ThreadContext const& );
|
||||
|
||||
public:
|
||||
ThreadContext( IRunContext& parentContext )
|
||||
: m_parentContext( parentContext )
|
||||
{}
|
||||
virtual ~ThreadContext();
|
||||
|
||||
private: // IRunContext
|
||||
|
||||
virtual void assertionEnded( AssertionResult const& result ) CATCH_OVERRIDE {
|
||||
m_assertions.push_back( result );
|
||||
}
|
||||
|
||||
virtual bool sectionStarted( SectionInfo const&, Counts& ) CATCH_OVERRIDE
|
||||
{
|
||||
throw std::logic_error( "Sections nested within threaded sections are not currently supported" );
|
||||
}
|
||||
|
||||
virtual void sectionEnded( SectionEndInfo const& ) CATCH_OVERRIDE {
|
||||
throw std::logic_error( "Sections nested within threaded sections are not currently supported" );
|
||||
}
|
||||
|
||||
virtual void sectionEndedEarly( SectionEndInfo const& ) CATCH_OVERRIDE {
|
||||
throw std::logic_error( "Sections nested within threaded sections are not currently supported" );
|
||||
}
|
||||
|
||||
virtual void pushScopedMessage( MessageInfo const& message ) CATCH_OVERRIDE {
|
||||
m_messages.push_back( message );
|
||||
}
|
||||
|
||||
virtual void popScopedMessage( MessageInfo const& message ) CATCH_OVERRIDE {
|
||||
m_messages.erase( std::remove( m_messages.begin(), m_messages.end(), message ), m_messages.end() );
|
||||
}
|
||||
|
||||
virtual std::string getCurrentTestName() const CATCH_OVERRIDE {
|
||||
return m_parentContext.getCurrentTestName();
|
||||
}
|
||||
|
||||
virtual AssertionResult const* getLastResult() const CATCH_OVERRIDE {
|
||||
return m_assertions.empty()
|
||||
? CATCH_NULL
|
||||
: &m_assertions.back();
|
||||
}
|
||||
virtual IConfig const& config() const CATCH_OVERRIDE {
|
||||
return m_parentContext.config();
|
||||
}
|
||||
|
||||
virtual void handleFatalErrorCondition( std::string const& message ) CATCH_OVERRIDE {
|
||||
m_parentContext.handleFatalErrorCondition( message );
|
||||
}
|
||||
|
||||
public:
|
||||
virtual bool isAborting() const CATCH_OVERRIDE {
|
||||
// Probably can't do this
|
||||
CATCH_NOT_IMPLEMENTED;
|
||||
}
|
||||
};
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_THREAD_CONTEXT_HPP_INCLUDED
|
@@ -55,7 +55,7 @@ namespace Detail {
|
||||
|
||||
std::string toString( std::string const& value ) {
|
||||
std::string s = value;
|
||||
IConfig const* config = getCurrentConfig();
|
||||
IConfig const* config = getGlobalConfig();
|
||||
if( config && config->showInvisibles() ) {
|
||||
for(size_t i = 0; i < s.size(); ++i ) {
|
||||
std::string subs;
|
||||
|
Reference in New Issue
Block a user