2 #include <colour_log_formatter.h>
3 #include <boost/test/unit_test_suite_impl.hpp>
4 #include <boost/test/framework.hpp>
5 #include <boost/test/utils/basic_cstring/io.hpp>
6 #include <boost/test/utils/lazy_ostream.hpp>
9 #include <boost/version.hpp>
15 #include <dpl/colors.h>
17 // ************************************************************************** //
18 // ************** colour_log_formatter ************** //
19 // ************************************************************************** //
21 using namespace boost::unit_test;
27 test_phase_identifier()
29 return framework::is_initialized()
30 ? const_string( framework::current_test_case().p_name.get() )
31 : BOOST_TEST_L( "Test setup" );
35 get_basename(const const_string &file_name) {
36 return basename(file_name.begin());
40 get_basename(const std::string &file_name) {
41 return basename(file_name.c_str());
46 //____________________________________________________________________________//
49 colour_log_formatter::log_start(
51 counter_t test_cases_amount )
53 if( test_cases_amount > 0 )
54 output << "Running " << test_cases_amount << " test "
55 << (test_cases_amount > 1 ? "cases" : "case") << "...\n";
58 //____________________________________________________________________________//
61 colour_log_formatter::log_finish( std::ostream& ostr )
66 //____________________________________________________________________________//
69 colour_log_formatter::log_build_info( std::ostream& output )
71 output << "Platform: " << BOOST_PLATFORM << '\n'
72 << "Compiler: " << BOOST_COMPILER << '\n'
73 << "STL : " << BOOST_STDLIB << '\n'
74 << "Boost : " << BOOST_VERSION/100000 << "."
75 << BOOST_VERSION/100 % 1000 << "."
76 << BOOST_VERSION % 100 << std::endl;
79 //____________________________________________________________________________//
82 colour_log_formatter::test_unit_start(
86 if (tu.p_type_name->find(const_string("suite")) == 0) {
87 output << "Starting test " << tu.p_type_name << " \"" << tu.p_name << "\"" << std::endl;
89 output << "Running test " << tu.p_type_name << " \"" << tu.p_name << "\"" << std::endl;
93 //____________________________________________________________________________//
96 colour_log_formatter::test_unit_finish(
99 unsigned long elapsed )
101 if (tu.p_type_name->find(const_string("suite")) == 0) {
102 output << "Finished test " << tu.p_type_name << " \"" << tu.p_name << "\""<< std::endl;
105 std::string color = CKM::Colors::Text::GREEN_BEGIN;
106 std::string status = "OK";
107 if (m_isTestCaseFailed) {
108 color = CKM::Colors::Text::RED_BEGIN;
111 output << "\t" << "[ " << color << status << CKM::Colors::Text::COLOR_END << " ]";
114 output << ", " << CKM::Colors::Text::CYAN_BEGIN << "time: ";
116 if( elapsed % 1000 == 0 )
117 output << elapsed/1000 << "ms";
119 output << elapsed << "mks";
124 output << CKM::Colors::Text::COLOR_END << std::endl;
125 m_isTestCaseFailed = false;
128 //____________________________________________________________________________//
131 colour_log_formatter::test_unit_skipped(
132 std::ostream& output,
133 test_unit const& tu )
135 output << "Test " << tu.p_type_name << " \"" << tu.p_name << "\"" << "is skipped" << std::endl;
138 //____________________________________________________________________________//
141 colour_log_formatter::log_exception(
142 std::ostream& output,
143 log_checkpoint_data const& checkpoint_data,
144 boost::execution_exception const& ex )
146 boost::execution_exception::location const& loc = ex.where();
147 output << '\t' << CKM::Colors::Text::BOLD_YELLOW_BEGIN << get_basename(loc.m_file_name)
148 << '(' << loc.m_line_num << "), ";
150 output << "fatal error in \""
151 << (loc.m_function.is_empty() ? test_phase_identifier() : loc.m_function ) << "\": ";
153 output << CKM::Colors::Text::COLOR_END << ex.what();
155 if( !checkpoint_data.m_file_name.is_empty() ) {
157 output << "\tlast checkpoint : " << get_basename(checkpoint_data.m_file_name)
158 << '(' << checkpoint_data.m_line_num << ")";
159 if( !checkpoint_data.m_message.empty() )
160 output << ": " << checkpoint_data.m_message;
164 m_isTestCaseFailed = true;
167 //____________________________________________________________________________//
170 colour_log_formatter::log_entry_start(
171 std::ostream& output,
172 log_entry_data const& entry_data,
173 log_entry_types let )
176 case BOOST_UTL_ET_INFO:
177 output << '\t' << entry_data.m_file_name << '(' << entry_data.m_line_num << "), ";
180 case BOOST_UTL_ET_MESSAGE:
182 case BOOST_UTL_ET_WARNING:
183 output << '\t' << get_basename(entry_data.m_file_name) << '(' << entry_data.m_line_num << "), ";
184 output << "warning in \"" << test_phase_identifier() << "\": ";
186 case BOOST_UTL_ET_ERROR:
187 output << '\t' << CKM::Colors::Text::BOLD_YELLOW_BEGIN << get_basename(entry_data.m_file_name)
188 << '(' << entry_data.m_line_num << "), ";
189 output << "error in \"" << test_phase_identifier() << "\": ";
190 m_isTestCaseFailed = true;
192 case BOOST_UTL_ET_FATAL_ERROR:
193 output << '\t' << CKM::Colors::Text::BOLD_YELLOW_BEGIN << get_basename(entry_data.m_file_name)
194 << '(' << entry_data.m_line_num << "), ";
195 output << " fatal error in \"" << test_phase_identifier() << "\": ";
196 m_isTestCaseFailed = true;
199 output << CKM::Colors::Text::COLOR_END;
202 //____________________________________________________________________________//
205 colour_log_formatter::log_entry_value(
206 std::ostream& output,
212 //____________________________________________________________________________//
215 colour_log_formatter::log_entry_value(
216 std::ostream& output,
217 lazy_ostream const& value )
222 //____________________________________________________________________________//
225 colour_log_formatter::log_entry_finish(
226 std::ostream& output )
231 //____________________________________________________________________________//
233 //____________________________________________________________________________//
237 //____________________________________________________________________________//