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
#include "crucible/testing/console_reporter.hpp" #include <iostream> namespace crucible::testing::console_reporter { namespace { constexpr char const MIDLINE[] = "─────"; constexpr char const BULLET[] = "•"; constexpr char const SEPARATOR[] = "/"; constexpr char const BEGIN_SUITE[] = "BEGIN SUITE"; constexpr char const EMPTY_SUITE[] = "No tests defined!"; constexpr char const PASS[] = "PASS"; constexpr char const FAIL[] = "FAIL"; 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 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_WHITE[] = "\x1b[1;37m"; 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; } } } ConsoleReporter::~ConsoleReporter() = default; auto ConsoleReporter::handle_empty_suite() -> void { std::cout << BRIGHT_YELLOW << EMPTY_SUITE << RESET << "\n"; } auto ConsoleReporter::handle_suite_start() -> void { std::cout << BRIGHT_WHITE << MIDLINE << RESET << " " << BRIGHT_WHITE << BEGIN_SUITE << RESET << " " << BRIGHT_WHITE << MIDLINE << RESET << "\n\n"; } auto ConsoleReporter::handle_suite_end(std::size_t const pass_count, std::size_t const fail_count, std::size_t fixture_count) -> void { std::cout << "\n" << BRIGHT_WHITE << MIDLINE << RESET << " " << BRIGHT_GREEN << pass_count << " " << PASS << RESET << " " << BRIGHT_WHITE << SEPARATOR << RESET << " " << BRIGHT_RED << fail_count << " " << FAIL << RESET << " " << BRIGHT_WHITE << SEPARATOR << RESET << " " << BRIGHT_BLUE << fixture_count << " " << FIXTURE << RESET << " " << BRIGHT_WHITE << MIDLINE << RESET << "\n"; } auto ConsoleReporter::handle_scenario_start(scenario::Scenario const &scenario) -> void { static_cast<void>(scenario); } auto ConsoleReporter::handle_scenario_end(scenario::Scenario const &scenario, outcome::Outcome const &outcome) -> void { std::cout << BULLET << " " << get_outcome_color(outcome) << get_outcome_keyword(outcome) << RESET << " " << scenario.get_name() << "\n"; if (outcome.failed()) { std::cout << " " << BULLET << " " << YELLOW << outcome.get_details() << RESET << "\n"; } } auto ConsoleReporter::handle_fixture_start(fixture::Fixture const &fixture) -> void { static_cast<void>(fixture); } 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 << BULLET << " " << BLUE << FIXTURE << RESET << " " << fixture.get_name() << " [" << BLUE << fixture.get_variant_name() << RESET << "]\n"; if (outcome.failed()) { std::cout << " " << BULLET << " " << YELLOW << outcome.get_details() << RESET << "\n"; } } auto ConsoleReporter::set_show_fixtures(bool const show_fixtures) -> void { my_show_fixtures = show_fixtures; } }