1 #ifndef TUT_CONSOLE_REPORTER
2 #define TUT_CONSOLE_REPORTER
8 * Template Unit Tests Framework for C++.
11 * @author Vladimir Dyuzhev, Vladimir.Dyuzhev@gmail.com
16 std::ostream& operator<<(std::ostream& os, const tut::test_result& tr)
20 case tut::test_result::ok:
23 case tut::test_result::fail:
24 os << '[' << tr.test << "=F]";
26 case tut::test_result::ex_ctor:
27 os << '[' << tr.test << "=C]";
29 case tut::test_result::ex:
30 os << '[' << tr.test << "=X]";
32 case tut::test_result::warn:
33 os << '[' << tr.test << "=W]";
35 case tut::test_result::term:
36 os << '[' << tr.test << "=T]";
38 case tut::test_result::rethrown:
39 os << '[' << tr.test << "=P]";
41 case tut::test_result::dummy:
42 assert(!"Should never be called");
54 * Default TUT callback handler.
56 class console_reporter : public tut::callback
58 std::string current_group;
59 typedef std::vector<tut::test_result> not_passed_list;
60 not_passed_list not_passed;
68 int terminations_count;
77 console_reporter(std::ostream& out)
88 void test_completed(const tut::test_result& tr)
90 if (tr.group != current_group)
92 os << std::endl << tr.group << ": " << std::flush;
93 current_group = tr.group;
96 os << tr << std::flush;
98 // update global statistics
100 case test_result::ok:
103 case test_result::fail:
104 case test_result::rethrown:
107 case test_result::ex:
108 case test_result::ex_ctor:
111 case test_result::warn:
114 case test_result::term:
115 terminations_count++;
117 case tut::test_result::dummy:
118 assert(!"Should never be called");
121 if (tr.result != tut::test_result::ok)
123 not_passed.push_back(tr);
131 if (not_passed.size() > 0)
133 not_passed_list::const_iterator i = not_passed.begin();
134 while (i != not_passed.end())
136 tut::test_result tr = *i;
140 os << "---> " << "group: " << tr.group
141 << ", test: test<" << tr.test << ">"
142 << (!tr.name.empty() ? (std::string(" : ") + tr.name) : std::string())
145 #if defined(TUT_USE_POSIX)
146 if(tr.pid != getpid())
148 os << " child pid: " << tr.pid << std::endl;
154 case test_result::rethrown:
155 os << "assertion failed in child" << std::endl;
157 case test_result::fail:
158 os << "assertion failed" << std::endl;
160 case test_result::ex:
161 case test_result::ex_ctor:
162 os << "unexpected exception" << std::endl;
163 if( tr.exception_typeid != "" )
165 os << " exception typeid: "
166 << tr.exception_typeid << std::endl;
169 case test_result::term:
170 os << "would be terminated" << std::endl;
172 case test_result::warn:
173 os << "test passed, but cleanup code (destructor) raised"
174 " an exception" << std::endl;
180 if (!tr.message.empty())
182 if (tr.result == test_result::fail)
184 os << " failed assertion: \"" << tr.message << "\""
189 os << " message: \"" << tr.message << "\""
200 os << "tests summary:";
201 if (terminations_count > 0)
203 os << " terminations:" << terminations_count;
205 if (exceptions_count > 0)
207 os << " exceptions:" << exceptions_count;
209 if (failures_count > 0)
211 os << " failures:" << failures_count;
213 if (warnings_count > 0)
215 os << " warnings:" << warnings_count;
217 os << " ok:" << ok_count;
223 return not_passed.empty();
231 exceptions_count = 0;
233 terminations_count = 0;