1 #ifndef TUT_CONSOLE_REPORTER
2 #define TUT_CONSOLE_REPORTER
7 * Template Unit Tests Framework for C++.
10 * @author Vladimir Dyuzhev, Vladimir.Dyuzhev@gmail.com
15 std::ostream& operator<<(std::ostream& os, const tut::test_result& tr)
19 case tut::test_result::ok:
22 case tut::test_result::fail:
23 os << '[' << tr.test << "=F]";
25 case tut::test_result::ex_ctor:
26 os << '[' << tr.test << "=C]";
28 case tut::test_result::ex:
29 os << '[' << tr.test << "=X]";
31 case tut::test_result::warn:
32 os << '[' << tr.test << "=W]";
34 case tut::test_result::term:
35 os << '[' << tr.test << "=T]";
37 case tut::test_result::rethrown:
38 os << '[' << tr.test << "=P]";
40 case tut::test_result::skipped:
41 os << '[' << tr.test << "=S]";
43 case tut::test_result::dummy:
44 throw tut::tut_error("console reporter called for dummy test result");
56 * Default TUT callback handler.
58 class console_reporter : public tut::callback
60 std::string current_group;
61 typedef std::vector<tut::test_result> not_passed_list;
62 not_passed_list not_passed;
65 console_reporter(const console_reporter &);
66 console_reporter &operator=(const console_reporter &);
72 int terminations_count;
83 terminations_count(0),
90 console_reporter(std::ostream& out)
97 terminations_count(0),
110 void test_completed(const tut::test_result& tr)
112 if (tr.group != current_group)
114 os << std::endl << tr.group << ": " << std::flush;
115 current_group = tr.group;
118 os << tr << std::flush;
120 // update global statistics
122 case test_result::ok:
125 case test_result::fail:
126 case test_result::rethrown:
129 case test_result::ex:
130 case test_result::ex_ctor:
133 case test_result::warn:
136 case test_result::term:
137 terminations_count++;
139 case test_result::skipped:
142 case tut::test_result::dummy:
143 assert( (tr.result != tut::test_result::dummy) && "Should never be called");
146 if ( (tr.result != tut::test_result::ok) &&
147 (tr.result != tut::test_result::skipped) )
149 not_passed.push_back(tr);
157 if (not_passed.size() > 0)
159 not_passed_list::const_iterator i = not_passed.begin();
160 while (i != not_passed.end())
162 tut::test_result tr = *i;
166 os << "---> " << "group: " << tr.group
167 << ", test: test<" << tr.test << ">"
168 << (!tr.name.empty() ? (std::string(" : ") + tr.name) : std::string())
171 #if defined(TUT_USE_POSIX)
172 if(tr.pid != getpid())
174 os << " child pid: " << tr.pid << std::endl;
180 case test_result::rethrown:
181 os << "assertion failed in child" << std::endl;
183 case test_result::fail:
184 os << "assertion failed" << std::endl;
186 case test_result::ex:
187 case test_result::ex_ctor:
188 os << "unexpected exception" << std::endl;
189 if( tr.exception_typeid != "" )
191 os << " exception typeid: "
192 << tr.exception_typeid << std::endl;
195 case test_result::term:
196 os << "would be terminated" << std::endl;
198 case test_result::warn:
199 os << "test passed, but cleanup code (destructor) raised"
200 " an exception" << std::endl;
206 if (!tr.message.empty())
208 if (tr.result == test_result::fail)
210 os << " failed assertion: `" << tr.message << "`"
215 os << " message: `" << tr.message << "`"
226 os << "tests summary:";
227 if (terminations_count > 0)
229 os << " terminations:" << terminations_count;
231 if (exceptions_count > 0)
233 os << " exceptions:" << exceptions_count;
235 if (failures_count > 0)
237 os << " failures:" << failures_count;
239 if (warnings_count > 0)
241 os << " warnings:" << warnings_count;
244 os << " ok:" << ok_count;
246 if(skipped_count > 0)
248 os << " skipped:" << skipped_count;
253 virtual bool all_ok() const
255 return not_passed.empty();
263 exceptions_count = 0;
265 terminations_count = 0;