catch2/include/internal/catch_run_context.hpp

145 lines
4.4 KiB
C++
Raw Normal View History

/*
2010-11-10 00:24:00 +01:00
* Created by Phil on 22/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_RUNNER_IMPL_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_RUNNER_IMPL_HPP_INCLUDED
2010-11-10 00:24:00 +01:00
2011-01-11 10:13:31 +01:00
#include "catch_interfaces_runner.h"
#include "catch_interfaces_reporter.h"
2012-05-11 09:16:39 +02:00
#include "catch_interfaces_exception.h"
2011-01-01 01:29:58 +01:00
#include "catch_config.hpp"
2011-01-05 22:16:54 +01:00
#include "catch_test_registry.hpp"
2012-08-14 20:30:30 +02:00
#include "catch_test_case_info.h"
2010-11-10 00:24:00 +01:00
#include "catch_capture.hpp"
#include "catch_totals.hpp"
#include "catch_test_spec.hpp"
#include "catch_test_case_tracker.hpp"
#include "catch_timer.h"
#include "catch_assertionhandler.h"
#include "catch_fatal_condition.h"
2010-11-10 00:24:00 +01:00
2011-02-08 09:42:05 +01:00
#include <string>
2012-05-16 09:02:20 +02:00
namespace Catch {
class StreamRedirect {
2011-02-21 09:50:05 +01:00
public:
StreamRedirect(std::ostream& stream, std::string& targetString);
~StreamRedirect();
2011-02-21 09:50:05 +01:00
private:
std::ostream& m_stream;
std::streambuf* m_prevBuf;
std::ostringstream m_oss;
std::string& m_targetString;
};
// StdErr has two constituent streams in C++, std::cerr and std::clog
// This means that we need to redirect 2 streams into 1 to keep proper
// order of writes and cannot use StreamRedirect on its own
class StdErrRedirect {
public:
StdErrRedirect(std::string& targetString);
~StdErrRedirect();
private:
std::streambuf* m_cerrBuf;
std::streambuf* m_clogBuf;
std::ostringstream m_oss;
std::string& m_targetString;
};
2011-01-28 19:56:26 +01:00
///////////////////////////////////////////////////////////////////////////
2012-05-16 09:02:20 +02:00
class RunContext : public IResultCapture, public IRunner {
2010-11-10 00:24:00 +01:00
public:
RunContext( RunContext const& ) = delete;
RunContext& operator =( RunContext const& ) = delete;
2011-01-11 20:48:48 +01:00
explicit RunContext(IConfigPtr const& _config, IStreamingReporterPtr&& reporter);
virtual ~RunContext();
void testGroupStarting(std::string const& testSpec, std::size_t groupIndex, std::size_t groupsCount);
void testGroupEnded(std::string const& testSpec, Totals const& totals, std::size_t groupIndex, std::size_t groupsCount);
Totals runTest(TestCase const& testCase);
IConfigPtr config() const;
IStreamingReporter& reporter() const;
private: // IResultCapture
void assertionStarting(AssertionInfo const& info) override;
void assertionEnded(AssertionResult const& result) override;
bool sectionStarted( SectionInfo const& sectionInfo, Counts& assertions ) override;
bool testForMissingAssertions(Counts& assertions);
void sectionEnded(SectionEndInfo const& endInfo) override;
void sectionEndedEarly(SectionEndInfo const& endInfo) override;
void benchmarkStarting( BenchmarkInfo const& info ) override;
void benchmarkEnded( BenchmarkStats const& stats ) override;
void pushScopedMessage(MessageInfo const& message) override;
void popScopedMessage(MessageInfo const& message) override;
std::string getCurrentTestName() const override;
const AssertionResult* getLastResult() const override;
void exceptionEarlyReported() override;
void handleFatalErrorCondition(std::string const& message) override;
bool lastAssertionPassed() override;
void assertionPassed() override;
void assertionRun() override;
2012-08-23 21:08:50 +02:00
public:
// !TBD We need to do this another way!
bool aborting() const override;
2012-08-23 21:08:50 +02:00
private:
void runCurrentTest(std::string& redirectedCout, std::string& redirectedCerr);
void invokeActiveTestCase();
2010-11-10 00:24:00 +01:00
private:
void handleUnfinishedSections();
2012-12-02 00:54:17 +01:00
TestRunInfo m_runInfo;
IMutableContext& m_context;
TestCase const* m_activeTestCase = nullptr;
2015-11-02 20:21:46 +01:00
ITracker* m_testCaseTracker;
Option<AssertionResult> m_lastResult;
IConfigPtr m_config;
Totals m_totals;
IStreamingReporterPtr m_reporter;
std::vector<MessageInfo> m_messages;
AssertionInfo m_lastAssertionInfo;
std::vector<SectionEndInfo> m_unfinishedSections;
2015-11-02 20:21:46 +01:00
std::vector<ITracker*> m_activeSections;
TrackerContext m_trackerContext;
size_t m_prevPassed = 0;
bool m_shouldReportUnexpected = true;
2010-11-10 00:24:00 +01:00
};
IResultCapture& getResultCapture();
} // end namespace Catch
2010-11-10 00:24:00 +01:00
#endif // TWOBLUECUBES_CATCH_RUNNER_IMPL_HPP_INCLUDED