]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | operator<<( utils::custom_printer<quote> const& p, T const& value ) | |
53 | { | |
54 | *p << '"' << value << '"'; | |
55 | ||
56 | return *p; | |
57 | } | |
58 | ||
59 | //____________________________________________________________________________// | |
60 | ||
61 | void | |
62 | print_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 | ||
82 | void | |
83 | plain_report_formatter::results_report_start( std::ostream& ostr ) | |
84 | { | |
85 | m_indent = 0; | |
86 | m_color_output = runtime_config::get<bool>( runtime_config::COLOR_OUTPUT ); | |
87 | ostr << '\n'; | |
88 | } | |
89 | ||
90 | //____________________________________________________________________________// | |
91 | ||
92 | void | |
93 | plain_report_formatter::results_report_finish( std::ostream& ostr ) | |
94 | { | |
95 | ostr.flush(); | |
96 | } | |
97 | ||
98 | //____________________________________________________________________________// | |
99 | ||
100 | void | |
101 | plain_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_aborted ) | |
112 | descr = "was aborted"; | |
113 | else | |
114 | descr = "has failed"; | |
115 | ||
116 | ostr << std::setw( static_cast<int>(m_indent) ) << "" | |
117 | << "Test " << tu.p_type_name << ' ' << quote() << tu.full_name() << ' ' << descr; | |
118 | ||
119 | if( tr.p_skipped ) { | |
120 | ostr << "\n"; | |
121 | m_indent += 2; | |
122 | return; | |
123 | } | |
124 | ||
125 | counter_t total_assertions = tr.p_assertions_passed + tr.p_assertions_failed; | |
126 | counter_t total_tc = tr.p_test_cases_passed + tr.p_test_cases_warned + tr.p_test_cases_failed + tr.p_test_cases_skipped; | |
127 | ||
128 | if( total_assertions > 0 || total_tc > 0 || tr.p_warnings_failed > 0) | |
129 | ostr << " with:"; | |
130 | ||
131 | ostr << '\n'; | |
132 | m_indent += 2; | |
133 | ||
134 | print_stat_value( ostr, tr.p_test_cases_passed , m_indent, total_tc , "test case", "passed" ); | |
135 | print_stat_value( ostr, tr.p_test_cases_warned , m_indent, total_tc , "test case", "passed with warnings" ); | |
136 | print_stat_value( ostr, tr.p_test_cases_failed , m_indent, total_tc , "test case", "failed" ); | |
137 | print_stat_value( ostr, tr.p_test_cases_skipped, m_indent, total_tc , "test case", "skipped" ); | |
138 | print_stat_value( ostr, tr.p_test_cases_aborted, m_indent, total_tc , "test case", "aborted" ); | |
139 | print_stat_value( ostr, tr.p_assertions_passed , m_indent, total_assertions, "assertion", "passed" ); | |
140 | print_stat_value( ostr, tr.p_assertions_failed , m_indent, total_assertions, "assertion", "failed" ); | |
141 | print_stat_value( ostr, tr.p_warnings_failed , m_indent, 0 , "warning" , "failed" ); | |
142 | print_stat_value( ostr, tr.p_expected_failures , m_indent, 0 , "failure" , "expected" ); | |
143 | ||
144 | ostr << '\n'; | |
145 | } | |
146 | ||
147 | //____________________________________________________________________________// | |
148 | ||
149 | void | |
150 | plain_report_formatter::test_unit_report_finish( test_unit const&, std::ostream& ) | |
151 | { | |
152 | m_indent -= 2; | |
153 | } | |
154 | ||
155 | //____________________________________________________________________________// | |
156 | ||
157 | void | |
158 | plain_report_formatter::do_confirmation_report( test_unit const& tu, std::ostream& ostr ) | |
159 | { | |
160 | test_results const& tr = results_collector.results( tu.p_id ); | |
161 | ||
162 | if( tr.passed() ) { | |
163 | BOOST_TEST_SCOPE_SETCOLOR( m_color_output, ostr, term_attr::BRIGHT, term_color::GREEN ); | |
164 | ||
165 | ostr << "*** No errors detected\n"; | |
166 | return; | |
167 | } | |
168 | ||
169 | BOOST_TEST_SCOPE_SETCOLOR( m_color_output, ostr, term_attr::BRIGHT, term_color::RED ); | |
170 | ||
171 | if( tr.p_skipped ) { | |
172 | ostr << "*** The test " << tu.p_type_name << ' ' << quote() << tu.full_name() << " was skipped" | |
173 | << "; see standard output for details\n"; | |
174 | return; | |
175 | } | |
176 | ||
177 | if( tr.p_aborted ) { | |
178 | ostr << "*** The test " << tu.p_type_name << ' ' << quote() << tu.full_name() << " was aborted" | |
179 | << "; see standard output for details\n"; | |
180 | } | |
181 | ||
182 | if( tr.p_assertions_failed == 0 ) { | |
183 | if( !tr.p_aborted ) | |
184 | ostr << "*** Errors were detected in the test " << tu.p_type_name << ' ' << quote() << tu.full_name() | |
185 | << "; see standard output for details\n"; | |
186 | return; | |
187 | } | |
188 | ||
189 | counter_t num_failures = tr.p_assertions_failed; | |
190 | ||
191 | ostr << "*** " << num_failures << " failure" << ( num_failures != 1 ? "s are" : " is" ) << " detected"; | |
192 | ||
193 | if( tr.p_expected_failures > 0 ) | |
194 | ostr << " (" << tr.p_expected_failures << " failure" << ( tr.p_expected_failures != 1 ? "s are" : " is" ) << " expected)"; | |
195 | ||
196 | ostr << " in the test " << tu.p_type_name << " " << quote() << tu.full_name() << "\n"; | |
197 | } | |
198 | ||
199 | //____________________________________________________________________________// | |
200 | ||
201 | } // namespace output | |
202 | } // namespace unit_test | |
203 | } // namespace boost | |
204 | ||
205 | #include <boost/test/detail/enable_warnings.hpp> | |
206 | ||
207 | #endif // BOOST_TEST_PLAIN_REPORT_FORMATTER_IPP_020105GER |