1#ifndef BANDIT_CRASH_REPORTER_H
2#define BANDIT_CRASH_REPORTER_H
3
4#include <iostream>
5#include <vector>
6#include <bandit/reporters/progress_reporter.h>
7
8namespace bandit {
9 namespace detail {
10 struct crash_reporter : public progress_reporter {
11 crash_reporter(std::ostream& stm, const failure_formatter& failure_formatter)
12 : progress_reporter(failure_formatter), stm_(stm) {}
13
14 crash_reporter(const failure_formatter& failure_formatter)
15 : crash_reporter(std::cout, failure_formatter) {}
16
17 crash_reporter& operator=(const crash_reporter&) {
18 return *this;
19 }
20
21 void test_run_complete() override {
22 progress_reporter::test_run_complete();
23 for (auto failure : failures_) {
24 stm_ << std::endl
25 << "# FAILED " << failure;
26 }
27 for (auto error : test_run_errors_) {
28 stm_ << std::endl
29 << "# ERROR " << error;
30 }
31 stm_.flush();
32 }
33
34 void test_run_error(const std::string& desc, const struct test_run_error& err) override {
35 progress_reporter::test_run_error(desc, err);
36 std::stringstream ss;
37 ss << current_context_name() << ": " << desc << ": " << err.what() << std::endl;
38 test_run_errors_.push_back(ss.str());
39 }
40
41 void it_skip(const std::string& desc) override {
42 progress_reporter::it_skip(desc);
43 }
44
45 void it_starting(const std::string& desc) override {
46 progress_reporter::it_starting(desc);
47 for (auto context : contexts_) {
48 stm_ << context << " | ";
49 }
50 stm_ << desc << std::endl;
51 }
52
53 void it_succeeded(const std::string& desc) override {
54 progress_reporter::it_succeeded(desc);
55 }
56
57 void it_failed(const std::string& desc, const assertion_exception& ex) override {
58 ++specs_failed_;
59
60 std::stringstream ss;
61 ss << current_context_name() << " " << desc << ":" << std::endl
62 << failure_formatter_.format(ex);
63 failures_.push_back(ss.str());
64
65 stm_ << "FAILED" << std::endl;
66 }
67
68 void it_unknown_error(const std::string& desc) override {
69 ++specs_failed_;
70
71 std::stringstream ss;
72 ss << current_context_name() << " " << desc << ": Unknown exception" << std::endl;
73 failures_.push_back(ss.str());
74
75 stm_ << "UNKNOWN EXCEPTION" << std::endl;
76 }
77
78 private:
79 std::ostream& stm_;
80 };
81 }
82}
83#endif
84