Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:02:50

0001 
0002 //              Copyright Catch2 Authors
0003 // Distributed under the Boost Software License, Version 1.0.
0004 //   (See accompanying file LICENSE.txt or copy at
0005 //        https://www.boost.org/LICENSE_1_0.txt)
0006 
0007 // SPDX-License-Identifier: BSL-1.0
0008 #ifndef CATCH_RUN_CONTEXT_HPP_INCLUDED
0009 #define CATCH_RUN_CONTEXT_HPP_INCLUDED
0010 
0011 #include <catch2/interfaces/catch_interfaces_capture.hpp>
0012 #include <catch2/internal/catch_test_registry.hpp>
0013 #include <catch2/internal/catch_test_run_info.hpp>
0014 #include <catch2/internal/catch_fatal_condition_handler.hpp>
0015 #include <catch2/catch_test_case_info.hpp>
0016 #include <catch2/catch_message.hpp>
0017 #include <catch2/catch_totals.hpp>
0018 #include <catch2/internal/catch_test_case_tracker.hpp>
0019 #include <catch2/catch_assertion_info.hpp>
0020 #include <catch2/catch_assertion_result.hpp>
0021 #include <catch2/internal/catch_optional.hpp>
0022 #include <catch2/internal/catch_move_and_forward.hpp>
0023 
0024 #include <string>
0025 
0026 namespace Catch {
0027 
0028     class IGeneratorTracker;
0029     class IConfig;
0030     class IEventListener;
0031     using IEventListenerPtr = Detail::unique_ptr<IEventListener>;
0032 
0033     ///////////////////////////////////////////////////////////////////////////
0034 
0035     class RunContext final : public IResultCapture {
0036 
0037     public:
0038         RunContext( RunContext const& ) = delete;
0039         RunContext& operator =( RunContext const& ) = delete;
0040 
0041         explicit RunContext( IConfig const* _config, IEventListenerPtr&& reporter );
0042 
0043         ~RunContext() override;
0044 
0045         Totals runTest(TestCaseHandle const& testCase);
0046 
0047     public: // IResultCapture
0048 
0049         // Assertion handlers
0050         void handleExpr
0051                 (   AssertionInfo const& info,
0052                     ITransientExpression const& expr,
0053                     AssertionReaction& reaction ) override;
0054         void handleMessage
0055                 (   AssertionInfo const& info,
0056                     ResultWas::OfType resultType,
0057                     StringRef message,
0058                     AssertionReaction& reaction ) override;
0059         void handleUnexpectedExceptionNotThrown
0060                 (   AssertionInfo const& info,
0061                     AssertionReaction& reaction ) override;
0062         void handleUnexpectedInflightException
0063                 (   AssertionInfo const& info,
0064                     std::string&& message,
0065                     AssertionReaction& reaction ) override;
0066         void handleIncomplete
0067                 (   AssertionInfo const& info ) override;
0068         void handleNonExpr
0069                 (   AssertionInfo const &info,
0070                     ResultWas::OfType resultType,
0071                     AssertionReaction &reaction ) override;
0072 
0073         void notifyAssertionStarted( AssertionInfo const& info ) override;
0074         bool sectionStarted( StringRef sectionName,
0075                              SourceLineInfo const& sectionLineInfo,
0076                              Counts& assertions ) override;
0077 
0078         void sectionEnded( SectionEndInfo&& endInfo ) override;
0079         void sectionEndedEarly( SectionEndInfo&& endInfo ) override;
0080 
0081         IGeneratorTracker*
0082         acquireGeneratorTracker( StringRef generatorName,
0083                                  SourceLineInfo const& lineInfo ) override;
0084         IGeneratorTracker* createGeneratorTracker(
0085             StringRef generatorName,
0086             SourceLineInfo lineInfo,
0087             Generators::GeneratorBasePtr&& generator ) override;
0088 
0089 
0090         void benchmarkPreparing( StringRef name ) override;
0091         void benchmarkStarting( BenchmarkInfo const& info ) override;
0092         void benchmarkEnded( BenchmarkStats<> const& stats ) override;
0093         void benchmarkFailed( StringRef error ) override;
0094 
0095         void pushScopedMessage( MessageInfo const& message ) override;
0096         void popScopedMessage( MessageInfo const& message ) override;
0097 
0098         void emplaceUnscopedMessage( MessageBuilder&& builder ) override;
0099 
0100         std::string getCurrentTestName() const override;
0101 
0102         const AssertionResult* getLastResult() const override;
0103 
0104         void exceptionEarlyReported() override;
0105 
0106         void handleFatalErrorCondition( StringRef message ) override;
0107 
0108         bool lastAssertionPassed() override;
0109 
0110         void assertionPassed() override;
0111 
0112     public:
0113         // !TBD We need to do this another way!
0114         bool aborting() const;
0115 
0116     private:
0117 
0118         void runCurrentTest( std::string& redirectedCout, std::string& redirectedCerr );
0119         void invokeActiveTestCase();
0120 
0121         void resetAssertionInfo();
0122         bool testForMissingAssertions( Counts& assertions );
0123 
0124         void assertionEnded( AssertionResult&& result );
0125         void reportExpr
0126                 (   AssertionInfo const &info,
0127                     ResultWas::OfType resultType,
0128                     ITransientExpression const *expr,
0129                     bool negated );
0130 
0131         void populateReaction( AssertionReaction& reaction );
0132 
0133     private:
0134 
0135         void handleUnfinishedSections();
0136 
0137         TestRunInfo m_runInfo;
0138         TestCaseHandle const* m_activeTestCase = nullptr;
0139         ITracker* m_testCaseTracker = nullptr;
0140         Optional<AssertionResult> m_lastResult;
0141 
0142         IConfig const* m_config;
0143         Totals m_totals;
0144         IEventListenerPtr m_reporter;
0145         std::vector<MessageInfo> m_messages;
0146         std::vector<ScopedMessage> m_messageScopes; /* Keeps owners of so-called unscoped messages. */
0147         AssertionInfo m_lastAssertionInfo;
0148         std::vector<SectionEndInfo> m_unfinishedSections;
0149         std::vector<ITracker*> m_activeSections;
0150         TrackerContext m_trackerContext;
0151         FatalConditionHandler m_fatalConditionhandler;
0152         bool m_lastAssertionPassed = false;
0153         bool m_shouldReportUnexpected = true;
0154         bool m_includeSuccessfulResults;
0155     };
0156 
0157     void seedRng(IConfig const& config);
0158     unsigned int rngSeed();
0159 } // end namespace Catch
0160 
0161 #endif // CATCH_RUN_CONTEXT_HPP_INCLUDED