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
11namespace beast::unit_test {
12
13// Predicate for implementing matches
15{
16public:
17 enum class ModeT {
18 // Run all tests except manual ones
20
21 // Run tests that match in any field
23
24 // Match on suite
26
27 // Match on library
29
30 // Match on module (used internally)
32
33 // Match nothing (used internally)
35 };
36
37private:
41
42public:
43 template <class = void>
44 explicit Selector(ModeT mode, std::string pattern = "");
45
46 template <class = void>
47 bool
48 operator()(SuiteInfo const& s);
49};
50
51//------------------------------------------------------------------------------
52
53template <class>
54Selector::Selector(ModeT mode, std::string pattern) : mode_(mode), pat_(std::move(pattern))
55{
56 if (mode_ == ModeT::Automatch && pat_.empty())
58}
59
60template <class>
61bool
63{
64 switch (mode_)
65 {
67 // suite or full name
68 if (s.name() == pat_ || s.fullName() == pat_)
69 {
71 return true;
72 }
73
74 // check module
75 if (pat_ == s.module())
76 {
78 library_ = s.library();
79 return !s.manual();
80 }
81
82 // check library
83 if (pat_ == s.library())
84 {
86 return !s.manual();
87 }
88
89 // check start of name
91 {
92 // Don't change the mode so that the partial pattern can match
93 // more than once
94 return !s.manual();
95 }
96
97 return false;
98
99 case ModeT::Suite:
100 return pat_ == s.name();
101
102 case ModeT::Module:
103 return pat_ == s.module() && !s.manual();
104
105 case ModeT::Library:
106 return pat_ == s.library() && !s.manual();
107
108 case ModeT::None:
109 return false;
110
111 case ModeT::All:
112 default:
113 break;
114 };
115
116 return !s.manual();
117}
118
119//------------------------------------------------------------------------------
120
121// Utility functions for producing predicates to select suites.
122
138inline Selector
140{
142}
143
145inline Selector
147{
149}
150
152inline Selector
154{
155 return Selector(Selector::ModeT::Suite, name);
156}
157
159inline Selector
161{
163}
164
165} // namespace beast::unit_test
std::string library_
Definition match.h:40
bool operator()(SuiteInfo const &s)
Definition match.h:62
Selector(ModeT mode, std::string pattern="")
Definition match.h:54
Associates a unit test type with metadata.
Definition suite_info.h:18
std::string const & library() const
Definition suite_info.h:58
std::string const & name() const
Definition suite_info.h:46
std::string fullName() const
Return the canonical suite name as a string.
Definition suite_info.h:72
bool manual() const
Returns true if this suite only runs manually.
Definition suite_info.h:65
std::string const & module() const
Definition suite_info.h:52
A testsuite class.
Definition suite.h:50
Selector matchSuite(std::string const &name)
Returns a predicate that matches a specific suite.
Definition match.h:153
Selector matchAuto(std::string const &name)
Returns a predicate that implements a smart matching rule.
Definition match.h:139
Selector matchLibrary(std::string const &name)
Returns a predicate that matches all suites in a library.
Definition match.h:160
Selector matchAll()
Return a predicate that matches all suites not marked manual.
Definition match.h:146
STL namespace.
T starts_with(T... args)