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