mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-17 11:12:25 +01:00
Fully removed Context class
- responsibilities subsumed by RunContext
This commit is contained in:
parent
eea9357284
commit
fdc8a2b2df
@ -29,7 +29,6 @@
|
||||
#endif
|
||||
|
||||
#include "internal/catch_notimplemented_exception.h"
|
||||
#include "internal/catch_context.h"
|
||||
#include "internal/catch_test_registry.hpp"
|
||||
#include "internal/catch_capture.hpp"
|
||||
#include "internal/catch_section.h"
|
||||
|
@ -9,7 +9,6 @@
|
||||
#define TWOBLUECUBES_CATCH_CONFIG_HPP_INCLUDED
|
||||
|
||||
#include "catch_test_spec_parser.hpp"
|
||||
#include "catch_context.h"
|
||||
#include "catch_interfaces_config.h"
|
||||
#include "catch_stream.h"
|
||||
|
||||
|
@ -1,45 +0,0 @@
|
||||
/*
|
||||
* 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_CONTEXT_H_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_CONTEXT_H_INCLUDED
|
||||
|
||||
#include "catch_ptr.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace Catch {
|
||||
|
||||
class TestCase;
|
||||
class Stream;
|
||||
struct IRunContext;
|
||||
struct IConfig;
|
||||
|
||||
struct IContext
|
||||
{
|
||||
virtual ~IContext();
|
||||
|
||||
virtual IRunContext* getCurrentRunContext() = 0;
|
||||
virtual IConfig const* getConfig() const = 0;
|
||||
};
|
||||
|
||||
struct IMutableContext : IContext
|
||||
{
|
||||
virtual ~IMutableContext();
|
||||
virtual void setResultCapture( IRunContext* resultCapture ) = 0;
|
||||
virtual void setConfig( Ptr<IConfig const> const& config ) = 0;
|
||||
};
|
||||
|
||||
IContext& getCurrentContext();
|
||||
IMutableContext& getCurrentMutableContext();
|
||||
void cleanUpContext();
|
||||
IConfig const* getCurrentConfig();
|
||||
}
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_CONTEXT_H_INCLUDED
|
@ -1,72 +0,0 @@
|
||||
/*
|
||||
* 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_CONTEXT_IMPL_HPP_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_CONTEXT_IMPL_HPP_INCLUDED
|
||||
|
||||
#include "catch_run_context.hpp"
|
||||
|
||||
#include "catch_context.h"
|
||||
#include "catch_stream.hpp"
|
||||
|
||||
namespace Catch {
|
||||
|
||||
class Context : public IMutableContext {
|
||||
|
||||
Context() : m_config( CATCH_NULL ), m_resultCapture( CATCH_NULL ) {}
|
||||
Context( Context const& );
|
||||
void operator=( Context const& );
|
||||
|
||||
public: // IContext
|
||||
virtual IRunContext* getCurrentRunContext() {
|
||||
return m_resultCapture;
|
||||
}
|
||||
virtual IConfig const* getConfig() const {
|
||||
return m_config.get();
|
||||
}
|
||||
|
||||
public: // IMutableContext
|
||||
virtual void setResultCapture( IRunContext* resultCapture ) {
|
||||
m_resultCapture = resultCapture;
|
||||
}
|
||||
virtual void setConfig( Ptr<IConfig const> const& config ) {
|
||||
m_config = config;
|
||||
}
|
||||
|
||||
friend IMutableContext& getCurrentMutableContext();
|
||||
|
||||
private:
|
||||
Ptr<IConfig const> m_config;
|
||||
IRunContext* m_resultCapture;
|
||||
};
|
||||
|
||||
namespace {
|
||||
Context* currentContext = CATCH_NULL;
|
||||
}
|
||||
IMutableContext& getCurrentMutableContext() {
|
||||
if( !currentContext )
|
||||
currentContext = new Context();
|
||||
return *currentContext;
|
||||
}
|
||||
IContext& getCurrentContext() {
|
||||
return getCurrentMutableContext();
|
||||
}
|
||||
|
||||
void cleanUpContext() {
|
||||
delete currentContext;
|
||||
currentContext = CATCH_NULL;
|
||||
}
|
||||
|
||||
IConfig const* getCurrentConfig() {
|
||||
return currentContext
|
||||
? currentContext->getConfig()
|
||||
: CATCH_NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_CONTEXT_IMPL_HPP_INCLUDED
|
@ -14,9 +14,8 @@ namespace Catch {
|
||||
|
||||
// Report the error condition then exit the process
|
||||
inline void fatal( std::string const& message, int exitCode ) {
|
||||
IContext& context = Catch::getCurrentContext();
|
||||
IRunContext* runContext = context.getCurrentRunContext();
|
||||
runContext->handleFatalErrorCondition( message );
|
||||
IRunContext& runContext = getCurrentRunContext();
|
||||
runContext.handleFatalErrorCondition( message );
|
||||
|
||||
if( Catch::alwaysTrue() ) // avoids "no return" warnings
|
||||
exit( exitCode );
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include "../catch_session.hpp"
|
||||
#include "catch_registry_hub.hpp"
|
||||
#include "catch_notimplemented_exception.hpp"
|
||||
#include "catch_context_impl.hpp"
|
||||
#include "catch_console_colour_impl.hpp"
|
||||
#include "catch_assertionresult.hpp"
|
||||
#include "catch_test_case_info.hpp"
|
||||
@ -35,6 +34,7 @@
|
||||
#include "catch_result_builder.hpp"
|
||||
#include "catch_tag_alias_registry.hpp"
|
||||
#include "catch_test_case_tracker.hpp"
|
||||
#include "catch_stream.hpp"
|
||||
|
||||
#include "../reporters/catch_reporter_multi.hpp"
|
||||
#include "../reporters/catch_reporter_xml.hpp"
|
||||
@ -52,7 +52,6 @@ namespace Catch {
|
||||
CoutStream::~CoutStream() CATCH_NOEXCEPT {}
|
||||
DebugOutStream::~DebugOutStream() CATCH_NOEXCEPT {}
|
||||
StreamBufBase::~StreamBufBase() CATCH_NOEXCEPT {}
|
||||
IContext::~IContext() {}
|
||||
IRunContext::~IRunContext() {}
|
||||
ITestCase::~ITestCase() {}
|
||||
ITestCaseRegistry::~ITestCaseRegistry() {}
|
||||
@ -75,7 +74,6 @@ namespace Catch {
|
||||
StreamingReporterBase::~StreamingReporterBase() {}
|
||||
ConsoleReporter::~ConsoleReporter() {}
|
||||
CompactReporter::~CompactReporter() {}
|
||||
IMutableContext::~IMutableContext() {}
|
||||
IConfig::~IConfig() {}
|
||||
XmlReporter::~XmlReporter() {}
|
||||
JunitReporter::~JunitReporter() {}
|
||||
|
@ -16,12 +16,14 @@ namespace Catch {
|
||||
|
||||
class TestCase;
|
||||
class AssertionResult;
|
||||
class ScopedMessageBuilder;
|
||||
|
||||
struct AssertionInfo;
|
||||
struct SectionInfo;
|
||||
struct SectionEndInfo;
|
||||
struct MessageInfo;
|
||||
class ScopedMessageBuilder;
|
||||
struct Counts;
|
||||
struct IConfig;
|
||||
|
||||
struct IRunContext {
|
||||
|
||||
@ -40,9 +42,12 @@ namespace Catch {
|
||||
virtual std::string getCurrentTestName() const = 0;
|
||||
virtual const AssertionResult* getLastResult() const = 0;
|
||||
virtual bool isAborting() const = 0;
|
||||
virtual IConfig const& config() const = 0;
|
||||
};
|
||||
|
||||
IRunContext* tryGetCurrentRunContext();
|
||||
IRunContext& getCurrentRunContext();
|
||||
IConfig const* getCurrentConfig();
|
||||
}
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_INTERFACES_CAPTURE_H_INCLUDED
|
||||
|
@ -74,7 +74,6 @@ namespace Catch {
|
||||
void cleanUp() {
|
||||
delete getTheRegistryHub();
|
||||
getTheRegistryHub() = CATCH_NULL;
|
||||
cleanUpContext();
|
||||
}
|
||||
std::string translateActiveException() {
|
||||
return getRegistryHub().getExceptionTranslatorRegistry().translateActiveException();
|
||||
|
@ -9,7 +9,6 @@
|
||||
#define TWOBLUECUBES_CATCH_RESULT_BUILDER_HPP_INCLUDED
|
||||
|
||||
#include "catch_result_builder.h"
|
||||
#include "catch_context.h"
|
||||
#include "catch_interfaces_config.h"
|
||||
#include "catch_interfaces_capture.h"
|
||||
#include "catch_interfaces_registry_hub.h"
|
||||
@ -97,12 +96,13 @@ namespace Catch {
|
||||
}
|
||||
void ResultBuilder::handleResult( AssertionResult const& result )
|
||||
{
|
||||
getCurrentRunContext().assertionEnded( result );
|
||||
IRunContext& context = getCurrentRunContext();
|
||||
context.assertionEnded( result );
|
||||
|
||||
if( !result.isOk() ) {
|
||||
if( getCurrentConfig()->shouldDebugBreak() )
|
||||
if( context.config().shouldDebugBreak() )
|
||||
m_shouldDebugBreak = true;
|
||||
if( getCurrentContext().getCurrentRunContext()->isAborting() || (m_assertionInfo.resultDisposition & ResultDisposition::Normal) )
|
||||
if( context.isAborting() || (m_assertionInfo.resultDisposition & ResultDisposition::Normal) )
|
||||
m_shouldThrow = true;
|
||||
}
|
||||
}
|
||||
|
@ -51,6 +51,31 @@ namespace Catch {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace {
|
||||
IRunContext* s_currentRunContext = CATCH_NULL;
|
||||
|
||||
void setCurrentRunContext( IRunContext* context ) {
|
||||
s_currentRunContext = context;
|
||||
}
|
||||
}
|
||||
|
||||
IRunContext* tryGetCurrentRunContext() {
|
||||
return s_currentRunContext;
|
||||
}
|
||||
|
||||
IRunContext& getCurrentRunContext() {
|
||||
if( IRunContext* capture = tryGetCurrentRunContext() )
|
||||
return *capture;
|
||||
else
|
||||
throw std::logic_error( "No current test runner" );
|
||||
}
|
||||
IConfig const* getCurrentConfig() {
|
||||
if( IRunContext* capture = tryGetCurrentRunContext() )
|
||||
return &capture->config();
|
||||
else
|
||||
return CATCH_NULL;
|
||||
}
|
||||
|
||||
class RunContext : public IRunContext {
|
||||
|
||||
RunContext( RunContext const& );
|
||||
@ -60,18 +85,17 @@ namespace Catch {
|
||||
|
||||
explicit RunContext( Ptr<IConfig const> const& _config, Ptr<IStreamingReporter> const& reporter )
|
||||
: m_runInfo( _config->name() ),
|
||||
m_context( getCurrentMutableContext() ),
|
||||
m_config( _config ),
|
||||
m_reporter( reporter ),
|
||||
m_activeTestCaseInfo( CATCH_NULL )
|
||||
{
|
||||
m_context.setConfig( m_config );
|
||||
m_context.setResultCapture( this );
|
||||
setCurrentRunContext( this );
|
||||
m_reporter->testRunStarting( m_runInfo );
|
||||
}
|
||||
|
||||
virtual ~RunContext() {
|
||||
m_reporter->testRunEnded( TestRunStats( m_runInfo, m_totals, isAborting() ) );
|
||||
setCurrentRunContext( CATCH_NULL );
|
||||
}
|
||||
|
||||
void testGroupStarting( std::string const& testSpec, std::size_t groupIndex, std::size_t groupsCount ) {
|
||||
@ -113,14 +137,10 @@ namespace Catch {
|
||||
return deltaTotals;
|
||||
}
|
||||
|
||||
Ptr<IConfig const> config() const {
|
||||
return m_config;
|
||||
}
|
||||
|
||||
private: // IRunContext
|
||||
|
||||
|
||||
virtual void assertionEnded( AssertionResult const& result ) {
|
||||
virtual void assertionEnded( AssertionResult const& result ) CATCH_OVERRIDE {
|
||||
if( result.getResultType() == ResultWas::Ok )
|
||||
m_totals.assertions.passed++;
|
||||
else if( !result.isOk() )
|
||||
@ -134,10 +154,9 @@ namespace Catch {
|
||||
m_lastResult = result;
|
||||
}
|
||||
|
||||
virtual bool sectionStarted (
|
||||
SectionInfo const& sectionInfo,
|
||||
Counts& assertions
|
||||
)
|
||||
virtual bool sectionStarted
|
||||
( SectionInfo const& sectionInfo,
|
||||
Counts& assertions ) CATCH_OVERRIDE
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << sectionInfo.name << "@" << sectionInfo.lineInfo;
|
||||
@ -167,7 +186,7 @@ namespace Catch {
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void sectionEnded( SectionEndInfo const& endInfo ) {
|
||||
virtual void sectionEnded( SectionEndInfo const& endInfo ) CATCH_OVERRIDE {
|
||||
Counts assertions = m_totals.assertions - endInfo.prevAssertions;
|
||||
bool missingAssertions = testForMissingAssertions( assertions );
|
||||
|
||||
@ -180,7 +199,7 @@ namespace Catch {
|
||||
m_messages.clear();
|
||||
}
|
||||
|
||||
virtual void sectionEndedEarly( SectionEndInfo const& endInfo ) {
|
||||
virtual void sectionEndedEarly( SectionEndInfo const& endInfo ) CATCH_OVERRIDE {
|
||||
if( m_unfinishedSections.empty() )
|
||||
m_activeSections.back()->fail();
|
||||
else
|
||||
@ -190,25 +209,28 @@ namespace Catch {
|
||||
m_unfinishedSections.push_back( endInfo );
|
||||
}
|
||||
|
||||
virtual void pushScopedMessage( MessageInfo const& message ) {
|
||||
virtual void pushScopedMessage( MessageInfo const& message ) CATCH_OVERRIDE {
|
||||
m_messages.push_back( message );
|
||||
}
|
||||
|
||||
virtual void popScopedMessage( MessageInfo const& 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 {
|
||||
virtual std::string getCurrentTestName() const CATCH_OVERRIDE {
|
||||
return m_activeTestCaseInfo
|
||||
? m_activeTestCaseInfo->name
|
||||
: "";
|
||||
}
|
||||
|
||||
virtual const AssertionResult* getLastResult() const {
|
||||
virtual const AssertionResult* getLastResult() const CATCH_OVERRIDE {
|
||||
return &m_lastResult;
|
||||
}
|
||||
virtual IConfig const& config() const CATCH_OVERRIDE {
|
||||
return *m_config;
|
||||
}
|
||||
|
||||
virtual void handleFatalErrorCondition( std::string const& message ) {
|
||||
virtual void handleFatalErrorCondition( std::string const& message ) CATCH_OVERRIDE {
|
||||
ResultBuilder resultBuilder = makeUnexpectedResultBuilder();
|
||||
resultBuilder.setResultType( ResultWas::FatalErrorCondition );
|
||||
resultBuilder << message;
|
||||
@ -319,7 +341,6 @@ namespace Catch {
|
||||
}
|
||||
|
||||
TestRunInfo m_runInfo;
|
||||
IMutableContext& m_context;
|
||||
|
||||
Ptr<IConfig const> m_config;
|
||||
Ptr<IStreamingReporter> m_reporter;
|
||||
@ -335,13 +356,6 @@ namespace Catch {
|
||||
std::vector<MessageInfo> m_messages;
|
||||
};
|
||||
|
||||
IRunContext& getCurrentRunContext() {
|
||||
if( IRunContext* capture = getCurrentContext().getCurrentRunContext() )
|
||||
return *capture;
|
||||
else
|
||||
throw std::logic_error( "No result capture instance" );
|
||||
}
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_RUNNER_IMPL_HPP_INCLUDED
|
||||
|
@ -11,7 +11,6 @@
|
||||
#include "catch_test_registry.hpp"
|
||||
#include "catch_test_case_info.h"
|
||||
#include "catch_test_spec.hpp"
|
||||
#include "catch_context.h"
|
||||
|
||||
#include <vector>
|
||||
#include <set>
|
||||
|
@ -147,8 +147,6 @@
|
||||
4A6D0C4C149B3E3D00DB3EAA /* catch_default_main.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_default_main.hpp; sourceTree = "<group>"; };
|
||||
4A6D0C4D149B3E3D00DB3EAA /* catch_evaluate.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; lineEnding = 0; path = catch_evaluate.hpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
|
||||
4A6D0C4E149B3E3D00DB3EAA /* catch_exception_translator_registry.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_exception_translator_registry.hpp; sourceTree = "<group>"; };
|
||||
4A6D0C51149B3E3D00DB3EAA /* catch_context.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = catch_context.h; sourceTree = "<group>"; };
|
||||
4A6D0C52149B3E3D00DB3EAA /* catch_context_impl.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_context_impl.hpp; sourceTree = "<group>"; };
|
||||
4A6D0C53149B3E3D00DB3EAA /* catch_interfaces_capture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = catch_interfaces_capture.h; sourceTree = "<group>"; };
|
||||
4A6D0C54149B3E3D00DB3EAA /* catch_interfaces_exception.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = catch_interfaces_exception.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
|
||||
4A6D0C55149B3E3D00DB3EAA /* catch_interfaces_reporter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = catch_interfaces_reporter.h; sourceTree = "<group>"; };
|
||||
@ -351,7 +349,6 @@
|
||||
263FD06017AF8DF200988A20 /* catch_timer.hpp */,
|
||||
4A4B0F9C15CEFA8300AE2392 /* catch_impl.hpp */,
|
||||
4A4B0F9715CE6CFB00AE2392 /* catch_registry_hub.hpp */,
|
||||
4A6D0C52149B3E3D00DB3EAA /* catch_context_impl.hpp */,
|
||||
4A6D0C5E149B3E3D00DB3EAA /* catch_run_context.hpp */,
|
||||
4A6D0C62149B3E3D00DB3EAA /* catch_test_case_registry_impl.hpp */,
|
||||
4AB1C73514F97BDA00F31DF7 /* catch_console_colour_impl.hpp */,
|
||||
@ -403,7 +400,6 @@
|
||||
261488FA184C81130041FBEB /* catch_test_spec.hpp */,
|
||||
2656C21F1925E5100040DB02 /* catch_test_spec_parser.hpp */,
|
||||
4A6D0C4A149B3E3D00DB3EAA /* catch_config.hpp */,
|
||||
4A6D0C51149B3E3D00DB3EAA /* catch_context.h */,
|
||||
4A6D0C61149B3E3D00DB3EAA /* catch_test_case_info.h */,
|
||||
4A7ADB4314F631E10094FE10 /* catch_totals.hpp */,
|
||||
4AB77CB71553B72B00857BF0 /* catch_section_info.hpp */,
|
||||
|
Loading…
Reference in New Issue
Block a user