LCOV - code coverage report
Current view: top level - opt/homebrew/include/boost/test/impl - plain_report_formatter.ipp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 15 89 16.9 %
Date: 2026-06-25 07:23:43 Functions: 3 7 42.9 %

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

Generated by: LCOV version 1.16