Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-16 08:52:14

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_TEST_CASE_INFO_HPP_INCLUDED
0009 #define CATCH_TEST_CASE_INFO_HPP_INCLUDED
0010 
0011 #include <catch2/interfaces/catch_interfaces_test_invoker.hpp>
0012 #include <catch2/internal/catch_source_line_info.hpp>
0013 #include <catch2/internal/catch_noncopyable.hpp>
0014 #include <catch2/internal/catch_stringref.hpp>
0015 #include <catch2/internal/catch_unique_ptr.hpp>
0016 
0017 
0018 #include <cstdint>
0019 #include <string>
0020 #include <cstdint>
0021 #include <vector>
0022 
0023 #ifdef __clang__
0024 #pragma clang diagnostic push
0025 #pragma clang diagnostic ignored "-Wpadded"
0026 #endif
0027 
0028 namespace Catch {
0029 
0030     /**
0031      * A **view** of a tag string that provides case insensitive comparisons
0032      *
0033      * Note that in Catch2 internals, the square brackets around tags are
0034      * not a part of tag's representation, so e.g. "[cool-tag]" is represented
0035      * as "cool-tag" internally.
0036      */
0037     struct Tag {
0038         constexpr Tag(StringRef original_):
0039             original(original_)
0040         {}
0041         StringRef original;
0042 
0043         friend bool operator< ( Tag const& lhs, Tag const& rhs );
0044         friend bool operator==( Tag const& lhs, Tag const& rhs );
0045     };
0046 
0047     class ITestInvoker;
0048     struct NameAndTags;
0049 
0050     enum class TestCaseProperties : uint8_t {
0051         None = 0,
0052         IsHidden = 1 << 1,
0053         ShouldFail = 1 << 2,
0054         MayFail = 1 << 3,
0055         Throws = 1 << 4,
0056         NonPortable = 1 << 5,
0057         Benchmark = 1 << 6
0058     };
0059 
0060     /**
0061      * Various metadata about the test case.
0062      *
0063      * A test case is uniquely identified by its (class)name and tags
0064      * combination, with source location being ignored, and other properties
0065      * being determined from tags.
0066      *
0067      * Tags are kept sorted.
0068      */
0069     struct TestCaseInfo : Detail::NonCopyable {
0070 
0071         TestCaseInfo(StringRef _className,
0072                      NameAndTags const& _nameAndTags,
0073                      SourceLineInfo const& _lineInfo);
0074 
0075         bool isHidden() const;
0076         bool throws() const;
0077         bool okToFail() const;
0078         bool expectedToFail() const;
0079 
0080         // Adds the tag(s) with test's filename (for the -# flag)
0081         void addFilenameTag();
0082 
0083         //! Orders by name, classname and tags
0084         friend bool operator<( TestCaseInfo const& lhs,
0085                                TestCaseInfo const& rhs );
0086 
0087 
0088         std::string tagsAsString() const;
0089 
0090         std::string name;
0091         StringRef className;
0092     private:
0093         std::string backingTags;
0094         // Internally we copy tags to the backing storage and then add
0095         // refs to this storage to the tags vector.
0096         void internalAppendTag(StringRef tagString);
0097     public:
0098         std::vector<Tag> tags;
0099         SourceLineInfo lineInfo;
0100         TestCaseProperties properties = TestCaseProperties::None;
0101     };
0102 
0103     /**
0104      * Wrapper over the test case information and the test case invoker
0105      *
0106      * Does not own either, and is specifically made to be cheap
0107      * to copy around.
0108      */
0109     class TestCaseHandle {
0110         TestCaseInfo* m_info;
0111         ITestInvoker* m_invoker;
0112     public:
0113         constexpr TestCaseHandle(TestCaseInfo* info, ITestInvoker* invoker) :
0114             m_info(info), m_invoker(invoker) {}
0115 
0116         void prepareTestCase() const {
0117             m_invoker->prepareTestCase();
0118         }
0119 
0120         void tearDownTestCase() const {
0121             m_invoker->tearDownTestCase();
0122         }
0123 
0124         void invoke() const {
0125             m_invoker->invoke();
0126         }
0127 
0128         constexpr TestCaseInfo const& getTestCaseInfo() const {
0129             return *m_info;
0130         }
0131     };
0132 
0133     Detail::unique_ptr<TestCaseInfo>
0134     makeTestCaseInfo( StringRef className,
0135                       NameAndTags const& nameAndTags,
0136                       SourceLineInfo const& lineInfo );
0137 }
0138 
0139 #ifdef __clang__
0140 #pragma clang diagnostic pop
0141 #endif
0142 
0143 #endif // CATCH_TEST_CASE_INFO_HPP_INCLUDED