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