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 <functional>
8#include <string>
9#include <tuple>
10#include <utility>
11
12namespace beast::unit_test {
13
14class Runner;
15
20{
21 using run_type = std::function<void(Runner&)>;
22
26 bool manual_;
29
30public:
35 bool manual,
36 int priority,
38 : name_(std::move(name))
39 , module_(std::move(module))
40 , library_(std::move(library))
42 , priority_(priority)
43 , run_(std::move(run))
44 {
45 }
46
47 [[nodiscard]] std::string const&
48 name() const
49 {
50 return name_;
51 }
52
53 [[nodiscard]] std::string const&
54 module() const
55 {
56 return module_;
57 }
58
59 [[nodiscard]] std::string const&
60 library() const
61 {
62 return library_;
63 }
64
68 [[nodiscard]] bool
69 manual() const
70 {
71 return manual_;
72 }
73
77 [[nodiscard]] std::string
78 fullName() const
79 {
80 return library_ + "." + module_ + "." + name_;
81 }
82
86 void
87 run(Runner& r) const
88 {
89 run_(r);
90 }
91
92 friend bool
93 operator<(SuiteInfo const& lhs, SuiteInfo const& rhs)
94 {
95 // we want higher priority suites sorted first, thus the negation
96 // of priority value here
97 return std::forward_as_tuple(-lhs.priority_, lhs.library_, lhs.module_, lhs.name_) <
99 }
100};
101
102//------------------------------------------------------------------------------
103
107template <class Suite>
108SuiteInfo
109makeSuiteInfo(std::string name, std::string module, std::string library, bool manual, int priority)
110{
111 return SuiteInfo(
112 std::move(name), std::move(module), std::move(library), manual, priority, [](Runner& r) {
113 Suite{}(r);
114 });
115}
116
117} // namespace beast::unit_test
Unit test runner interface.
Definition runner.h:23
Associates a unit test type with metadata.
Definition suite_info.h:20
std::string const & library() const
Definition suite_info.h:60
std::function< void(Runner &)> run_type
Definition suite_info.h:21
friend bool operator<(SuiteInfo const &lhs, SuiteInfo const &rhs)
Definition suite_info.h:93
std::string const & name() const
Definition suite_info.h:48
std::string fullName() const
Return the canonical suite name as a string.
Definition suite_info.h:78
void run(Runner &r) const
Run a new instance of the associated test suite.
Definition suite_info.h:87
bool manual() const
Returns true if this suite only runs manually.
Definition suite_info.h:69
SuiteInfo(std::string name, std::string module, std::string library, bool manual, int priority, run_type run)
Definition suite_info.h:31
std::string const & module() const
Definition suite_info.h:54
A testsuite class.
Definition suite.h:52
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:109
STL namespace.