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