xrpld
Loading...
Searching...
No Matches
suite_info.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 <cstring>
8#include <functional>
9#include <string>
10#include <utility>
11
12namespace beast::unit_test {
13
14class Runner;
15
18{
19 using run_type = std::function<void(Runner&)>;
20
24 bool manual_;
27
28public:
33 bool manual,
34 int priority,
36 : name_(std::move(name))
37 , module_(std::move(module))
38 , library_(std::move(library))
40 , priority_(priority)
41 , run_(std::move(run))
42 {
43 }
44
45 [[nodiscard]] std::string const&
46 name() const
47 {
48 return name_;
49 }
50
51 [[nodiscard]] std::string const&
52 module() const
53 {
54 return module_;
55 }
56
57 [[nodiscard]] std::string const&
58 library() const
59 {
60 return library_;
61 }
62
64 [[nodiscard]] bool
65 manual() const
66 {
67 return manual_;
68 }
69
71 [[nodiscard]] std::string
72 fullName() const
73 {
74 return library_ + "." + module_ + "." + name_;
75 }
76
78 void
79 run(Runner& r) const
80 {
81 run_(r);
82 }
83
84 friend bool
85 operator<(SuiteInfo const& lhs, SuiteInfo const& rhs)
86 {
87 // we want higher priority suites sorted first, thus the negation
88 // of priority value here
89 return std::forward_as_tuple(-lhs.priority_, lhs.library_, lhs.module_, lhs.name_) <
91 }
92};
93
94//------------------------------------------------------------------------------
95
97template <class Suite>
98SuiteInfo
99makeSuiteInfo(std::string name, std::string module, std::string library, bool manual, int priority)
100{
101 return SuiteInfo(
102 std::move(name), std::move(module), std::move(library), manual, priority, [](Runner& r) {
103 Suite{}(r);
104 });
105}
106
107} // namespace beast::unit_test
Unit test runner interface.
Definition runner.h:22
Associates a unit test type with metadata.
Definition suite_info.h:18
std::string const & library() const
Definition suite_info.h:58
std::function< void(Runner &)> run_type
Definition suite_info.h:19
friend bool operator<(SuiteInfo const &lhs, SuiteInfo const &rhs)
Definition suite_info.h:85
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
void run(Runner &r) const
Run a new instance of the associated test suite.
Definition suite_info.h:79
bool manual() const
Returns true if this suite only runs manually.
Definition suite_info.h:65
SuiteInfo(std::string name, std::string module, std::string library, bool manual, int priority, run_type run)
Definition suite_info.h:29
std::string const & module() const
Definition suite_info.h:52
A testsuite class.
Definition suite.h:50
T forward_as_tuple(T... args)
SuiteInfo makeSuiteInfo(std::string name, std::string module, std::string library, bool manual, int priority)
Convenience for producing SuiteInfo for a given test type.
Definition suite_info.h:99
STL namespace.