Files
Catch2/src/catch2/internal/catch_run_context.hpp
T

152 lines
5.4 KiB
C++
Raw Normal View History

// Copyright Catch2 Authors
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// https://www.boost.org/LICENSE_1_0.txt)
// SPDX-License-Identifier: BSL-1.0
#ifndef CATCH_RUN_CONTEXT_HPP_INCLUDED
#define CATCH_RUN_CONTEXT_HPP_INCLUDED
2010-11-09 23:24:00 +00:00
2020-03-30 10:34:21 +02:00
#include <catch2/interfaces/catch_interfaces_reporter.hpp>
#include <catch2/internal/catch_test_registry.hpp>
2021-03-27 17:54:22 +01:00
#include <catch2/internal/catch_fatal_condition_handler.hpp>
2020-03-30 10:34:21 +02:00
#include <catch2/catch_test_case_info.hpp>
2020-05-10 16:44:27 +02:00
#include <catch2/catch_message.hpp>
2020-03-30 10:34:21 +02:00
#include <catch2/catch_totals.hpp>
#include <catch2/internal/catch_test_case_tracker.hpp>
2020-07-29 16:29:41 +02:00
#include <catch2/catch_assertion_info.hpp>
#include <catch2/catch_assertion_result.hpp>
#include <catch2/internal/catch_option.hpp>
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 {
2017-08-29 16:44:02 +02:00
struct IMutableContext;
struct IGeneratorTracker;
2020-07-29 16:29:41 +02:00
struct IConfig;
2017-08-29 16:44:02 +02:00
2011-01-28 18:56:26 +00:00
///////////////////////////////////////////////////////////////////////////
2012-05-16 08:02:20 +01:00
2021-05-13 09:14:26 +02:00
class RunContext : public IResultCapture {
2013-07-03 19:14:59 +01:00
2010-11-09 23:24:00 +00:00
public:
RunContext( RunContext const& ) = delete;
RunContext& operator =( RunContext const& ) = delete;
2011-01-11 19:48:48 +00:00
explicit RunContext( IConfig const* _config, IStreamingReporterPtr&& reporter );
2013-07-03 19:14:59 +01:00
2017-11-28 11:24:26 +03:00
~RunContext() override;
2017-12-05 16:18:53 +00:00
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 );
2019-11-04 21:35:57 +01:00
Totals runTest(TestCaseHandle const& testCase);
2017-12-05 16:18:53 +00:00
public: // IResultCapture
// Assertion handlers
void handleExpr
( AssertionInfo const& info,
ITransientExpression const& expr,
2017-12-05 16:18:53 +00:00
AssertionReaction& reaction ) override;
void handleMessage
( AssertionInfo const& info,
ResultWas::OfType resultType,
StringRef message,
2017-12-05 16:18:53 +00:00
AssertionReaction& reaction ) override;
void handleUnexpectedExceptionNotThrown
( AssertionInfo const& info,
2017-12-05 16:18:53 +00:00
AssertionReaction& reaction ) override;
void handleUnexpectedInflightException
( AssertionInfo const& info,
std::string const& message,
2017-12-05 16:18:53 +00:00
AssertionReaction& reaction ) override;
void handleIncomplete
2017-12-05 16:18:53 +00:00
( AssertionInfo const& info ) override;
void handleNonExpr
( AssertionInfo const &info,
ResultWas::OfType resultType,
2017-12-05 16:18:53 +00:00
AssertionReaction &reaction ) override;
2013-07-03 19:14:59 +01:00
bool sectionStarted( SectionInfo const& sectionInfo, Counts& assertions ) override;
2017-12-05 16:18:53 +00:00
void sectionEnded( SectionEndInfo const& endInfo ) override;
void sectionEndedEarly( SectionEndInfo const& endInfo ) override;
2020-06-01 19:04:23 +02:00
auto acquireGeneratorTracker( StringRef generatorName, SourceLineInfo const& lineInfo ) -> IGeneratorTracker& override;
2018-06-12 17:50:39 +01:00
void benchmarkPreparing( StringRef name ) override;
void benchmarkStarting( BenchmarkInfo const& info ) override;
2019-04-23 23:41:13 +02:00
void benchmarkEnded( BenchmarkStats<> const& stats ) override;
void benchmarkFailed( StringRef error ) override;
2013-07-03 19:14:59 +01:00
2017-12-05 16:18:53 +00:00
void pushScopedMessage( MessageInfo const& message ) override;
void popScopedMessage( MessageInfo const& message ) override;
2019-02-01 09:11:30 -06:00
void emplaceUnscopedMessage( MessageBuilder const& builder ) override;
std::string getCurrentTestName() const override;
const AssertionResult* getLastResult() const override;
void exceptionEarlyReported() override;
2017-09-14 20:05:25 +02:00
void handleFatalErrorCondition( StringRef message ) override;
bool lastAssertionPassed() override;
void assertionPassed() override;
2012-08-23 20:08:50 +01:00
public:
// !TBD We need to do this another way!
2021-05-13 09:14:26 +02:00
bool aborting() const;
2012-08-23 20:08:50 +01:00
private:
2017-12-05 16:18:53 +00:00
void runCurrentTest( std::string& redirectedCout, std::string& redirectedCerr );
void invokeActiveTestCase();
2017-11-17 18:55:47 +00:00
void resetAssertionInfo();
2017-12-05 16:18:53 +00:00
bool testForMissingAssertions( Counts& assertions );
void assertionEnded( AssertionResult const& result );
void reportExpr
( AssertionInfo const &info,
ResultWas::OfType resultType,
ITransientExpression const *expr,
bool negated );
void populateReaction( AssertionReaction& reaction );
2017-11-17 18:55:47 +00:00
2010-11-09 23:24:00 +00:00
private:
void handleUnfinishedSections();
2012-12-01 23:54:17 +00:00
TestRunInfo m_runInfo;
IMutableContext& m_context;
2019-11-04 21:35:57 +01:00
TestCaseHandle const* m_activeTestCase = nullptr;
2019-01-07 18:55:33 +01:00
ITracker* m_testCaseTracker = nullptr;
Option<AssertionResult> m_lastResult;
IConfig const* m_config;
2012-02-23 08:49:52 +00:00
Totals m_totals;
IStreamingReporterPtr m_reporter;
2013-02-02 19:58:04 +00:00
std::vector<MessageInfo> m_messages;
2019-02-01 09:11:30 -06:00
std::vector<ScopedMessage> m_messageScopes; /* Keeps owners of so-called unscoped messages. */
AssertionInfo m_lastAssertionInfo;
std::vector<SectionEndInfo> m_unfinishedSections;
2015-11-02 19:21:46 +00:00
std::vector<ITracker*> m_activeSections;
TrackerContext m_trackerContext;
2021-03-27 17:54:22 +01:00
FatalConditionHandler m_fatalConditionhandler;
bool m_lastAssertionPassed = false;
bool m_shouldReportUnexpected = true;
bool m_includeSuccessfulResults;
2010-11-09 23:24:00 +00:00
};
2013-07-03 19:14:59 +01:00
void seedRng(IConfig const& config);
unsigned int rngSeed();
} // end namespace Catch
2010-11-09 23:24:00 +00:00
#endif // CATCH_RUN_CONTEXT_HPP_INCLUDED