Back to home page

EIC code displayed by LXR

 
 

    


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

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 : plain report formatter definition
0013 // ***************************************************************************
0014 
0015 #ifndef BOOST_TEST_PLAIN_REPORT_FORMATTER_IPP_020105GER
0016 #define BOOST_TEST_PLAIN_REPORT_FORMATTER_IPP_020105GER
0017 
0018 // Boost.Test
0019 #include <boost/test/output/plain_report_formatter.hpp>
0020 #include <boost/test/utils/custom_manip.hpp>
0021 #include <boost/test/results_collector.hpp>
0022 #include <boost/test/unit_test_parameters.hpp>
0023 
0024 #include <boost/test/tree/test_unit.hpp>
0025 
0026 #include <boost/test/utils/basic_cstring/io.hpp>
0027 #include <boost/test/utils/setcolor.hpp>
0028 
0029 // STL
0030 #include <iomanip>
0031 #include <boost/config/no_tr1/cmath.hpp>
0032 #include <iostream>
0033 
0034 #include <boost/test/detail/suppress_warnings.hpp>
0035 
0036 # ifdef BOOST_NO_STDC_NAMESPACE
0037 namespace std { using ::log10; }
0038 # endif
0039 
0040 //____________________________________________________________________________//
0041 
0042 namespace boost {
0043 namespace unit_test {
0044 namespace output {
0045 
0046 namespace {
0047 
0048 typedef utils::custom_manip<struct quote_t> quote;
0049 
0050 template<typename T>
0051 inline std::ostream&
0052 operator<<( utils::custom_printer<quote> const& p, T const& value )
0053 {
0054     *p << '"' << value << '"';
0055 
0056     return *p;
0057 }
0058 
0059 //____________________________________________________________________________//
0060 
0061 void
0062 print_stat_value( std::ostream& ostr, counter_t v, counter_t indent, counter_t total, const_string name, const_string res )
0063 {
0064     if( v == 0 )
0065         return;
0066 
0067     if( total > 0 )
0068         ostr << std::setw( static_cast<int>(indent) ) << "" << v << ' ' << name << ( v != 1 ? "s" : "" )
0069              << " out of " << total << ' ' << res << '\n';
0070     else
0071         ostr << std::setw( static_cast<int>(indent) ) << "" << v << ' ' << res << ' ' << name << ( v != 1 ? "s" : "" ) << '\n';
0072 }
0073 
0074 //____________________________________________________________________________//
0075 
0076 } // local namespace
0077 
0078 // ************************************************************************** //
0079 // **************             plain_report_formatter           ************** //
0080 // ************************************************************************** //
0081 
0082 void
0083 plain_report_formatter::results_report_start( std::ostream& ostr )
0084 {
0085     m_indent = 0;
0086     m_color_output = runtime_config::get<bool>( runtime_config::btrt_color_output );
0087     ostr << '\n';
0088 }
0089 
0090 //____________________________________________________________________________//
0091 
0092 void
0093 plain_report_formatter::results_report_finish( std::ostream& ostr )
0094 {
0095     ostr.flush();
0096 }
0097 
0098 //____________________________________________________________________________//
0099 
0100 void
0101 plain_report_formatter::test_unit_report_start( test_unit const& tu, std::ostream& ostr )
0102 {
0103     test_results const& tr = results_collector.results( tu.p_id );
0104 
0105     const_string descr;
0106 
0107     if( tr.passed() )
0108         descr = "has passed";
0109     else if( tr.p_skipped )
0110         descr = "was skipped";
0111     else if( tr.p_timed_out )
0112         descr = "has timed out";
0113     else if( tr.p_aborted )
0114         descr = "was aborted";
0115     else
0116         descr = "has failed";
0117 
0118     ostr << std::setw( static_cast<int>(m_indent) ) << ""
0119          << "Test " << tu.p_type_name << ' ' << quote() << tu.full_name() << ' ' << descr;
0120 
0121     if( tr.p_skipped ) {
0122         ostr  << "\n";
0123         m_indent += 2;
0124         return;
0125     }
0126 
0127     // aborted test case within failed ones, timed-out TC exclusive with failed/aborted
0128     counter_t total_assertions  = tr.p_assertions_passed + tr.p_assertions_failed;
0129     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;
0130 
0131     if( total_assertions > 0 || total_tc > 0 || tr.p_warnings_failed > 0)
0132         ostr << " with:";
0133 
0134     ostr << '\n';
0135     m_indent += 2;
0136 
0137     print_stat_value( ostr, tr.p_test_cases_passed , m_indent, total_tc        , "test case", "passed" );
0138     print_stat_value( ostr, tr.p_test_cases_warned , m_indent, total_tc        , "test case", "passed with warnings" );
0139     print_stat_value( ostr, tr.p_test_cases_failed , m_indent, total_tc        , "test case", "failed" );
0140     print_stat_value( ostr, tr.p_test_cases_timed_out, m_indent, total_tc      , "test case", "timed-out" );
0141     print_stat_value( ostr, tr.p_test_suites_timed_out, m_indent, tr.p_test_suites, "test suite", "timed-out" );
0142     print_stat_value( ostr, tr.p_test_cases_skipped, m_indent, total_tc        , "test case", "skipped" );
0143     print_stat_value( ostr, tr.p_test_cases_aborted, m_indent, total_tc        , "test case", "aborted" );
0144     print_stat_value( ostr, tr.p_assertions_passed , m_indent, total_assertions, "assertion", "passed" );
0145     print_stat_value( ostr, tr.p_assertions_failed , m_indent, total_assertions, "assertion", "failed" );
0146     print_stat_value( ostr, tr.p_warnings_failed   , m_indent, 0               , "warning"  , "failed" );
0147     print_stat_value( ostr, tr.p_expected_failures , m_indent, 0               , "failure"  , "expected" );
0148 
0149     ostr << '\n';
0150 }
0151 
0152 //____________________________________________________________________________//
0153 
0154 void
0155 plain_report_formatter::test_unit_report_finish( test_unit const&, std::ostream& )
0156 {
0157     m_indent -= 2;
0158 }
0159 
0160 //____________________________________________________________________________//
0161 
0162 void
0163 plain_report_formatter::do_confirmation_report( test_unit const& tu, std::ostream& ostr )
0164 {
0165     test_results const& tr = results_collector.results( tu.p_id );
0166 
0167     if( tr.passed() ) {
0168         BOOST_TEST_SCOPE_SETCOLOR( m_color_output, ostr, term_attr::BRIGHT, term_color::GREEN );
0169 
0170         ostr << "*** No errors detected\n";
0171         return;
0172     }
0173 
0174     BOOST_TEST_SCOPE_SETCOLOR( m_color_output, ostr, term_attr::BRIGHT, term_color::RED );
0175 
0176     if( tr.p_skipped ) {
0177         ostr << "*** The test " << tu.p_type_name << ' ' << quote() << tu.full_name() << " was skipped"
0178              << "; see standard output for details\n";
0179         return;
0180     }
0181 
0182     if( tr.p_timed_out ) {
0183         ostr << "*** The test " << tu.p_type_name << ' ' << quote() << tu.full_name() << " has timed out"
0184              << "; see standard output for details\n";
0185         return;
0186     }
0187 
0188     if( tr.p_aborted ) {
0189         ostr << "*** The test " << tu.p_type_name << ' ' << quote() << tu.full_name() << " was aborted"
0190              << "; see standard output for details\n";
0191     }
0192 
0193     if( tr.p_assertions_failed == 0 ) {
0194         if( !tr.p_aborted )
0195             ostr << "*** Errors were detected in the test " << tu.p_type_name << ' ' << quote() << tu.full_name()
0196                  << "; see standard output for details\n";
0197         return;
0198     }
0199 
0200     counter_t num_failures = tr.p_assertions_failed;
0201 
0202     ostr << "*** " << num_failures << " failure" << ( num_failures != 1 ? "s are" : " is" ) << " detected";
0203 
0204     if( tr.p_expected_failures > 0 )
0205         ostr << " (" << tr.p_expected_failures << " failure" << ( tr.p_expected_failures != 1 ? "s are" : " is" ) << " expected)";
0206 
0207     ostr << " in the test " << tu.p_type_name << " " << quote() << tu.full_name() << "\n";
0208 }
0209 
0210 //____________________________________________________________________________//
0211 
0212 } // namespace output
0213 } // namespace unit_test
0214 } // namespace boost
0215 
0216 #include <boost/test/detail/enable_warnings.hpp>
0217 
0218 #endif // BOOST_TEST_PLAIN_REPORT_FORMATTER_IPP_020105GER