]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/beast/subtree/unit_test/include/boost/beast/unit_test/match.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / beast / subtree / unit_test / include / boost / beast / unit_test / match.hpp
1 //
2 // Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // Official repository: https://github.com/boostorg/beast
8 //
9
10 #ifndef BOOST_BEAST_UNIT_TEST_MATCH_HPP
11 #define BOOST_BEAST_UNIT_TEST_MATCH_HPP
12
13 #include <boost/beast/unit_test/suite_info.hpp>
14 #include <string>
15
16 namespace boost {
17 namespace beast {
18 namespace unit_test {
19
20 // Predicate for implementing matches
21 class selector
22 {
23 public:
24 enum mode_t
25 {
26 // Run all tests except manual ones
27 all,
28
29 // Run tests that match in any field
30 automatch,
31
32 // Match on suite
33 suite,
34
35 // Match on library
36 library,
37
38 // Match on module (used internally)
39 module,
40
41 // Match nothing (used internally)
42 none
43 };
44
45 private:
46 mode_t mode_;
47 std::string pat_;
48 std::string library_;
49
50 public:
51 template<class = void>
52 explicit
53 selector(mode_t mode, std::string const& pattern = "");
54
55 template<class = void>
56 bool
57 operator()(suite_info const& s);
58 };
59
60 //------------------------------------------------------------------------------
61
62 template<class>
63 selector::selector(mode_t mode, std::string const& pattern)
64 : mode_(mode)
65 , pat_(pattern)
66 {
67 if(mode_ == automatch && pattern.empty())
68 mode_ = all;
69 }
70
71 template<class>
72 bool
73 selector::operator()(suite_info const& s)
74 {
75 switch(mode_)
76 {
77 case automatch:
78 // suite or full name
79 if(s.name() == pat_ || s.full_name() == pat_)
80 {
81 mode_ = none;
82 return true;
83 }
84
85 // check module
86 if(pat_ == s.module())
87 {
88 mode_ = module;
89 library_ = s.library();
90 return ! s.manual();
91 }
92
93 // check library
94 if(pat_ == s.library())
95 {
96 mode_ = library;
97 return ! s.manual();
98 }
99
100 return false;
101
102 case suite:
103 return pat_ == s.name();
104
105 case module:
106 return pat_ == s.module() && ! s.manual();
107
108 case library:
109 return pat_ == s.library() && ! s.manual();
110
111 case none:
112 return false;
113
114 case all:
115 default:
116 // fall through
117 break;
118 };
119
120 return ! s.manual();
121 }
122
123 //------------------------------------------------------------------------------
124
125 // Utility functions for producing predicates to select suites.
126
127 /** Returns a predicate that implements a smart matching rule.
128 The predicate checks the suite, module, and library fields of the
129 suite_info in that order. When it finds a match, it changes modes
130 depending on what was found:
131
132 If a suite is matched first, then only the suite is selected. The
133 suite may be marked manual.
134
135 If a module is matched first, then only suites from that module
136 and library not marked manual are selected from then on.
137
138 If a library is matched first, then only suites from that library
139 not marked manual are selected from then on.
140
141 */
142 inline
143 selector
144 match_auto(std::string const& name)
145 {
146 return selector(selector::automatch, name);
147 }
148
149 /** Return a predicate that matches all suites not marked manual. */
150 inline
151 selector
152 match_all()
153 {
154 return selector(selector::all);
155 }
156
157 /** Returns a predicate that matches a specific suite. */
158 inline
159 selector
160 match_suite(std::string const& name)
161 {
162 return selector(selector::suite, name);
163 }
164
165 /** Returns a predicate that matches all suites in a library. */
166 inline
167 selector
168 match_library(std::string const& name)
169 {
170 return selector(selector::library, name);
171 }
172
173 } // unit_test
174 } // beast
175 } // boost
176
177 #endif