C++Spec 1.0.0
BDD testing for C++
Loading...
Searching...
No Matches
verbose.hpp
Go to the documentation of this file.
1
2#pragma once
3
4#include "formatters_base.hpp"
5#include "it_base.hpp"
6#include "term_colors.hpp"
7
8namespace CppSpec::Formatters {
9
10class Verbose : public BaseFormatter {
11 bool first = true;
12
13 public:
14 Verbose() = default;
15 explicit Verbose(std::ostream& out_stream) : BaseFormatter(out_stream) {}
16 Verbose(const BaseFormatter& base, std::ostream& out_stream) : BaseFormatter(base, out_stream) {}
17 explicit Verbose(const BaseFormatter& base) : BaseFormatter(base) {}
18
19 void format(const Description& description) override;
20 void format(const ItBase& it) override;
21};
22
23inline void Verbose::format(const Description& description) {
24 if (!first && !description.has_parent()) {
25 out_stream << std::endl;
26 }
27 out_stream << description.padding() << description.get_description() << description.get_subject_type() << std::endl;
28 if (first) {
29 this->first = false;
30 }
31}
32
33inline void Verbose::format(const ItBase& it) {
34 out_stream << status_color(it.get_result().status());
35 out_stream << it.padding() << it.get_description() << std::endl;
36 out_stream << reset_color();
37
38 // Print any failures if we've got them
39 // 'it' having a bad status necessarily
40 // implies that there are failure messages
41 for (const Result& result : it.get_results()) {
42 if (result.is_failure()) {
43 out_stream << set_color(RED);
44 out_stream << result.get_message() << std::endl;
45 out_stream << reset_color();
46 }
47 }
48
49 get_and_increment_test_counter();
50}
51
52static Verbose verbose;
53
54} // namespace CppSpec::Formatters
Definition description.hpp:20
Definition verbose.hpp:10
Base class for it expressions.
Definition it_base.hpp:32
std::string padding() const noexcept
Generate padding (indentation) fore the current object.
Definition runnable.hpp:154
bool has_parent() noexcept
Check to see if the Runnable has a parent.
Definition runnable.hpp:56