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_SPEC_HPP_INCLUDED
0009 #define CATCH_TEST_SPEC_HPP_INCLUDED
0010 
0011 #ifdef __clang__
0012 #pragma clang diagnostic push
0013 #pragma clang diagnostic ignored "-Wpadded"
0014 #endif
0015 
0016 #include <catch2/internal/catch_unique_ptr.hpp>
0017 #include <catch2/internal/catch_wildcard_pattern.hpp>
0018 
0019 #include <iosfwd>
0020 #include <string>
0021 #include <vector>
0022 
0023 namespace Catch {
0024 
0025     class IConfig;
0026     struct TestCaseInfo;
0027     class TestCaseHandle;
0028 
0029     class TestSpec {
0030 
0031         class Pattern {
0032         public:
0033             explicit Pattern( std::string const& name );
0034             virtual ~Pattern();
0035             virtual bool matches( TestCaseInfo const& testCase ) const = 0;
0036             std::string const& name() const;
0037         private:
0038             virtual void serializeTo( std::ostream& out ) const = 0;
0039             // Writes string that would be reparsed into the pattern
0040             friend std::ostream& operator<<(std::ostream& out,
0041                                             Pattern const& pattern) {
0042                 pattern.serializeTo( out );
0043                 return out;
0044             }
0045 
0046             std::string const m_name;
0047         };
0048 
0049         class NamePattern : public Pattern {
0050         public:
0051             explicit NamePattern( std::string const& name, std::string const& filterString );
0052             bool matches( TestCaseInfo const& testCase ) const override;
0053         private:
0054             void serializeTo( std::ostream& out ) const override;
0055 
0056             WildcardPattern m_wildcardPattern;
0057         };
0058 
0059         class TagPattern : public Pattern {
0060         public:
0061             explicit TagPattern( std::string const& tag, std::string const& filterString );
0062             bool matches( TestCaseInfo const& testCase ) const override;
0063         private:
0064             void serializeTo( std::ostream& out ) const override;
0065 
0066             std::string m_tag;
0067         };
0068 
0069         struct Filter {
0070             std::vector<Detail::unique_ptr<Pattern>> m_required;
0071             std::vector<Detail::unique_ptr<Pattern>> m_forbidden;
0072 
0073             //! Serializes this filter into a string that would be parsed into
0074             //! an equivalent filter
0075             void serializeTo( std::ostream& out ) const;
0076             friend std::ostream& operator<<(std::ostream& out, Filter const& f) {
0077                 f.serializeTo( out );
0078                 return out;
0079             }
0080 
0081             bool matches( TestCaseInfo const& testCase ) const;
0082         };
0083 
0084         static std::string extractFilterName( Filter const& filter );
0085 
0086     public:
0087         struct FilterMatch {
0088             std::string name;
0089             std::vector<TestCaseHandle const*> tests;
0090         };
0091         using Matches = std::vector<FilterMatch>;
0092         using vectorStrings = std::vector<std::string>;
0093 
0094         bool hasFilters() const;
0095         bool matches( TestCaseInfo const& testCase ) const;
0096         Matches matchesByFilter( std::vector<TestCaseHandle> const& testCases, IConfig const& config ) const;
0097         const vectorStrings & getInvalidSpecs() const;
0098 
0099     private:
0100         std::vector<Filter> m_filters;
0101         std::vector<std::string> m_invalidSpecs;
0102 
0103         friend class TestSpecParser;
0104         //! Serializes this test spec into a string that would be parsed into
0105         //! equivalent test spec
0106         void serializeTo( std::ostream& out ) const;
0107         friend std::ostream& operator<<(std::ostream& out,
0108                                         TestSpec const& spec) {
0109             spec.serializeTo( out );
0110             return out;
0111         }
0112     };
0113 }
0114 
0115 #ifdef __clang__
0116 #pragma clang diagnostic pop
0117 #endif
0118 
0119 #endif // CATCH_TEST_SPEC_HPP_INCLUDED