]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | // |
b32b8144 | 2 | // Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com) |
7c673cae FG |
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 | // | |
b32b8144 FG |
7 | // Official repository: https://github.com/boostorg/beast |
8 | // | |
7c673cae | 9 | |
b32b8144 FG |
10 | #ifndef BOOST_BEAST_UNIT_TEST_SUITE_INFO_HPP |
11 | #define BOOST_BEAST_UNIT_TEST_SUITE_INFO_HPP | |
7c673cae FG |
12 | |
13 | #include <cstring> | |
14 | #include <functional> | |
15 | #include <string> | |
16 | #include <utility> | |
17 | ||
b32b8144 | 18 | namespace boost { |
7c673cae FG |
19 | namespace beast { |
20 | namespace unit_test { | |
21 | ||
22 | class runner; | |
23 | ||
24 | /** Associates a unit test type with metadata. */ | |
25 | class suite_info | |
26 | { | |
27 | using run_type = std::function<void(runner&)>; | |
28 | ||
29 | std::string name_; | |
30 | std::string module_; | |
31 | std::string library_; | |
32 | bool manual_; | |
33 | run_type run_; | |
34 | ||
35 | public: | |
36 | suite_info( | |
37 | std::string name, | |
38 | std::string module, | |
39 | std::string library, | |
40 | bool manual, | |
41 | run_type run) | |
42 | : name_(std::move(name)) | |
43 | , module_(std::move(module)) | |
44 | , library_(std::move(library)) | |
45 | , manual_(manual) | |
46 | , run_(std::move(run)) | |
47 | { | |
48 | } | |
49 | ||
50 | std::string const& | |
51 | name() const | |
52 | { | |
53 | return name_; | |
54 | } | |
55 | ||
56 | std::string const& | |
57 | module() const | |
58 | { | |
59 | return module_; | |
60 | } | |
61 | ||
62 | std::string const& | |
63 | library() const | |
64 | { | |
65 | return library_; | |
66 | } | |
67 | ||
68 | /// Returns `true` if this suite only runs manually. | |
69 | bool | |
70 | manual() const | |
71 | { | |
72 | return manual_; | |
73 | } | |
74 | ||
75 | /// Return the canonical suite name as a string. | |
76 | std::string | |
77 | full_name() const | |
78 | { | |
79 | return library_ + "." + module_ + "." + name_; | |
80 | } | |
81 | ||
82 | /// Run a new instance of the associated test suite. | |
83 | void | |
84 | run(runner& r) const | |
85 | { | |
86 | run_(r); | |
87 | } | |
88 | ||
89 | friend | |
90 | bool | |
91 | operator<(suite_info const& lhs, suite_info const& rhs) | |
92 | { | |
93 | return | |
94 | std::tie(lhs.library_, lhs.module_, lhs.name_) < | |
95 | std::tie(rhs.library_, rhs.module_, rhs.name_); | |
96 | } | |
97 | }; | |
98 | ||
99 | //------------------------------------------------------------------------------ | |
100 | ||
101 | /// Convenience for producing suite_info for a given test type. | |
102 | template<class Suite> | |
103 | suite_info | |
104 | make_suite_info( | |
105 | std::string name, | |
106 | std::string module, | |
107 | std::string library, | |
108 | bool manual) | |
109 | { | |
110 | return suite_info( | |
111 | std::move(name), | |
112 | std::move(module), | |
113 | std::move(library), | |
114 | manual, | |
115 | [](runner& r) | |
116 | { | |
117 | Suite{}(r); | |
118 | } | |
119 | ); | |
120 | } | |
121 | ||
122 | } // unit_test | |
123 | } // beast | |
b32b8144 | 124 | } // boost |
7c673cae FG |
125 | |
126 | #endif |