]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/test/impl/compiler_log_formatter.ipp
import new upstream nautilus stable release 14.2.8
[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, bool log_build_info )
84 {
85 if(log_build_info) {
86 output << "Platform: " << BOOST_PLATFORM << '\n'
87 << "Compiler: " << BOOST_COMPILER << '\n'
88 << "STL : " << BOOST_STDLIB << '\n'
89 << "Boost : " << BOOST_VERSION/100000 << "."
90 << BOOST_VERSION/100 % 1000 << "."
91 << BOOST_VERSION % 100 << std::endl;
92 }
93 }
94
95 //____________________________________________________________________________//
96
97 void
98 compiler_log_formatter::test_unit_start( std::ostream& output, test_unit const& tu )
99 {
100 BOOST_TEST_SCOPE_SETCOLOR( m_color_output, output, term_attr::BRIGHT, term_color::BLUE );
101
102 print_prefix( output, tu.p_file_name, tu.p_line_num );
103
104 output << "Entering test " << tu.p_type_name << " \"" << tu.p_name << "\"" << std::endl;
105 }
106
107 //____________________________________________________________________________//
108
109 void
110 compiler_log_formatter::test_unit_finish( std::ostream& output, test_unit const& tu, unsigned long elapsed )
111 {
112 BOOST_TEST_SCOPE_SETCOLOR( m_color_output, output, term_attr::BRIGHT, term_color::BLUE );
113
114 print_prefix( output, tu.p_file_name, tu.p_line_num );
115
116 output << "Leaving test " << tu.p_type_name << " \"" << tu.p_name << "\"";
117
118 if( elapsed > 0 ) {
119 output << "; testing time: ";
120 if( elapsed % 1000 == 0 )
121 output << elapsed/1000 << "ms";
122 else
123 output << elapsed << "us";
124 }
125
126 output << std::endl;
127 }
128
129 //____________________________________________________________________________//
130
131 void
132 compiler_log_formatter::test_unit_skipped( std::ostream& output, test_unit const& tu, const_string reason )
133 {
134 BOOST_TEST_SCOPE_SETCOLOR( m_color_output, output, term_attr::BRIGHT, term_color::YELLOW );
135
136 print_prefix( output, tu.p_file_name, tu.p_line_num );
137
138 output << "Test " << tu.p_type_name << " \"" << tu.full_name() << "\"" << " is skipped because " << reason << std::endl;
139 }
140
141 //____________________________________________________________________________//
142
143 void
144 compiler_log_formatter::log_exception_start( std::ostream& output, log_checkpoint_data const& checkpoint_data, execution_exception const& ex )
145 {
146 execution_exception::location const& loc = ex.where();
147
148 print_prefix( output, loc.m_file_name, loc.m_line_num );
149
150 {
151 BOOST_TEST_SCOPE_SETCOLOR( m_color_output, output, term_attr::UNDERLINE, term_color::RED );
152
153 output << "fatal error: in \"" << (loc.m_function.is_empty() ? test_phase_identifier() : loc.m_function ) << "\": "
154 << ex.what();
155 }
156
157 if( !checkpoint_data.m_file_name.is_empty() ) {
158 output << '\n';
159 print_prefix( output, checkpoint_data.m_file_name, checkpoint_data.m_line_num );
160
161 BOOST_TEST_SCOPE_SETCOLOR( m_color_output, output, term_attr::BRIGHT, term_color::CYAN );
162
163 output << "last checkpoint";
164 if( !checkpoint_data.m_message.empty() )
165 output << ": " << checkpoint_data.m_message;
166 }
167 }
168
169 //____________________________________________________________________________//
170
171 void
172 compiler_log_formatter::log_exception_finish( std::ostream& output )
173 {
174 output << std::endl;
175 }
176
177 //____________________________________________________________________________//
178
179 void
180 compiler_log_formatter::log_entry_start( std::ostream& output, log_entry_data const& entry_data, log_entry_types let )
181 {
182 using namespace utils;
183
184 switch( let ) {
185 case BOOST_UTL_ET_INFO:
186 print_prefix( output, entry_data.m_file_name, entry_data.m_line_num );
187 output << setcolor( m_color_output, term_attr::BRIGHT, term_color::GREEN );
188 output << "info: ";
189 break;
190 case BOOST_UTL_ET_MESSAGE:
191 output << setcolor( m_color_output, 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 output << setcolor( m_color_output, term_attr::BRIGHT, term_color::YELLOW );
196 output << "warning: in \"" << test_phase_identifier() << "\": ";
197 break;
198 case BOOST_UTL_ET_ERROR:
199 print_prefix( output, entry_data.m_file_name, entry_data.m_line_num );
200 output << setcolor( m_color_output, term_attr::BRIGHT, term_color::RED );
201 output << "error: in \"" << test_phase_identifier() << "\": ";
202 break;
203 case BOOST_UTL_ET_FATAL_ERROR:
204 print_prefix( output, entry_data.m_file_name, entry_data.m_line_num );
205 output << setcolor( m_color_output, term_attr::UNDERLINE, term_color::RED );
206 output << "fatal error: in \"" << test_phase_identifier() << "\": ";
207 break;
208 }
209 }
210
211 //____________________________________________________________________________//
212
213 void
214 compiler_log_formatter::log_entry_value( std::ostream& output, const_string value )
215 {
216 output << value;
217 }
218
219 //____________________________________________________________________________//
220
221 void
222 compiler_log_formatter::log_entry_value( std::ostream& output, lazy_ostream const& value )
223 {
224 output << value;
225 }
226
227 //____________________________________________________________________________//
228
229 void
230 compiler_log_formatter::log_entry_finish( std::ostream& output )
231 {
232 if( m_color_output )
233 output << utils::setcolor(m_color_output);
234
235 output << std::endl;
236 }
237
238
239 //____________________________________________________________________________//
240
241 void
242 compiler_log_formatter::print_prefix( std::ostream& output, const_string file_name, std::size_t line_num )
243 {
244 if( !file_name.empty() ) {
245 #ifdef __APPLE_CC__
246 // Xcode-compatible logging format, idea by Richard Dingwall at
247 // <http://richarddingwall.name/2008/06/01/using-the-boost-unit-test-framework-with-xcode-3/>.
248 output << file_name << ':' << line_num << ": ";
249 #else
250 output << file_name << '(' << line_num << "): ";
251 #endif
252 }
253 }
254
255 //____________________________________________________________________________//
256
257 void
258 compiler_log_formatter::entry_context_start( std::ostream& output, log_level l )
259 {
260 if( l == log_messages ) {
261 output << "\n[context:";
262 }
263 else {
264 output << (l == log_successful_tests ? "\nAssertion" : "\nFailure" ) << " occurred in a following context:";
265 }
266 }
267
268 //____________________________________________________________________________//
269
270 void
271 compiler_log_formatter::entry_context_finish( std::ostream& output, log_level l )
272 {
273 if( l == log_messages ) {
274 output << "]";
275 }
276 output.flush();
277 }
278
279 //____________________________________________________________________________//
280
281 void
282 compiler_log_formatter::log_entry_context( std::ostream& output, log_level /*l*/, const_string context_descr )
283 {
284 output << "\n " << context_descr;
285 }
286
287 //____________________________________________________________________________//
288
289 } // namespace output
290 } // namespace unit_test
291 } // namespace boost
292
293 #include <boost/test/detail/enable_warnings.hpp>
294
295 #endif // BOOST_TEST_COMPILER_LOG_FORMATTER_IPP_020105GER