console_reporter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include "crucible/testing/console_reporter.hpp" #include <iostream> namespace crucible::testing::console_reporter { namespace { constexpr char const BULLET[] { "•" }; constexpr char const SEPARATOR[] { "/" }; constexpr char const EMPTY_SUITE[] { "No tests defined!" }; constexpr char const PASS[] { "✓ Pass" }; constexpr char const FAIL[] { "✖ Fail" }; constexpr char const GROUP[] { "# Group" }; constexpr char const SCENARIO[] { "✎ Scenario" }; constexpr char const FIXTURE[] { "⚙ Fixture" }; constexpr char const RED[] { "\x1b[31m" }; constexpr char const GREEN[] { "\x1b[32m" }; constexpr char const YELLOW[] { "\x1b[33m" }; constexpr char const BLUE[] { "\x1b[34m" }; constexpr char const MAGENTA[] { "\x1b[35m" }; constexpr char const CYAN[] { "\x1b[36m" }; constexpr char const BRIGHT_RED[] { "\x1b[1;31m" }; constexpr char const BRIGHT_GREEN[] { "\x1b[1;32m" }; constexpr char const BRIGHT_YELLOW[] { "\x1b[1;33m" }; constexpr char const BRIGHT_BLUE[] { "\x1b[1;34m" }; constexpr char const BRIGHT_CYAN[] { "\x1b[1;36m" }; constexpr char const RESET[] { "\x1b[0m" }; auto get_outcome_color(outcome::Outcome const &outcome) -> char const * { if (outcome.passed()) { return GREEN; } else { return RED; } } auto get_outcome_keyword(outcome::Outcome const &outcome) -> char const * { if (outcome.passed()) { return PASS; } else { return FAIL; } } auto replicate(std::string const &pattern, std::size_t const amount) -> std::string { std::string result {}; for (std::size_t i { 0 }; i < amount; ++i) { result += pattern; } return result; } auto get_indent(std::size_t const amount) -> std::string { return replicate(" ", amount); } } ConsoleReporter::~ConsoleReporter() = default; auto ConsoleReporter::handle_empty_suite() -> void { std::cout << BULLET << " " << BRIGHT_YELLOW << EMPTY_SUITE << RESET << "\n"; } auto ConsoleReporter::handle_suite_end(std::size_t const pass_count, std::size_t const fail_count, std::size_t const scenario_count, std::size_t fixture_count) -> void { std::cout << "\n" << BRIGHT_GREEN << PASS << " " << pass_count << RESET << " " << SEPARATOR << " " << BRIGHT_RED << FAIL << " " << fail_count << RESET << " " << SEPARATOR << " " << BRIGHT_CYAN << SCENARIO << " " << scenario_count << RESET << " " << SEPARATOR << " " << BRIGHT_BLUE << FIXTURE << " " << fixture_count << RESET << "\n"; } auto ConsoleReporter::handle_group_start(const std::string &group) -> void { std::cout << BULLET << " " << MAGENTA << GROUP << RESET << " " << group << "\n"; } auto ConsoleReporter::handle_scenario_end(scenario::Scenario const &scenario, outcome::Outcome const &outcome) -> void { std::cout << get_indent(2) << BULLET << " " << CYAN << SCENARIO << RESET << " " << scenario.get_name() << "\n"; std::cout << get_indent(4) << BULLET << " " << get_outcome_color(outcome) << get_outcome_keyword(outcome) << RESET << "\n"; if (outcome.failed()) { std::cout << get_indent(6) << BULLET << " " << YELLOW << outcome.get_details() << RESET << "\n"; } } auto ConsoleReporter::handle_fixture_end(fixture::Fixture const &fixture, outcome::Outcome const &outcome) -> void { if (not my_show_fixtures and outcome.passed()) { return; } std::cout << get_indent(2) << BULLET << " " << BLUE << FIXTURE << RESET << " " << fixture.get_name() << " [" << BLUE << fixture.get_variant_name() << RESET << "]\n"; std::cout << get_indent(4) << BULLET << " " << get_outcome_color(outcome) << get_outcome_keyword(outcome) << RESET << "\n"; if (outcome.failed()) { std::cout << get_indent(6) << BULLET << " " << YELLOW << outcome.get_details() << RESET << "\n"; } } auto ConsoleReporter::set_show_fixtures(bool const show_fixtures) -> void { my_show_fixtures = show_fixtures; } }