blob: 1d83f606e3edc259dfa6cde3b63b4a31d28a5e4d [file] [log] [blame]
Jeff Thompsonef2d5a42013-08-22 19:09:24 -07001// (C) Copyright Gennadiy Rozental 2005-2008.
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: 57992 $
11//
12// Description : implements compiler like Log formatter
13// ***************************************************************************
14
Jeff Thompson3d613fd2013-10-15 15:39:04 -070015#ifndef NDNBOOST_TEST_COMPILER_LOG_FORMATTER_IPP_020105GER
16#define NDNBOOST_TEST_COMPILER_LOG_FORMATTER_IPP_020105GER
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070017
18// Boost.Test
19#include <ndnboost/test/output/compiler_log_formatter.hpp>
20#include <ndnboost/test/unit_test_suite_impl.hpp>
21#include <ndnboost/test/framework.hpp>
22#include <ndnboost/test/utils/basic_cstring/io.hpp>
23#include <ndnboost/test/utils/lazy_ostream.hpp>
24
25// Boost
26#include <ndnboost/version.hpp>
27
28// STL
29#include <iostream>
30
31#include <ndnboost/test/detail/suppress_warnings.hpp>
32
33//____________________________________________________________________________//
34
35namespace ndnboost {
36
37namespace unit_test {
38
39namespace output {
40
41// ************************************************************************** //
42// ************** compiler_log_formatter ************** //
43// ************************************************************************** //
44
45namespace {
46
47const_string
48test_phase_identifier()
49{
50 return framework::is_initialized()
51 ? const_string( framework::current_test_case().p_name.get() )
Jeff Thompson3d613fd2013-10-15 15:39:04 -070052 : NDNBOOST_TEST_L( "Test setup" );
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070053}
54
55} // local namespace
56
57//____________________________________________________________________________//
58
59void
60compiler_log_formatter::log_start( std::ostream& output, counter_t test_cases_amount )
61{
62 if( test_cases_amount > 0 )
63 output << "Running " << test_cases_amount << " test "
64 << (test_cases_amount > 1 ? "cases" : "case") << "...\n";
65}
66
67//____________________________________________________________________________//
68
69void
70compiler_log_formatter::log_finish( std::ostream& ostr )
71{
72 ostr.flush();
73}
74
75//____________________________________________________________________________//
76
77void
78compiler_log_formatter::log_build_info( std::ostream& output )
79{
Jeff Thompson3d613fd2013-10-15 15:39:04 -070080 output << "Platform: " << NDNBOOST_PLATFORM << '\n'
81 << "Compiler: " << NDNBOOST_COMPILER << '\n'
82 << "STL : " << NDNBOOST_STDLIB << '\n'
83 << "Boost : " << NDNBOOST_VERSION/100000 << "."
84 << NDNBOOST_VERSION/100 % 1000 << "."
85 << NDNBOOST_VERSION % 100 << std::endl;
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070086}
87
88//____________________________________________________________________________//
89
90void
91compiler_log_formatter::test_unit_start( std::ostream& output, test_unit const& tu )
92{
93 output << "Entering test " << tu.p_type_name << " \"" << tu.p_name << "\"" << std::endl;
94}
95
96//____________________________________________________________________________//
97
98void
99compiler_log_formatter::test_unit_finish( std::ostream& output, test_unit const& tu, unsigned long elapsed )
100{
101 output << "Leaving test " << tu.p_type_name << " \"" << tu.p_name << "\"";
102
103 if( elapsed > 0 ) {
104 output << "; testing time: ";
105 if( elapsed % 1000 == 0 )
106 output << elapsed/1000 << "ms";
107 else
108 output << elapsed << "mks";
109 }
110
111 output << std::endl;
112}
113
114//____________________________________________________________________________//
115
116void
117compiler_log_formatter::test_unit_skipped( std::ostream& output, test_unit const& tu )
118{
119 output << "Test " << tu.p_type_name << " \"" << tu.p_name << "\"" << "is skipped" << std::endl;
120}
121
122//____________________________________________________________________________//
123
124void
125compiler_log_formatter::log_exception( std::ostream& output, log_checkpoint_data const& checkpoint_data, execution_exception const& ex )
126{
127 execution_exception::location const& loc = ex.where();
128 print_prefix( output, loc.m_file_name, loc.m_line_num );
129
130 output << "fatal error in \"" << (loc.m_function.is_empty() ? test_phase_identifier() : loc.m_function ) << "\": ";
131
132 output << ex.what();
133
134 if( !checkpoint_data.m_file_name.is_empty() ) {
135 output << '\n';
136 print_prefix( output, checkpoint_data.m_file_name, checkpoint_data.m_line_num );
137 output << "last checkpoint";
138 if( !checkpoint_data.m_message.empty() )
139 output << ": " << checkpoint_data.m_message;
140 }
141
142 output << std::endl;
143}
144
145//____________________________________________________________________________//
146
147void
148compiler_log_formatter::log_entry_start( std::ostream& output, log_entry_data const& entry_data, log_entry_types let )
149{
150 switch( let ) {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700151 case NDNBOOST_UTL_ET_INFO:
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700152 print_prefix( output, entry_data.m_file_name, entry_data.m_line_num );
153 output << "info: ";
154 break;
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700155 case NDNBOOST_UTL_ET_MESSAGE:
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700156 break;
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700157 case NDNBOOST_UTL_ET_WARNING:
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700158 print_prefix( output, entry_data.m_file_name, entry_data.m_line_num );
159 output << "warning in \"" << test_phase_identifier() << "\": ";
160 break;
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700161 case NDNBOOST_UTL_ET_ERROR:
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700162 print_prefix( output, entry_data.m_file_name, entry_data.m_line_num );
163 output << "error in \"" << test_phase_identifier() << "\": ";
164 break;
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700165 case NDNBOOST_UTL_ET_FATAL_ERROR:
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700166 print_prefix( output, entry_data.m_file_name, entry_data.m_line_num );
167 output << "fatal error in \"" << test_phase_identifier() << "\": ";
168 break;
169 }
170}
171
172//____________________________________________________________________________//
173
174void
175compiler_log_formatter::log_entry_value( std::ostream& output, const_string value )
176{
177 output << value;
178}
179
180//____________________________________________________________________________//
181
182void
183compiler_log_formatter::log_entry_value( std::ostream& output, lazy_ostream const& value )
184{
185 output << value;
186}
187
188//____________________________________________________________________________//
189
190void
191compiler_log_formatter::log_entry_finish( std::ostream& output )
192{
193 output << std::endl;
194}
195
196//____________________________________________________________________________//
197
198void
199compiler_log_formatter::print_prefix( std::ostream& output, const_string file, std::size_t line )
200{
201#ifdef __APPLE_CC__
202 // Xcode-compatible logging format, idea by Richard Dingwall at
203 // <http://richarddingwall.name/2008/06/01/using-the-boost-unit-test-framework-with-xcode-3/>.
204 output << file << ':' << line << ": ";
205#else
206 output << file << '(' << line << "): ";
207#endif
208}
209
210//____________________________________________________________________________//
211
212} // namespace output
213
214} // namespace unit_test
215
216} // namespace ndnboost
217
218//____________________________________________________________________________//
219
220#include <ndnboost/test/detail/enable_warnings.hpp>
221
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700222#endif // NDNBOOST_TEST_COMPILER_LOG_FORMATTER_IPP_020105GER