forked from boostorg/regex
merged changes in regex5 branch
[SVN r26692]
This commit is contained in:
184
test/regress/info.hpp
Normal file
184
test/regress/info.hpp
Normal file
@ -0,0 +1,184 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2004
|
||||
* Dr John Maddock
|
||||
*
|
||||
* Use, modification and distribution are subject to the
|
||||
* Boost Software License, Version 1.0. (See accompanying file
|
||||
* LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* LOCATION: see http://www.boost.org for most recent version.
|
||||
* FILE info.hpp
|
||||
* VERSION see <boost/version.hpp>
|
||||
* DESCRIPTION: Error handling for test cases.
|
||||
*/
|
||||
|
||||
#ifndef BOOST_REGEX_REGRESS_INFO_HPP
|
||||
#define BOOST_REGEX_REGRESS_INFO_HPP
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <boost/regex.hpp>
|
||||
//
|
||||
// class test info,
|
||||
// store information about the test we are about to conduct:
|
||||
//
|
||||
template <class charT>
|
||||
class test_info_base
|
||||
{
|
||||
public:
|
||||
typedef std::basic_string<charT> string_type;
|
||||
private:
|
||||
struct data_type
|
||||
{
|
||||
std::string file;
|
||||
int line;
|
||||
string_type expression;
|
||||
boost::regex_constants::syntax_option_type options;
|
||||
string_type search_text;
|
||||
boost::regex_constants::match_flag_type match_options;
|
||||
const int* answer_table;
|
||||
string_type format_string;
|
||||
string_type result_string;
|
||||
bool need_to_print;
|
||||
std::string expression_type_name;
|
||||
};
|
||||
static data_type& data()
|
||||
{
|
||||
static data_type d;
|
||||
return d;
|
||||
}
|
||||
public:
|
||||
test_info_base(){};
|
||||
static void set_info(
|
||||
const char* file,
|
||||
int line,
|
||||
const string_type& ex,
|
||||
boost::regex_constants::syntax_option_type opt,
|
||||
const string_type& search_text = string_type(),
|
||||
boost::regex_constants::match_flag_type match_options = boost::match_default,
|
||||
const int* answer_table = 0,
|
||||
const string_type& format_string = string_type(),
|
||||
const string_type& result_string = string_type())
|
||||
{
|
||||
data_type& dat = data();
|
||||
dat.file = file;
|
||||
dat.line = line;
|
||||
dat.expression = ex;
|
||||
dat.options = opt;
|
||||
dat.search_text = search_text;
|
||||
dat.match_options = match_options;
|
||||
dat.answer_table = answer_table;
|
||||
dat.format_string = format_string;
|
||||
dat.result_string = result_string;
|
||||
dat.need_to_print = true;
|
||||
}
|
||||
static void set_typename(const std::string& n)
|
||||
{
|
||||
data().expression_type_name = n;
|
||||
}
|
||||
|
||||
static const string_type& expression()
|
||||
{
|
||||
return data().expression;
|
||||
}
|
||||
static boost::regex_constants::syntax_option_type syntax_options()
|
||||
{
|
||||
return data().options;
|
||||
}
|
||||
static const string_type& search_text()
|
||||
{
|
||||
return data().search_text;
|
||||
}
|
||||
static boost::regex_constants::match_flag_type match_options()
|
||||
{
|
||||
return data().match_options;
|
||||
}
|
||||
static const int* answer_table()
|
||||
{
|
||||
return data().answer_table;
|
||||
}
|
||||
static const string_type& format_string()
|
||||
{
|
||||
return data().format_string;
|
||||
}
|
||||
static const string_type& result_string()
|
||||
{
|
||||
return data().result_string;
|
||||
}
|
||||
static bool need_to_print()
|
||||
{
|
||||
return data().need_to_print;
|
||||
}
|
||||
static const std::string& file()
|
||||
{
|
||||
return data().file;
|
||||
}
|
||||
static int line()
|
||||
{
|
||||
return data().line;
|
||||
}
|
||||
static void clear()
|
||||
{
|
||||
data().need_to_print = false;
|
||||
}
|
||||
static std::string& expression_typename()
|
||||
{
|
||||
return data().expression_type_name;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct test_info
|
||||
: public test_info_base<wchar_t>
|
||||
{};
|
||||
|
||||
template<>
|
||||
struct test_info<char>
|
||||
: public test_info_base<char>
|
||||
{};
|
||||
|
||||
template <class charT>
|
||||
std::ostream& operator<<(std::ostream& os, const test_info<charT>&)
|
||||
{
|
||||
if(test_info<charT>::need_to_print())
|
||||
{
|
||||
os << test_info<charT>::file() << ":" << test_info<charT>::line() << ": Error in test here:" << std::endl;
|
||||
test_info<charT>::clear();
|
||||
}
|
||||
return os;
|
||||
}
|
||||
//
|
||||
// define some test macros:
|
||||
//
|
||||
extern int error_count;
|
||||
|
||||
#define BOOST_REGEX_TEST_ERROR(msg, charT)\
|
||||
++error_count;\
|
||||
std::cerr << test_info<charT>();\
|
||||
std::cerr << " " << __FILE__ << ":" << __LINE__ << ":" << msg \
|
||||
<< " (While testing " << test_info<charT>::expression_typename() << ")" << std::endl
|
||||
|
||||
class errors_as_warnings
|
||||
{
|
||||
public:
|
||||
errors_as_warnings()
|
||||
{
|
||||
m_saved_error_count = error_count;
|
||||
}
|
||||
~errors_as_warnings()
|
||||
{
|
||||
if(m_saved_error_count != error_count)
|
||||
{
|
||||
std::cerr << "<note>The above " << (error_count - m_saved_error_count) << " errors are treated as warnings only.</note>" << std::endl;
|
||||
error_count = m_saved_error_count;
|
||||
}
|
||||
}
|
||||
private:
|
||||
int m_saved_error_count;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user