Ticket #2099: boost_test_no_exceptions.diff

File boost_test_no_exceptions.diff, 16.8 KB (added by anonymous, 14 years ago)
  • boost/test/execution_monitor.hpp

    diff -r 510d5bd079ad boost/test/execution_monitor.hpp
    a b  
    8282   
    8383//  design rationale: fear of being out (or nearly out) of memory.
    8484   
    85 class BOOST_TEST_DECL execution_exception {
     85class BOOST_TEST_DECL execution_exception :  public std::exception {
    8686    typedef boost::unit_test::const_string const_string;
    8787public:
    8888    enum error_code {
     
    119119
    120120    // access methods
    121121    error_code      code() const { return m_error_code; }
    122     const_string    what() const { return m_what; }
     122    const char* what() const throw() { return m_what.begin(); }
    123123
    124124private:
    125125    // Data members
     
    203203    {
    204204        try {
    205205            return m_next ? (*m_next)( F ) : F();
    206         } catch( Exception const& e ) {
     206        }
     207#ifndef BOOST_NO_EXCEPTIONS
     208        catch( Exception const& e ) {
    207209            m_translator( e );
    208210            return boost::exit_exception_failure;
    209211        }
     212#endif
    210213    }
    211214
    212215private:
     
    228231// **************               execution_aborted              ************** //
    229232// ************************************************************************** //
    230233
    231 struct execution_aborted {};
     234struct execution_aborted : public std::exception {};
    232235
    233236// ************************************************************************** //
    234237// **************                  system_error                ************** //
    235238// ************************************************************************** //
    236239
    237 class system_error {
     240    class system_error : public std::exception {
    238241public:
    239242    // Constructor
    240243    explicit    system_error( char const* exp );
     
    243246    unit_test::readonly_property<char const*>   p_failed_exp;
    244247};
    245248
    246 #define BOOST_TEST_SYS_ASSERT( exp ) if( (exp) ) ; else throw ::boost::system_error( BOOST_STRINGIZE( exp ) )
     249#define BOOST_TEST_SYS_ASSERT( exp ) if( (exp) ) ; else boost::throw_exception( ::boost::system_error( BOOST_STRINGIZE( exp ) ) );
    247250
    248251}  // namespace boost
    249252
  • boost/test/impl/cpp_main.ipp

    diff -r 510d5bd079ad boost/test/impl/cpp_main.ipp
    a b  
    8484            result = ::boost::exit_failure;
    8585        }
    8686    }
     87#ifndef BOOST_NO_EXCEPTIONS
    8788    catch( ::boost::execution_exception const& exex ) {
    8889        std::cout << "\n**** exception(" << exex.code() << "): " << exex.what() << std::endl;
    8990        result = ::boost::exit_exception_failure;
     
    9495                  << "\n**** error(" << ex.p_errno << "): " << std::strerror( ex.p_errno ) << std::endl;
    9596        result = ::boost::exit_exception_failure;
    9697    }
     98#endif
    9799
    98100    if( result != ::boost::exit_success ) {
    99101        std::cerr << "******** errors detected; see standard output for details ********" << std::endl;
  • boost/test/impl/exception_safety.ipp

    diff -r 510d5bd079ad boost/test/impl/exception_safety.ipp
    a b  
    1717
    1818// Boost.Test
    1919#include <boost/test/detail/config.hpp>
     20#include <boost/throw_exception.hpp>
    2021
    2122#if !BOOST_WORKAROUND(__GNUC__, < 3) && \
    2223    !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) && \
     
    106107
    107108struct exception_safety_tester : itest::manager, test_observer {
    108109    // helpers types
    109     struct unique_exception {};
     110    struct unique_exception : std::exception {};
    110111
    111112    // Constructor
    112113    explicit            exception_safety_tester( const_string test_name );
     
    393394    if( m_exec_path_counter == m_break_exec_path )
    394395        debug::debugger_break();
    395396   
    396     throw unique_exception();
     397    boost::throw_exception(unique_exception());
    397398}
    398399
    399400//____________________________________________________________________________//
  • boost/test/impl/execution_monitor.ipp

    diff -r 510d5bd079ad boost/test/impl/execution_monitor.ipp
    a b  
    3131#include <boost/test/debug.hpp>
    3232
    3333// Boost
     34#include <boost/throw_exception.hpp>
    3435#include <boost/cstdlib.hpp>    // for exit codes
    3536#include <boost/config.hpp>     // for workarounds
    3637
     
    191192    BOOST_TEST_VSNPRINTF( buf, sizeof(buf), format, args );
    192193    va_end( args );
    193194
    194     throw execution_exception( ec, buf );
     195    boost::throw_exception(execution_exception( ec, buf ));
    195196}
    196197
    197198//____________________________________________________________________________//
     
    219220// **************    boost::detail::system_signal_exception    ************** //
    220221// ************************************************************************** //
    221222
    222 class system_signal_exception {
     223class system_signal_exception : public std::exception {
    223224public:
    224225    // Constructor
    225226    system_signal_exception()
     
    727728
    728729    if( !sigsetjmp( signal_handler::jump_buffer(), 1 ) )
    729730        return detail::do_invoke( m_custom_translators , F );
    730     else
    731         throw local_signal_handler.sys_sig();
     731    else {
     732        boost::throw_exception(local_signal_handler.sys_sig());
     733        return 0;
     734    }
    732735}
    733736
    734737//____________________________________________________________________________//
     
    10631066    //  required.  Programmers ask for const anyhow, so we supply it.  That's
    10641067    //  easier than answering questions about non-const usage.
    10651068
     1069#ifndef BOOST_NO_EXCEPTIONS
     1070
    10661071    catch( char const* ex )
    10671072      { detail::report_error( execution_exception::cpp_exception_error, "C string: %s", ex ); }
    10681073    catch( std::string const& ex )
     
    11211126    catch( ... )
    11221127      { detail::report_error( execution_exception::cpp_exception_error, "unknown type" ); }
    11231128
     1129#endif // BOOST_NO_EXCEPTIONS
     1130
    11241131    return 0;  // never reached; supplied to quiet compiler warnings
    11251132} // execute
    11261133
  • boost/test/impl/framework.ipp

    diff -r 510d5bd079ad boost/test/impl/framework.ipp
    a b  
    3434#include <boost/test/utils/foreach.hpp>
    3535
    3636// Boost
     37#include <boost/throw_exception.hpp>
    3738#include <boost/timer.hpp>
    3839
    3940// STL
     
    8889    {
    8990#ifdef BOOST_TEST_ALTERNATIVE_INIT_API
    9091        if( !(*m_init_func)() )
    91             throw std::runtime_error( "test module initialization failed" );
     92            boost::throw_exception(std::runtime_error( "test module initialization failed" ));
    9293#else
    9394        test_suite*  manual_test_units = (*m_init_func)( framework::master_test_suite().argc, framework::master_test_suite().argv );
    9495
     
    162163        m_curr_test_case = bkup;
    163164
    164165        if( unit_test_monitor.is_critical_error( run_result ) )
    165             throw test_being_aborted();
     166            boost::throw_exception(test_being_aborted());
    166167    }
    167168
    168169    bool            test_suite_start( test_suite const& ts )
     
    257258
    258259        em.execute( tic );
    259260    }
     261#ifndef BOOST_NO_EXCEPTIONS
    260262    catch( execution_exception const& ex )  {
    261263        throw setup_error( ex.what() );
    262264    }
     265#endif
    263266
    264267    s_frk_impl().m_is_initialized = true;
    265268}
     
    278281register_test_unit( test_case* tc )
    279282{
    280283    if( tc->p_id != INV_TEST_UNIT_ID )
    281         throw setup_error( BOOST_TEST_L( "test case already registered" ) );
     284        boost::throw_exception(setup_error( BOOST_TEST_L( "test case already registered" ) ));
    282285
    283286    test_unit_id new_id = s_frk_impl().m_next_test_case_id;
    284287
    285288    if( new_id == MAX_TEST_CASE_ID )
    286         throw setup_error( BOOST_TEST_L( "too many test cases" ) );
     289        boost::throw_exception(setup_error( BOOST_TEST_L( "too many test cases" ) ));
    287290
    288291    typedef framework_impl::test_unit_store::value_type map_value_type;
    289292
     
    299302register_test_unit( test_suite* ts )
    300303{
    301304    if( ts->p_id != INV_TEST_UNIT_ID )
    302         throw setup_error( BOOST_TEST_L( "test suite already registered" ) );
     305        boost::throw_exception(setup_error( BOOST_TEST_L( "test suite already registered" ) ));
    303306
    304307    test_unit_id new_id = s_frk_impl().m_next_test_suite_id;
    305308
    306309    if( new_id == MAX_TEST_SUITE_ID )
    307         throw setup_error( BOOST_TEST_L( "too many test suites" ) );
     310        boost::throw_exception(setup_error( BOOST_TEST_L( "too many test suites" ) ));
    308311
    309312    typedef framework_impl::test_unit_store::value_type map_value_type;
    310313    s_frk_impl().m_test_units.insert( map_value_type( new_id, ts ) );
     
    364367    test_unit* res = s_frk_impl().m_test_units[id];
    365368
    366369    if( (res->p_type & t) == 0 )
    367         throw internal_error( "Invalid test unit type" );
     370        boost::throw_exception(internal_error( "Invalid test unit type" ));
    368371
    369372    return *res;
    370373}
     
    381384    traverse_test_tree( id, tcc );
    382385
    383386    if( tcc.p_count == 0 )
    384         throw setup_error( runtime_config::test_to_run().is_empty()
    385                                 ? BOOST_TEST_L( "test tree is empty" )
    386                                 : BOOST_TEST_L( "no test cases matching filter" ) );
     387        boost::throw_exception(setup_error( runtime_config::test_to_run().is_empty()
     388                                            ? BOOST_TEST_L( "test tree is empty" )
     389                                            : BOOST_TEST_L( "no test cases matching filter" ) ));
    387390
    388391    bool    call_start_finish   = !continue_test || !s_frk_impl().m_test_in_progress;
    389392    bool    was_in_progress     = s_frk_impl().m_test_in_progress;
     
    397400            try {
    398401                em.execute( ut_detail::test_start_caller( to, tcc.p_count ) );
    399402            }
     403#ifndef BOOST_NO_EXCEPTIONS
    400404            catch( execution_exception const& ex )  {
    401                 throw setup_error( ex.what() );
     405                boost::throw_exception(setup_error( ex.what() ));
    402406            }
     407#endif
    403408        }
    404409    }
    405410
  • boost/test/impl/interaction_based.ipp

    diff -r 510d5bd079ad boost/test/impl/interaction_based.ipp
    a b  
    3131#include <boost/test/framework.hpp>     // for setup_error
    3232
    3333#include <boost/test/detail/suppress_warnings.hpp>
     34#include <boost/throw_exception.hpp>
    3435
    3536// STL
    3637#include <stdexcept>
     
    7071    if( reset ) {
    7172        if( new_ptr ) {
    7273            if( ptr != &dummy )
    73                 throw unit_test::framework::setup_error( BOOST_TEST_L( "Couldn't run two interation based test the same time" ) );
     74                boost::throw_exception( unit_test::framework::setup_error( BOOST_TEST_L( "Couldn't run two interation based test the same time" ) ));
    7475               
    7576            ptr = new_ptr;
    7677        }
  • boost/test/impl/test_tools.ipp

    diff -r 510d5bd079ad boost/test/impl/test_tools.ipp
    a b  
    2525
    2626// Boost
    2727#include <boost/config.hpp>
     28#include <boost/throw_exception.hpp>
    2829
    2930// STL
    3031#include <fstream>
     
    7071    using namespace unit_test;
    7172
    7273    if( !framework::is_initialized() )
    73         throw std::runtime_error( "can't use testing tools before framework is initialized" );
     74        boost::throw_exception(std::runtime_error( "can't use testing tools before framework is initialized" ));
    7475
    7576    if( !!pr )
    7677        tl = PASS;
     
    319320
    320321        framework::test_unit_aborted( framework::current_test_case() );
    321322
    322         throw execution_aborted();
     323        boost::throw_exception(execution_aborted());
    323324    }
    324325}
    325326
  • boost/test/impl/unit_test_main.ipp

    diff -r 510d5bd079ad boost/test/impl/unit_test_main.ipp
    a b  
    182182                    ? boost::exit_success
    183183                    : results_collector.results( framework::master_test_suite().p_id ).result_code();
    184184    }
     185#ifndef BOOST_NO_EXCEPTIONS
    185186    catch( framework::internal_error const& ex ) {
    186187        results_reporter::get_stream() << "Boost.Test framework internal error: " << ex.what() << std::endl;
    187188       
     
    197198       
    198199        return boost::exit_exception_failure;
    199200    }
     201#endif
    200202}
    201203
    202204} // namespace unit_test
  • boost/test/impl/unit_test_monitor.ipp

    diff -r 510d5bd079ad boost/test/impl/unit_test_monitor.ipp
    a b  
    6868
    6969        execute( callback0<int>( zero_return_wrapper( tc.test_func() ) ) );
    7070    }
     71#ifndef BOOST_NO_EXCEPTIONS
    7172    catch( execution_exception const& ex ) {
    7273        framework::exception_caught( ex );
    7374        framework::test_unit_aborted( framework::current_test_case() );
     
    8485        default:                                        return unexpected_exception;
    8586        }
    8687    }
     88#endif
    8789
    8890    return test_ok;
    8991}
  • boost/test/impl/unit_test_suite.ipp

    diff -r 510d5bd079ad boost/test/impl/unit_test_suite.ipp
    a b  
    205205            BOOST_TEST_FOREACH( test_unit_id, id, members )
    206206                traverse_test_tree( id, V );
    207207        }
    208        
    209     } catch( test_being_aborted const& ) {
     208    }
     209#ifndef BOOST_NO_EXCEPTIONS       
     210    catch( test_being_aborted const& ) {
    210211        V.test_suite_finish( suite );
    211212        framework::test_unit_aborted( suite );
    212213
    213214        throw;
    214215    }
     216#endif
    215217
    216218    V.test_suite_finish( suite );
    217219}
  • boost/test/interaction_based.hpp

    diff -r 510d5bd079ad boost/test/interaction_based.hpp
    a b  
    1818// Boost.Test
    1919#include <boost/test/detail/config.hpp>
    2020#include <boost/test/detail/global_typedef.hpp>
     21#include <boost/throw_exception.hpp>
    2122
    2223#include <boost/test/utils/wrap_stringstream.hpp>
    2324
     
    210211    if( res )
    211212        ::boost::itest::manager::instance().allocated( l.m_file_name, l.m_line_num, res, s );
    212213    else
    213         throw std::bad_alloc();
     214        boost::throw_exception(std::bad_alloc());
    214215       
    215216    return res;
    216217}
     
    225226    if( res )
    226227        ::boost::itest::manager::instance().allocated( l.m_file_name, l.m_line_num, res, s );
    227228    else
    228         throw std::bad_alloc();
     229        boost::throw_exception(std::bad_alloc());
    229230       
    230231    return res;
    231232}
  • boost/test/minimal.hpp

    diff -r 510d5bd079ad boost/test/minimal.hpp
    a b  
    8282{
    8383    report_error( msg, file, line, func_name, is_msg );
    8484
    85     throw boost::execution_aborted();
     85    boost::throw_exception(boost::execution_aborted());
    8686}
    8787
    8888class caller {
     
    116116
    117117        BOOST_CHECK( run_result == 0 || run_result == boost::exit_success );
    118118    }
     119#ifndef BOOST_NO_EXCEPTIONS
    119120    catch( boost::execution_exception const& exex ) {
    120121        if( exex.code() != boost::execution_exception::no_error )
    121122            BOOST_ERROR( (std::string( "exception \"" ).
     
    123124                            append( "\" caught" ) ).c_str() );
    124125        std::cerr << "\n**** Testing aborted.";
    125126    }
     127#endif
    126128
    127129    if( boost::minimal_test::errors_counter() != 0 ) {
    128130        std::cerr << "\n**** " << errors_counter()
  • boost/test/unit_test_suite_impl.hpp

    diff -r 510d5bd079ad boost/test/unit_test_suite_impl.hpp
    a b  
    214214// **************               test_being_aborted             ************** //
    215215// ************************************************************************** //
    216216
    217 struct BOOST_TEST_DECL test_being_aborted {};
     217struct BOOST_TEST_DECL test_being_aborted : public std::exception {};
    218218
    219219// ************************************************************************** //
    220220// **************               object generators              ************** //
  • boost/test/utils/named_params.hpp

    diff -r 510d5bd079ad boost/test/utils/named_params.hpp
    a b  
    1818// Boost
    1919#include <boost/config.hpp>
    2020#include <boost/detail/workaround.hpp>
     21#include <boost/throw_exception.hpp>
    2122
    2223// Boost.Test
    2324#include <boost/test/utils/rtti.hpp>
     
    4647// **************          access_to_invalid_parameter         ************** //
    4748// ************************************************************************** //
    4849
    49 struct access_to_invalid_parameter {};
     50struct access_to_invalid_parameter : public std::exception {};
    5051
    5152//____________________________________________________________________________//
    5253
    5354inline void
    5455report_access_to_invalid_parameter()
    5556{
    56     throw access_to_invalid_parameter();
     57    boost::throw_exception(access_to_invalid_parameter());
    5758}
    5859
    5960//____________________________________________________________________________//