wibble 1.1
tut_reporter.h
Go to the documentation of this file.
1#ifndef TUT_REPORTER
2#define TUT_REPORTER
3
4#include <wibble/tests/tut.h>
5
12namespace
13{
14 std::ostream& operator << (std::ostream& os,const tut::test_result& tr)
15 {
16 switch(tr.result)
17 {
19 os << '.';
20 break;
21
23 os << '[' << tr.test << "=F]";
24 break;
25
27 os << '[' << tr.test << "=C]";
28 break;
29
31 os << '[' << tr.test << "=X]";
32 break;
33
35 os << '[' << tr.test << "=W]";
36 break;
37
39 os << '[' << tr.test << "=T]";
40 break;
41 }
42
43 return os;
44 }
45}
46
47namespace tut
48{
52 class reporter : public tut::callback
53 {
54 std::string current_group;
55 typedef std::vector<tut::test_result> not_passed_list;
56 not_passed_list not_passed;
57 std::ostream& os;
58
59 public:
65
66 reporter() : os(std::cout)
67 {
68 init();
69 }
70
71 reporter(std::ostream& out) : os(out)
72 {
73 init();
74 }
75
77 {
78 init();
79 }
80
82 {
83 if( tr.group != current_group )
84 {
85 os << std::endl << tr.group << ": " << std::flush;
86 current_group = tr.group;
87 }
88
89 os << tr << std::flush;
95 else terminations_count++;
96
98 {
99 not_passed.push_back(tr);
100 }
101 }
102
104 {
105 os << std::endl;
106
107 if( not_passed.size() > 0 )
108 {
109 not_passed_list::const_iterator i = not_passed.begin();
110 while( i != not_passed.end() )
111 {
112 tut::test_result tr = *i;
113
114 os << std::endl;
115
116 os << "---> " << "group: " << tr.group << ", test: test<" << tr.test << ">" << std::endl;
117
118 os << " problem: ";
119 switch(tr.result)
120 {
121 case test_result::fail:
122 os << "assertion failed" << std::endl;
123 break;
124 case test_result::ex:
126 os << "unexpected exception" << std::endl;
127 if( tr.exception_typeid != "" )
128 {
129 os << " exception typeid: "
130 << tr.exception_typeid << std::endl;
131 }
132 break;
133 case test_result::term:
134 os << "would be terminated" << std::endl;
135 break;
136 case test_result::warn:
137 os << "test passed, but cleanup code (destructor) raised an exception" << std::endl;
138 break;
139 default: break;
140 }
141
142 if( tr.message != "" )
143 {
144 if( tr.result == test_result::fail )
145 {
146 os << " failed assertion: \"" << tr.message << "\"" << std::endl;
147 }
148 else
149 {
150 os << " message: \"" << tr.message << "\"" << std::endl;
151 }
152 }
153
154 ++i;
155 }
156 }
157
158 os << std::endl;
159
160 os << "tests summary:";
161 if( terminations_count > 0 ) os << " terminations:" << terminations_count;
162 if( exceptions_count > 0 ) os << " exceptions:" << exceptions_count;
163 if( failures_count > 0 ) os << " failures:" << failures_count;
164 if( warnings_count > 0 ) os << " warnings:" << warnings_count;
165 os << " ok:" << ok_count;
166 os << std::endl;
167 }
168
169 bool all_ok() const
170 {
171 return not_passed.size() == 0;
172 }
173
174 private:
175 void init()
176 {
177 ok_count = 0;
178 exceptions_count = 0;
179 failures_count = 0;
181 warnings_count = 0;
182
183 not_passed.clear();
184 }
185 };
186};
187
188#endif
Default TUT callback handler.
Definition tut_reporter.h:53
reporter(std::ostream &out)
Definition tut_reporter.h:71
int warnings_count
Definition tut_reporter.h:64
int ok_count
Definition tut_reporter.h:60
int terminations_count
Definition tut_reporter.h:63
int failures_count
Definition tut_reporter.h:62
reporter()
Definition tut_reporter.h:66
void test_completed(const tut::test_result &tr)
Called when a test finished.
Definition tut_reporter.h:81
void run_completed()
Called when all tests in run completed.
Definition tut_reporter.h:103
bool all_ok() const
Definition tut_reporter.h:169
void run_started()
Called when new test run started.
Definition tut_reporter.h:76
int exceptions_count
Definition tut_reporter.h:61
Template Unit Tests Framework for C++.
Definition tut-main.cpp:7
Test runner callback interface.
Definition tut.h:185
Return type of runned test/test group.
Definition tut.h:106
std::string exception_typeid
Definition tut.h:131
result_type result
Definition tut.h:125
std::string group
Test group name.
Definition tut.h:110
std::string message
Exception message for failed test.
Definition tut.h:130
@ term
Definition tut.h:124
@ fail
Definition tut.h:124
@ ex_ctor
Definition tut.h:124
@ ok
Definition tut.h:124
@ warn
Definition tut.h:124
@ ex
Definition tut.h:124
int test
Test number in group.
Definition tut.h:115