1 /* 2 * Created by Phil on 14/8/2012. 3 * Copyright 2010 Two Blue Cubes Ltd. All rights reserved. 4 * 5 * Distributed under the Boost Software License, Version 1.0. (See accompanying 6 * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 */ 8 #ifndef TWOBLUECUBES_CATCH_TEST_SPEC_HPP_INCLUDED 9 #define TWOBLUECUBES_CATCH_TEST_SPEC_HPP_INCLUDED 10 11 #ifdef __clang__ 12 #pragma clang diagnostic push 13 #pragma clang diagnostic ignored "-Wpadded" 14 #endif 15 16 #include "catch_wildcard_pattern.h" 17 #include "catch_test_case_info.h" 18 19 #include <string> 20 #include <vector> 21 #include <memory> 22 23 namespace Catch { 24 25 struct IConfig; 26 27 class TestSpec { 28 class Pattern { 29 public: 30 explicit Pattern( std::string const& name ); 31 virtual ~Pattern(); 32 virtual bool matches( TestCaseInfo const& testCase ) const = 0; 33 std::string const& name() const; 34 private: 35 std::string const m_name; 36 }; 37 using PatternPtr = std::shared_ptr<Pattern>; 38 39 class NamePattern : public Pattern { 40 public: 41 explicit NamePattern( std::string const& name, std::string const& filterString ); 42 bool matches( TestCaseInfo const& testCase ) const override; 43 private: 44 WildcardPattern m_wildcardPattern; 45 }; 46 47 class TagPattern : public Pattern { 48 public: 49 explicit TagPattern( std::string const& tag, std::string const& filterString ); 50 bool matches( TestCaseInfo const& testCase ) const override; 51 private: 52 std::string m_tag; 53 }; 54 55 class ExcludedPattern : public Pattern { 56 public: 57 explicit ExcludedPattern( PatternPtr const& underlyingPattern ); 58 bool matches( TestCaseInfo const& testCase ) const override; 59 private: 60 PatternPtr m_underlyingPattern; 61 }; 62 63 struct Filter { 64 std::vector<PatternPtr> m_patterns; 65 66 bool matches( TestCaseInfo const& testCase ) const; 67 std::string name() const; 68 }; 69 70 public: 71 struct FilterMatch { 72 std::string name; 73 std::vector<TestCase const*> tests; 74 }; 75 using Matches = std::vector<FilterMatch>; 76 using vectorStrings = std::vector<std::string>; 77 78 bool hasFilters() const; 79 bool matches( TestCaseInfo const& testCase ) const; 80 Matches matchesByFilter( std::vector<TestCase> const& testCases, IConfig const& config ) const; 81 const vectorStrings & getInvalidArgs() const; 82 83 private: 84 std::vector<Filter> m_filters; 85 std::vector<std::string> m_invalidArgs; 86 friend class TestSpecParser; 87 }; 88 } 89 90 #ifdef __clang__ 91 #pragma clang diagnostic pop 92 #endif 93 94 #endif // TWOBLUECUBES_CATCH_TEST_SPEC_HPP_INCLUDED 95