xrpld
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#include <utility>
11
12namespace beast::unit_test {
13
14// Predicate for implementing matches
16{
17public:
18 enum class ModeT {
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)
36 };
37
38private:
42
43public:
44 template <class = void>
45 explicit Selector(ModeT mode, std::string pattern = "");
46
47 template <class = void>
48 bool
49 operator()(SuiteInfo const& s);
50};
51
52//------------------------------------------------------------------------------
53
54template <class>
55Selector::Selector(ModeT mode, std::string pattern) : mode_(mode), pat_(std::move(pattern))
56{
57 if (mode_ == ModeT::Automatch && pat_.empty())
59}
60
61template <class>
62bool
64{
65 switch (mode_)
66 {
68 // suite or full name
69 if (s.name() == pat_ || s.fullName() == pat_)
70 {
72 return true;
73 }
74
75 // check module
76 if (pat_ == s.module())
77 {
79 library_ = s.library();
80 return !s.manual();
81 }
82
83 // check library
84 if (pat_ == s.library())
85 {
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 ModeT::Suite:
101 return pat_ == s.name();
102
103 case ModeT::Module:
104 return pat_ == s.module() && !s.manual();
105
106 case ModeT::Library:
107 return pat_ == s.library() && !s.manual();
108
109 case ModeT::None:
110 return false;
111
112 case ModeT::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{
143}
144
148inline Selector
150{
152}
153
157inline Selector
159{
160 return Selector(Selector::ModeT::Suite, name);
161}
162
166inline Selector
168{
170}
171
172} // namespace beast::unit_test
std::string library_
Definition match.h:41
bool operator()(SuiteInfo const &s)
Definition match.h:63
Selector(ModeT mode, std::string pattern="")
Definition match.h:55
Associates a unit test type with metadata.
Definition suite_info.h:20
std::string const & library() const
Definition suite_info.h:60
std::string const & name() const
Definition suite_info.h:48
std::string fullName() const
Return the canonical suite name as a string.
Definition suite_info.h:78
bool manual() const
Returns true if this suite only runs manually.
Definition suite_info.h:69
std::string const & module() const
Definition suite_info.h:54
A testsuite class.
Definition suite.h:52
Selector matchSuite(std::string const &name)
Returns a predicate that matches a specific suite.
Definition match.h:158
Selector matchAuto(std::string const &name)
Returns a predicate that implements a smart matching rule.
Definition match.h:140
Selector matchLibrary(std::string const &name)
Returns a predicate that matches all suites in a library.
Definition match.h:167
Selector matchAll()
Return a predicate that matches all suites not marked manual.
Definition match.h:149
STL namespace.
T starts_with(T... args)