Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:08

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/internal/catch_source_line_info.hpp>
0012 #include <catch2/internal/catch_noncopyable.hpp>
0013 #include <catch2/internal/catch_stringref.hpp>
0014 #include <catch2/internal/catch_test_registry.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 
0049     enum class TestCaseProperties : uint8_t {
0050         None = 0,
0051         IsHidden = 1 << 1,
0052         ShouldFail = 1 << 2,
0053         MayFail = 1 << 3,
0054         Throws = 1 << 4,
0055         NonPortable = 1 << 5,
0056         Benchmark = 1 << 6
0057     };
0058 
0059     /**
0060      * Various metadata about the test case.
0061      *
0062      * A test case is uniquely identified by its (class)name and tags
0063      * combination, with source location being ignored, and other properties
0064      * being determined from tags.
0065      *
0066      * Tags are kept sorted.
0067      */
0068     struct TestCaseInfo : Detail::NonCopyable {
0069 
0070         TestCaseInfo(StringRef _className,
0071                      NameAndTags const& _tags,
0072                      SourceLineInfo const& _lineInfo);
0073 
0074         bool isHidden() const;
0075         bool throws() const;
0076         bool okToFail() const;
0077         bool expectedToFail() const;
0078 
0079         // Adds the tag(s) with test's filename (for the -# flag)
0080         void addFilenameTag();
0081 
0082         //! Orders by name, classname and tags
0083         friend bool operator<( TestCaseInfo const& lhs,
0084                                TestCaseInfo const& rhs );
0085 
0086 
0087         std::string tagsAsString() const;
0088 
0089         std::string name;
0090         StringRef className;
0091     private:
0092         std::string backingTags;
0093         // Internally we copy tags to the backing storage and then add
0094         // refs to this storage to the tags vector.
0095         void internalAppendTag(StringRef tagString);
0096     public:
0097         std::vector<Tag> tags;
0098         SourceLineInfo lineInfo;
0099         TestCaseProperties properties = TestCaseProperties::None;
0100     };
0101 
0102     /**
0103      * Wrapper over the test case information and the test case invoker
0104      *
0105      * Does not own either, and is specifically made to be cheap
0106      * to copy around.
0107      */
0108     class TestCaseHandle {
0109         TestCaseInfo* m_info;
0110         ITestInvoker* m_invoker;
0111     public:
0112         TestCaseHandle(TestCaseInfo* info, ITestInvoker* invoker) :
0113             m_info(info), m_invoker(invoker) {}
0114 
0115         void invoke() const {
0116             m_invoker->invoke();
0117         }
0118 
0119         TestCaseInfo const& getTestCaseInfo() const;
0120     };
0121 
0122     Detail::unique_ptr<TestCaseInfo>
0123     makeTestCaseInfo( StringRef className,
0124                       NameAndTags const& nameAndTags,
0125                       SourceLineInfo const& lineInfo );
0126 }
0127 
0128 #ifdef __clang__
0129 #pragma clang diagnostic pop
0130 #endif
0131 
0132 #endif // CATCH_TEST_CASE_INFO_HPP_INCLUDED