6 * Use, modification and distribution are subject to the
7 * Boost Software License, Version 1.0. (See accompanying file
8 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
13 * LOCATION: see http://www.boost.org for most recent version.
15 * VERSION see <boost/version.hpp>
16 * DESCRIPTION: Error handling for test cases.
19 #ifndef BOOST_REGEX_REGRESS_INFO_HPP
20 #define BOOST_REGEX_REGRESS_INFO_HPP
23 #include <boost/regex.hpp>
26 #include <boost/thread/once.hpp>
27 #include <boost/thread.hpp>
31 // store information about the test we are about to conduct:
33 template <class charT>
37 typedef std::basic_string<charT> string_type;
43 string_type expression;
44 boost::regex_constants::syntax_option_type options;
45 string_type search_text;
46 boost::regex_constants::match_flag_type match_options;
47 const int* answer_table;
48 string_type format_string;
49 string_type result_string;
51 std::string expression_type_name;
54 static data_type& do_get_data()
56 static boost::thread_specific_ptr<data_type> pd;
58 pd.reset(new data_type());
61 static void init_data()
66 static data_type& data()
69 static boost::once_flag f = BOOST_ONCE_INIT;
70 boost::call_once(f,&init_data);
82 const string_type& ex,
83 boost::regex_constants::syntax_option_type opt,
84 const string_type& search_text = string_type(),
85 boost::regex_constants::match_flag_type match_options = boost::match_default,
86 const int* answer_table = 0,
87 const string_type& format_string = string_type(),
88 const string_type& result_string = string_type())
90 data_type& dat = data();
95 dat.search_text = search_text;
96 dat.match_options = match_options;
97 dat.answer_table = answer_table;
98 dat.format_string = format_string;
99 dat.result_string = result_string;
100 dat.need_to_print = true;
102 static void set_typename(const std::string& n)
104 data().expression_type_name = n;
107 static const string_type& expression()
109 return data().expression;
111 static boost::regex_constants::syntax_option_type syntax_options()
113 return data().options;
115 static const string_type& search_text()
117 return data().search_text;
119 static boost::regex_constants::match_flag_type match_options()
121 return data().match_options;
123 static const int* answer_table()
125 return data().answer_table;
127 static const string_type& format_string()
129 return data().format_string;
131 static const string_type& result_string()
133 return data().result_string;
135 static bool need_to_print()
137 return data().need_to_print;
139 static const std::string& file()
149 data().need_to_print = false;
151 static std::string& expression_typename()
153 return data().expression_type_name;
159 : public test_info_base<wchar_t>
163 struct test_info<char>
164 : public test_info_base<char>
167 #if BOOST_WORKAROUND(__DECCXX_VER, BOOST_TESTED_AT(60590042))
169 // Some template instantiation modes (namely local, implicit local, and weak) of
170 // this compiler need an explicit instantiation because otherwise we end up with
171 // multiple copies of the static variable defined in this method. This explicit
172 // instantiation generates the static variable with common linkage, which makes
173 // the linker choose only one of the available definitions. For more details,
176 template test_info_base<wchar_t>::data_type & test_info_base<wchar_t>::data();
177 template test_info_base<char>::data_type & test_info_base<char>::data();
181 template <class charT>
182 std::ostream& operator<<(std::ostream& os, const test_info<charT>&)
184 if(test_info<charT>::need_to_print())
186 os << test_info<charT>::file() << ":" << test_info<charT>::line() << ": Error in test here:" << std::endl;
187 test_info<charT>::clear();
192 // define some test macros:
194 extern int error_count;
196 #define BOOST_REGEX_TEST_ERROR(msg, charT)\
198 std::cerr << test_info<charT>();\
199 std::cerr << " " << __FILE__ << ":" << __LINE__ << ":" << msg \
200 << " (While testing " << test_info<charT>::expression_typename() << ")" << std::endl
202 class errors_as_warnings
207 m_saved_error_count = error_count;
209 ~errors_as_warnings()
211 if(m_saved_error_count != error_count)
213 std::cerr << "<note>The above " << (error_count - m_saved_error_count) << " errors are treated as warnings only.</note>" << std::endl;
214 error_count = m_saved_error_count;
218 int m_saved_error_count;