1 // (C) Copyright Gennadiy Rozental 2001.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
6 // See http://www.boost.org/libs/test for the library home page.
10 // Version : $Revision$
12 // Description : implements compiler like Log formatter
13 // ***************************************************************************
15 #ifndef BOOST_TEST_COMPILER_LOG_FORMATTER_IPP_020105GER
16 #define BOOST_TEST_COMPILER_LOG_FORMATTER_IPP_020105GER
19 #include <boost/test/output/compiler_log_formatter.hpp>
21 #include <boost/test/framework.hpp>
22 #include <boost/test/execution_monitor.hpp>
23 #include <boost/test/unit_test_parameters.hpp>
25 #include <boost/test/tree/test_unit.hpp>
27 #include <boost/test/utils/basic_cstring/io.hpp>
28 #include <boost/test/utils/lazy_ostream.hpp>
29 #include <boost/test/utils/setcolor.hpp>
33 #include <boost/version.hpp>
38 #include <boost/test/detail/suppress_warnings.hpp>
40 //____________________________________________________________________________//
46 // ************************************************************************** //
47 // ************** compiler_log_formatter ************** //
48 // ************************************************************************** //
53 test_phase_identifier()
55 return framework::test_in_progress() ? framework::current_test_unit().full_name() : std::string( "Test setup" );
60 //____________________________________________________________________________//
63 compiler_log_formatter::log_start( std::ostream& output, counter_t test_cases_amount )
65 m_color_output = runtime_config::get<bool>( runtime_config::btrt_color_output );
67 if( test_cases_amount > 0 )
68 output << "Running " << test_cases_amount << " test "
69 << (test_cases_amount > 1 ? "cases" : "case") << "...\n";
72 //____________________________________________________________________________//
75 compiler_log_formatter::log_finish( std::ostream& ostr )
80 //____________________________________________________________________________//
83 compiler_log_formatter::log_build_info( std::ostream& output, bool log_build_info )
86 output << "Platform: " << BOOST_PLATFORM << '\n'
87 << "Compiler: " << BOOST_COMPILER << '\n'
88 << "STL : " << BOOST_STDLIB << '\n'
89 << "Boost : " << BOOST_VERSION/100000 << "."
90 << BOOST_VERSION/100 % 1000 << "."
91 << BOOST_VERSION % 100 << std::endl;
95 //____________________________________________________________________________//
98 compiler_log_formatter::test_unit_start( std::ostream& output, test_unit const& tu )
100 BOOST_TEST_SCOPE_SETCOLOR( m_color_output, output, term_attr::BRIGHT, term_color::BLUE );
102 print_prefix( output, tu.p_file_name, tu.p_line_num );
104 output << "Entering test " << tu.p_type_name << " \"" << tu.p_name << "\"" << std::endl;
107 //____________________________________________________________________________//
110 compiler_log_formatter::test_unit_finish( std::ostream& output, test_unit const& tu, unsigned long elapsed )
112 BOOST_TEST_SCOPE_SETCOLOR( m_color_output, output, term_attr::BRIGHT, term_color::BLUE );
114 print_prefix( output, tu.p_file_name, tu.p_line_num );
116 output << "Leaving test " << tu.p_type_name << " \"" << tu.p_name << "\"";
119 output << "; testing time: ";
120 if( elapsed % 1000 == 0 )
121 output << elapsed/1000 << "ms";
123 output << elapsed << "us";
129 //____________________________________________________________________________//
132 compiler_log_formatter::test_unit_skipped( std::ostream& output, test_unit const& tu, const_string reason )
134 BOOST_TEST_SCOPE_SETCOLOR( m_color_output, output, term_attr::BRIGHT, term_color::YELLOW );
136 print_prefix( output, tu.p_file_name, tu.p_line_num );
138 output << "Test " << tu.p_type_name << " \"" << tu.full_name() << "\"" << " is skipped because " << reason << std::endl;
141 //____________________________________________________________________________//
144 compiler_log_formatter::log_exception_start( std::ostream& output, log_checkpoint_data const& checkpoint_data, execution_exception const& ex )
146 execution_exception::location const& loc = ex.where();
148 print_prefix( output, loc.m_file_name, loc.m_line_num );
151 BOOST_TEST_SCOPE_SETCOLOR( m_color_output, output, term_attr::UNDERLINE, term_color::RED );
153 output << "fatal error: in \"" << (loc.m_function.is_empty() ? test_phase_identifier() : loc.m_function ) << "\": "
157 if( !checkpoint_data.m_file_name.is_empty() ) {
159 print_prefix( output, checkpoint_data.m_file_name, checkpoint_data.m_line_num );
161 BOOST_TEST_SCOPE_SETCOLOR( m_color_output, output, term_attr::BRIGHT, term_color::CYAN );
163 output << "last checkpoint";
164 if( !checkpoint_data.m_message.empty() )
165 output << ": " << checkpoint_data.m_message;
169 //____________________________________________________________________________//
172 compiler_log_formatter::log_exception_finish( std::ostream& output )
177 //____________________________________________________________________________//
180 compiler_log_formatter::log_entry_start( std::ostream& output, log_entry_data const& entry_data, log_entry_types let )
182 using namespace utils;
185 case BOOST_UTL_ET_INFO:
186 print_prefix( output, entry_data.m_file_name, entry_data.m_line_num );
187 output << setcolor( m_color_output, term_attr::BRIGHT, term_color::GREEN );
190 case BOOST_UTL_ET_MESSAGE:
191 output << setcolor( m_color_output, term_attr::BRIGHT, term_color::CYAN );
193 case BOOST_UTL_ET_WARNING:
194 print_prefix( output, entry_data.m_file_name, entry_data.m_line_num );
195 output << setcolor( m_color_output, term_attr::BRIGHT, term_color::YELLOW );
196 output << "warning: in \"" << test_phase_identifier() << "\": ";
198 case BOOST_UTL_ET_ERROR:
199 print_prefix( output, entry_data.m_file_name, entry_data.m_line_num );
200 output << setcolor( m_color_output, term_attr::BRIGHT, term_color::RED );
201 output << "error: in \"" << test_phase_identifier() << "\": ";
203 case BOOST_UTL_ET_FATAL_ERROR:
204 print_prefix( output, entry_data.m_file_name, entry_data.m_line_num );
205 output << setcolor( m_color_output, term_attr::UNDERLINE, term_color::RED );
206 output << "fatal error: in \"" << test_phase_identifier() << "\": ";
211 //____________________________________________________________________________//
214 compiler_log_formatter::log_entry_value( std::ostream& output, const_string value )
219 //____________________________________________________________________________//
222 compiler_log_formatter::log_entry_value( std::ostream& output, lazy_ostream const& value )
227 //____________________________________________________________________________//
230 compiler_log_formatter::log_entry_finish( std::ostream& output )
233 output << utils::setcolor(m_color_output);
239 //____________________________________________________________________________//
242 compiler_log_formatter::print_prefix( std::ostream& output, const_string file_name, std::size_t line_num )
244 if( !file_name.empty() ) {
246 // Xcode-compatible logging format, idea by Richard Dingwall at
247 // <http://richarddingwall.name/2008/06/01/using-the-boost-unit-test-framework-with-xcode-3/>.
248 output << file_name << ':' << line_num << ": ";
250 output << file_name << '(' << line_num << "): ";
255 //____________________________________________________________________________//
258 compiler_log_formatter::entry_context_start( std::ostream& output, log_level l )
260 if( l == log_messages ) {
261 output << "\n[context:";
264 output << (l == log_successful_tests ? "\nAssertion" : "\nFailure" ) << " occurred in a following context:";
268 //____________________________________________________________________________//
271 compiler_log_formatter::entry_context_finish( std::ostream& output, log_level l )
273 if( l == log_messages ) {
279 //____________________________________________________________________________//
282 compiler_log_formatter::log_entry_context( std::ostream& output, log_level /*l*/, const_string context_descr )
284 output << "\n " << context_descr;
287 //____________________________________________________________________________//
289 } // namespace output
290 } // namespace unit_test
293 #include <boost/test/detail/enable_warnings.hpp>
295 #endif // BOOST_TEST_COMPILER_LOG_FORMATTER_IPP_020105GER