2 * (C) Copyright Gennadiy Rozental 2005-2008.
3 * Distributed under the Boost Software License, Version 1.0.
4 * (See accompanying file LICENSE_1_0.txt or copy at
5 * http://www.boost.org/LICENSE_1_0.txt)
7 * See http://www.boost.org/libs/test for the library home page.
10 * @file colour_log_formatter.cpp
11 * @author Zofia Abramowska (z.abramowska@samsung.com)
16 #include <colour_log_formatter.h>
17 #include <boost/test/unit_test_suite_impl.hpp>
18 #include <boost/test/framework.hpp>
19 #include <boost/test/utils/basic_cstring/io.hpp>
20 #include <boost/test/utils/lazy_ostream.hpp>
23 #include <boost/version.hpp>
29 #include <dpl/colors.h>
31 // ************************************************************************** //
32 // ************** colour_log_formatter ************** //
33 // ************************************************************************** //
35 using namespace boost::unit_test;
41 test_phase_identifier()
43 return framework::is_initialized()
44 ? const_string(framework::current_test_case().p_name.get())
45 : BOOST_TEST_L("Test setup");
49 get_basename(const const_string &file_name)
51 return basename(file_name.begin());
55 get_basename(const std::string &file_name)
57 return basename(file_name.c_str());
62 //____________________________________________________________________________//
65 colour_log_formatter::log_start(
67 counter_t test_cases_amount)
69 if (test_cases_amount > 0)
70 output << "Running " << test_cases_amount << " test "
71 << (test_cases_amount > 1 ? "cases" : "case") << "...\n";
74 //____________________________________________________________________________//
77 colour_log_formatter::log_finish(std::ostream &ostr)
82 //____________________________________________________________________________//
85 colour_log_formatter::log_build_info(std::ostream &output)
87 output << "Platform: " << BOOST_PLATFORM << '\n'
88 << "Compiler: " << BOOST_COMPILER << '\n'
89 << "STL : " << BOOST_STDLIB << '\n'
90 << "Boost : " << BOOST_VERSION / 100000 << "."
91 << BOOST_VERSION / 100 % 1000 << "."
92 << BOOST_VERSION % 100 << std::endl;
95 //____________________________________________________________________________//
98 colour_log_formatter::test_unit_start(
102 if (tu.p_type_name->find(const_string("suite")) == 0) {
103 output << "Starting test " << tu.p_type_name << " \"" << tu.p_name << "\"" <<
106 output << "Running test " << tu.p_type_name << " \"" << tu.p_name << "\"" <<
111 //____________________________________________________________________________//
114 colour_log_formatter::test_unit_finish(
115 std::ostream &output,
117 unsigned long elapsed)
119 if (tu.p_type_name->find(const_string("suite")) == 0) {
120 output << "Finished test " << tu.p_type_name << " \"" << tu.p_name << "\"" <<
125 std::string color = CKM::Colors::Text::GREEN_BEGIN;
126 std::string status = "OK";
128 if (m_isTestCaseFailed) {
129 color = CKM::Colors::Text::RED_BEGIN;
133 output << "\t" << "[ " << color << status << CKM::Colors::Text::COLOR_END <<
137 output << ", " << CKM::Colors::Text::CYAN_BEGIN << "time: ";
140 if (elapsed % 1000 == 0)
141 output << elapsed / 1000 << "ms";
143 output << elapsed << "mks";
148 output << CKM::Colors::Text::COLOR_END << std::endl;
149 m_isTestCaseFailed = false;
152 //____________________________________________________________________________//
155 colour_log_formatter::test_unit_skipped(
156 std::ostream &output,
159 output << "Test " << tu.p_type_name << " \"" << tu.p_name << "\"" <<
160 "is skipped" << std::endl;
163 //____________________________________________________________________________//
166 colour_log_formatter::log_exception(
167 std::ostream &output,
168 log_checkpoint_data const &checkpoint_data,
169 boost::execution_exception const &ex)
171 boost::execution_exception::location const &loc = ex.where();
172 output << '\t' << CKM::Colors::Text::BOLD_YELLOW_BEGIN << get_basename(
174 << '(' << loc.m_line_num << "), ";
176 output << "fatal error in \""
177 << (loc.m_function.is_empty() ? test_phase_identifier() : loc.m_function) <<
180 output << CKM::Colors::Text::COLOR_END << ex.what();
182 if (!checkpoint_data.m_file_name.is_empty()) {
184 output << "\tlast checkpoint : " << get_basename(checkpoint_data.m_file_name)
185 << '(' << checkpoint_data.m_line_num << ")";
187 if (!checkpoint_data.m_message.empty())
188 output << ": " << checkpoint_data.m_message;
192 m_isTestCaseFailed = true;
195 //____________________________________________________________________________//
198 colour_log_formatter::log_entry_start(
199 std::ostream &output,
200 log_entry_data const &entry_data,
204 case BOOST_UTL_ET_INFO:
205 output << '\t' << entry_data.m_file_name << '(' << entry_data.m_line_num <<
210 case BOOST_UTL_ET_MESSAGE:
213 case BOOST_UTL_ET_WARNING:
214 output << '\t' << get_basename(entry_data.m_file_name) << '(' <<
215 entry_data.m_line_num << "), ";
216 output << "warning in \"" << test_phase_identifier() << "\": ";
219 case BOOST_UTL_ET_ERROR:
220 output << '\t' << CKM::Colors::Text::BOLD_YELLOW_BEGIN << get_basename(
221 entry_data.m_file_name)
222 << '(' << entry_data.m_line_num << "), ";
223 output << "error in \"" << test_phase_identifier() << "\": ";
224 m_isTestCaseFailed = true;
227 case BOOST_UTL_ET_FATAL_ERROR:
228 output << '\t' << CKM::Colors::Text::BOLD_YELLOW_BEGIN << get_basename(
229 entry_data.m_file_name)
230 << '(' << entry_data.m_line_num << "), ";
231 output << " fatal error in \"" << test_phase_identifier() << "\": ";
232 m_isTestCaseFailed = true;
236 output << CKM::Colors::Text::COLOR_END;
239 //____________________________________________________________________________//
242 colour_log_formatter::log_entry_value(
243 std::ostream &output,
249 //____________________________________________________________________________//
252 colour_log_formatter::log_entry_value(
253 std::ostream &output,
254 lazy_ostream const &value)
259 //____________________________________________________________________________//
262 colour_log_formatter::log_entry_finish(
263 std::ostream &output)
268 //____________________________________________________________________________//
270 //____________________________________________________________________________//
274 //____________________________________________________________________________//