xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
include
xrpl
beast
unit_test
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
12
namespace
beast::unit_test
{
13
14
// Predicate for implementing matches
15
class
Selector
16
{
17
public
:
18
enum class
ModeT
{
19
// Run all tests except manual ones
20
All
,
21
22
// Run tests that match in any field
23
Automatch
,
24
25
// Match on suite
26
Suite
,
27
28
// Match on library
29
Library
,
30
31
// Match on module (used internally)
32
Module
,
33
34
// Match nothing (used internally)
35
None
36
};
37
38
private
:
39
ModeT
mode_
;
40
std::string
pat_
;
41
std::string
library_
;
42
43
public
:
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
54
template
<
class
>
55
Selector::Selector
(
ModeT
mode,
std::string
pattern) :
mode_
(mode),
pat_
(
std
::move(pattern))
56
{
57
if
(
mode_
==
ModeT::Automatch
&&
pat_
.empty())
58
mode_
=
ModeT::All
;
59
}
60
61
template
<
class
>
62
bool
63
Selector::operator()
(
SuiteInfo
const
& s)
64
{
65
switch
(
mode_
)
66
{
67
case
ModeT::Automatch
:
68
// suite or full name
69
if
(s.
name
() ==
pat_
|| s.
fullName
() ==
pat_
)
70
{
71
mode_
=
ModeT::None
;
72
return
true
;
73
}
74
75
// check module
76
if
(
pat_
== s.
module
())
77
{
78
mode_
=
ModeT::Module
;
79
library_
= s.
library
();
80
return
!s.
manual
();
81
}
82
83
// check library
84
if
(
pat_
== s.
library
())
85
{
86
mode_
=
ModeT::Library
;
87
return
!s.
manual
();
88
}
89
90
// check start of name
91
if
(s.
name
().
starts_with
(
pat_
) || s.
fullName
().
starts_with
(
pat_
))
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
139
inline
Selector
140
matchAuto
(
std::string
const
& name)
141
{
142
return
Selector
(
Selector::ModeT::Automatch
, name);
143
}
144
148
inline
Selector
149
matchAll
()
150
{
151
return
Selector
(
Selector::ModeT::All
);
152
}
153
157
inline
Selector
158
matchSuite
(
std::string
const
& name)
159
{
160
return
Selector
(
Selector::ModeT::Suite
, name);
161
}
162
166
inline
Selector
167
matchLibrary
(
std::string
const
& name)
168
{
169
return
Selector
(
Selector::ModeT::Library
, name);
170
}
171
172
}
// namespace beast::unit_test
std::string
beast::unit_test::Selector
Definition
match.h:16
beast::unit_test::Selector::ModeT
ModeT
Definition
match.h:18
beast::unit_test::Selector::ModeT::Library
@ Library
Definition
match.h:29
beast::unit_test::Selector::ModeT::Suite
@ Suite
Definition
match.h:26
beast::unit_test::Selector::ModeT::None
@ None
Definition
match.h:35
beast::unit_test::Selector::ModeT::All
@ All
Definition
match.h:20
beast::unit_test::Selector::ModeT::Automatch
@ Automatch
Definition
match.h:23
beast::unit_test::Selector::ModeT::Module
@ Module
Definition
match.h:32
beast::unit_test::Selector::library_
std::string library_
Definition
match.h:41
beast::unit_test::Selector::pat_
std::string pat_
Definition
match.h:40
beast::unit_test::Selector::operator()
bool operator()(SuiteInfo const &s)
Definition
match.h:63
beast::unit_test::Selector::Selector
Selector(ModeT mode, std::string pattern="")
Definition
match.h:55
beast::unit_test::Selector::mode_
ModeT mode_
Definition
match.h:39
beast::unit_test::SuiteInfo
Associates a unit test type with metadata.
Definition
suite_info.h:20
beast::unit_test::SuiteInfo::library
std::string const & library() const
Definition
suite_info.h:60
beast::unit_test::SuiteInfo::name
std::string const & name() const
Definition
suite_info.h:48
beast::unit_test::SuiteInfo::fullName
std::string fullName() const
Return the canonical suite name as a string.
Definition
suite_info.h:78
beast::unit_test::SuiteInfo::manual
bool manual() const
Returns true if this suite only runs manually.
Definition
suite_info.h:69
beast::unit_test::SuiteInfo::module
std::string const & module() const
Definition
suite_info.h:54
beast::unit_test::Suite
A testsuite class.
Definition
suite.h:52
beast::unit_test
Definition
include/xrpl/beast/unit_test/amount.h:11
beast::unit_test::matchSuite
Selector matchSuite(std::string const &name)
Returns a predicate that matches a specific suite.
Definition
match.h:158
beast::unit_test::matchAuto
Selector matchAuto(std::string const &name)
Returns a predicate that implements a smart matching rule.
Definition
match.h:140
beast::unit_test::matchLibrary
Selector matchLibrary(std::string const &name)
Returns a predicate that matches all suites in a library.
Definition
match.h:167
beast::unit_test::matchAll
Selector matchAll()
Return a predicate that matches all suites not marked manual.
Definition
match.h:149
std
STL namespace.
std::string::starts_with
T starts_with(T... args)
string
utility
Generated by
1.17.0