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 )
85 output << "Platform: " << BOOST_PLATFORM << '\n'
86 << "Compiler: " << BOOST_COMPILER << '\n'
87 << "STL : " << BOOST_STDLIB << '\n'
88 << "Boost : " << BOOST_VERSION/100000 << "."
89 << BOOST_VERSION/100 % 1000 << "."
90 << BOOST_VERSION % 100 << std::endl;
93 //____________________________________________________________________________//
96 compiler_log_formatter::test_unit_start( std::ostream& output, test_unit const& tu )
98 BOOST_TEST_SCOPE_SETCOLOR( m_color_output, output, term_attr::BRIGHT, term_color::BLUE );
100 print_prefix( output, tu.p_file_name, tu.p_line_num );
102 output << "Entering test " << tu.p_type_name << " \"" << tu.p_name << "\"" << std::endl;
105 //____________________________________________________________________________//
108 compiler_log_formatter::test_unit_finish( std::ostream& output, test_unit const& tu, unsigned long elapsed )
110 BOOST_TEST_SCOPE_SETCOLOR( m_color_output, output, term_attr::BRIGHT, term_color::BLUE );
112 print_prefix( output, tu.p_file_name, tu.p_line_num );
114 output << "Leaving test " << tu.p_type_name << " \"" << tu.p_name << "\"";
117 output << "; testing time: ";
118 if( elapsed % 1000 == 0 )
119 output << elapsed/1000 << "ms";
121 output << elapsed << "us";
127 //____________________________________________________________________________//
130 compiler_log_formatter::test_unit_skipped( std::ostream& output, test_unit const& tu, const_string reason )
132 BOOST_TEST_SCOPE_SETCOLOR( m_color_output, output, term_attr::BRIGHT, term_color::YELLOW );
134 print_prefix( output, tu.p_file_name, tu.p_line_num );
136 output << "Test " << tu.p_type_name << " \"" << tu.full_name() << "\"" << " is skipped because " << reason << std::endl;
139 //____________________________________________________________________________//
142 compiler_log_formatter::log_exception_start( std::ostream& output, log_checkpoint_data const& checkpoint_data, execution_exception const& ex )
144 execution_exception::location const& loc = ex.where();
146 print_prefix( output, loc.m_file_name, loc.m_line_num );
149 BOOST_TEST_SCOPE_SETCOLOR( m_color_output, output, term_attr::UNDERLINE, term_color::RED );
151 output << "fatal error: in \"" << (loc.m_function.is_empty() ? test_phase_identifier() : loc.m_function ) << "\": "
155 if( !checkpoint_data.m_file_name.is_empty() ) {
157 print_prefix( output, checkpoint_data.m_file_name, checkpoint_data.m_line_num );
159 BOOST_TEST_SCOPE_SETCOLOR( m_color_output, output, term_attr::BRIGHT, term_color::CYAN );
161 output << "last checkpoint";
162 if( !checkpoint_data.m_message.empty() )
163 output << ": " << checkpoint_data.m_message;
167 //____________________________________________________________________________//
170 compiler_log_formatter::log_exception_finish( std::ostream& output )
175 //____________________________________________________________________________//
178 compiler_log_formatter::log_entry_start( std::ostream& output, log_entry_data const& entry_data, log_entry_types let )
180 using namespace utils;
183 case BOOST_UTL_ET_INFO:
184 print_prefix( output, entry_data.m_file_name, entry_data.m_line_num );
186 output << setcolor( term_attr::BRIGHT, term_color::GREEN );
189 case BOOST_UTL_ET_MESSAGE:
191 output << setcolor( 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 );
196 output << setcolor( term_attr::BRIGHT, term_color::YELLOW );
197 output << "warning: in \"" << test_phase_identifier() << "\": ";
199 case BOOST_UTL_ET_ERROR:
200 print_prefix( output, entry_data.m_file_name, entry_data.m_line_num );
202 output << setcolor( term_attr::BRIGHT, term_color::RED );
203 output << "error: in \"" << test_phase_identifier() << "\": ";
205 case BOOST_UTL_ET_FATAL_ERROR:
206 print_prefix( output, entry_data.m_file_name, entry_data.m_line_num );
208 output << setcolor( term_attr::UNDERLINE, term_color::RED );
209 output << "fatal error: in \"" << test_phase_identifier() << "\": ";
214 //____________________________________________________________________________//
217 compiler_log_formatter::log_entry_value( std::ostream& output, const_string value )
222 //____________________________________________________________________________//
225 compiler_log_formatter::log_entry_value( std::ostream& output, lazy_ostream const& value )
230 //____________________________________________________________________________//
233 compiler_log_formatter::log_entry_finish( std::ostream& output )
236 output << utils::setcolor();
242 //____________________________________________________________________________//
245 compiler_log_formatter::print_prefix( std::ostream& output, const_string file_name, std::size_t line_num )
247 if( !file_name.empty() ) {
249 // Xcode-compatible logging format, idea by Richard Dingwall at
250 // <http://richarddingwall.name/2008/06/01/using-the-boost-unit-test-framework-with-xcode-3/>.
251 output << file_name << ':' << line_num << ": ";
253 output << file_name << '(' << line_num << "): ";
258 //____________________________________________________________________________//
261 compiler_log_formatter::entry_context_start( std::ostream& output, log_level l )
263 if( l == log_messages ) {
264 output << "\n[context:";
267 output << (l == log_successful_tests ? "\nAssertion" : "\nFailure" ) << " occurred in a following context:";
271 //____________________________________________________________________________//
274 compiler_log_formatter::entry_context_finish( std::ostream& output, log_level l )
276 if( l == log_messages ) {
282 //____________________________________________________________________________//
285 compiler_log_formatter::log_entry_context( std::ostream& output, log_level l, const_string context_descr )
287 output << "\n " << context_descr;
290 //____________________________________________________________________________//
292 } // namespace output
293 } // namespace unit_test
296 #include <boost/test/detail/enable_warnings.hpp>
298 #endif // BOOST_TEST_COMPILER_LOG_FORMATTER_IPP_020105GER