compiler_log_formatter.ipp 6.9 KB

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