rippled
Loading...
Searching...
No Matches
match.h
1// Distributed under the Boost Software License, Version 1.0. (See accompanying
2// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
3//
4
5#ifndef BEAST_UNIT_TEST_MATCH_HPP
6#define BEAST_UNIT_TEST_MATCH_HPP
7
8#include <xrpl/beast/unit_test/suite_info.h>
9
10#include <string>
11
12namespace beast {
13namespace unit_test {
14
15// Predicate for implementing matches
17{
18public:
19 enum mode_t {
20 // Run all tests except manual ones
22
23 // Run tests that match in any field
25
26 // Match on suite
28
29 // Match on library
31
32 // Match on module (used internally)
34
35 // Match nothing (used internally)
36 none
37 };
38
39private:
43
44public:
45 template <class = void>
46 explicit selector(mode_t mode, std::string const& pattern = "");
47
48 template <class = void>
49 bool
50 operator()(suite_info const& s);
51};
52
53//------------------------------------------------------------------------------
54
55template <class>
57 : mode_(mode), pat_(pattern)
58{
59 if (mode_ == automatch && pattern.empty())
60 mode_ = all;
61}
62
63template <class>
64bool
66{
67 switch (mode_)
68 {
69 case automatch:
70 // suite or full name
71 if (s.name() == pat_ || s.full_name() == pat_)
72 {
73 mode_ = none;
74 return true;
75 }
76
77 // check module
78 if (pat_ == s.module())
79 {
80 mode_ = module;
81 library_ = s.library();
82 return !s.manual();
83 }
84
85 // check library
86 if (pat_ == s.library())
87 {
88 mode_ = library;
89 return !s.manual();
90 }
91
92 // check start of name
94 {
95 // Don't change the mode so that the partial pattern can match
96 // more than once
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 break;
117 };
118
119 return !s.manual();
120}
121
122//------------------------------------------------------------------------------
123
124// Utility functions for producing predicates to select suites.
125
141inline selector
143{
144 return selector(selector::automatch, name);
145}
146
148inline selector
150{
151 return selector(selector::all);
152}
153
155inline selector
157{
158 return selector(selector::suite, name);
159}
160
162inline selector
164{
165 return selector(selector::library, name);
166}
167
168} // namespace unit_test
169} // namespace beast
170
171#endif
std::string library_
Definition match.h:42
selector(mode_t mode, std::string const &pattern="")
Definition match.h:56
bool operator()(suite_info const &s)
Definition match.h:65
Associates a unit test type with metadata.
Definition suite_info.h:20
std::string full_name() const
Return the canonical suite name as a string.
Definition suite_info.h:74
bool manual() const
Returns true if this suite only runs manually.
Definition suite_info.h:67
std::string const & library() const
Definition suite_info.h:60
std::string const & module() const
Definition suite_info.h:54
std::string const & name() const
Definition suite_info.h:48
T empty(T... args)
selector match_auto(std::string const &name)
Returns a predicate that implements a smart matching rule.
Definition match.h:142
selector match_all()
Return a predicate that matches all suites not marked manual.
Definition match.h:149
selector match_suite(std::string const &name)
Returns a predicate that matches a specific suite.
Definition match.h:156
selector match_library(std::string const &name)
Returns a predicate that matches all suites in a library.
Definition match.h:163
T starts_with(T... args)