2011-12-28 11:23:32 +01:00
|
|
|
/*
|
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)
|
|
|
|
*/
|
2012-09-17 07:42:29 +02:00
|
|
|
#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"
|
2010-12-31 23:46:51 +01:00
|
|
|
#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"
|
2017-09-07 12:24:33 +02:00
|
|
|
#include "catch_test_registry.h"
|
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"
|
2017-09-07 12:24:33 +02:00
|
|
|
#include "catch_totals.h"
|
|
|
|
#include "catch_test_spec.h"
|
|
|
|
#include "catch_test_case_tracker.h"
|
2013-08-07 19:56:35 +02:00
|
|
|
#include "catch_timer.h"
|
2017-08-09 10:08:33 +02:00
|
|
|
#include "catch_assertionhandler.h"
|
2017-07-06 22:28:42 +02:00
|
|
|
#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 {
|
|
|
|
|
2017-08-29 16:44:02 +02:00
|
|
|
struct IMutableContext;
|
|
|
|
|
2012-05-16 09:02:20 +02:00
|
|
|
class StreamRedirect {
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2011-02-21 09:50:05 +01:00
|
|
|
public:
|
2017-07-15 16:48:21 +02:00
|
|
|
StreamRedirect(std::ostream& stream, std::string& targetString);
|
|
|
|
~StreamRedirect();
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2011-02-21 09:50:05 +01:00
|
|
|
private:
|
|
|
|
std::ostream& m_stream;
|
|
|
|
std::streambuf* m_prevBuf;
|
2017-11-07 19:01:10 +01:00
|
|
|
ReusableStringStream m_oss;
|
2011-02-21 09:50:05 +01:00
|
|
|
std::string& m_targetString;
|
|
|
|
};
|
2012-11-04 22:09:22 +01:00
|
|
|
|
2017-08-09 15:28:40 +02:00
|
|
|
// 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:
|
2017-08-10 11:34:26 +02:00
|
|
|
StdErrRedirect(std::string& targetString);
|
|
|
|
~StdErrRedirect();
|
2017-08-09 15:28:40 +02:00
|
|
|
private:
|
|
|
|
std::streambuf* m_cerrBuf;
|
|
|
|
std::streambuf* m_clogBuf;
|
2017-11-07 19:01:10 +01:00
|
|
|
ReusableStringStream m_oss;
|
2017-08-09 15:28:40 +02:00
|
|
|
std::string& m_targetString;
|
|
|
|
};
|
|
|
|
|
2011-01-28 19:56:26 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2012-05-16 09:02:20 +02:00
|
|
|
|
2013-06-05 09:18:52 +02:00
|
|
|
class RunContext : public IResultCapture, public IRunner {
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2010-11-10 00:24:00 +01:00
|
|
|
public:
|
2017-07-15 16:48:21 +02:00
|
|
|
RunContext( RunContext const& ) = delete;
|
|
|
|
RunContext& operator =( RunContext const& ) = delete;
|
2011-01-11 20:48:48 +01:00
|
|
|
|
2017-07-15 16:48:21 +02:00
|
|
|
explicit RunContext(IConfigPtr const& _config, IStreamingReporterPtr&& reporter);
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2017-07-15 16:48:21 +02:00
|
|
|
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);
|
2010-12-31 21:49:58 +01:00
|
|
|
|
2017-07-15 16:48:21 +02:00
|
|
|
Totals runTest(TestCase const& testCase);
|
2010-12-31 21:49:58 +01:00
|
|
|
|
2017-07-15 16:48:21 +02:00
|
|
|
IConfigPtr config() const;
|
|
|
|
IStreamingReporter& reporter() const;
|
|
|
|
|
|
|
|
private: // IResultCapture
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2012-11-17 18:22:37 +01:00
|
|
|
|
2017-08-04 20:23:30 +02:00
|
|
|
void assertionStarting(AssertionInfo const& info) override;
|
2017-08-04 13:13:58 +02:00
|
|
|
void assertionEnded(AssertionResult const& result) override;
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2017-08-04 13:13:58 +02:00
|
|
|
bool sectionStarted( SectionInfo const& sectionInfo, Counts& assertions ) override;
|
2017-07-15 16:48:21 +02:00
|
|
|
bool testForMissingAssertions(Counts& assertions);
|
|
|
|
|
2017-08-04 13:13:58 +02:00
|
|
|
void sectionEnded(SectionEndInfo const& endInfo) override;
|
|
|
|
void sectionEndedEarly(SectionEndInfo const& endInfo) override;
|
2017-07-15 16:48:21 +02:00
|
|
|
|
2017-08-04 20:23:30 +02:00
|
|
|
void benchmarkStarting( BenchmarkInfo const& info ) override;
|
|
|
|
void benchmarkEnded( BenchmarkStats const& stats ) override;
|
2017-07-15 16:48:21 +02:00
|
|
|
|
2017-08-04 20:23:30 +02:00
|
|
|
void pushScopedMessage(MessageInfo const& message) override;
|
2017-08-04 13:13:58 +02:00
|
|
|
void popScopedMessage(MessageInfo const& message) override;
|
2017-07-15 16:48:21 +02:00
|
|
|
|
2017-08-04 13:13:58 +02:00
|
|
|
std::string getCurrentTestName() const override;
|
2017-07-15 16:48:21 +02:00
|
|
|
|
2017-08-04 13:13:58 +02:00
|
|
|
const AssertionResult* getLastResult() const override;
|
2017-07-15 16:48:21 +02:00
|
|
|
|
2017-08-04 13:13:58 +02:00
|
|
|
void exceptionEarlyReported() override;
|
2017-07-15 16:48:21 +02:00
|
|
|
|
2017-09-14 20:05:25 +02:00
|
|
|
void handleFatalErrorCondition( StringRef message ) override;
|
2014-08-22 20:33:28 +02:00
|
|
|
|
2017-08-04 13:13:58 +02:00
|
|
|
bool lastAssertionPassed() override;
|
2017-06-26 21:30:23 +02:00
|
|
|
|
2017-08-04 13:13:58 +02:00
|
|
|
void assertionPassed() override;
|
2017-06-26 21:30:23 +02:00
|
|
|
|
2017-08-04 13:13:58 +02:00
|
|
|
void assertionRun() override;
|
2017-06-26 21:30:23 +02:00
|
|
|
|
2012-08-23 21:08:50 +02:00
|
|
|
public:
|
|
|
|
// !TBD We need to do this another way!
|
2017-07-25 17:16:28 +02:00
|
|
|
bool aborting() const override;
|
2012-08-23 21:08:50 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2017-07-15 16:48:21 +02:00
|
|
|
void runCurrentTest(std::string& redirectedCout, std::string& redirectedCerr);
|
|
|
|
void invokeActiveTestCase();
|
2014-08-22 09:07:39 +02:00
|
|
|
|
2017-11-17 19:55:47 +01:00
|
|
|
void resetAssertionInfo();
|
|
|
|
|
2010-11-10 00:24:00 +01:00
|
|
|
private:
|
2014-08-22 20:33:28 +02:00
|
|
|
|
2017-07-15 16:48:21 +02:00
|
|
|
void handleUnfinishedSections();
|
2014-08-22 20:33:28 +02:00
|
|
|
|
2012-12-02 00:54:17 +01:00
|
|
|
TestRunInfo m_runInfo;
|
2012-05-21 19:52:09 +02:00
|
|
|
IMutableContext& m_context;
|
2017-04-25 19:56:53 +02:00
|
|
|
TestCase const* m_activeTestCase = nullptr;
|
2015-11-02 20:21:46 +01:00
|
|
|
ITracker* m_testCaseTracker;
|
2017-08-08 02:02:24 +02:00
|
|
|
Option<AssertionResult> m_lastResult;
|
2010-12-31 21:49:58 +01:00
|
|
|
|
2017-04-25 21:18:02 +02:00
|
|
|
IConfigPtr m_config;
|
2012-02-23 09:49:52 +01:00
|
|
|
Totals m_totals;
|
2017-04-25 21:42:01 +02:00
|
|
|
IStreamingReporterPtr m_reporter;
|
2013-02-02 20:58:04 +01:00
|
|
|
std::vector<MessageInfo> m_messages;
|
2012-11-04 22:09:22 +01:00
|
|
|
AssertionInfo m_lastAssertionInfo;
|
2015-09-27 03:12:21 +02:00
|
|
|
std::vector<SectionEndInfo> m_unfinishedSections;
|
2015-11-02 20:21:46 +01:00
|
|
|
std::vector<ITracker*> m_activeSections;
|
|
|
|
TrackerContext m_trackerContext;
|
2017-09-18 18:13:17 +02:00
|
|
|
std::size_t m_prevPassed = 0;
|
2017-04-25 19:56:53 +02:00
|
|
|
bool m_shouldReportUnexpected = true;
|
2010-11-10 00:24:00 +01:00
|
|
|
};
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2017-07-15 16:48:21 +02:00
|
|
|
IResultCapture& getResultCapture();
|
2014-05-28 19:53:01 +02:00
|
|
|
|
2012-05-21 19:52:09 +02:00
|
|
|
} // end namespace Catch
|
2010-11-10 00:24:00 +01:00
|
|
|
|
2012-09-17 07:42:29 +02:00
|
|
|
#endif // TWOBLUECUBES_CATCH_RUNNER_IMPL_HPP_INCLUDED
|