]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/test/impl/compiler_log_formatter.ipp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / test / impl / compiler_log_formatter.ipp
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 : implements compiler like Log formatter
13 // ***************************************************************************
14
15 #ifndef BOOST_TEST_COMPILER_LOG_FORMATTER_IPP_020105GER
16 #define BOOST_TEST_COMPILER_LOG_FORMATTER_IPP_020105GER
17
18 // Boost.Test
19 #include <boost/test/output/compiler_log_formatter.hpp>
20
21 #include <boost/test/framework.hpp>
22 #include <boost/test/execution_monitor.hpp>
23 #include <boost/test/unit_test_parameters.hpp>
24
25 #include <boost/test/tree/test_unit.hpp>
26
27 #include <boost/test/utils/basic_cstring/io.hpp>
28 #include <boost/test/utils/lazy_ostream.hpp>
29 #include <boost/test/utils/setcolor.hpp>
30
31
32 // Boost
33 #include <boost/version.hpp>
34
35 // STL
36 #include <iostream>
37
38 #include <boost/test/detail/suppress_warnings.hpp>
39
40 //____________________________________________________________________________//
41
42 namespace boost {
43 namespace unit_test {
44 namespace output {
45
46 // ************************************************************************** //
47 // ************** compiler_log_formatter ************** //
48 // ************************************************************************** //
49
50 namespace {
51
52 std::string
53 test_phase_identifier()
54 {
55 return framework::test_in_progress() ? framework::current_test_unit().full_name() : std::string( "Test setup" );
56 }
57
58 } // local namespace
59
60 //____________________________________________________________________________//
61
62 void
63 compiler_log_formatter::log_start( std::ostream& output, counter_t test_cases_amount )
64 {
65 m_color_output = runtime_config::get<bool>( runtime_config::btrt_color_output );
66
67 if( test_cases_amount > 0 )
68 output << "Running " << test_cases_amount << " test "
69 << (test_cases_amount > 1 ? "cases" : "case") << "...\n";
70 }
71
72 //____________________________________________________________________________//
73
74 void
75 compiler_log_formatter::log_finish( std::ostream& ostr )
76 {
77 ostr.flush();
78 }
79
80 //____________________________________________________________________________//
81
82 void
83 compiler_log_formatter::log_build_info( std::ostream& output )
84 {
85 output << "Platform: " << BOOST_PLATFORM << '\n'
86 << "Compiler: " << BOOST_COMPILER << '\n'
87 << "STL : " << BOOST_STDLIB << '\n'
88 << "Boost : " << BOOST_VERSION/100000 << "."
89 << BOOST_VERSION/100 % 1000 << "."
90 << BOOST_VERSION % 100 << std::endl;
91 }
92
93 //____________________________________________________________________________//
94
95 void
96 compiler_log_formatter::test_unit_start( std::ostream& output, test_unit const& tu )
97 {
98 BOOST_TEST_SCOPE_SETCOLOR( m_color_output, output, term_attr::BRIGHT, term_color::BLUE );
99
100 print_prefix( output, tu.p_file_name, tu.p_line_num );
101
102 output << "Entering test " << tu.p_type_name << " \"" << tu.p_name << "\"" << std::endl;
103 }
104
105 //____________________________________________________________________________//
106
107 void
108 compiler_log_formatter::test_unit_finish( std::ostream& output, test_unit const& tu, unsigned long elapsed )
109 {
110 BOOST_TEST_SCOPE_SETCOLOR( m_color_output, output, term_attr::BRIGHT, term_color::BLUE );
111
112 print_prefix( output, tu.p_file_name, tu.p_line_num );
113
114 output << "Leaving test " << tu.p_type_name << " \"" << tu.p_name << "\"";
115
116 if( elapsed > 0 ) {
117 output << "; testing time: ";
118 if( elapsed % 1000 == 0 )
119 output << elapsed/1000 << "ms";
120 else
121 output << elapsed << "us";
122 }
123
124 output << std::endl;
125 }
126
127 //____________________________________________________________________________//
128
129 void
130 compiler_log_formatter::test_unit_skipped( std::ostream& output, test_unit const& tu, const_string reason )
131 {
132 BOOST_TEST_SCOPE_SETCOLOR( m_color_output, output, term_attr::BRIGHT, term_color::YELLOW );
133
134 print_prefix( output, tu.p_file_name, tu.p_line_num );
135
136 output << "Test " << tu.p_type_name << " \"" << tu.full_name() << "\"" << " is skipped because " << reason << std::endl;
137 }
138
139 //____________________________________________________________________________//
140
141 void
142 compiler_log_formatter::log_exception_start( std::ostream& output, log_checkpoint_data const& checkpoint_data, execution_exception const& ex )
143 {
144 execution_exception::location const& loc = ex.where();
145
146 print_prefix( output, loc.m_file_name, loc.m_line_num );
147
148 {
149 BOOST_TEST_SCOPE_SETCOLOR( m_color_output, output, term_attr::UNDERLINE, term_color::RED );
150
151 output << "fatal error: in \"" << (loc.m_function.is_empty() ? test_phase_identifier() : loc.m_function ) << "\": "
152 << ex.what();
153 }
154
155 if( !checkpoint_data.m_file_name.is_empty() ) {
156 output << '\n';
157 print_prefix( output, checkpoint_data.m_file_name, checkpoint_data.m_line_num );
158
159 BOOST_TEST_SCOPE_SETCOLOR( m_color_output, output, term_attr::BRIGHT, term_color::CYAN );
160
161 output << "last checkpoint";
162 if( !checkpoint_data.m_message.empty() )
163 output << ": " << checkpoint_data.m_message;
164 }
165 }
166
167 //____________________________________________________________________________//
168
169 void
170 compiler_log_formatter::log_exception_finish( std::ostream& output )
171 {
172 output << std::endl;
173 }
174
175 //____________________________________________________________________________//
176
177 void
178 compiler_log_formatter::log_entry_start( std::ostream& output, log_entry_data const& entry_data, log_entry_types let )
179 {
180 using namespace utils;
181
182 switch( let ) {
183 case BOOST_UTL_ET_INFO:
184 print_prefix( output, entry_data.m_file_name, entry_data.m_line_num );
185 if( m_color_output )
186 output << setcolor( term_attr::BRIGHT, term_color::GREEN );
187 output << "info: ";
188 break;
189 case BOOST_UTL_ET_MESSAGE:
190 if( m_color_output )
191 output << setcolor( term_attr::BRIGHT, term_color::CYAN );
192 break;
193 case BOOST_UTL_ET_WARNING:
194 print_prefix( output, entry_data.m_file_name, entry_data.m_line_num );
195 if( m_color_output )
196 output << setcolor( term_attr::BRIGHT, term_color::YELLOW );
197 output << "warning: in \"" << test_phase_identifier() << "\": ";
198 break;
199 case BOOST_UTL_ET_ERROR:
200 print_prefix( output, entry_data.m_file_name, entry_data.m_line_num );
201 if( m_color_output )
202 output << setcolor( term_attr::BRIGHT, term_color::RED );
203 output << "error: in \"" << test_phase_identifier() << "\": ";
204 break;
205 case BOOST_UTL_ET_FATAL_ERROR:
206 print_prefix( output, entry_data.m_file_name, entry_data.m_line_num );
207 if( m_color_output )
208 output << setcolor( term_attr::UNDERLINE, term_color::RED );
209 output << "fatal error: in \"" << test_phase_identifier() << "\": ";
210 break;
211 }
212 }
213
214 //____________________________________________________________________________//
215
216 void
217 compiler_log_formatter::log_entry_value( std::ostream& output, const_string value )
218 {
219 output << value;
220 }
221
222 //____________________________________________________________________________//
223
224 void
225 compiler_log_formatter::log_entry_value( std::ostream& output, lazy_ostream const& value )
226 {
227 output << value;
228 }
229
230 //____________________________________________________________________________//
231
232 void
233 compiler_log_formatter::log_entry_finish( std::ostream& output )
234 {
235 if( m_color_output )
236 output << utils::setcolor();
237
238 output << std::endl;
239 }
240
241
242 //____________________________________________________________________________//
243
244 void
245 compiler_log_formatter::print_prefix( std::ostream& output, const_string file_name, std::size_t line_num )
246 {
247 if( !file_name.empty() ) {
248 #ifdef __APPLE_CC__
249 // Xcode-compatible logging format, idea by Richard Dingwall at
250 // <http://richarddingwall.name/2008/06/01/using-the-boost-unit-test-framework-with-xcode-3/>.
251 output << file_name << ':' << line_num << ": ";
252 #else
253 output << file_name << '(' << line_num << "): ";
254 #endif
255 }
256 }
257
258 //____________________________________________________________________________//
259
260 void
261 compiler_log_formatter::entry_context_start( std::ostream& output, log_level l )
262 {
263 if( l == log_messages ) {
264 output << "\n[context:";
265 }
266 else {
267 output << (l == log_successful_tests ? "\nAssertion" : "\nFailure" ) << " occurred in a following context:";
268 }
269 }
270
271 //____________________________________________________________________________//
272
273 void
274 compiler_log_formatter::entry_context_finish( std::ostream& output, log_level l )
275 {
276 if( l == log_messages ) {
277 output << "]";
278 }
279 output.flush();
280 }
281
282 //____________________________________________________________________________//
283
284 void
285 compiler_log_formatter::log_entry_context( std::ostream& output, log_level l, const_string context_descr )
286 {
287 output << "\n " << context_descr;
288 }
289
290 //____________________________________________________________________________//
291
292 } // namespace output
293 } // namespace unit_test
294 } // namespace boost
295
296 #include <boost/test/detail/enable_warnings.hpp>
297
298 #endif // BOOST_TEST_COMPILER_LOG_FORMATTER_IPP_020105GER