Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:00:58

0001 //  (C) Copyright Gennadiy Rozental 2001.
0002 //  Distributed under the Boost Software License, Version 1.0.
0003 //  (See accompanying file LICENSE_1_0.txt or copy at
0004 //  http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 //  See http://www.boost.org/libs/test for the library home page.
0007 //
0008 //  File        : $RCSfile$
0009 //
0010 //  Version     : $Revision$
0011 //
0012 //  Description : implements compiler like Log formatter
0013 // ***************************************************************************
0014 
0015 #ifndef BOOST_TEST_COMPILER_LOG_FORMATTER_IPP_020105GER
0016 #define BOOST_TEST_COMPILER_LOG_FORMATTER_IPP_020105GER
0017 
0018 // Boost.Test
0019 #include <boost/test/output/compiler_log_formatter.hpp>
0020 
0021 #include <boost/test/framework.hpp>
0022 #include <boost/test/execution_monitor.hpp>
0023 #include <boost/test/unit_test_parameters.hpp>
0024 
0025 #include <boost/test/tree/test_unit.hpp>
0026 
0027 #include <boost/test/utils/basic_cstring/io.hpp>
0028 #include <boost/test/utils/lazy_ostream.hpp>
0029 
0030 // Boost
0031 #include <boost/version.hpp>
0032 
0033 // STL
0034 #include <iostream>
0035 
0036 #include <boost/test/detail/suppress_warnings.hpp>
0037 
0038 //____________________________________________________________________________//
0039 
0040 namespace boost {
0041 namespace unit_test {
0042 namespace output {
0043 
0044 // ************************************************************************** //
0045 // **************            compiler_log_formatter            ************** //
0046 // ************************************************************************** //
0047 
0048 namespace {
0049 
0050 std::string
0051 test_phase_identifier()
0052 {
0053     return framework::test_in_progress() ? framework::current_test_unit().full_name() : std::string( "Test setup" );
0054 }
0055 
0056 } // local namespace
0057 
0058 //____________________________________________________________________________//
0059 
0060 void
0061 compiler_log_formatter::log_start( std::ostream& output, counter_t test_cases_amount )
0062 {
0063     m_color_output = runtime_config::get<bool>( runtime_config::btrt_color_output );
0064 
0065     if( test_cases_amount > 0 )
0066         output  << "Running " << test_cases_amount << " test "
0067                 << (test_cases_amount > 1 ? "cases" : "case") << "...\n";
0068 }
0069 
0070 //____________________________________________________________________________//
0071 
0072 void
0073 compiler_log_formatter::log_finish( std::ostream& ostr )
0074 {
0075     ostr.flush();
0076 }
0077 
0078 //____________________________________________________________________________//
0079 
0080 void
0081 compiler_log_formatter::log_build_info( std::ostream& output, bool log_build_info )
0082 {
0083     if(log_build_info) {
0084         output  << "Platform: " << BOOST_PLATFORM            << '\n'
0085                 << "Compiler: " << BOOST_COMPILER            << '\n'
0086                 << "STL     : " << BOOST_STDLIB              << '\n'
0087                 << "Boost   : " << BOOST_VERSION/100000      << "."
0088                                 << BOOST_VERSION/100 % 1000  << "."
0089                                 << BOOST_VERSION % 100       << std::endl;
0090     }
0091 }
0092 
0093 //____________________________________________________________________________//
0094 
0095 void
0096 compiler_log_formatter::test_unit_start( std::ostream& output, test_unit const& tu )
0097 {
0098     BOOST_TEST_SCOPE_SETCOLOR( m_color_output, output, term_attr::BRIGHT, term_color::BLUE );
0099 
0100     print_prefix( output, tu.p_file_name, tu.p_line_num );
0101 
0102     output << "Entering test " << tu.p_type_name << " \"" << tu.p_name << "\"" << std::endl;
0103 }
0104 
0105 //____________________________________________________________________________//
0106 
0107 void
0108 compiler_log_formatter::test_unit_finish( std::ostream& output, test_unit const& tu, unsigned long elapsed )
0109 {
0110     BOOST_TEST_SCOPE_SETCOLOR( m_color_output, output, term_attr::BRIGHT, term_color::BLUE );
0111 
0112     print_prefix( output, tu.p_file_name, tu.p_line_num );
0113 
0114     output << "Leaving test " << tu.p_type_name << " \"" << tu.p_name << "\"";
0115 
0116     if( elapsed > 0 ) {
0117         output << "; testing time: ";
0118         if( elapsed % 1000 == 0 )
0119             output << elapsed/1000 << "ms";
0120         else
0121             output << elapsed << "us";
0122     }
0123 
0124     output << std::endl;
0125 }
0126 
0127 //____________________________________________________________________________//
0128 
0129 void
0130 compiler_log_formatter::test_unit_skipped( std::ostream& output, test_unit const& tu, const_string reason )
0131 {
0132     BOOST_TEST_SCOPE_SETCOLOR( m_color_output, output, term_attr::BRIGHT, term_color::YELLOW );
0133 
0134     print_prefix( output, tu.p_file_name, tu.p_line_num );
0135 
0136     output  << "Test " << tu.p_type_name << " \"" << tu.full_name() << "\"" << " is skipped because " << reason << std::endl;
0137 }
0138 
0139 //____________________________________________________________________________//
0140 
0141 void
0142 compiler_log_formatter::log_exception_start( std::ostream& output, log_checkpoint_data const& checkpoint_data, execution_exception const& ex )
0143 {
0144     execution_exception::location const& loc = ex.where();
0145 
0146     print_prefix( output, loc.m_file_name, loc.m_line_num );
0147 
0148     {
0149         BOOST_TEST_SCOPE_SETCOLOR( m_color_output, output, term_attr::UNDERLINE, term_color::RED );
0150 
0151         output << "fatal error: in \"" << (loc.m_function.is_empty() ? test_phase_identifier() : loc.m_function ) << "\": "
0152                << ex.what();
0153     }
0154 
0155     if( !checkpoint_data.m_file_name.is_empty() ) {
0156         output << '\n';
0157         print_prefix( output, checkpoint_data.m_file_name, checkpoint_data.m_line_num );
0158 
0159         BOOST_TEST_SCOPE_SETCOLOR( m_color_output, output, term_attr::BRIGHT, term_color::CYAN );
0160 
0161         output << "last checkpoint";
0162         if( !checkpoint_data.m_message.empty() )
0163             output << ": " << checkpoint_data.m_message;
0164     }
0165 }
0166 
0167 //____________________________________________________________________________//
0168 
0169 void
0170 compiler_log_formatter::log_exception_finish( std::ostream& output )
0171 {
0172     output << std::endl;
0173 }
0174 
0175 //____________________________________________________________________________//
0176 
0177 void
0178 compiler_log_formatter::log_entry_start( std::ostream& output, log_entry_data const& entry_data, log_entry_types let )
0179 {
0180     using namespace utils;
0181 
0182     switch( let ) {
0183         case BOOST_UTL_ET_INFO:
0184             print_prefix( output, entry_data.m_file_name, entry_data.m_line_num );
0185             output << setcolor( m_color_output, term_attr::BRIGHT, term_color::GREEN, term_color::ORIGINAL, &m_color_state);
0186             output << "info: ";
0187             break;
0188         case BOOST_UTL_ET_MESSAGE:
0189             output << setcolor( m_color_output, term_attr::BRIGHT, term_color::CYAN, term_color::ORIGINAL, &m_color_state);
0190             break;
0191         case BOOST_UTL_ET_WARNING:
0192             print_prefix( output, entry_data.m_file_name, entry_data.m_line_num );
0193             output << setcolor( m_color_output, term_attr::BRIGHT, term_color::YELLOW, term_color::ORIGINAL, &m_color_state);
0194             output << "warning: in \"" << test_phase_identifier() << "\": ";
0195             break;
0196         case BOOST_UTL_ET_ERROR:
0197             print_prefix( output, entry_data.m_file_name, entry_data.m_line_num );
0198             output << setcolor( m_color_output, term_attr::BRIGHT, term_color::RED, term_color::ORIGINAL, &m_color_state);
0199             output << "error: in \"" << test_phase_identifier() << "\": ";
0200             break;
0201         case BOOST_UTL_ET_FATAL_ERROR:
0202             print_prefix( output, entry_data.m_file_name, entry_data.m_line_num );
0203             output << setcolor( m_color_output, term_attr::UNDERLINE, term_color::RED, term_color::ORIGINAL, &m_color_state);
0204             output << "fatal error: in \"" << test_phase_identifier() << "\": ";
0205             break;
0206     }
0207 }
0208 
0209 //____________________________________________________________________________//
0210 
0211 void
0212 compiler_log_formatter::log_entry_value( std::ostream& output, const_string value )
0213 {
0214     output << value;
0215 }
0216 
0217 //____________________________________________________________________________//
0218 
0219 void
0220 compiler_log_formatter::log_entry_value( std::ostream& output, lazy_ostream const& value )
0221 {
0222     output << value;
0223 }
0224 
0225 //____________________________________________________________________________//
0226 
0227 void
0228 compiler_log_formatter::log_entry_finish( std::ostream& output )
0229 {
0230     if( m_color_output )
0231         output << utils::setcolor(m_color_output, &m_color_state);
0232 
0233     output << std::endl;
0234 }
0235 
0236 
0237 //____________________________________________________________________________//
0238 
0239 void
0240 compiler_log_formatter::print_prefix( std::ostream& output, const_string file_name, std::size_t line_num )
0241 {
0242     if( !file_name.empty() ) {
0243 #ifdef __APPLE_CC__
0244         // Xcode-compatible logging format, idea by Richard Dingwall at
0245         // <http://richarddingwall.name/2008/06/01/using-the-boost-unit-test-framework-with-xcode-3/>.
0246         output << file_name << ':' << line_num << ": ";
0247 #else
0248         output << file_name << '(' << line_num << "): ";
0249 #endif
0250     }
0251 }
0252 
0253 //____________________________________________________________________________//
0254 
0255 void
0256 compiler_log_formatter::entry_context_start( std::ostream& output, log_level l )
0257 {
0258     if( l == log_messages ) {
0259         output << "\n[context:";
0260     }
0261     else {
0262         output << (l == log_successful_tests ? "\nAssertion" : "\nFailure" ) << " occurred in a following context:";
0263     }
0264 }
0265 
0266 //____________________________________________________________________________//
0267 
0268 void
0269 compiler_log_formatter::entry_context_finish( std::ostream& output, log_level l )
0270 {
0271     if( l == log_messages ) {
0272         output << "]";
0273     }
0274     output.flush();
0275 }
0276 
0277 //____________________________________________________________________________//
0278 
0279 void
0280 compiler_log_formatter::log_entry_context( std::ostream& output, log_level /*l*/, const_string context_descr )
0281 {
0282     output << "\n    " << context_descr;
0283 }
0284 
0285 //____________________________________________________________________________//
0286 
0287 } // namespace output
0288 } // namespace unit_test
0289 } // namespace boost
0290 
0291 #include <boost/test/detail/enable_warnings.hpp>
0292 
0293 #endif // BOOST_TEST_COMPILER_LOG_FORMATTER_IPP_020105GER