Specs
Beautiful C++ Test Framework
Loading...
Searching...
No Matches
SpecDebugReporter.h
Go to the documentation of this file.
1#pragma once
2
3#include <Specs/API.h>
4#include <_Log_.h>
5#include <string_format.h>
6
8
9namespace SpecsCpp {
10
12 void report_start() override {}
13
14 void report_suite_begin(unsigned int specCount) override {}
15
16 void report_test_begin(ISpecGroup*, ISpec* spec) override {}
17
18 void report_setup(ISpecRunResult* result) override {}
19
20 void report_test(ISpecRunResult* result) override {}
21
22 void report_teardown(ISpecRunResult* result) override {}
23
24 void report_test_result(ISpecRunResult* result) override {
25 auto fullDescription = string_format(
26 "{} > {}", result->group()->full_description(), result->spec()->description()
27 );
28 if (!result->group()) fullDescription = result->spec()->description();
29
30 switch (result->status()) {
33 string_format("\n[PASSED] {}\n", fullDescription), Colors::Color::Green
34 );
35 break;
38 string_format("\n[FAILED] {}\n", fullDescription), Colors::Color::Red
39 );
40 if (auto* message = result->message())
42 string_format("\n{}\n", message), Colors::Color::DarkGray
43 );
44 break;
47 string_format("\n[NOT RUN] {}\n", fullDescription), Colors::Color::Yellow
48 );
49 break;
52 string_format("\n[TIMEOUT] {}\n", fullDescription), Colors::Color::LightRed
53 );
54 break;
55 }
56 }
57
58 void report_suite_result(ISpecSuiteRunResult* result) override {
59 Colors::Color foregroundColor = Colors::Color::White;
60 Colors::Color backgroundColor = Colors::Color::Yellow;
61
62 if (result->passed() > 0) backgroundColor = Colors::Color::Green;
63 if (result->failed() > 0) backgroundColor = Colors::Color::Red;
64
65 std::string output;
66
67 if (result->failed() > 0) output += string_format("{} failed", result->failed());
68
69 if (result->passed() > 0) {
70 if (!output.empty()) output += ", ";
71 output += string_format("{} passed", result->passed());
72 }
73
74 if (result->not_run() > 0) {
75 if (!output.empty()) output += ", ";
76 output += string_format("{} not run", result->not_run());
77 }
78
79 Colors::PrintColor(string_format("\n{}\n", output), foregroundColor, backgroundColor);
80 }
81 };
82}
void PrintColor(std::string_view text, Color foreground=Color::None, Color background=Color::None, Unix::Style style=Unix::Style::Normal)
Definition PrintColor.h:86
Definition API.h:3
virtual const char * full_description() const =0
virtual const char * description() const =0
virtual RunResultStatus status() const =0
virtual ISpecGroup * group() const =0
virtual ISpec * spec() const =0
virtual const char * message() const =0
virtual std::uint32_t not_run() const =0
virtual std::uint32_t failed() const =0
virtual std::uint32_t passed() const =0