Fix GCC test compiles with exception handling disabled.

This commit is contained in:
jzmaddock
2013-12-18 17:06:08 +00:00
parent 6230db51b1
commit d9cb36d0d3
6 changed files with 49 additions and 24 deletions

View File

@ -184,19 +184,6 @@ const int* make_array(int first, ...)
return data;
}
#ifdef BOOST_NO_EXCEPTIONS
namespace boost{
void throw_exception(std::exception const & e)
{
std::abort();
}
}
#endif
void test(const char& c, const test_regex_replace_tag& tag)
{
do_test(c, tag);
@ -225,7 +212,7 @@ void test(const wchar_t& c, const test_invalid_regex_tag& tag)
}
#endif
#ifdef BOOST_NO_EXCETIONS
#ifdef BOOST_NO_EXCEPTIONS
namespace boost{
void throw_exception( std::exception const & e )
@ -235,6 +222,14 @@ void throw_exception( std::exception const & e )
}
}
#endif
int main(int argc, char * argv[])
{
return cpp_main(argc, argv);
}
#else
#include <boost/test/included/prg_exec_monitor.hpp>
#endif

View File

@ -136,7 +136,10 @@ void test_deprecated(const char&, const test_regex_search_tag&)
//
if(test_info<char>::syntax_options() & ~boost::regex::icase)
return;
try{
#ifndef BOOST_NO_EXCEPTIONS
try
#endif
{
boost::RegEx e(expression, (test_info<char>::syntax_options() & boost::regex::icase) != 0);
if(e.error_code())
{
@ -180,6 +183,7 @@ void test_deprecated(const char&, const test_regex_search_tag&)
}
}
}
#ifndef BOOST_NO_EXCEPTIONS
catch(const boost::bad_expression& r)
{
BOOST_REGEX_TEST_ERROR("Expression did not compile with RegEx class: " << r.what(), char);
@ -196,7 +200,7 @@ void test_deprecated(const char&, const test_regex_search_tag&)
{
BOOST_REGEX_TEST_ERROR("Unexpected exception of unknown type", char);
}
#endif
}
void test_deprecated(const wchar_t&, const test_regex_search_tag&)
@ -302,11 +306,15 @@ void test_deprecated(const char&, const test_invalid_regex_tag&)
if(test_info<char>::syntax_options() & ~boost::regex::icase)
return;
bool have_catch = false;
try{
#ifndef BOOST_NO_EXCEPTIONS
try
#endif
{
boost::RegEx e(expression, (test_info<char>::syntax_options() & boost::regex::icase) != 0);
if(e.error_code())
have_catch = true;
}
#ifndef BOOST_NO_EXCEPTIONS
catch(const boost::bad_expression&)
{
have_catch = true;
@ -326,6 +334,7 @@ void test_deprecated(const char&, const test_invalid_regex_tag&)
have_catch = true;
BOOST_REGEX_TEST_ERROR("Expected a bad_expression exception, but got an exception of unknown type instead", char);
}
#endif
if(!have_catch)
{
// oops expected exception was not thrown:

View File

@ -47,7 +47,7 @@ test_locale::test_locale(const char* c_name, boost::uint32_t lcid)
#else
s_c_locale = no_test;
#endif
#ifndef BOOST_NO_STD_LOCALE
#if !defined(BOOST_NO_STD_LOCALE) && !defined(BOOST_NO_EXCEPTIONS)
// back up the C++ locale and create the new one:
m_old_cpp_locale = s_cpp_locale_inst;
m_old_cpp_state = s_cpp_locale;
@ -55,7 +55,8 @@ test_locale::test_locale(const char* c_name, boost::uint32_t lcid)
s_cpp_locale_inst = std::locale(c_name);
s_cpp_locale = test_with_locale;
std::cout << "Testing the C++ locale: " << c_name << std::endl;
}catch(std::runtime_error const &)
}
catch(std::runtime_error const &)
{
s_cpp_locale = no_test;
std::cout << "The C++ locale: " << c_name << " is not available and will not be tested." << std::endl;

View File

@ -62,7 +62,9 @@ void test(boost::basic_regex<charT, traits>& r, const test_invalid_regex_tag&)
//
// try it with exceptions disabled first:
//
#ifndef BOOST_NO_EXCEPTIONS
try
#endif
{
if(0 == r.assign(expression, syntax_options | boost::regex_constants::no_except).status())
{
@ -70,21 +72,27 @@ void test(boost::basic_regex<charT, traits>& r, const test_invalid_regex_tag&)
}
test_empty(r);
}
#ifndef BOOST_NO_EXCEPTIONS
catch(...)
{
BOOST_REGEX_TEST_ERROR("Unexpected exception thrown.", charT);
}
#endif
//
// now try again with exceptions:
//
bool have_catch = false;
try{
#ifndef BOOST_NO_EXCEPTIONS
try
#endif
{
r.assign(expression, syntax_options);
#ifdef BOOST_NO_EXCEPTIONS
if(r.status())
have_catch = true;
#endif
}
#ifndef BOOST_NO_EXCEPTIONS
catch(const boost::bad_expression&)
{
have_catch = true;
@ -105,6 +113,7 @@ void test(boost::basic_regex<charT, traits>& r, const test_invalid_regex_tag&)
have_catch = true;
BOOST_REGEX_TEST_ERROR("Expected a bad_expression exception, but got an exception of unknown type instead", charT);
}
#endif
if(!have_catch)
{
// oops expected exception was not thrown:

View File

@ -44,7 +44,10 @@ void test(boost::basic_regex<charT, traits>& r, const test_regex_replace_tag&)
{
const std::basic_string<charT>& expression = test_info<charT>::expression();
boost::regex_constants::syntax_option_type syntax_options = test_info<charT>::syntax_options();
try{
#ifndef BOOST_NO_EXCEPTIONS
try
#endif
{
r.assign(expression, syntax_options);
if(r.status())
{
@ -52,6 +55,7 @@ void test(boost::basic_regex<charT, traits>& r, const test_regex_replace_tag&)
}
test_regex_replace(r);
}
#ifndef BOOST_NO_EXCEPTIONS
catch(const boost::bad_expression& e)
{
BOOST_REGEX_TEST_ERROR("Expression did not compile when it should have done: " << e.what(), charT);
@ -68,6 +72,7 @@ void test(boost::basic_regex<charT, traits>& r, const test_regex_replace_tag&)
{
BOOST_REGEX_TEST_ERROR("Received an unexpected exception of unknown type", charT);
}
#endif
}

View File

@ -476,7 +476,10 @@ void test(boost::basic_regex<charT, traits>& r, const test_regex_search_tag&)
{
const std::basic_string<charT>& expression = test_info<charT>::expression();
boost::regex_constants::syntax_option_type syntax_options = test_info<charT>::syntax_options();
try{
#ifndef BOOST_NO_EXCEPTIONS
try
#endif
{
r.assign(expression, syntax_options);
if(r.status())
{
@ -494,6 +497,7 @@ void test(boost::basic_regex<charT, traits>& r, const test_regex_search_tag&)
//
// Verify sub-expression locations:
//
#ifndef BOOST_NO_EXCEPTIONS
if((syntax_options & boost::regbase::save_subexpression_location) == 0)
{
bool have_except = false;
@ -510,6 +514,7 @@ void test(boost::basic_regex<charT, traits>& r, const test_regex_search_tag&)
BOOST_REGEX_TEST_ERROR("Expected std::out_of_range error was not found.", charT);
}
}
#endif
r.assign(expression, syntax_options | boost::regbase::save_subexpression_location);
for(std::size_t i = 0; i < r.mark_count(); ++i)
{
@ -524,6 +529,7 @@ void test(boost::basic_regex<charT, traits>& r, const test_regex_search_tag&)
}
}
}
#ifndef BOOST_NO_EXCEPTIONS
catch(const boost::bad_expression& e)
{
BOOST_REGEX_TEST_ERROR("Expression did not compile when it should have done: " << e.what(), charT);
@ -540,7 +546,7 @@ void test(boost::basic_regex<charT, traits>& r, const test_regex_search_tag&)
{
BOOST_REGEX_TEST_ERROR("Received an unexpected exception of unknown type", charT);
}
#endif
}