9#include <source_location>
20class Description :
public Runnable {
21 using VoidBlock = std::function<void()>;
24 using Block = std::function<void(Description&)>;
26 std::forward_list<LetBase*> lets;
27 std::deque<VoidBlock> after_alls;
28 std::deque<VoidBlock> before_eaches;
29 std::deque<VoidBlock> after_eaches;
35 std::string description;
37 void exec_before_eaches();
38 void exec_after_eaches();
42 Description(
const char* description,
44 std::source_location location = std::source_location::current()) noexcept
45 : Runnable(location), block(std::move(block)), description(description) {
46 this->set_location(location);
49 Description(std::source_location location, std::string&& description) noexcept
50 : Runnable(location), description(std::move(description)) {}
52 Description(std::source_location location,
const char* description, Block block) noexcept
53 : Runnable(location), block(std::move(block)), description(description) {}
57 ItD& it(
const char* name, ItD::Block body, std::source_location location = std::source_location::current());
58 ItD& it(ItD::Block body, std::source_location location = std::source_location::current());
62 template <
class T = std::
nullptr_t>
63 Description& context(
const char* description,
65 std::source_location location = std::source_location::current());
67 template <Util::not_c_
string T,
class B>
68 ClassDescription<T>& context(T& subject, B block, std::source_location location = std::source_location::current());
70 template <
class T,
class B>
74 std::source_location location = std::source_location::current());
76 template <Util::not_c_
string T,
class B>
77 ClassDescription<T>& context(T&& subject, B block, std::source_location location = std::source_location::current());
79 template <
class T,
class B>
83 std::source_location location = std::source_location::current());
85 template <
class T,
typename U>
88 std::source_location location = std::source_location::current());
92 void before_each(VoidBlock block);
93 void before_all(VoidBlock block);
94 void after_each(VoidBlock block);
95 void after_all(VoidBlock block);
100 auto let(T body) ->
Let<
decltype(body())>;
101 void reset_lets()
noexcept;
105 [[nodiscard]]
virtual std::string get_description()
const noexcept {
return description; }
106 [[nodiscard]]
virtual std::string get_subject_type()
const noexcept {
return ""; }
112 template <
typename Formatter>
113 inline auto as_main();
122inline ItD& Description::it(
const char* description, ItD::Block block, std::source_location location) {
123 auto* it = this->make_child<ItD>(location, description, block);
126 exec_before_eaches();
130inline ItD& Description::it(ItD::Block block, std::source_location location) {
131 auto* it = this->make_child<ItD>(location, block);
134 exec_before_eaches();
141inline Context& Description::context(
const char* description, Block body, std::source_location location) {
142 auto* context = this->make_child<Context>(location, description, body);
143 context->before_eaches = this->before_eaches;
144 context->after_eaches = this->after_eaches;
145 context->timed_run();
151inline void Description::before_each(VoidBlock b) {
152 before_eaches.push_back(b);
163inline void Description::before_all(VoidBlock b) {
167inline void Description::after_each(VoidBlock b) {
168 after_eaches.push_back(b);
171inline void Description::after_all(VoidBlock b) {
172 after_alls.push_back(b);
177inline void Description::exec_before_eaches() {
178 for (VoidBlock& b : before_eaches) {
183inline void Description::exec_after_eaches() {
184 for (VoidBlock& b : after_eaches) {
206 Let<
decltype(block())>
let(block);
207 lets.push_front(&
let);
212inline void Description::reset_lets() noexcept {
214 for (
auto& let : lets) {
220 this->get_parent_as<Description>()->reset_lets();
226inline void Description::run() {
228 for (VoidBlock& a : after_alls) {
237inline void ItD::run() {
239 this->get_parent_as<Description>()->reset_lets();
A Description with a defined subject.
Definition class_description.hpp:22
Definition description.hpp:20
auto let(T body) -> Let< decltype(body())>
Object generator for Let.
Definition description.hpp:199
An it embedded in a Description.
Definition it.hpp:27
A container that memoizes the result of a block in `it's.
Definition let.hpp:34
bool has_parent() noexcept
Check to see if the Runnable has a parent.
Definition runnable.hpp:56