1 | // (C) Copyright Gennadiy Rozental 2005.
|
---|
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: plain_report_formatter.ipp,v $
|
---|
9 | //
|
---|
10 | // Version : $Revision: 1.1.2.2 $
|
---|
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_suite.hpp>
|
---|
23 |
|
---|
24 | #include <boost/test/utils/basic_cstring/io.hpp>
|
---|
25 |
|
---|
26 | // STL
|
---|
27 | #include <iomanip>
|
---|
28 | #include <cmath>
|
---|
29 | #include <iostream>
|
---|
30 |
|
---|
31 | #include <boost/test/detail/suppress_warnings.hpp>
|
---|
32 |
|
---|
33 | # ifdef BOOST_NO_STDC_NAMESPACE
|
---|
34 | namespace std { using ::log10; }
|
---|
35 | # endif
|
---|
36 |
|
---|
37 | //____________________________________________________________________________//
|
---|
38 |
|
---|
39 | namespace boost {
|
---|
40 |
|
---|
41 | namespace unit_test {
|
---|
42 |
|
---|
43 | namespace output {
|
---|
44 |
|
---|
45 | namespace {
|
---|
46 |
|
---|
47 | typedef custom_manip<struct quote_t> quote;
|
---|
48 |
|
---|
49 | template<typename T>
|
---|
50 | inline std::ostream&
|
---|
51 | operator<<( custom_printer<quote> const& p, T const& value )
|
---|
52 | {
|
---|
53 | *p << '"' << value << '"';
|
---|
54 |
|
---|
55 | return *p;
|
---|
56 | }
|
---|
57 |
|
---|
58 | //____________________________________________________________________________//
|
---|
59 |
|
---|
60 | void
|
---|
61 | print_stat_value( std::ostream& ostr, counter_t v, counter_t indent, counter_t total,
|
---|
62 | const_string name, const_string res )
|
---|
63 | {
|
---|
64 | if( v > 0 ) {
|
---|
65 | ostr << std::setw( indent ) << ""
|
---|
66 | << v << ' ' << name << ( v != 1 ? "s" : "" );
|
---|
67 | if( total > 0 )
|
---|
68 | ostr << " out of " << total;
|
---|
69 |
|
---|
70 | ostr << ' ' << res << '\n';
|
---|
71 | }
|
---|
72 | }
|
---|
73 |
|
---|
74 | //____________________________________________________________________________//
|
---|
75 |
|
---|
76 | } // local namespace
|
---|
77 |
|
---|
78 | // ************************************************************************** //
|
---|
79 | // ************** plain_report_formatter ************** //
|
---|
80 | // ************************************************************************** //
|
---|
81 |
|
---|
82 | void
|
---|
83 | plain_report_formatter::results_report_start( std::ostream& ostr )
|
---|
84 | {
|
---|
85 | m_indent = 0;
|
---|
86 | ostr << '\n';
|
---|
87 | }
|
---|
88 |
|
---|
89 | //____________________________________________________________________________//
|
---|
90 |
|
---|
91 | void
|
---|
92 | plain_report_formatter::results_report_finish( std::ostream& ostr )
|
---|
93 | {
|
---|
94 | ostr.flush();
|
---|
95 | }
|
---|
96 |
|
---|
97 | //____________________________________________________________________________//
|
---|
98 |
|
---|
99 | void
|
---|
100 | plain_report_formatter::test_unit_report_start( test_unit const& tu, std::ostream& ostr )
|
---|
101 | {
|
---|
102 | test_results const& tr = results_collector.results( tu.p_id );
|
---|
103 |
|
---|
104 | const_string descr;
|
---|
105 |
|
---|
106 | if( tr.passed() )
|
---|
107 | descr = "passed";
|
---|
108 | else if( tr.p_skipped )
|
---|
109 | descr = "skipped";
|
---|
110 | else if( tr.p_aborted )
|
---|
111 | descr = "aborted";
|
---|
112 | else
|
---|
113 | descr = "failed";
|
---|
114 |
|
---|
115 | ostr << std::setw( m_indent ) << ""
|
---|
116 | << "Test " << (tu.p_type == tut_case ? "case " : "suite " ) << quote() << tu.p_name << ' ' << descr;
|
---|
117 |
|
---|
118 | if( tr.p_skipped ) {
|
---|
119 | ostr << '\n';
|
---|
120 | m_indent += 2;
|
---|
121 | return;
|
---|
122 | }
|
---|
123 |
|
---|
124 | counter_t total_assertions = tr.p_assertions_passed + tr.p_assertions_failed;
|
---|
125 | counter_t total_tc = tr.p_test_cases_passed + tr.p_test_cases_failed + tr.p_test_cases_skipped;
|
---|
126 |
|
---|
127 | if( total_assertions > 0 || total_tc > 0 )
|
---|
128 | ostr << " with:";
|
---|
129 |
|
---|
130 | ostr << '\n';
|
---|
131 | m_indent += 2;
|
---|
132 |
|
---|
133 | print_stat_value( ostr, tr.p_assertions_passed, m_indent, total_assertions, "assertion", "passed" );
|
---|
134 | print_stat_value( ostr, tr.p_assertions_failed, m_indent, total_assertions, "assertion", "failed" );
|
---|
135 | print_stat_value( ostr, tr.p_expected_failures, m_indent, 0 , "failure" , "expected" );
|
---|
136 | print_stat_value( ostr, tr.p_test_cases_passed, m_indent, total_tc , "test case", "passed" );
|
---|
137 | print_stat_value( ostr, tr.p_test_cases_failed, m_indent, total_tc , "test case", "failed" );
|
---|
138 | print_stat_value( ostr, tr.p_test_cases_skipped, m_indent, total_tc , "test case", "skipped" );
|
---|
139 |
|
---|
140 | ostr << '\n';
|
---|
141 | }
|
---|
142 |
|
---|
143 | //____________________________________________________________________________//
|
---|
144 |
|
---|
145 | void
|
---|
146 | plain_report_formatter::test_unit_report_finish( test_unit const&, std::ostream& )
|
---|
147 | {
|
---|
148 | m_indent -= 2;
|
---|
149 | }
|
---|
150 |
|
---|
151 | //____________________________________________________________________________//
|
---|
152 |
|
---|
153 | void
|
---|
154 | plain_report_formatter::do_confirmation_report( test_unit const& tu, std::ostream& ostr )
|
---|
155 | {
|
---|
156 | test_results const& tr = results_collector.results( tu.p_id );
|
---|
157 |
|
---|
158 | if( tr.passed() ) {
|
---|
159 | ostr << "*** No errors detected\n";
|
---|
160 | return;
|
---|
161 | }
|
---|
162 |
|
---|
163 | if( tr.p_skipped ) {
|
---|
164 | ostr << "*** Test " << tu.p_type_name << " skipped \n";
|
---|
165 | return;
|
---|
166 | }
|
---|
167 |
|
---|
168 | if( tr.p_assertions_failed == 0 ) {
|
---|
169 | ostr << "*** errors detected in test " << tu.p_type_name << " " << quote() << tu.p_name
|
---|
170 | << "; see standard output for details\n";
|
---|
171 | return;
|
---|
172 | }
|
---|
173 |
|
---|
174 |
|
---|
175 | ostr << "*** " << tr.p_assertions_failed << " failure" << ( tr.p_assertions_failed != 1 ? "s" : "" ) << " detected";
|
---|
176 |
|
---|
177 | if( tr.p_expected_failures > 0 )
|
---|
178 | ostr << " (" << tr.p_expected_failures << " failure" << ( tr.p_expected_failures != 1 ? "s" : "" ) << " expected)";
|
---|
179 |
|
---|
180 | ostr << " in test " << tu.p_type_name << " " << quote() << tu.p_name << "\n";
|
---|
181 | }
|
---|
182 |
|
---|
183 | //____________________________________________________________________________//
|
---|
184 |
|
---|
185 | } // namespace output
|
---|
186 |
|
---|
187 | } // namespace unit_test
|
---|
188 |
|
---|
189 | } // namespace boost
|
---|
190 |
|
---|
191 | //____________________________________________________________________________//
|
---|
192 |
|
---|
193 | #include <boost/test/detail/enable_warnings.hpp>
|
---|
194 |
|
---|
195 | // ***************************************************************************
|
---|
196 | // Revision History :
|
---|
197 | //
|
---|
198 | // $Log: plain_report_formatter.ipp,v $
|
---|
199 | // Revision 1.1.2.2 2005/11/28 11:57:07 dgregor
|
---|
200 | // Make that.... iostream
|
---|
201 | //
|
---|
202 | // Revision 1.1.2.1 2005/11/28 00:02:36 dgregor
|
---|
203 | // Include ostream
|
---|
204 | //
|
---|
205 | // Revision 1.1 2005/02/20 08:27:07 rogeeff
|
---|
206 | // This a major update for Boost.Test framework. See release docs for complete list of fixes/updates
|
---|
207 | //
|
---|
208 | // ***************************************************************************
|
---|
209 |
|
---|
210 | #endif // BOOST_TEST_PLAIN_REPORT_FORMATTER_IPP_020105GER
|
---|