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 37namespace std { using ::log10; } 38# endif 39 40//____________________________________________________________________________// 41 42namespace boost { 43namespace unit_test { 44namespace output { 45 46namespace { 47 48typedef utils::custom_manip<struct quote_t> quote; 49 50template<typename T> 51inline std::ostream& 52operator<<( utils::custom_printer<quote> const& p, T const& value ) 53{ 54 *p << '"' << value << '"'; 55 56 return *p; 57} 58 59//____________________________________________________________________________// 60 61void 62print_stat_value( std::ostream& ostr, counter_t v, counter_t indent, counter_t total, const_string name, const_string res ) 63{ 64 if( v == 0 ) 65 return; 66 67 if( total > 0 ) 68 ostr << std::setw( static_cast<int>(indent) ) << "" << v << ' ' << name << ( v != 1 ? "s" : "" ) 69 << " out of " << total << ' ' << res << '\n'; 70 else 71 ostr << std::setw( static_cast<int>(indent) ) << "" << v << ' ' << res << ' ' << name << ( v != 1 ? "s" : "" ) << '\n'; 72} 73 74//____________________________________________________________________________// 75 76} // local namespace 77 78// ************************************************************************** // 79// ************** plain_report_formatter ************** // 80// ************************************************************************** // 81 82void 83plain_report_formatter::results_report_start( std::ostream& ostr ) 84{ 85 m_indent = 0; 86 m_color_output = runtime_config::get<bool>( runtime_config::btrt_color_output ); 87 ostr << '\n'; 88} 89 90//____________________________________________________________________________// 91 92void 93plain_report_formatter::results_report_finish( std::ostream& ostr ) 94{ 95 ostr.flush(); 96} 97 98//____________________________________________________________________________// 99 100void 101plain_report_formatter::test_unit_report_start( test_unit const& tu, std::ostream& ostr ) 102{ 103 test_results const& tr = results_collector.results( tu.p_id ); 104 105 const_string descr; 106 107 if( tr.passed() ) 108 descr = "has passed"; 109 else if( tr.p_skipped ) 110 descr = "was skipped"; 111 else if( tr.p_timed_out ) 112 descr = "has timed out"; 113 else if( tr.p_aborted ) 114 descr = "was aborted"; 115 else 116 descr = "has failed"; 117 118 ostr << std::setw( static_cast<int>(m_indent) ) << "" 119 << "Test " << tu.p_type_name << ' ' << quote() << tu.full_name() << ' ' << descr; 120 121 if( tr.p_skipped ) { 122 ostr << "\n"; 123 m_indent += 2; 124 return; 125 } 126 127 // aborted test case within failed ones, timed-out TC exclusive with failed/aborted 128 counter_t total_assertions = tr.p_assertions_passed + tr.p_assertions_failed; 129 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 if( total_assertions > 0 || total_tc > 0 || tr.p_warnings_failed > 0) 132 ostr << " with:"; 133 134 ostr << '\n'; 135 m_indent += 2; 136 137 print_stat_value( ostr, tr.p_test_cases_passed , m_indent, total_tc , "test case", "passed" ); 138 print_stat_value( ostr, tr.p_test_cases_warned , m_indent, total_tc , "test case", "passed with warnings" ); 139 print_stat_value( ostr, tr.p_test_cases_failed , m_indent, total_tc , "test case", "failed" ); 140 print_stat_value( ostr, tr.p_test_cases_timed_out, m_indent, total_tc , "test case", "timed-out" ); 141 print_stat_value( ostr, tr.p_test_suites_timed_out, m_indent, tr.p_test_suites, "test suite", "timed-out" ); 142 print_stat_value( ostr, tr.p_test_cases_skipped, m_indent, total_tc , "test case", "skipped" ); 143 print_stat_value( ostr, tr.p_test_cases_aborted, m_indent, total_tc , "test case", "aborted" ); 144 print_stat_value( ostr, tr.p_assertions_passed , m_indent, total_assertions, "assertion", "passed" ); 145 print_stat_value( ostr, tr.p_assertions_failed , m_indent, total_assertions, "assertion", "failed" ); 146 print_stat_value( ostr, tr.p_warnings_failed , m_indent, 0 , "warning" , "failed" ); 147 print_stat_value( ostr, tr.p_expected_failures , m_indent, 0 , "failure" , "expected" ); 148 149 ostr << '\n'; 150} 151 152//____________________________________________________________________________// 153 154void 155plain_report_formatter::test_unit_report_finish( test_unit const&, std::ostream& ) 156{ 157 m_indent -= 2; 158} 159 160//____________________________________________________________________________// 161 162void 163plain_report_formatter::do_confirmation_report( test_unit const& tu, std::ostream& ostr ) 164{ 165 test_results const& tr = results_collector.results( tu.p_id ); 166 167 if( tr.passed() ) { 168 BOOST_TEST_SCOPE_SETCOLOR( m_color_output, ostr, term_attr::BRIGHT, term_color::GREEN ); 169 170 ostr << "*** No errors detected\n"; 171 return; 172 } 173 174 BOOST_TEST_SCOPE_SETCOLOR( m_color_output, ostr, term_attr::BRIGHT, term_color::RED ); 175 176 if( tr.p_skipped ) { 177 ostr << "*** The test " << tu.p_type_name << ' ' << quote() << tu.full_name() << " was skipped" 178 << "; see standard output for details\n"; 179 return; 180 } 181 182 if( tr.p_timed_out ) { 183 ostr << "*** The test " << tu.p_type_name << ' ' << quote() << tu.full_name() << " has timed out" 184 << "; see standard output for details\n"; 185 return; 186 } 187 188 if( tr.p_aborted ) { 189 ostr << "*** The test " << tu.p_type_name << ' ' << quote() << tu.full_name() << " was aborted" 190 << "; see standard output for details\n"; 191 } 192 193 if( tr.p_assertions_failed == 0 ) { 194 if( !tr.p_aborted ) 195 ostr << "*** Errors were detected in the test " << tu.p_type_name << ' ' << quote() << tu.full_name() 196 << "; see standard output for details\n"; 197 return; 198 } 199 200 counter_t num_failures = tr.p_assertions_failed; 201 202 ostr << "*** " << num_failures << " failure" << ( num_failures != 1 ? "s are" : " is" ) << " detected"; 203 204 if( tr.p_expected_failures > 0 ) 205 ostr << " (" << tr.p_expected_failures << " failure" << ( tr.p_expected_failures != 1 ? "s are" : " is" ) << " expected)"; 206 207 ostr << " in the test " << tu.p_type_name << " " << quote() << tu.full_name() << "\n"; 208} 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 219