1// (C) Copyright Gennadiy Rozental 2005-2008. 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) 5 6// See http://www.boost.org/libs/test for the library home page. 7// 8// File : $RCSfile$ 9// 10// Version : $Revision: 57992 $ 11// 12// Description : implements compiler like Log formatter 13// *************************************************************************** 14 15#ifndef BOOST_TEST_COMPILER_LOG_FORMATTER_IPP_020105GER 16#define BOOST_TEST_COMPILER_LOG_FORMATTER_IPP_020105GER 17 18// Boost.Test 19#include <boost/test/output/compiler_log_formatter.hpp> 20#include <boost/test/unit_test_suite_impl.hpp> 21#include <boost/test/framework.hpp> 22#include <boost/test/utils/basic_cstring/io.hpp> 23#include <boost/test/utils/lazy_ostream.hpp> 24 25// Boost 26#include <boost/version.hpp> 27 28// STL 29#include <iostream> 30 31#include <boost/test/detail/suppress_warnings.hpp> 32 33//____________________________________________________________________________// 34 35namespace boost { 36 37namespace unit_test { 38 39namespace output { 40 41// ************************************************************************** // 42// ************** compiler_log_formatter ************** // 43// ************************************************************************** // 44 45namespace { 46 47const_string 48test_phase_identifier() 49{ 50 return framework::is_initialized() 51 ? const_string( framework::current_test_case().p_name.get() ) 52 : BOOST_TEST_L( "Test setup" ); 53} 54 55} // local namespace 56 57//____________________________________________________________________________// 58 59void 60compiler_log_formatter::log_start( std::ostream& output, counter_t test_cases_amount ) 61{ 62 if( test_cases_amount > 0 ) 63 output << "Running " << test_cases_amount << " test " 64 << (test_cases_amount > 1 ? "cases" : "case") << "...\n"; 65} 66 67//____________________________________________________________________________// 68 69void 70compiler_log_formatter::log_finish( std::ostream& ostr ) 71{ 72 ostr.flush(); 73} 74 75//____________________________________________________________________________// 76 77void 78compiler_log_formatter::log_build_info( std::ostream& output ) 79{ 80 output << "Platform: " << BOOST_PLATFORM << '\n' 81 << "Compiler: " << BOOST_COMPILER << '\n' 82 << "STL : " << BOOST_STDLIB << '\n' 83 << "Boost : " << BOOST_VERSION/100000 << "." 84 << BOOST_VERSION/100 % 1000 << "." 85 << BOOST_VERSION % 100 << std::endl; 86} 87 88//____________________________________________________________________________// 89 90void 91compiler_log_formatter::test_unit_start( std::ostream& output, test_unit const& tu ) 92{ 93 output << "Entering test " << tu.p_type_name << " \"" << tu.p_name << "\"" << std::endl; 94} 95 96//____________________________________________________________________________// 97 98void 99compiler_log_formatter::test_unit_finish( std::ostream& output, test_unit const& tu, unsigned long elapsed ) 100{ 101 output << "Leaving test " << tu.p_type_name << " \"" << tu.p_name << "\""; 102 103 if( elapsed > 0 ) { 104 output << "; testing time: "; 105 if( elapsed % 1000 == 0 ) 106 output << elapsed/1000 << "ms"; 107 else 108 output << elapsed << "mks"; 109 } 110 111 output << std::endl; 112} 113 114//____________________________________________________________________________// 115 116void 117compiler_log_formatter::test_unit_skipped( std::ostream& output, test_unit const& tu ) 118{ 119 output << "Test " << tu.p_type_name << " \"" << tu.p_name << "\"" << "is skipped" << std::endl; 120} 121 122//____________________________________________________________________________// 123 124void 125compiler_log_formatter::log_exception( std::ostream& output, log_checkpoint_data const& checkpoint_data, execution_exception const& ex ) 126{ 127 execution_exception::location const& loc = ex.where(); 128 print_prefix( output, loc.m_file_name, loc.m_line_num ); 129 130 output << "fatal error in \"" << (loc.m_function.is_empty() ? test_phase_identifier() : loc.m_function ) << "\": "; 131 132 output << ex.what(); 133 134 if( !checkpoint_data.m_file_name.is_empty() ) { 135 output << '\n'; 136 print_prefix( output, checkpoint_data.m_file_name, checkpoint_data.m_line_num ); 137 output << "last checkpoint"; 138 if( !checkpoint_data.m_message.empty() ) 139 output << ": " << checkpoint_data.m_message; 140 } 141 142 output << std::endl; 143} 144 145//____________________________________________________________________________// 146 147void 148compiler_log_formatter::log_entry_start( std::ostream& output, log_entry_data const& entry_data, log_entry_types let ) 149{ 150 switch( let ) { 151 case BOOST_UTL_ET_INFO: 152 print_prefix( output, entry_data.m_file_name, entry_data.m_line_num ); 153 output << "info: "; 154 break; 155 case BOOST_UTL_ET_MESSAGE: 156 break; 157 case BOOST_UTL_ET_WARNING: 158 print_prefix( output, entry_data.m_file_name, entry_data.m_line_num ); 159 output << "warning in \"" << test_phase_identifier() << "\": "; 160 break; 161 case BOOST_UTL_ET_ERROR: 162 print_prefix( output, entry_data.m_file_name, entry_data.m_line_num ); 163 output << "error in \"" << test_phase_identifier() << "\": "; 164 break; 165 case BOOST_UTL_ET_FATAL_ERROR: 166 print_prefix( output, entry_data.m_file_name, entry_data.m_line_num ); 167 output << "fatal error in \"" << test_phase_identifier() << "\": "; 168 break; 169 } 170} 171 172//____________________________________________________________________________// 173 174void 175compiler_log_formatter::log_entry_value( std::ostream& output, const_string value ) 176{ 177 output << value; 178} 179 180//____________________________________________________________________________// 181 182void 183compiler_log_formatter::log_entry_value( std::ostream& output, lazy_ostream const& value ) 184{ 185 output << value; 186} 187 188//____________________________________________________________________________// 189 190void 191compiler_log_formatter::log_entry_finish( std::ostream& output ) 192{ 193 output << std::endl; 194} 195 196//____________________________________________________________________________// 197 198void 199compiler_log_formatter::print_prefix( std::ostream& output, const_string file, std::size_t line ) 200{ 201#ifdef __APPLE_CC__ 202 // Xcode-compatible logging format, idea by Richard Dingwall at 203 // <http://richarddingwall.name/2008/06/01/using-the-boost-unit-test-framework-with-xcode-3/>. 204 output << file << ':' << line << ": "; 205#else 206 output << file << '(' << line << "): "; 207#endif 208} 209 210//____________________________________________________________________________// 211 212} // namespace output 213 214} // namespace unit_test 215 216} // namespace boost 217 218//____________________________________________________________________________// 219 220#include <boost/test/detail/enable_warnings.hpp> 221 222#endif // BOOST_TEST_COMPILER_LOG_FORMATTER_IPP_020105GER 223