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