diff --git a/include/boost/leaf/config.hpp b/include/boost/leaf/config.hpp index 0159e086..9765dc81 100644 --- a/include/boost/leaf/config.hpp +++ b/include/boost/leaf/config.hpp @@ -79,6 +79,14 @@ # endif #endif +#ifndef BOOST_LEAF_CFG_DIAGNOSTICS_FIRST_DELIMITER +# define BOOST_LEAF_CFG_DIAGNOSTICS_FIRST_DELIMITER "\n " +#endif + +#ifndef BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER +# define BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "\n " +#endif + #if BOOST_LEAF_CFG_DIAGNOSTICS!=0 && BOOST_LEAF_CFG_DIAGNOSTICS!=1 # error BOOST_LEAF_CFG_DIAGNOSTICS must be 0 or 1. #endif diff --git a/include/boost/leaf/context.hpp b/include/boost/leaf/context.hpp index 0518d2b1..748445ce 100644 --- a/include/boost/leaf/context.hpp +++ b/include/boost/leaf/context.hpp @@ -41,6 +41,7 @@ namespace leaf_detail struct handler_argument_traits_defaults { using error_type = typename std::decay::type; + using context_types = leaf_detail_mp11::mp_list; constexpr static bool always_available = false; template @@ -81,10 +82,10 @@ namespace leaf_detail } }; - template + template struct handler_argument_always_available { - using error_type = E; + using context_types = leaf_detail_mp11::mp_list; constexpr static bool always_available = true; template @@ -102,7 +103,7 @@ namespace leaf_detail template <> struct handler_argument_traits { - using error_type = void; + using context_types = leaf_detail_mp11::mp_list<>; constexpr static bool always_available = false; template @@ -134,6 +135,47 @@ namespace leaf_detail //////////////////////////////////////// +namespace leaf_detail +{ + template + struct get_dispatch + { + static BOOST_LEAF_CONSTEXPR T const * get(T const * x) noexcept + { + return x; + } + static BOOST_LEAF_CONSTEXPR T const * get(void const *) noexcept + { + return nullptr; + } + }; + + template + BOOST_LEAF_CONSTEXPR inline T * find_in_tuple(std::tuple<> const &) + { + return nullptr; + } + + template + BOOST_LEAF_CONSTEXPR inline typename std::enable_if::type const * + find_in_tuple(std::tuple const & t) noexcept + { + return get_dispatch::get(&std::get(t)); + } + + template + BOOST_LEAF_CONSTEXPR inline typename std::enable_if::type const * + find_in_tuple(std::tuple const & t) noexcept + { + if( T const * x = get_dispatch::get(&std::get(t)) ) + return x; + else + return find_in_tuple(t); + } +} + +//////////////////////////////////////// + namespace leaf_detail { template @@ -193,7 +235,6 @@ namespace leaf_detail namespace leaf_detail { template struct does_not_participate_in_context_deduction: std::is_abstract { }; - template <> struct does_not_participate_in_context_deduction: std::true_type { }; template <> struct does_not_participate_in_context_deduction: std::true_type { }; template @@ -205,7 +246,7 @@ namespace leaf_detail using type = leaf_detail_mp11::mp_remove_if< leaf_detail_mp11::mp_unique< - leaf_detail_mp11::mp_list::error_type...> + leaf_detail_mp11::mp_append::context_types...> >, does_not_participate_in_context_deduction >; @@ -317,6 +358,13 @@ class context return os << '\n'; } + template + BOOST_LEAF_CONSTEXPR E const * get() const noexcept + { + leaf_detail::slot const * e = leaf_detail::find_in_tuple>(tup_); + return e ? e->has_value() : nullptr; + } + template BOOST_LEAF_CONSTEXPR R handle_error( error_id, H && ... ) const; diff --git a/include/boost/leaf/detail/print.hpp b/include/boost/leaf/detail/print.hpp index b72e3252..15ebbac5 100644 --- a/include/boost/leaf/detail/print.hpp +++ b/include/boost/leaf/detail/print.hpp @@ -52,12 +52,9 @@ namespace leaf_detail { static_assert(show_in_diagnostics::value, "show_in_diagnostics violation"); BOOST_LEAF_ASSERT(delimiter); - if( prefix ) - { - os << prefix; - prefix = nullptr; - } - os << delimiter << parse_name(); + char const * p = prefix; + prefix = nullptr; + os << (p ? p : delimiter) << parse_name(); if( mid ) os << mid << x; return true; @@ -110,7 +107,12 @@ namespace leaf_detail template static bool print(std::basic_ostream & os, char const * & prefix, char const * delimiter, Exception const & ex) { - return print_impl(os, prefix, delimiter, ", std::exception::what(): ", static_cast(ex).what()); + if( print_impl(os, prefix, delimiter, ", \"", static_cast(ex).what()) ) + { + os << '"'; + return true; + } + return false; } }; diff --git a/include/boost/leaf/diagnostics.hpp b/include/boost/leaf/diagnostics.hpp index 2102c8c1..ae0f99ff 100644 --- a/include/boost/leaf/diagnostics.hpp +++ b/include/boost/leaf/diagnostics.hpp @@ -35,7 +35,7 @@ class diagnostic_info: public error_info void print_diagnostic_info(std::basic_ostream & os) const { print_error_info(os); - char const * prefix = exception() ? nullptr : "\nCaught:"; + char const * prefix = exception() ? nullptr : "\nCaught:" BOOST_LEAF_CFG_DIAGNOSTICS_FIRST_DELIMITER; print_tuple_contents_(os, tup_, error(), prefix); } @@ -59,7 +59,7 @@ namespace leaf_detail }; template <> - struct handler_argument_traits: handler_argument_always_available + struct handler_argument_traits: handler_argument_always_available { template BOOST_LEAF_CONSTEXPR static diagnostic_info_ get( Tup const & tup, error_info const & ei ) noexcept @@ -108,7 +108,7 @@ namespace leaf_detail }; template <> - struct handler_argument_traits: handler_argument_always_available + struct handler_argument_traits: handler_argument_always_available { template BOOST_LEAF_CONSTEXPR static diagnostic_info_ get( Tup const &, error_info const & ei ) noexcept @@ -147,7 +147,7 @@ class diagnostic_details: public diagnostic_info print_diagnostic_info(os); if( da_ ) { - char const * prefix = "\nDiagnostic details:"; + char const * prefix = "\nDiagnostic details:" BOOST_LEAF_CFG_DIAGNOSTICS_FIRST_DELIMITER; da_->print(os, error(), prefix); } } @@ -162,36 +162,6 @@ class diagnostic_details: public diagnostic_info namespace leaf_detail { - template - struct get_dispatch - { - static BOOST_LEAF_CONSTEXPR T const * get(T const * x) noexcept - { - return x; - } - static BOOST_LEAF_CONSTEXPR T const * get(void const *) noexcept - { - return nullptr; - } - }; - - template - BOOST_LEAF_CONSTEXPR inline typename std::enable_if::type const * - find_in_tuple(std::tuple const & t) noexcept - { - return get_dispatch::get(&std::get(t)); - } - - template - BOOST_LEAF_CONSTEXPR inline typename std::enable_if::type const * - find_in_tuple(std::tuple const & t) noexcept - { - if( T const * x = get_dispatch::get(&std::get(t)) ) - return x; - else - return find_in_tuple(t); - } - struct diagnostic_details_: diagnostic_details { template @@ -202,7 +172,7 @@ namespace leaf_detail }; template <> - struct handler_argument_traits: handler_argument_always_available + struct handler_argument_traits: handler_argument_always_available { template BOOST_LEAF_CONSTEXPR static diagnostic_details_ get( Tup const & tup, error_info const & ei ) noexcept @@ -254,7 +224,7 @@ namespace leaf_detail }; template <> - struct handler_argument_traits: handler_argument_always_available + struct handler_argument_traits: handler_argument_always_available { template BOOST_LEAF_CONSTEXPR static diagnostic_details_ get( Tup const & tup, error_info const & ei ) noexcept @@ -305,7 +275,7 @@ namespace leaf_detail }; template <> - struct handler_argument_traits: handler_argument_always_available + struct handler_argument_traits: handler_argument_always_available { template BOOST_LEAF_CONSTEXPR static diagnostic_details_ get( Tup const &, error_info const & ei ) noexcept diff --git a/include/boost/leaf/error.hpp b/include/boost/leaf/error.hpp index f47de612..bdad6c7f 100644 --- a/include/boost/leaf/error.hpp +++ b/include/boost/leaf/error.hpp @@ -72,12 +72,17 @@ struct BOOST_LEAF_SYMBOL_VISIBLE e_source_location char const * function; template - friend std::ostream & operator<<( std::basic_ostream & os, e_source_location const & x ) + friend std::ostream & operator<<(std::basic_ostream & os, e_source_location const & x) { - return os << x.file << '(' << x.line << ") in function " << x.function; + os << x.file << '(' << x.line << ") in function " << x.function; } }; +template <> +struct show_in_diagnostics: std::false_type +{ +}; + //////////////////////////////////////// namespace leaf_detail @@ -148,7 +153,7 @@ namespace leaf_detail { if( to_print && to_print.value() != k ) return; - if( diagnostic::print(os, prefix, "\n\t", value(k)) && !to_print ) + if( diagnostic::print(os, prefix, BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER, value(k)) && !to_print ) os << '(' << k/4 << ')'; } } diff --git a/include/boost/leaf/handle_errors.hpp b/include/boost/leaf/handle_errors.hpp index ee6b14f5..0ee5073c 100644 --- a/include/boost/leaf/handle_errors.hpp +++ b/include/boost/leaf/handle_errors.hpp @@ -34,6 +34,7 @@ class BOOST_LEAF_SYMBOL_VISIBLE error_info std::exception * const ex_; #endif + e_source_location const * const loc_; error_id const err_id_; protected: @@ -42,17 +43,19 @@ class BOOST_LEAF_SYMBOL_VISIBLE error_info public: - BOOST_LEAF_CONSTEXPR explicit error_info( error_id id ) noexcept: + BOOST_LEAF_CONSTEXPR explicit error_info(error_id id, e_source_location const * loc = nullptr) noexcept: #ifndef BOOST_LEAF_NO_EXCEPTIONS ex_(nullptr), #endif + loc_(loc), err_id_(id) { } #ifndef BOOST_LEAF_NO_EXCEPTIONS - explicit error_info( std::exception * ex ) noexcept: + explicit error_info(std::exception * ex, e_source_location const * loc = nullptr) noexcept: ex_(ex), + loc_(loc), err_id_(unpack_error_id(ex_)) { } @@ -75,18 +78,20 @@ class BOOST_LEAF_SYMBOL_VISIBLE error_info template void print_error_info(std::basic_ostream & os) const { - os << "Error serial #" << err_id_; + os << "Error with serial #" << err_id_; + if( loc_ ) + os << " reported at " << loc_->file << '(' << loc_->line << ") in function " << loc_->function; #ifndef BOOST_LEAF_NO_EXCEPTIONS if( ex_ ) { - os << "\nCaught C++ exception:\n\tType: "; + os << "\nCaught:" BOOST_LEAF_CFG_DIAGNOSTICS_FIRST_DELIMITER; #if BOOST_LEAF_CFG_DIAGNOSTICS if( auto eb = dynamic_cast(ex_) ) eb->print_type_name(os); else #endif leaf_detail::demangle_and_print(os, typeid(*ex_).name()); - os << "\n\tstd::exception::what(): " << ex_->what(); + os << ", \"" << ex_->what() << '"'; } #endif } @@ -102,7 +107,7 @@ class BOOST_LEAF_SYMBOL_VISIBLE error_info namespace leaf_detail { template <> - struct handler_argument_traits: handler_argument_always_available + struct handler_argument_traits: handler_argument_always_available<> { template BOOST_LEAF_CONSTEXPR static error_info const & get(Tup const &, error_info const & ei) noexcept @@ -475,7 +480,7 @@ context:: handle_error( error_id id, H && ... h ) const { BOOST_LEAF_ASSERT(!is_active()); - return leaf_detail::handle_error_(tup(), error_info(id), std::forward(h)...); + return leaf_detail::handle_error_(tup(), error_info(id, this->get()), std::forward(h)...); } template @@ -486,7 +491,7 @@ context:: handle_error( error_id id, H && ... h ) { BOOST_LEAF_ASSERT(!is_active()); - return leaf_detail::handle_error_(tup(), error_info(id), std::forward(h)...); + return leaf_detail::handle_error_(tup(), error_info(id, this->get()), std::forward(h)...); } //////////////////////////////////////// @@ -581,7 +586,7 @@ namespace leaf_detail catch( std::exception & ex ) { ctx.deactivate(); - error_info e(&ex); + error_info e(&ex, ctx.template get()); return handle_error_(ctx.tup(), e, std::forward(h)..., [&]() -> R { @@ -592,7 +597,7 @@ namespace leaf_detail catch(...) { ctx.deactivate(); - error_info e(nullptr); + error_info e(nullptr, ctx.template get()); return handle_error_(ctx.tup(), e, std::forward(h)..., [&]() -> R { @@ -671,7 +676,7 @@ try_catch( TryBlock && try_block, H && ... h ) catch( std::exception & ex ) { ctx.deactivate(); - error_info e(&ex); + error_info e(&ex, ctx.template get()); return leaf_detail::handle_error_(ctx.tup(), e, std::forward(h)..., [&]() -> R { @@ -682,7 +687,7 @@ try_catch( TryBlock && try_block, H && ... h ) catch(...) { ctx.deactivate(); - error_info e(nullptr); + error_info e(nullptr, ctx.template get()); return leaf_detail::handle_error_(ctx.tup(), e, std::forward(h)..., [&]() -> R { @@ -842,7 +847,7 @@ namespace leaf_detail template struct handler_argument_traits> { - using error_type = void; + using context_types = leaf_detail_mp11::mp_list<>; constexpr static bool always_available = false; template diff --git a/test/boost_exception_test.cpp b/test/boost_exception_test.cpp index a45fa236..a20fd114 100644 --- a/test/boost_exception_test.cpp +++ b/test/boost_exception_test.cpp @@ -39,7 +39,7 @@ int main() static_assert(std::is_same>().matched)>::value, "handler_argument_traits deduction bug"); using tr = leaf::leaf_detail::handler_argument_traits>; - static_assert(std::is_same::value, "handler_argument_traits deduction bug"); + static_assert(std::is_same, tr::context_types>::value, "handler_argument_traits deduction bug"); { int r = leaf::try_catch( diff --git a/test/context_deduction_test.cpp b/test/context_deduction_test.cpp index 53f6af69..e7a4efe3 100644 --- a/test/context_deduction_test.cpp +++ b/test/context_deduction_test.cpp @@ -37,10 +37,10 @@ typename unwrap_tuple +template void test( U * ) { - static_assert(std::is_same::value,"context deduction"); + static_assert(std::is_same, U>::value,"context deduction"); } template struct info { int value; }; @@ -71,84 +71,84 @@ namespace std void not_called_on_purpose() { - test< std::tuple<> >( expd([]( leaf::error_info const & ){ }) ); - - test< std::tuple> >( expd([]( info<1> ){ }) ); - test< std::tuple> >( expd([]( info<1> const ){ }) ); - test< std::tuple> >( expd([]( info<1> const & ){ }) ); - test< std::tuple> >( expd([]( info<1>, leaf::error_info const & ){ }) ); - - test< std::tuple,info<2>> >( expd([]( info<1> ){ }, []( info<2> ){ }) ); - test< std::tuple,info<2>> >( expd([]( info<1> ){ }, []( info<1>, info<2> ){ }) ); - test< std::tuple,info<2>> >( expd([]( info<1>, info<2> ){ }, []( info<2> ){ }) ); - test< std::tuple,info<2>> >( expd([]( info<1>, info<2> ){ }, []( info<1>, info<2> ){ }) ); - - test< std::tuple,info<2>> >( expd([]( leaf::error_info const &, info<1> ){ }, []( info<2> ){ }) ); - test< std::tuple,info<2>> >( expd([]( leaf::error_info const &, info<1> ){ }, []( info<1>, info<2> ){ }) ); - test< std::tuple,info<2>> >( expd([]( leaf::error_info const &, info<1>, info<2> ){ }, []( info<2> ){ }) ); - test< std::tuple,info<2>> >( expd([]( leaf::error_info const &, info<1>, info<2> ){ }, []( info<1>, info<2> ){ }) ); - - test< std::tuple,info<2>> >( expd([]( info<1>, leaf::error_info const & ){ }, []( info<2> ){ }) ); - test< std::tuple,info<2>> >( expd([]( info<1>, leaf::error_info const & ){ }, []( info<1>, info<2> ){ }) ); - test< std::tuple,info<2>> >( expd([]( info<1>, leaf::error_info const &, info<2> ){ }, []( info<2> ){ }) ); - test< std::tuple,info<2>> >( expd([]( info<1>, leaf::error_info const &, info<2> ){ }, []( info<1>, info<2> ){ }) ); - - test< std::tuple,info<2>> >( expd([]( info<1> ){ }, []( leaf::error_info const &, info<2> ){ }) ); - test< std::tuple,info<2>> >( expd([]( info<1> ){ }, []( leaf::error_info const &, info<1>, info<2> ){ }) ); - test< std::tuple,info<2>> >( expd([]( info<1>, info<2> ){ }, []( leaf::error_info const &, info<2> ){ }) ); - test< std::tuple,info<2>> >( expd([]( info<1>, info<2> ){ }, []( leaf::error_info const &, info<1>, info<2> ){ }) ); - - test< std::tuple,info<2>> >( expd([]( info<1> ){ }, []( info<2>, leaf::error_info const & ){ }) ); - test< std::tuple,info<2>> >( expd([]( info<1> ){ }, []( info<1>, leaf::error_info const &, info<2> ){ }) ); - test< std::tuple,info<2>> >( expd([]( info<1>, info<2> ){ }, []( info<2>, leaf::error_info const & ){ }) ); - test< std::tuple,info<2>> >( expd([]( info<1>, info<2> ){ }, []( info<1>, leaf::error_info const &, info<2> ){ }) ); - - test< std::tuple,info<2>,info<3>> >( expd([]( info<1> ){ }, []( info<2> ){ }, []( info<3> ){ }) ); - test< std::tuple,info<2>,info<3>> >( expd([]( info<1> ){ }, []( info<1>, info<2> ){ }, []( info<1>, info<3> ){ }) ); - test< std::tuple,info<2>,info<3>> >( expd([]( info<1> ){ }, []( info<1>, info<2> ){ }, []( info<1>, info<3> ){ }) ); - test< std::tuple,info<2>,info<3>> >( expd([]( info<1>, info<2> ){ }, []( info<2> ){ }, []( info<3> ){ }) ); - test< std::tuple,info<2>,info<3>> >( expd([]( info<1>, info<2> ){ }, []( info<2> ){ }, []( info<3> ){ }) ); - test< std::tuple,info<2>,info<3>> >( expd([]( info<1> ){ }, []( info<2> ){ }, []( info<3>, info<2> ){ }) ); - test< std::tuple,info<2>,info<3>> >( expd([]( info<1> ){ }, []( info<2> ){ }, []( info<3>, info<2> ){ }) ); - test< std::tuple,info<3>,info<2>> >( expd([]( info<1>, info<3> ){ }, []( info<2> ){ }, []( info<3> ){ }) ); - test< std::tuple,info<3>,info<2>> >( expd([]( info<1>, info<3> ){ }, []( info<2> ){ }, []( info<3> ){ }) ); - test< std::tuple,info<2>,info<3>> >( expd([]( info<1> ){ }, []( info<2>, info<3> ){ }, []( info<3> ){ }) ); - test< std::tuple,info<2>,info<3>> >( expd([]( info<1> ){ }, []( info<2>, info<3> ){ }, []( info<3> ){ }) ); - - test< std::tuple >( expd([]( leaf::match ){ }) ); + test<>( expd([]( leaf::error_info const & ){ }) ); + + test>( expd([]( info<1> ){ }) ); + test>( expd([]( info<1> const ){ }) ); + test>( expd([]( info<1> const & ){ }) ); + test>( expd([]( info<1>, leaf::error_info const & ){ }) ); + + test, info<2>>( expd([]( info<1> ){ }, []( info<2> ){ }) ); + test, info<2>>( expd([]( info<1> ){ }, []( info<1>, info<2> ){ }) ); + test, info<2>>( expd([]( info<1>, info<2> ){ }, []( info<2> ){ }) ); + test, info<2>>( expd([]( info<1>, info<2> ){ }, []( info<1>, info<2> ){ }) ); + + test, info<2>>( expd([]( leaf::error_info const &, info<1> ){ }, []( info<2> ){ }) ); + test, info<2>>( expd([]( leaf::error_info const &, info<1> ){ }, []( info<1>, info<2> ){ }) ); + test, info<2>>( expd([]( leaf::error_info const &, info<1>, info<2> ){ }, []( info<2> ){ }) ); + test, info<2>>( expd([]( leaf::error_info const &, info<1>, info<2> ){ }, []( info<1>, info<2> ){ }) ); + + test, info<2>>( expd([]( info<1>, leaf::error_info const & ){ }, []( info<2> ){ }) ); + test, info<2>>( expd([]( info<1>, leaf::error_info const & ){ }, []( info<1>, info<2> ){ }) ); + test, info<2>>( expd([]( info<1>, leaf::error_info const &, info<2> ){ }, []( info<2> ){ }) ); + test, info<2>>( expd([]( info<1>, leaf::error_info const &, info<2> ){ }, []( info<1>, info<2> ){ }) ); + + test, info<2>>( expd([]( info<1> ){ }, []( leaf::error_info const &, info<2> ){ }) ); + test, info<2>>( expd([]( info<1> ){ }, []( leaf::error_info const &, info<1>, info<2> ){ }) ); + test, info<2>>( expd([]( info<1>, info<2> ){ }, []( leaf::error_info const &, info<2> ){ }) ); + test, info<2>>( expd([]( info<1>, info<2> ){ }, []( leaf::error_info const &, info<1>, info<2> ){ }) ); + + test, info<2>>( expd([]( info<1> ){ }, []( info<2>, leaf::error_info const & ){ }) ); + test, info<2>>( expd([]( info<1> ){ }, []( info<1>, leaf::error_info const &, info<2> ){ }) ); + test, info<2>>( expd([]( info<1>, info<2> ){ }, []( info<2>, leaf::error_info const & ){ }) ); + test, info<2>>( expd([]( info<1>, info<2> ){ }, []( info<1>, leaf::error_info const &, info<2> ){ }) ); + + test, info<2>, info<3>>( expd([]( info<1> ){ }, []( info<2> ){ }, []( info<3> ){ }) ); + test, info<2>, info<3>>( expd([]( info<1> ){ }, []( info<1>, info<2> ){ }, []( info<1>, info<3> ){ }) ); + test, info<2>, info<3>>( expd([]( info<1> ){ }, []( info<1>, info<2> ){ }, []( info<1>, info<3> ){ }) ); + test, info<2>, info<3>>( expd([]( info<1>, info<2> ){ }, []( info<2> ){ }, []( info<3> ){ }) ); + test, info<2>, info<3>>( expd([]( info<1>, info<2> ){ }, []( info<2> ){ }, []( info<3> ){ }) ); + test, info<2>, info<3>>( expd([]( info<1> ){ }, []( info<2> ){ }, []( info<3>, info<2> ){ }) ); + test, info<2>, info<3>>( expd([]( info<1> ){ }, []( info<2> ){ }, []( info<3>, info<2> ){ }) ); + test, info<3>, info<2>>( expd([]( info<1>, info<3> ){ }, []( info<2> ){ }, []( info<3> ){ }) ); + test, info<3>, info<2>>( expd([]( info<1>, info<3> ){ }, []( info<2> ){ }, []( info<3> ){ }) ); + test, info<2>, info<3>>( expd([]( info<1> ){ }, []( info<2>, info<3> ){ }, []( info<3> ){ }) ); + test, info<2>, info<3>>( expd([]( info<1> ){ }, []( info<2>, info<3> ){ }, []( info<3> ){ }) ); + + test( expd([]( leaf::match ){ }) ); #if BOOST_LEAF_CFG_STD_SYSTEM_ERROR - test< std::tuple >( expd([]( leaf::match, cond_x::x00> ){ }) ); + test( expd([]( leaf::match, cond_x::x00> ){ }) ); #endif - test< std::tuple> >( expd([]( leaf::match_value,42> ){ }) ); + test>( expd([]( leaf::match_value,42> ){ }) ); #if BOOST_LEAF_CFG_STD_SYSTEM_ERROR - test< std::tuple >( expd([]( leaf::match, my_error_condition::cond1> ){ }) ); + test( expd([]( leaf::match, my_error_condition::cond1> ){ }) ); #if __cplusplus >= 201703L - test< std::tuple >( expd([]( leaf::match ){ }) ); - test< std::tuple >( expd([]( leaf::match ){ }) ); + test( expd([]( leaf::match ){ }) ); + test( expd([]( leaf::match ){ }) ); #endif #endif #ifndef BOOST_LEAF_NO_EXCEPTIONS - test< std::tuple> >( expd([]( leaf::catch_, info<1> ){ }) ); + test>( expd([]( leaf::catch_, info<1> ){ }) ); #endif - test< std::tuple,info<2>,info<3>> >( expd([]( info<1> const *, info<2> ){ }, []( info<1>, info<3> const * ){ }) ); - test< std::tuple,info<2>,info<3>> >( expd([]( info<1> const, info<2> ){ }, []( info<1> const *, info<3> ){ }) ); + test, info<2>, info<3>>( expd([]( info<1> const *, info<2> ){ }, []( info<1>, info<3> const * ){ }) ); + test, info<2>, info<3>>( expd([]( info<1> const, info<2> ){ }, []( info<1> const *, info<3> ){ }) ); - test< std::tuple,info<2>> >( expd([]( info<1>, info<2>, leaf::diagnostic_info const & ){ }, []( info<1>, info<2> ){ }) ); + test, info<2>, leaf::e_source_location>( expd([]( info<1>, info<2>, leaf::diagnostic_info const & ){ }, []( info<1>, info<2> ){ }) ); #if BOOST_LEAF_CFG_DIAGNOSTICS && BOOST_LEAF_CFG_CAPTURE - test< std::tuple,info<2>,leaf::leaf_detail::dynamic_allocator> >( expd([]( info<1>, info<2>, leaf::diagnostic_details const & ){ }, []( info<1>, info<2> ){ }) ); + test, info<2>, leaf::e_source_location, leaf::leaf_detail::dynamic_allocator>( expd([]( info<1>, info<2>, leaf::diagnostic_details const & ){ }, []( info<1>, info<2> ){ }) ); #else - test< std::tuple,info<2>> >( expd([]( info<1>, info<2> ){ }, []( info<1>, leaf::diagnostic_details const &, info<2> ){ }) ); + test, info<2>>( expd([]( info<1>, info<2>, leaf::e_source_location ){ }, []( info<1>, leaf::diagnostic_details const &, info<2> ){ }) ); #endif { auto error_handlers = std::make_tuple( []( info<2> ) { }, []( info<3> ) { } ); - test< std::tuple, info<2>, info<3>, info<4>, info<5>>>( expd( + test, info<2>, info<3>, info<4>, info<5>>( expd( []( info<1> ) { }, error_handlers, []( info<4>, info<5> ) { } ) ); @@ -162,7 +162,7 @@ void not_called_on_purpose() []( info<2> ) { }, []( info<3> ) { }, error_handlers1 ); - test< std::tuple, info<2>, info<3>, info<4>, info<5>, info<6>>>( expd( + test, info<2>, info<3>, info<4>, info<5>, info<6>>( expd( []( info<1> ) { }, error_handlers2, []( info<4>, info<5> ) { }, diff --git a/test/diagnostics_test1.cpp b/test/diagnostics_test1.cpp index c9e99088..18ffbf4c 100644 --- a/test/diagnostics_test1.cpp +++ b/test/diagnostics_test1.cpp @@ -112,22 +112,23 @@ template <> struct show_in_diagnostics"); + s.replace(search_prefix_end, s2 - search_prefix_end, ""); } void remove_variance(std::string & s) { s.erase(std::remove(s.begin(), s.end(), '\r'), s.end()); - remove_value(s, "boost::leaf::e_source_location: "); - remove_value(s, "Caught C++ exception:\n\tType: "); + remove_value(s, " reported at ", "\n"); } bool cmp(std::string a, std::string const & b) noexcept @@ -149,12 +150,55 @@ namespace } #endif -#define BOOST_LEAF_DIAGNOSTIC_INFO_NO_BOOST_LEAF_CFG_DIAGNOSTICS "\nboost::leaf::diagnostic_info N/A due to BOOST_LEAF_CFG_DIAGNOSTICS=0\n" -#define BOOST_LEAF_DIAGNOSTIC_DETAILS_NO_BOOST_LEAF_CFG_CAPTURE "\nboost::leaf::diagnostic_details N/A due to BOOST_LEAF_CFG_CAPTURE=0\n" -#define BOOST_LEAF_DIAGNOSTIC_DETAILS_NO_BOOST_LEAF_CFG_DIAGNOSTICS "\nboost::leaf::diagnostic_details N/A due to BOOST_LEAF_CFG_DIAGNOSTICS=0\n" +#define BOOST_LEAF_DIAGNOSTIC_INFO_NO_BOOST_LEAF_CFG_DIAGNOSTICS "\nboost::leaf::diagnostic_info N/A due to BOOST_LEAF_CFG_DIAGNOSTICS=0" +#define BOOST_LEAF_DIAGNOSTIC_DETAILS_NO_BOOST_LEAF_CFG_CAPTURE "\nboost::leaf::diagnostic_details N/A due to BOOST_LEAF_CFG_CAPTURE=0" +#define BOOST_LEAF_DIAGNOSTIC_DETAILS_NO_BOOST_LEAF_CFG_DIAGNOSTICS "\nboost::leaf::diagnostic_details N/A due to BOOST_LEAF_CFG_DIAGNOSTICS=0" int main() { + std::cout << "1\n2\n3\n"; + std::cout << __LINE__ << " ---- result / error_info / no e_source_location\n"; + leaf::try_handle_all( + []() -> leaf::result + { + return BOOST_LEAF_NEW_ERROR( + printable_info_printable_value(), + printable_info_non_printable_value(), + non_printable_info_printable_value(), + non_printable_info_non_printable_value(), + hidden_printable_info_printable_value(), + hidden_non_printable_info_printable_value(), + enum_class::enum0, + leaf::e_errno{ENOENT} ); + }, + []( + printable_info_printable_value, + printable_info_non_printable_value, + non_printable_info_printable_value, + non_printable_info_non_printable_value, + hidden_printable_info_printable_value, + hidden_non_printable_info_printable_value, + enum_class, + leaf::e_errno, + leaf::error_info const & unmatched ) + { +#if BOOST_LEAF_CFG_STD_STRING + std::ostringstream st; + st << unmatched; + std::string s = st.str(); + std::cout << s << std::endl; + BOOST_TEST(cmp(s, + "Error with serial #1" + "\n" + )); + +#endif + }, + []() + { + BOOST_ERROR("Bad error dispatch"); + } ); + std::cout << __LINE__ << " ---- result / error_info\n"; leaf::try_handle_all( []() -> leaf::result @@ -187,7 +231,8 @@ int main() std::string s = st.str(); std::cout << s << std::endl; BOOST_TEST(cmp(s, - "Error serial #1\n" + "Error with serial #2 reported at " + "\n" )); #endif @@ -230,20 +275,21 @@ int main() std::cout << s << std::endl; if( BOOST_LEAF_CFG_DIAGNOSTICS ) BOOST_TEST(cmp(s, - "Error serial #2\n" - "Caught:" - "\n\tboost::leaf::e_source_location: " - "\n\tprintable_info_printable_value: printed printable_value" - "\n\tprintable_info_non_printable_value: *** printable_info non_printable_value ***" - "\n\tnon_printable_info_printable_value: printed printable_value" - "\n\tnon_printable_info_non_printable_value" - "\n\tenum_class: 1" - "\n\tboost::leaf::e_errno: 2, \"No such file or directory\"\n" + "Error with serial #3 reported at " + "\nCaught:" + BOOST_LEAF_CFG_DIAGNOSTICS_FIRST_DELIMITER "printable_info_printable_value: printed printable_value" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "printable_info_non_printable_value: *** printable_info non_printable_value ***" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "non_printable_info_printable_value: printed printable_value" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "non_printable_info_non_printable_value" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "enum_class: 1" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "boost::leaf::e_errno: 2, \"No such file or directory\"" + "\n" )); else BOOST_TEST(cmp(s, - "Error serial #2" + "Error with serial #3" BOOST_LEAF_DIAGNOSTIC_INFO_NO_BOOST_LEAF_CFG_DIAGNOSTICS + "\n" )); #endif }, @@ -288,36 +334,37 @@ int main() if( BOOST_LEAF_CFG_DIAGNOSTICS ) if( BOOST_LEAF_CFG_CAPTURE ) BOOST_TEST(cmp(s, - "Error serial #3\n" - "Caught:" - "\n\tboost::leaf::e_source_location: " - "\n\tprintable_info_printable_value: printed printable_value" - "\n\tprintable_info_non_printable_value: *** printable_info non_printable_value ***" - "\n\tnon_printable_info_printable_value: printed printable_value" - "\n\tnon_printable_info_non_printable_value" - "\n\tenum_class: 0" - "\n\tboost::leaf::e_errno: 2, \"No such file or directory\"\n" - "Diagnostic details:" - "\n\tunexpected_test<1>: 1" - "\n\tunexpected_test<2>: 2\n" + "Error with serial #4 reported at " + "\nCaught:" + BOOST_LEAF_CFG_DIAGNOSTICS_FIRST_DELIMITER "printable_info_printable_value: printed printable_value" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "printable_info_non_printable_value: *** printable_info non_printable_value ***" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "non_printable_info_printable_value: printed printable_value" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "non_printable_info_non_printable_value" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "enum_class: 0" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "boost::leaf::e_errno: 2, \"No such file or directory\"" + "\nDiagnostic details:" + BOOST_LEAF_CFG_DIAGNOSTICS_FIRST_DELIMITER "unexpected_test<1>: 1" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "unexpected_test<2>: 2" + "\n" )); else BOOST_TEST(cmp(s, - "Error serial #3\n" - "Caught:" - "\n\tboost::leaf::e_source_location: " - "\n\tprintable_info_printable_value: printed printable_value" - "\n\tprintable_info_non_printable_value: *** printable_info non_printable_value ***" - "\n\tnon_printable_info_printable_value: printed printable_value" - "\n\tnon_printable_info_non_printable_value" - "\n\tenum_class: 0" - "\n\tboost::leaf::e_errno: 2, \"No such file or directory\"" + "Error with serial #4 reported at " + "\nCaught:" + BOOST_LEAF_CFG_DIAGNOSTICS_FIRST_DELIMITER "printable_info_printable_value: printed printable_value" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "printable_info_non_printable_value: *** printable_info non_printable_value ***" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "non_printable_info_printable_value: printed printable_value" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "non_printable_info_non_printable_value" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "enum_class: 0" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "boost::leaf::e_errno: 2, \"No such file or directory\"" BOOST_LEAF_DIAGNOSTIC_DETAILS_NO_BOOST_LEAF_CFG_CAPTURE + "\n" )); else BOOST_TEST(cmp(s, - "Error serial #3" + "Error with serial #4" BOOST_LEAF_DIAGNOSTIC_DETAILS_NO_BOOST_LEAF_CFG_DIAGNOSTICS + "\n" )); #endif }, @@ -352,27 +399,29 @@ int main() if( BOOST_LEAF_CFG_DIAGNOSTICS ) if( BOOST_LEAF_CFG_CAPTURE ) BOOST_TEST(cmp(s, - "Error serial #4\n" - "Diagnostic details:" - "\n\tprintable_info_printable_value: printed printable_value" - "\n\tprintable_info_non_printable_value: *** printable_info non_printable_value ***" - "\n\tnon_printable_info_printable_value: printed printable_value" - "\n\tnon_printable_info_non_printable_value" - "\n\tunexpected_test<1>: 1" - "\n\tunexpected_test<2>: 2" - "\n\tenum_class: 0" - "\n\tboost::leaf::e_errno: 2, \"No such file or directory\"" - "\n\tboost::leaf::e_source_location: " + "Error with serial #5 reported at " + "\nDiagnostic details:" + BOOST_LEAF_CFG_DIAGNOSTICS_FIRST_DELIMITER "printable_info_printable_value: printed printable_value" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "printable_info_non_printable_value: *** printable_info non_printable_value ***" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "non_printable_info_printable_value: printed printable_value" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "non_printable_info_non_printable_value" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "unexpected_test<1>: 1" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "unexpected_test<2>: 2" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "enum_class: 0" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "boost::leaf::e_errno: 2, \"No such file or directory\"" + "\n" )); else BOOST_TEST(cmp(s, - "Error serial #4" + "Error with serial #5" BOOST_LEAF_DIAGNOSTIC_DETAILS_NO_BOOST_LEAF_CFG_CAPTURE + "\n" )); else BOOST_TEST(cmp(s, - "Error serial #4" + "Error with serial #5" BOOST_LEAF_DIAGNOSTIC_DETAILS_NO_BOOST_LEAF_CFG_DIAGNOSTICS + "\n" )); #endif }, @@ -385,6 +434,45 @@ int main() #ifndef BOOST_LEAF_NO_EXCEPTIONS + std::cout << __LINE__ << " ---- exception / error_info / no e_source_location\n"; + leaf::try_catch( + [] + { + BOOST_LEAF_THROW_EXCEPTION( my_exception(), + printable_info_printable_value(), + printable_info_non_printable_value(), + non_printable_info_printable_value(), + non_printable_info_non_printable_value(), + hidden_printable_info_printable_value(), + hidden_non_printable_info_printable_value(), + enum_class::enum1, + leaf::e_errno{ENOENT} ); + }, + []( + printable_info_printable_value, + printable_info_non_printable_value, + non_printable_info_printable_value, + non_printable_info_non_printable_value, + hidden_printable_info_printable_value, + hidden_non_printable_info_printable_value, + enum_class, + leaf::e_errno, + leaf::error_info const & unmatched ) + { +#if BOOST_LEAF_CFG_STD_STRING + std::ostringstream st; + st << unmatched; + std::string s = st.str(); + std::cout << s << std::endl; + BOOST_TEST(cmp(s, + "Error with serial #6" + "\nCaught:" + BOOST_LEAF_CFG_DIAGNOSTICS_FIRST_DELIMITER "struct my_exception, \"my_exception what\"" + "\n" + )); +#endif + } ); + std::cout << __LINE__ << " ---- exception / error_info\n"; leaf::try_catch( [] @@ -417,10 +505,10 @@ int main() std::string s = st.str(); std::cout << s << std::endl; BOOST_TEST(cmp(s, - "Error serial #5\n" - "Caught C++ exception:" - "\n\tType: " - "\n\tstd::exception::what(): my_exception what\n" + "Error with serial #7 reported at " + "\nCaught:" + BOOST_LEAF_CFG_DIAGNOSTICS_FIRST_DELIMITER "struct my_exception, \"my_exception what\"" + "\n" )); #endif } ); @@ -458,25 +546,24 @@ int main() std::cout << s << std::endl; if( BOOST_LEAF_CFG_DIAGNOSTICS ) BOOST_TEST(cmp(s, - "Error serial #6\n" - "Caught C++ exception:" - "\n\tType: " - "\n\tstd::exception::what(): my_exception what" - "\n\tboost::leaf::e_source_location: " - "\n\tprintable_info_printable_value: printed printable_value" - "\n\tprintable_info_non_printable_value: *** printable_info non_printable_value ***" - "\n\tnon_printable_info_printable_value: printed printable_value" - "\n\tnon_printable_info_non_printable_value" - "\n\tenum_class: 0" - "\n\tboost::leaf::e_errno: 2, \"No such file or directory\"\n" + "Error with serial #8 reported at " + "\nCaught:" + BOOST_LEAF_CFG_DIAGNOSTICS_FIRST_DELIMITER "struct my_exception, \"my_exception what\"" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "printable_info_printable_value: printed printable_value" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "printable_info_non_printable_value: *** printable_info non_printable_value ***" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "non_printable_info_printable_value: printed printable_value" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "non_printable_info_non_printable_value" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "enum_class: 0" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "boost::leaf::e_errno: 2, \"No such file or directory\"" + "\n" )); else BOOST_TEST(cmp(s, - "Error serial #6\n" - "Caught C++ exception:" - "\n\tType: " - "\n\tstd::exception::what(): my_exception what" + "Error with serial #8" + "\nCaught:" + BOOST_LEAF_CFG_DIAGNOSTICS_FIRST_DELIMITER "struct my_exception, \"my_exception what\"" BOOST_LEAF_DIAGNOSTIC_INFO_NO_BOOST_LEAF_CFG_DIAGNOSTICS + "\n" )); #endif } ); @@ -517,43 +604,41 @@ int main() if( BOOST_LEAF_CFG_DIAGNOSTICS ) if( BOOST_LEAF_CFG_CAPTURE ) BOOST_TEST(cmp(s, - "Error serial #7\n" - "Caught C++ exception:" - "\n\tType: " - "\n\tstd::exception::what(): my_exception what" - "\n\tboost::leaf::e_source_location: " - "\n\tprintable_info_printable_value: printed printable_value" - "\n\tprintable_info_non_printable_value: *** printable_info non_printable_value ***" - "\n\tnon_printable_info_printable_value: printed printable_value" - "\n\tnon_printable_info_non_printable_value" - "\n\tenum_class: 1" - "\n\tboost::leaf::e_errno: 2, \"No such file or directory\"\n" - "Diagnostic details:" - "\n\tunexpected_test<1>: 1" - "\n\tunexpected_test<2>: 2\n" + "Error with serial #9 reported at " + "\nCaught:" + BOOST_LEAF_CFG_DIAGNOSTICS_FIRST_DELIMITER "struct my_exception, \"my_exception what\"" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "printable_info_printable_value: printed printable_value" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "printable_info_non_printable_value: *** printable_info non_printable_value ***" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "non_printable_info_printable_value: printed printable_value" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "non_printable_info_non_printable_value" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "enum_class: 1" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "boost::leaf::e_errno: 2, \"No such file or directory\"" + "\nDiagnostic details:" + BOOST_LEAF_CFG_DIAGNOSTICS_FIRST_DELIMITER "unexpected_test<1>: 1" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "unexpected_test<2>: 2" + "\n" )); else BOOST_TEST(cmp(s, - "Error serial #7\n" - "Caught C++ exception:" - "\n\tType: " - "\n\tstd::exception::what(): my_exception what" - "\n\tboost::leaf::e_source_location: " - "\n\tprintable_info_printable_value: printed printable_value" - "\n\tprintable_info_non_printable_value: *** printable_info non_printable_value ***" - "\n\tnon_printable_info_printable_value: printed printable_value" - "\n\tnon_printable_info_non_printable_value" - "\n\tenum_class: 1" - "\n\tboost::leaf::e_errno: 2, \"No such file or directory\"" + "Error with serial #9 reported at " + "\nCaught:" + BOOST_LEAF_CFG_DIAGNOSTICS_FIRST_DELIMITER "struct my_exception, \"my_exception what\"" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "printable_info_printable_value: printed printable_value" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "printable_info_non_printable_value: *** printable_info non_printable_value ***" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "non_printable_info_printable_value: printed printable_value" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "non_printable_info_non_printable_value" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "enum_class: 1" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "boost::leaf::e_errno: 2, \"No such file or directory\"" BOOST_LEAF_DIAGNOSTIC_DETAILS_NO_BOOST_LEAF_CFG_CAPTURE + "\n" )); else BOOST_TEST(cmp(s, - "Error serial #7\n" - "Caught C++ exception:" - "\n\tType: " - "\n\tstd::exception::what(): my_exception what" + "Error with serial #9" + "\nCaught:" + BOOST_LEAF_CFG_DIAGNOSTICS_FIRST_DELIMITER "struct my_exception, \"my_exception what\"" BOOST_LEAF_DIAGNOSTIC_DETAILS_NO_BOOST_LEAF_CFG_DIAGNOSTICS + "\n" )); #endif } ); @@ -584,36 +669,35 @@ int main() if( BOOST_LEAF_CFG_DIAGNOSTICS ) if( BOOST_LEAF_CFG_CAPTURE ) BOOST_TEST(cmp(s, - "Error serial #8\n" - "Caught C++ exception:" - "\n\tType: " - "\n\tstd::exception::what(): my_exception what\n" - "Diagnostic details:" - "\n\tprintable_info_printable_value: printed printable_value" - "\n\tprintable_info_non_printable_value: *** printable_info non_printable_value ***" - "\n\tnon_printable_info_printable_value: printed printable_value" - "\n\tnon_printable_info_non_printable_value" - "\n\tenum_class: 1" - "\n\tunexpected_test<1>: 1" - "\n\tunexpected_test<2>: 2" - "\n\tboost::leaf::e_errno: 2, \"No such file or directory\"" - "\n\tboost::leaf::e_source_location: " + "Error with serial #10 reported at " + "\nCaught:" + BOOST_LEAF_CFG_DIAGNOSTICS_FIRST_DELIMITER "struct my_exception, \"my_exception what\"" + "\nDiagnostic details:" + BOOST_LEAF_CFG_DIAGNOSTICS_FIRST_DELIMITER "printable_info_printable_value: printed printable_value" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "printable_info_non_printable_value: *** printable_info non_printable_value ***" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "non_printable_info_printable_value: printed printable_value" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "non_printable_info_non_printable_value" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "enum_class: 1" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "unexpected_test<1>: 1" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "unexpected_test<2>: 2" + BOOST_LEAF_CFG_DIAGNOSTICS_DELIMITER "boost::leaf::e_errno: 2, \"No such file or directory\"" + "\n" )); else BOOST_TEST(cmp(s, - "Error serial #8\n" - "Caught C++ exception:" - "\n\tType: " - "\n\tstd::exception::what(): my_exception what" + "Error with serial #10" + "\nCaught:" + BOOST_LEAF_CFG_DIAGNOSTICS_FIRST_DELIMITER "struct my_exception, \"my_exception what\"" BOOST_LEAF_DIAGNOSTIC_DETAILS_NO_BOOST_LEAF_CFG_CAPTURE + "\n" )); else BOOST_TEST(cmp(s, - "Error serial #8\n" - "Caught C++ exception:" - "\n\tType: " - "\n\tstd::exception::what(): my_exception what" + "Error with serial #10" + "\nCaught:" + BOOST_LEAF_CFG_DIAGNOSTICS_FIRST_DELIMITER "struct my_exception, \"my_exception what\"" BOOST_LEAF_DIAGNOSTIC_DETAILS_NO_BOOST_LEAF_CFG_DIAGNOSTICS + "\n" )); #endif } ); diff --git a/test/print_test.cpp b/test/print_test.cpp index 342ce75f..77b15719 100644 --- a/test/print_test.cpp +++ b/test/print_test.cpp @@ -75,6 +75,7 @@ std::string print(T const & x, char const * prefix, char const * delimiter) using namespace leaf::leaf_detail; std::ostringstream s; diagnostic::print(s, prefix, delimiter, x); + diagnostic::print(s, prefix, delimiter, x); std::string q = s.str(); std::cout << "[LINE " << Line << "] " << q << '\n'; return q; @@ -88,39 +89,28 @@ struct my_exception: std::exception int main() { { - std::string out = print<__LINE__>(c0{}, "Title", " --> "); - BOOST_TEST_NE(out.find("Title --> "), out.npos); - BOOST_TEST_NE(out.find("c0"), out.npos); - BOOST_TEST_NE(out.find(": info"), out.npos); + std::string out = print<__LINE__>(c0{}, "Title " , ", "); + BOOST_TEST_EQ(out, "Title c0: info, c0: info"); } { - std::string out = print<__LINE__>(c1{42}, "Title", " --> "); - BOOST_TEST_NE(out.find("Title --> "), out.npos); - BOOST_TEST_NE(out.find("c1"), out.npos); - BOOST_TEST_NE(out.find(": value 42"), out.npos); + std::string out = print<__LINE__>(c1{42}, "Title ", ", "); + BOOST_TEST_EQ(out, "Title c1: value 42, c1: value 42"); } { - std::string out = print<__LINE__>(c2{42}, "Title", " --> "); - BOOST_TEST_NE(out.find("Title --> "), out.npos); - BOOST_TEST_NE(out.find("c2"), out.npos); - BOOST_TEST_NE(out.find(": value 42"), out.npos); + std::string out = print<__LINE__>(c2{42}, "Title ", ", "); + BOOST_TEST_EQ(out, "Title c2: value 42, c2: value 42"); } { - std::string out = print<__LINE__>(c3{42}, "Title", " --> "); - BOOST_TEST_NE(out.find("Title --> "), out.npos); - BOOST_TEST_NE(out.find("c3"), out.npos); - BOOST_TEST_NE(out.find(": 42"), out.npos); + std::string out = print<__LINE__>(c3{42}, "Title ", ", "); + BOOST_TEST_EQ(out, "Title c3: 42, c3: 42"); } { - std::string out = print<__LINE__>(c4{}, "Title", " --> "); - BOOST_TEST_NE(out.find("Title --> "), out.npos); - BOOST_TEST_NE(out.find("c4"), out.npos); - BOOST_TEST_EQ(out.find(": "), out.npos); + std::string out = print<__LINE__>(c4{}, "Title ", ", "); + BOOST_TEST_EQ(out, "Title c4, c4"); } { - std::string out = print<__LINE__>(my_exception{}, "Title", " --> "); - BOOST_TEST_NE(out.find("Title --> "), out.npos); - BOOST_TEST_NE(out.find("my_exception, std::exception::what(): my_exception what"), out.npos); + std::string out = print<__LINE__>(my_exception{}, "Title ", ", "); + BOOST_TEST_EQ(out, "Title my_exception, \"my_exception what\", my_exception, \"my_exception what\""); } return boost::report_errors(); }