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#pragma once
6
7#include <xrpl/beast/unit_test/suite_info.h>
8
9#include <string>
10
11namespace beast {
12namespace unit_test {
13
14// Predicate for implementing matches
16{
17public:
18 enum mode_t {
19 // Run all tests except manual ones
21
22 // Run tests that match in any field
24
25 // Match on suite
27
28 // Match on library
30
31 // Match on module (used internally)
33
34 // Match nothing (used internally)
35 none
36 };
37
38private:
42
43public:
44 template <class = void>
45 explicit selector(mode_t mode, std::string const& pattern = "");
46
47 template <class = void>
48 bool
49 operator()(suite_info const& s);
50};
51
52//------------------------------------------------------------------------------
53
54template <class>
55selector::selector(mode_t mode, std::string const& pattern) : mode_(mode), pat_(pattern)
56{
57 if (mode_ == automatch && pattern.empty())
58 mode_ = all;
59}
60
61template <class>
62bool
64{
65 switch (mode_)
66 {
67 case automatch:
68 // suite or full name
69 if (s.name() == pat_ || s.full_name() == pat_)
70 {
71 mode_ = none;
72 return true;
73 }
74
75 // check module
76 if (pat_ == s.module())
77 {
78 mode_ = module;
79 library_ = s.library();
80 return !s.manual();
81 }
82
83 // check library
84 if (pat_ == s.library())
85 {
86 mode_ = library;
87 return !s.manual();
88 }
89
90 // check start of name
92 {
93 // Don't change the mode so that the partial pattern can match
94 // more than once
95 return !s.manual();
96 }
97
98 return false;
99
100 case suite:
101 return pat_ == s.name();
102
103 case module:
104 return pat_ == s.module() && !s.manual();
105
106 case library:
107 return pat_ == s.library() && !s.manual();
108
109 case none:
110 return false;
111
112 case all:
113 default:
114 break;
115 };
116
117 return !s.manual();
118}
119
120//------------------------------------------------------------------------------
121
122// Utility functions for producing predicates to select suites.
123
139inline selector
141{
142 return selector(selector::automatch, name);
143}
144
146inline selector
148{
149 return selector(selector::all);
150}
151
153inline selector
155{
156 return selector(selector::suite, name);
157}
158
160inline selector
162{
163 return selector(selector::library, name);
164}
165
166} // namespace unit_test
167} // namespace beast
std::string library_
Definition match.h:41
selector(mode_t mode, std::string const &pattern="")
Definition match.h:55
bool operator()(suite_info const &s)
Definition match.h:63
Associates a unit test type with metadata.
Definition suite_info.h:19
std::string full_name() const
Return the canonical suite name as a string.
Definition suite_info.h:67
bool manual() const
Returns true if this suite only runs manually.
Definition suite_info.h:60
std::string const & library() const
Definition suite_info.h:53
std::string const & module() const
Definition suite_info.h:47
std::string const & name() const
Definition suite_info.h:41
T empty(T... args)
selector match_auto(std::string const &name)
Returns a predicate that implements a smart matching rule.
Definition match.h:140
selector match_all()
Return a predicate that matches all suites not marked manual.
Definition match.h:147
selector match_suite(std::string const &name)
Returns a predicate that matches a specific suite.
Definition match.h:154
selector match_library(std::string const &name)
Returns a predicate that matches all suites in a library.
Definition match.h:161
T starts_with(T... args)