plain_report_formatter.ipp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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)
  5. // See http://www.boost.org/libs/test for the library home page.
  6. //
  7. // File : $RCSfile$
  8. //
  9. // Version : $Revision$
  10. //
  11. // Description : plain report formatter definition
  12. // ***************************************************************************
  13. #ifndef BOOST_TEST_PLAIN_REPORT_FORMATTER_IPP_020105GER
  14. #define BOOST_TEST_PLAIN_REPORT_FORMATTER_IPP_020105GER
  15. // Boost.Test
  16. #include <boost/test/output/plain_report_formatter.hpp>
  17. #include <boost/test/utils/custom_manip.hpp>
  18. #include <boost/test/results_collector.hpp>
  19. #include <boost/test/unit_test_parameters.hpp>
  20. #include <boost/test/tree/test_unit.hpp>
  21. #include <boost/test/utils/basic_cstring/io.hpp>
  22. #include <boost/test/utils/setcolor.hpp>
  23. // STL
  24. #include <iomanip>
  25. #include <boost/config/no_tr1/cmath.hpp>
  26. #include <iostream>
  27. #include <boost/test/detail/suppress_warnings.hpp>
  28. # ifdef BOOST_NO_STDC_NAMESPACE
  29. namespace std { using ::log10; }
  30. # endif
  31. //____________________________________________________________________________//
  32. namespace boost {
  33. namespace unit_test {
  34. namespace output {
  35. namespace {
  36. typedef utils::custom_manip<struct quote_t> quote;
  37. template<typename T>
  38. inline std::ostream&
  39. operator<<( utils::custom_printer<quote> const& p, T const& value )
  40. {
  41. *p << '"' << value << '"';
  42. return *p;
  43. }
  44. //____________________________________________________________________________//
  45. void
  46. print_stat_value( std::ostream& ostr, counter_t v, counter_t indent, counter_t total, const_string name, const_string res )
  47. {
  48. if( v == 0 )
  49. return;
  50. if( total > 0 )
  51. ostr << std::setw( static_cast<int>(indent) ) << "" << v << ' ' << name << ( v != 1 ? "s" : "" )
  52. << " out of " << total << ' ' << res << '\n';
  53. else
  54. ostr << std::setw( static_cast<int>(indent) ) << "" << v << ' ' << res << ' ' << name << ( v != 1 ? "s" : "" ) << '\n';
  55. }
  56. //____________________________________________________________________________//
  57. } // local namespace
  58. // ************************************************************************** //
  59. // ************** plain_report_formatter ************** //
  60. // ************************************************************************** //
  61. void
  62. plain_report_formatter::results_report_start( std::ostream& ostr )
  63. {
  64. m_indent = 0;
  65. m_color_output = runtime_config::get<bool>( runtime_config::btrt_color_output );
  66. ostr << '\n';
  67. }
  68. //____________________________________________________________________________//
  69. void
  70. plain_report_formatter::results_report_finish( std::ostream& ostr )
  71. {
  72. ostr.flush();
  73. }
  74. //____________________________________________________________________________//
  75. void
  76. plain_report_formatter::test_unit_report_start( test_unit const& tu, std::ostream& ostr )
  77. {
  78. test_results const& tr = results_collector.results( tu.p_id );
  79. const_string descr;
  80. if( tr.passed() )
  81. descr = "has passed";
  82. else if( tr.p_skipped )
  83. descr = "was skipped";
  84. else if( tr.p_timed_out )
  85. descr = "has timed out";
  86. else if( tr.p_aborted )
  87. descr = "was aborted";
  88. else
  89. descr = "has failed";
  90. ostr << std::setw( static_cast<int>(m_indent) ) << ""
  91. << "Test " << tu.p_type_name << ' ' << quote() << tu.full_name() << ' ' << descr;
  92. if( tr.p_skipped ) {
  93. ostr << "\n";
  94. m_indent += 2;
  95. return;
  96. }
  97. // aborted test case within failed ones, timed-out TC exclusive with failed/aborted
  98. counter_t total_assertions = tr.p_assertions_passed + tr.p_assertions_failed;
  99. counter_t total_tc = tr.p_test_cases_passed + tr.p_test_cases_warned + tr.p_test_cases_failed + tr.p_test_cases_skipped + tr.p_test_cases_timed_out;
  100. if( total_assertions > 0 || total_tc > 0 || tr.p_warnings_failed > 0)
  101. ostr << " with:";
  102. ostr << '\n';
  103. m_indent += 2;
  104. print_stat_value( ostr, tr.p_test_cases_passed , m_indent, total_tc , "test case", "passed" );
  105. print_stat_value( ostr, tr.p_test_cases_warned , m_indent, total_tc , "test case", "passed with warnings" );
  106. print_stat_value( ostr, tr.p_test_cases_failed , m_indent, total_tc , "test case", "failed" );
  107. print_stat_value( ostr, tr.p_test_cases_timed_out, m_indent, total_tc , "test case", "timed-out" );
  108. print_stat_value( ostr, tr.p_test_suites_timed_out, m_indent, tr.p_test_suites, "test suite", "timed-out" );
  109. print_stat_value( ostr, tr.p_test_cases_skipped, m_indent, total_tc , "test case", "skipped" );
  110. print_stat_value( ostr, tr.p_test_cases_aborted, m_indent, total_tc , "test case", "aborted" );
  111. print_stat_value( ostr, tr.p_assertions_passed , m_indent, total_assertions, "assertion", "passed" );
  112. print_stat_value( ostr, tr.p_assertions_failed , m_indent, total_assertions, "assertion", "failed" );
  113. print_stat_value( ostr, tr.p_warnings_failed , m_indent, 0 , "warning" , "failed" );
  114. print_stat_value( ostr, tr.p_expected_failures , m_indent, 0 , "failure" , "expected" );
  115. ostr << '\n';
  116. }
  117. //____________________________________________________________________________//
  118. void
  119. plain_report_formatter::test_unit_report_finish( test_unit const&, std::ostream& )
  120. {
  121. m_indent -= 2;
  122. }
  123. //____________________________________________________________________________//
  124. void
  125. plain_report_formatter::do_confirmation_report( test_unit const& tu, std::ostream& ostr )
  126. {
  127. test_results const& tr = results_collector.results( tu.p_id );
  128. if( tr.passed() ) {
  129. BOOST_TEST_SCOPE_SETCOLOR( m_color_output, ostr, term_attr::BRIGHT, term_color::GREEN );
  130. ostr << "*** No errors detected\n";
  131. return;
  132. }
  133. BOOST_TEST_SCOPE_SETCOLOR( m_color_output, ostr, term_attr::BRIGHT, term_color::RED );
  134. if( tr.p_skipped ) {
  135. ostr << "*** The test " << tu.p_type_name << ' ' << quote() << tu.full_name() << " was skipped"
  136. << "; see standard output for details\n";
  137. return;
  138. }
  139. if( tr.p_timed_out ) {
  140. ostr << "*** The test " << tu.p_type_name << ' ' << quote() << tu.full_name() << " has timed out"
  141. << "; see standard output for details\n";
  142. return;
  143. }
  144. if( tr.p_aborted ) {
  145. ostr << "*** The test " << tu.p_type_name << ' ' << quote() << tu.full_name() << " was aborted"
  146. << "; see standard output for details\n";
  147. }
  148. if( tr.p_assertions_failed == 0 ) {
  149. if( !tr.p_aborted )
  150. ostr << "*** Errors were detected in the test " << tu.p_type_name << ' ' << quote() << tu.full_name()
  151. << "; see standard output for details\n";
  152. return;
  153. }
  154. counter_t num_failures = tr.p_assertions_failed;
  155. ostr << "*** " << num_failures << " failure" << ( num_failures != 1 ? "s are" : " is" ) << " detected";
  156. if( tr.p_expected_failures > 0 )
  157. ostr << " (" << tr.p_expected_failures << " failure" << ( tr.p_expected_failures != 1 ? "s are" : " is" ) << " expected)";
  158. ostr << " in the test " << tu.p_type_name << " " << quote() << tu.full_name() << "\n";
  159. }
  160. //____________________________________________________________________________//
  161. } // namespace output
  162. } // namespace unit_test
  163. } // namespace boost
  164. #include <boost/test/detail/enable_warnings.hpp>
  165. #endif // BOOST_TEST_PLAIN_REPORT_FORMATTER_IPP_020105GER