1 | #ifndef BANDIT_REPORTERS_SINGLE_LINE_REPORTER_H |
2 | #define BANDIT_REPORTERS_SINGLE_LINE_REPORTER_H |
3 | |
4 | #include <bandit/reporters/colored_reporter.h> |
5 | #include <bandit/reporters/test_run_summary.h> |
6 | |
7 | namespace bandit { |
8 | namespace detail { |
9 | struct single_line_reporter : public colored_reporter { |
10 | single_line_reporter(std::ostream& stm, const failure_formatter& failure_formatter, |
11 | const colorizer& colorizer) |
12 | : colored_reporter(stm, failure_formatter, colorizer) {} |
13 | |
14 | single_line_reporter(const failure_formatter& failure_formatter, |
15 | const colorizer& colorizer) |
16 | : single_line_reporter(std::cout, failure_formatter, colorizer) {} |
17 | |
18 | single_line_reporter& operator=(const single_line_reporter&) { |
19 | return *this; |
20 | } |
21 | |
22 | void test_run_complete() override { |
23 | progress_reporter::test_run_complete(); |
24 | |
25 | stm_ << std::endl; |
26 | |
27 | test_run_summary summary(specs_run_, specs_failed_, specs_succeeded_, specs_skipped_, failures_, |
28 | test_run_errors_, colorizer_); |
29 | summary.write(stm_); |
30 | } |
31 | |
32 | void test_run_error(const std::string& desc, const struct test_run_error& err) override { |
33 | progress_reporter::test_run_error(desc, err); |
34 | |
35 | std::stringstream ss; |
36 | ss << std::endl; |
37 | ss << "Failed to run \"" << current_context_name() << "\": error \"" << err.what() << "\"" << std::endl; |
38 | |
39 | test_run_errors_.push_back(ss.str()); |
40 | } |
41 | |
42 | void it_starting(const std::string& desc) override { |
43 | print_status_line(); |
44 | progress_reporter::it_starting(desc); |
45 | } |
46 | |
47 | void it_succeeded(const std::string& desc) override { |
48 | progress_reporter::it_succeeded(desc); |
49 | print_status_line(); |
50 | } |
51 | |
52 | void it_failed(const std::string& desc, const assertion_exception& ex) override { |
53 | progress_reporter::it_failed(desc, ex); |
54 | print_status_line(); |
55 | } |
56 | |
57 | void it_unknown_error(const std::string& desc) override { |
58 | progress_reporter::it_unknown_error(desc); |
59 | print_status_line(); |
60 | } |
61 | |
62 | private: |
63 | void print_status_line() { |
64 | stm_ << '\r'; |
65 | stm_ << "Executed " << specs_run_ << " tests." ; |
66 | |
67 | if (specs_failed_) { |
68 | stm_ |
69 | << " " << specs_succeeded_ << " succeeded. " |
70 | << colorizer_.red() << specs_failed_ << " failed." |
71 | << colorizer_.reset(); |
72 | } |
73 | stm_.flush(); |
74 | } |
75 | }; |
76 | } |
77 | } |
78 | #endif |
79 | |