diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 585ac634..377ffc01 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -9,6 +9,18 @@ "command": "cd ${workspaceRoot} && meson setup -D leaf_boost_examples=true -D leaf_lua_examples=true _bld/debug && meson setup -D leaf_boost_examples=true -D leaf_lua_examples=true -D leaf_hpp=true _bld/debug_leaf_hpp && meson setup -D leaf_boost_examples=true -D leaf_lua_examples=true _bld/release --buildtype release && meson setup -D leaf_boost_examples=true -D leaf_lua_examples=true -D leaf_hpp=true _bld/release_leaf_hpp --buildtype release && meson setup -D leaf_diagnostics=0 -D cpp_eh=none -D b_ndebug=true -D b_lto=true -D leaf_enable_benchmarks=true _bld/benchmark --buildtype release", "problemMatcher": [] }, + { + "label": "Configure Meson build directories (no diagnostics)", + "type": "shell", + "command": "cd ${workspaceRoot} && meson setup -D leaf_diagnostics=0 -D leaf_boost_examples=true -D leaf_lua_examples=true _bld/debug && meson setup -D leaf_diagnostics=0 -D leaf_boost_examples=true -D leaf_lua_examples=true -D leaf_hpp=true _bld/debug_leaf_hpp && meson setup -D leaf_diagnostics=0 -D leaf_boost_examples=true -D leaf_lua_examples=true _bld/release --buildtype release && meson setup -D leaf_diagnostics=0 -D leaf_boost_examples=true -D leaf_lua_examples=true -D leaf_hpp=true _bld/release_leaf_hpp --buildtype release", + "problemMatcher": [] + }, + { + "label": "Configure Meson build directories (no capture)", + "type": "shell", + "command": "cd ${workspaceRoot} && meson setup -D leaf_capture=0 -D leaf_boost_examples=true -D leaf_lua_examples=true _bld/debug && meson setup -D leaf_capture=0 -D leaf_boost_examples=true -D leaf_lua_examples=true -D leaf_hpp=true _bld/debug_leaf_hpp && meson setup -D leaf_capture=0 -D leaf_boost_examples=true -D leaf_lua_examples=true _bld/release --buildtype release && meson setup -D leaf_capture=0 -D leaf_boost_examples=true -D leaf_lua_examples=true -D leaf_hpp=true _bld/release_leaf_hpp --buildtype release", + "problemMatcher": [] + }, { "label": "Configure Meson build directories (no Boost)", "type": "shell", diff --git a/include/boost/leaf/common.hpp b/include/boost/leaf/common.hpp index 44c154cb..e55e4826 100644 --- a/include/boost/leaf/common.hpp +++ b/include/boost/leaf/common.hpp @@ -58,7 +58,7 @@ struct BOOST_LEAF_SYMBOL_VISIBLE e_errno template friend std::ostream & operator<<(std::basic_ostream & os, e_errno const & err) { - return os << parse_name() << ": " << err.value << ", \"" << std::strerror(err.value) << '"'; + return os << err.value << ", \"" << std::strerror(err.value) << '"'; } }; @@ -102,7 +102,7 @@ namespace windows *--z = 0; if( z[-1] == '\r' ) *--z = 0; - return os << parse_name() << ": " << err.value << ", \"" << (LPCSTR)mb.p << '"'; + return os << err.value << ", \"" << (LPCSTR)mb.p << '"'; } return os; } diff --git a/include/boost/leaf/config.hpp b/include/boost/leaf/config.hpp index 46308345..0159e086 100644 --- a/include/boost/leaf/config.hpp +++ b/include/boost/leaf/config.hpp @@ -19,13 +19,6 @@ //////////////////////////////////////// -#ifdef BOOST_LEAF_DIAGNOSTICS -# warning BOOST_LEAF_DIAGNOSTICS has been renamed to BOOST_LEAF_CFG_DIAGNOSTICS. -# define BOOST_LEAF_CFG_DIAGNOSTICS BOOST_LEAF_DIAGNOSTICS -#endif - -//////////////////////////////////////// - #ifdef BOOST_LEAF_TLS_FREERTOS # ifndef BOOST_LEAF_EMBEDDED diff --git a/include/boost/leaf/context.hpp b/include/boost/leaf/context.hpp index b0156e74..4f86598c 100644 --- a/include/boost/leaf/context.hpp +++ b/include/boost/leaf/context.hpp @@ -136,50 +136,56 @@ namespace leaf_detail namespace leaf_detail { - template + template struct tuple_for_each { - BOOST_LEAF_CONSTEXPR static void activate( Tuple & tup ) noexcept + BOOST_LEAF_CONSTEXPR static void activate( Tup & tup ) noexcept { static_assert(!std::is_same(tup))>::type>::value, "Bug in LEAF: context type deduction"); - tuple_for_each::activate(tup); + tuple_for_each::activate(tup); std::get(tup).activate(); } - BOOST_LEAF_CONSTEXPR static void deactivate( Tuple & tup ) noexcept + BOOST_LEAF_CONSTEXPR static void deactivate( Tup & tup ) noexcept { static_assert(!std::is_same(tup))>::type>::value, "Bug in LEAF: context type deduction"); std::get(tup).deactivate(); - tuple_for_each::deactivate(tup); + tuple_for_each::deactivate(tup); } - BOOST_LEAF_CONSTEXPR static void unload( Tuple & tup, int err_id ) noexcept + BOOST_LEAF_CONSTEXPR static void unload( Tup & tup, int err_id ) noexcept { static_assert(!std::is_same(tup))>::type>::value, "Bug in LEAF: context type deduction"); BOOST_LEAF_ASSERT(err_id != 0); auto & sl = std::get(tup); sl.unload(err_id); - tuple_for_each::unload(tup, err_id); + tuple_for_each::unload(tup, err_id); } template - static void print( std::basic_ostream & os, void const * tup, int err_id_to_print ) + static void print(std::basic_ostream & os, void const * tup, error_id to_print, char const * & prefix) { BOOST_LEAF_ASSERT(tup != nullptr); - tuple_for_each::print(os, tup, err_id_to_print); - std::get(*static_cast(tup)).print(os, err_id_to_print); + tuple_for_each::print(os, tup, to_print, prefix); + std::get(*static_cast(tup)).print(os, to_print, prefix); } }; - template - struct tuple_for_each<0, Tuple> + template + struct tuple_for_each<0, Tup> { - BOOST_LEAF_CONSTEXPR static void activate( Tuple & ) noexcept { } - BOOST_LEAF_CONSTEXPR static void deactivate( Tuple & ) noexcept { } - BOOST_LEAF_CONSTEXPR static void unload( Tuple &, int ) noexcept { } + BOOST_LEAF_CONSTEXPR static void activate( Tup & ) noexcept { } + BOOST_LEAF_CONSTEXPR static void deactivate( Tup & ) noexcept { } + BOOST_LEAF_CONSTEXPR static void unload( Tup &, int ) noexcept { } template - BOOST_LEAF_CONSTEXPR static void print( std::basic_ostream &, void const *, int ) { } + BOOST_LEAF_CONSTEXPR static void print(std::basic_ostream &, void const *, error_id, char const * &) { } }; + + template + BOOST_LEAF_CONSTEXPR void print_tuple_contents(std::basic_ostream & os, void const * tup, error_id to_print, char const * & prefix) + { + tuple_for_each::value, Tup>::print(os, tup, to_print, prefix); + } } //////////////////////////////////////////// @@ -300,14 +306,15 @@ class context template void print( std::basic_ostream & os ) const { - leaf_detail::tuple_for_each::value,Tup>::print(os, &tup_, 0); + char const * prefix = "Contents:"; + leaf_detail::print_tuple_contents(os, &tup_, error_id(), prefix); } template friend std::ostream & operator<<( std::basic_ostream & os, context const & ctx ) { ctx.print(os); - return os; + return os << '\n'; } template diff --git a/include/boost/leaf/detail/capture_list.hpp b/include/boost/leaf/detail/capture_list.hpp index 3ad7987f..b5058287 100644 --- a/include/boost/leaf/detail/capture_list.hpp +++ b/include/boost/leaf/detail/capture_list.hpp @@ -7,6 +7,7 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include +#include #if BOOST_LEAF_CFG_CAPTURE @@ -14,6 +15,8 @@ namespace boost { namespace leaf { +class error_id; + namespace leaf_detail { struct BOOST_LEAF_SYMBOL_VISIBLE tls_tag_id_factory_current_id; @@ -31,7 +34,7 @@ namespace leaf_detail virtual void unload( int err_id ) = 0; #if BOOST_LEAF_CFG_DIAGNOSTICS - virtual void print( std::ostream &, int err_id_to_print ) const = 0; + virtual void print(std::ostream &, error_id const & to_print, char const * & prefix) const = 0; #endif protected: @@ -94,23 +97,21 @@ namespace leaf_detail } template - void print(std::basic_ostream & os, int const err_id_to_print, char const * title = nullptr) const + void print(std::basic_ostream & os, error_id const & to_print, char const * & prefix) const { #if BOOST_LEAF_CFG_DIAGNOSTICS if( first_ ) { - if( title ) - os << title; for_each( - [&os, err_id_to_print]( node const & n ) + [&os, &to_print, &prefix]( node const & n ) { - n.print(os, err_id_to_print); + n.print(os, to_print, prefix); } ); } #else (void) os; - (void) title; - (void) err_id_to_print; + (void) prefix; + (void) to_print; #endif } }; diff --git a/include/boost/leaf/detail/demangle.hpp b/include/boost/leaf/detail/demangle.hpp index 1511a245..a6b12e95 100644 --- a/include/boost/leaf/detail/demangle.hpp +++ b/include/boost/leaf/detail/demangle.hpp @@ -109,69 +109,77 @@ namespace leaf_detail { return cpp11_suffix::check(str, suffix) ? S1 - S2 : 0; } -} -struct parsed_name -{ - char const * name; - int len; - parsed_name(char const * name, int len) noexcept: - name(name), - len(len) - { - } - template - parsed_name(char const(&name)[S]) noexcept: - name(name), - len(S-1) - { - } - bool parse_success() const noexcept + struct parsed_name { - return name[len] != 0; - } - template - friend std::ostream & operator<<(std::basic_ostream & os, parsed_name const & pn) + char const * name; + int len; + parsed_name(char const * name, int len) noexcept: + name(name), + len(len) + { + } + template + parsed_name(char const(&name)[S]) noexcept: + name(name), + len(S-1) + { + } + bool parse_success() const noexcept + { + return name[len] != 0; + } + template + friend std::ostream & operator<<(std::basic_ostream & os, parsed_name const & pn) + { + return os.write(pn.name, pn.len); + } + }; + + // Workaround - we only use this function if parse_name (below) fails to parse __PRETTY_FUNCTION__ / __FUNCSIG__. + // In this case parse_name should be fixed to support the newly encountered (note, parsing is done at compile-time). + template + parsed_name please_update_parse_name() { - return os.write(pn.name, pn.len); + return parsed_name(BOOST_LEAF_PRETTY_FUNCTION); } -}; -template -parsed_name parse_name() -{ - // Workaround for older gcc compilers where __PRETTY_FUNCTION__ is not constexpr. - // Instead of evaluating constexpr int x = f(__PRETTY_FUNCTION__), which fails, - // we evaluate int const x = f(__PRETTY_FUNCTION__). Then we enforce compile-time - // execution by evaluating sizeof(char[1 + x]) -1. + template + parsed_name parse_name() + { + // Workaround for older gcc compilers where __PRETTY_FUNCTION__ is not constexpr. + // Instead of evaluating constexpr int x = f(__PRETTY_FUNCTION__), which fails, + // we evaluate int const x = f(__PRETTY_FUNCTION__). Then we enforce compile-time + // execution by evaluating sizeof(char[1 + x]) -1. #define BOOST_LEAF_PARSE_PF(prefix, suffix) \ - { \ - if( int const s = leaf_detail::check_suffix(BOOST_LEAF_PRETTY_FUNCTION, suffix) ) \ - if( int const p = leaf_detail::check_prefix(BOOST_LEAF_PRETTY_FUNCTION, prefix) ) \ - return parsed_name(BOOST_LEAF_PRETTY_FUNCTION + sizeof(char[1 + p]) - 1, sizeof(char[1 + s - p]) - 1); \ - } - // clang style: - BOOST_LEAF_PARSE_PF( "parsed_name boost::leaf::parse_name() [Name = ", "]"); - // old clang style: - BOOST_LEAF_PARSE_PF( "boost::leaf::parsed_name boost::leaf::parse_name() [Name = ", "]"); - // gcc style: - BOOST_LEAF_PARSE_PF( "boost::leaf::parsed_name boost::leaf::parse_name() [with Name = ", "]"); - // msvc style, __cdecl, struct/class/enum: - BOOST_LEAF_PARSE_PF( "struct boost::leaf::parsed_name __cdecl boost::leaf::parse_name(void)"); - BOOST_LEAF_PARSE_PF( "struct boost::leaf::parsed_name __cdecl boost::leaf::parse_name(void)"); - BOOST_LEAF_PARSE_PF( "struct boost::leaf::parsed_name __cdecl boost::leaf::parse_name(void)"); - // msvc style, __stdcall, struct/class/enum: - BOOST_LEAF_PARSE_PF( "struct boost::leaf::parsed_name __stdcall boost::leaf::parse_name(void)"); - BOOST_LEAF_PARSE_PF( "struct boost::leaf::parsed_name __stdcall boost::leaf::parse_name(void)"); - BOOST_LEAF_PARSE_PF( "struct boost::leaf::parsed_name __stdcall boost::leaf::parse_name(void)"); - // msvc style, __fastcall, struct/class/enum: - BOOST_LEAF_PARSE_PF( "struct boost::leaf::parsed_name __fastcall boost::leaf::parse_name(void)"); - BOOST_LEAF_PARSE_PF( "struct boost::leaf::parsed_name __fastcall boost::leaf::parse_name(void)"); - BOOST_LEAF_PARSE_PF( "struct boost::leaf::parsed_name __fastcall boost::leaf::parse_name(void)"); + { \ + if( int const s = leaf_detail::check_suffix(BOOST_LEAF_PRETTY_FUNCTION, suffix) ) \ + if( int const p = leaf_detail::check_prefix(BOOST_LEAF_PRETTY_FUNCTION, prefix) ) \ + return parsed_name(BOOST_LEAF_PRETTY_FUNCTION + sizeof(char[1 + p]) - 1, sizeof(char[1 + s - p]) - 1); \ + } + // clang style: + BOOST_LEAF_PARSE_PF( "parsed_name boost::leaf::leaf_detail::parse_name() [Name = ", "]"); + // old clang style: + BOOST_LEAF_PARSE_PF( "boost::leaf::leaf_detail::parsed_name boost::leaf::leaf_detail::parse_name() [Name = ", "]"); + // gcc style: + BOOST_LEAF_PARSE_PF( "boost::leaf::leaf_detail::parsed_name boost::leaf::leaf_detail::parse_name() [with Name = ", "]"); + // msvc style, __cdecl, struct/class/enum: + BOOST_LEAF_PARSE_PF( "struct boost::leaf::leaf_detail::parsed_name __cdecl boost::leaf::leaf_detail::parse_name(void)"); + BOOST_LEAF_PARSE_PF( "struct boost::leaf::leaf_detail::parsed_name __cdecl boost::leaf::leaf_detail::parse_name(void)"); + BOOST_LEAF_PARSE_PF( "struct boost::leaf::leaf_detail::parsed_name __cdecl boost::leaf::leaf_detail::parse_name(void)"); + // msvc style, __stdcall, struct/class/enum: + BOOST_LEAF_PARSE_PF( "struct boost::leaf::leaf_detail::parsed_name __stdcall boost::leaf::leaf_detail::parse_name(void)"); + BOOST_LEAF_PARSE_PF( "struct boost::leaf::leaf_detail::parsed_name __stdcall boost::leaf::leaf_detail::parse_name(void)"); + BOOST_LEAF_PARSE_PF( "struct boost::leaf::leaf_detail::parsed_name __stdcall boost::leaf::leaf_detail::parse_name(void)"); + // msvc style, __fastcall, struct/class/enum: + BOOST_LEAF_PARSE_PF( "struct boost::leaf::leaf_detail::parsed_name __fastcall boost::leaf::leaf_detail::parse_name(void)"); + BOOST_LEAF_PARSE_PF( "struct boost::leaf::leaf_detail::parsed_name __fastcall boost::leaf::leaf_detail::parse_name(void)"); + BOOST_LEAF_PARSE_PF( "struct boost::leaf::leaf_detail::parsed_name __fastcall boost::leaf::leaf_detail::parse_name(void)"); #undef BOOST_LEAF_PARSE_PF - // Unrecognized __PRETTY_FUNCTION__/__FUNSIG__ format, return as-is. Note, parsing is done at compile-time. - return parsed_name(BOOST_LEAF_PRETTY_FUNCTION); + // Unrecognized __PRETTY_FUNCTION__ / __FUNCSIG__ format, return as-is. Note, parsing is done at compile-time. + return please_update_parse_name(); + } } } } diff --git a/include/boost/leaf/detail/print.hpp b/include/boost/leaf/detail/print.hpp index 63b4febf..b72e3252 100644 --- a/include/boost/leaf/detail/print.hpp +++ b/include/boost/leaf/detail/print.hpp @@ -47,85 +47,90 @@ namespace leaf_detail //////////////////////////////////////// + template + bool print_impl(std::basic_ostream & os, char const * & prefix, char const * delimiter, char const * mid, PrintableInfo const & x) + { + static_assert(show_in_diagnostics::value, "show_in_diagnostics violation"); + BOOST_LEAF_ASSERT(delimiter); + if( prefix ) + { + os << prefix; + prefix = nullptr; + } + os << delimiter << parse_name(); + if( mid ) + os << mid << x; + return true; + } + + //////////////////////////////////////// + template < class Wrapper, + bool ShowInDiagnostics = show_in_diagnostics::value, bool WrapperPrintable = is_printable::value, bool ValuePrintable = has_printable_member_value::value, bool IsException = std::is_base_of::value, bool IsEnum = std::is_enum::value> struct diagnostic; - template - struct diagnostic + template + struct diagnostic { - static constexpr bool is_invisible = false; - template - static void print( std::basic_ostream & os, Wrapper const & x ) + static bool print(std::basic_ostream &, char const * &, char const *, Wrapper const & x) noexcept { - os << x; + return false; } }; - template - struct diagnostic + template + struct diagnostic { - static constexpr bool is_invisible = false; - template - static void print( std::basic_ostream & os, Wrapper const & x ) + static bool print(std::basic_ostream & os, char const * & prefix, char const * delimiter, Wrapper const & x) { - os << parse_name() << ": " << x.value; + return print_impl(os, prefix, delimiter, ": ", x); } }; - template - struct diagnostic + template + struct diagnostic { - static constexpr bool is_invisible = false; - template - static void print( std::basic_ostream & os, Wrapper const & ex ) + static bool print(std::basic_ostream & os, char const * & prefix, char const * delimiter, Wrapper const & x) { - os << parse_name() << ": std::exception::what(): " << ex.what(); + return print_impl(os, prefix, delimiter, ": ", x.value); } }; - template - struct diagnostic + template + struct diagnostic { - static constexpr bool is_invisible = false; - template - static void print( std::basic_ostream & os, Wrapper const & ) + static bool print(std::basic_ostream & os, char const * & prefix, char const * delimiter, Exception const & ex) { - os << parse_name() << - (show_in_diagnostics::value ? - ": {not printable}" : - ": {hidden by show_in_diagnostics}"); + return print_impl(os, prefix, delimiter, ", std::exception::what(): ", static_cast(ex).what()); } }; template - struct diagnostic + struct diagnostic { - static constexpr bool is_invisible = false; - template - static void print( std::basic_ostream & os, Wrapper const & w ) + static bool print(std::basic_ostream & os, char const * & prefix, char const * delimiter, Wrapper const &) { - os << parse_name() << ": " << static_cast::type>(w); + return print_impl(os, prefix, delimiter, nullptr, 0); } }; - template <> - struct diagnostic + template + struct diagnostic { - static constexpr bool is_invisible = true; - template - BOOST_LEAF_CONSTEXPR static void print( std::basic_ostream &, std::exception_ptr const & ) + static bool print(std::basic_ostream & os, char const * & prefix, char const * delimiter, Enum const & enum_) { + return print_impl(os, prefix, delimiter, ": ", static_cast::type>(enum_)); } }; } diff --git a/include/boost/leaf/diagnostics.hpp b/include/boost/leaf/diagnostics.hpp index 1a5c72e6..2102c8c1 100644 --- a/include/boost/leaf/diagnostics.hpp +++ b/include/boost/leaf/diagnostics.hpp @@ -17,7 +17,7 @@ namespace boost { namespace leaf { class diagnostic_info: public error_info { void const * tup_; - void (*print_context_content_)( std::ostream &, void const * tup, int err_id_to_print ); + void (*print_tuple_contents_)(std::ostream &, void const * tup, error_id to_print, char const * & prefix); protected: @@ -27,16 +27,23 @@ class diagnostic_info: public error_info BOOST_LEAF_CONSTEXPR diagnostic_info( error_info const & ei, Tup const & tup ) noexcept: error_info(ei), tup_(&tup), - print_context_content_(&leaf_detail::tuple_for_each::value, Tup>::print) + print_tuple_contents_(&leaf_detail::print_tuple_contents) { } + template + void print_diagnostic_info(std::basic_ostream & os) const + { + print_error_info(os); + char const * prefix = exception() ? nullptr : "\nCaught:"; + print_tuple_contents_(os, tup_, error(), prefix); + } + template friend std::ostream & operator<<( std::basic_ostream & os, diagnostic_info const & x ) { - os << static_cast(x); - x.print_context_content_(os, x.tup_, x.error().value()); - return os; + x.print_diagnostic_info(os); + return os << '\n'; } }; @@ -75,10 +82,18 @@ class diagnostic_info: public error_info { } + template + void print_diagnostic_info( std::basic_ostream & os ) const + { + print_error_info(os); + os << "\nboost::leaf::diagnostic_info N/A due to BOOST_LEAF_CFG_DIAGNOSTICS=0"; + } + template friend std::ostream & operator<<( std::basic_ostream & os, diagnostic_info const & x ) { - return os << "diagnostic_info not available due to BOOST_LEAF_CFG_DIAGNOSTICS=0. Basic error_info follows.\n" << static_cast(x); + x.print_diagnostic_info(os); + return os << "\n"; } }; @@ -126,13 +141,22 @@ class diagnostic_details: public diagnostic_info { } + template + void print_diagnostic_details( std::basic_ostream & os) const + { + print_diagnostic_info(os); + if( da_ ) + { + char const * prefix = "\nDiagnostic details:"; + da_->print(os, error(), prefix); + } + } + template friend std::ostream & operator<<( std::basic_ostream & os, diagnostic_details const & x ) { - os << static_cast(x); - if( x.da_ ) - x.da_->print(os, x.error().value()); - return os; + x.print_diagnostic_details(os); + return os << '\n'; } }; @@ -203,10 +227,18 @@ class diagnostic_details: public diagnostic_info { } + template + void print_diagnostic_details( std::basic_ostream & os ) const + { + print_diagnostic_info(os); + os << "\nboost::leaf::diagnostic_details N/A due to BOOST_LEAF_CFG_CAPTURE=0"; + } + template friend std::ostream & operator<<( std::basic_ostream & os, diagnostic_details const & x ) { - return os << "diagnostic_details not available due to BOOST_LEAF_CFG_CAPTURE=0. Basic diagnostic_info follows.\n" << static_cast(x); + x.print_diagnostic_details(os); + return os << "\n"; } }; @@ -247,10 +279,18 @@ class diagnostic_details: public diagnostic_info { } + template + void print_diagnostic_details( std::basic_ostream & os ) const + { + print_error_info(os); + os << "\nboost::leaf::diagnostic_details N/A due to BOOST_LEAF_CFG_DIAGNOSTICS=0"; + } + template friend std::ostream & operator<<( std::basic_ostream & os, diagnostic_details const & x ) { - return os << "diagnostic_details not available due to BOOST_LEAF_CFG_DIAGNOSTICS=0. Basic error_info follows.\n" << static_cast(x); + x.print_diagnostic_details(os); + return os << "\n"; } }; diff --git a/include/boost/leaf/error.hpp b/include/boost/leaf/error.hpp index 4598ec10..dd78c966 100644 --- a/include/boost/leaf/error.hpp +++ b/include/boost/leaf/error.hpp @@ -10,7 +10,6 @@ #include #include #include -#include #if BOOST_LEAF_CFG_DIAGNOSTICS # include @@ -68,6 +67,8 @@ namespace boost { namespace leaf { +class BOOST_LEAF_SYMBOL_VISIBLE error_id; + struct BOOST_LEAF_SYMBOL_VISIBLE e_source_location { char const * file; @@ -77,13 +78,28 @@ struct BOOST_LEAF_SYMBOL_VISIBLE e_source_location template friend std::ostream & operator<<( std::basic_ostream & os, e_source_location const & x ) { - return os << leaf::parse_name() << ": " << x.file << '(' << x.line << ") in function " << x.function; + return os << x.file << '(' << x.line << ") in function " << x.function; } }; //////////////////////////////////////// -class BOOST_LEAF_SYMBOL_VISIBLE error_id; +namespace leaf_detail +{ + class BOOST_LEAF_SYMBOL_VISIBLE exception_base + { + public: + virtual error_id get_error_id() const noexcept = 0; +#if BOOST_LEAF_CFG_DIAGNOSTICS && !defined(BOOST_LEAF_NO_EXCEPTIONS) + virtual void print_type_name(std::ostream &) const = 0; +#endif + protected: + exception_base() noexcept { } + ~exception_base() noexcept { } + }; +} + +//////////////////////////////////////// namespace leaf_detail { @@ -129,22 +145,16 @@ namespace leaf_detail void unload( int err_id ) noexcept(!BOOST_LEAF_CFG_CAPTURE); - template - void print( std::basic_ostream & os, int err_id_to_print ) const + template + void print(std::basic_ostream & os, ErrorID to_print, char const * & prefix) const { - if( !diagnostic::is_invisible ) - if( int k = this->key() ) - { - if( err_id_to_print ) - { - if( err_id_to_print!=k ) - return; - } - else - os << '[' << k << "] "; - diagnostic::print(os, value(k)); - os << '\n'; - } + if( int k = this->key() ) + { + if( to_print && to_print.value() != k ) + return; + if( diagnostic::print(os, prefix, "\n\t", value(k)) && !to_print ) + os << '(' << k/4 << ')'; + } } using impl::load; @@ -201,9 +211,9 @@ namespace leaf_detail } #if BOOST_LEAF_CFG_DIAGNOSTICS - void print( std::ostream & os, int err_id_to_print ) const final override + void print(std::ostream & os, error_id const & to_print, char const * & prefix) const final override { - impl::print(os, err_id_to_print); + impl::print(os, to_print, prefix); } #endif @@ -237,7 +247,7 @@ namespace leaf_detail } #if BOOST_LEAF_CFG_DIAGNOSTICS - void print( std::ostream &, int err_id_to_print ) const final override + void print(std::ostream &, error_id const &, char const * &) const final override { } #endif @@ -315,17 +325,6 @@ namespace leaf_detail using capture_list::print; }; - template <> - struct diagnostic - { - static constexpr bool is_invisible = true; - - template - BOOST_LEAF_CONSTEXPR static void print( std::basic_ostream &, dynamic_allocator const & ) - { - } - }; - template <> inline void slot::deactivate() const noexcept { @@ -409,6 +408,11 @@ namespace leaf_detail } } +template <> +struct show_in_diagnostics: std::false_type +{ +}; + #endif //////////////////////////////////////// @@ -551,7 +555,7 @@ namespace leaf_detail }; template - atomic_unsigned_int id_factory::counter(unsigned(-3)); + atomic_unsigned_int id_factory::counter(1); inline int current_id() noexcept { @@ -569,9 +573,9 @@ namespace leaf_detail struct inject_loc { - char const * const file; - int const line; - char const * const fn; + char const * file; + int line; + char const * fn; template friend T operator+( inject_loc loc, T && x ) noexcept @@ -737,7 +741,7 @@ class BOOST_LEAF_SYMBOL_VISIBLE error_id template friend std::ostream & operator<<( std::basic_ostream & os, error_id x ) { - return os << x.value_; + return os << (x.value_ / 4); } BOOST_LEAF_CONSTEXPR void load_source_location_( char const * file, int line, char const * function ) const noexcept diff --git a/include/boost/leaf/exception.hpp b/include/boost/leaf/exception.hpp index 5d2e6718..28c4524a 100644 --- a/include/boost/leaf/exception.hpp +++ b/include/boost/leaf/exception.hpp @@ -26,18 +26,6 @@ namespace leaf_detail { ::boost::throw_exception(std::move(e)); } - - class BOOST_LEAF_SYMBOL_VISIBLE exception_base - { - public: - - virtual error_id get_error_id() const noexcept = 0; - - protected: - - exception_base() noexcept { } - ~exception_base() noexcept { } - }; } } } @@ -56,22 +44,17 @@ namespace leaf_detail throw std::move(e); } - class BOOST_LEAF_SYMBOL_VISIBLE exception_base + class exception_id_bump { std::shared_ptr auto_id_bump_; - - public: - - virtual error_id get_error_id() const noexcept = 0; - protected: - exception_base(): + exception_id_bump(): auto_id_bump_(nullptr, [](void const *) { (void) new_id(); }) { } - ~exception_base() noexcept { } + ~exception_id_bump() noexcept { } }; } @@ -113,12 +96,22 @@ namespace leaf_detail public Ex, public exception_base, public error_id +#ifndef BOOST_LEAF_NO_EXCEPTIONS + ,exception_id_bump +#endif { error_id get_error_id() const noexcept final override { return *this; } +#if BOOST_LEAF_CFG_DIAGNOSTICS && !defined(BOOST_LEAF_NO_EXCEPTIONS) + void print_type_name(std::ostream & os) const final override + { + leaf_detail::demangle_and_print(os, typeid(Ex).name()); + } +#endif + public: exception( exception const & ) = default; diff --git a/include/boost/leaf/handle_errors.hpp b/include/boost/leaf/handle_errors.hpp index 91113638..ee778f10 100644 --- a/include/boost/leaf/handle_errors.hpp +++ b/include/boost/leaf/handle_errors.hpp @@ -70,17 +70,28 @@ class BOOST_LEAF_SYMBOL_VISIBLE error_info } template - friend std::ostream & operator<<(std::basic_ostream & os, error_info const & x) + void print_error_info(std::basic_ostream & os) const { - os << "Error ID: " << x.err_id_.value(); + os << "Error serial #" << err_id_; #ifndef BOOST_LEAF_NO_EXCEPTIONS - if( x.ex_ ) + if( ex_ ) { - os << "\nException dynamic type: "; - leaf_detail::demangle_and_print(os, typeid(*x.ex_).name()) << "\n" - "std::exception::what(): " << x.ex_->what(); + os << "\nCaught C++ exception:\n\tType: "; +#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(); } #endif + } + + template + friend std::ostream & operator<<(std::basic_ostream & os, error_info const & x) + { + x.print_error_info(os); return os << '\n'; } }; @@ -117,7 +128,7 @@ namespace leaf_detail constexpr static int value = 1 + type_index::value; }; - template + template struct tuple_type_index; template diff --git a/include/boost/leaf/on_error.hpp b/include/boost/leaf/on_error.hpp index 0218bb6d..c1668e65 100644 --- a/include/boost/leaf/on_error.hpp +++ b/include/boost/leaf/on_error.hpp @@ -71,21 +71,21 @@ class error_monitor namespace leaf_detail { - template + template struct tuple_for_each_preload { - BOOST_LEAF_CONSTEXPR static void trigger( Tuple & tup, int err_id ) noexcept + BOOST_LEAF_CONSTEXPR static void trigger( Tup & tup, int err_id ) noexcept { BOOST_LEAF_ASSERT((err_id&3)==1); - tuple_for_each_preload::trigger(tup,err_id); + tuple_for_each_preload::trigger(tup,err_id); std::get(tup).trigger(err_id); } }; - template - struct tuple_for_each_preload<0, Tuple> + template + struct tuple_for_each_preload<0, Tup> { - BOOST_LEAF_CONSTEXPR static void trigger( Tuple const &, int ) noexcept { } + BOOST_LEAF_CONSTEXPR static void trigger( Tup const &, int ) noexcept { } }; template diff --git a/include/boost/leaf/result.hpp b/include/boost/leaf/result.hpp index 3aafbf93..bc302ebe 100644 --- a/include/boost/leaf/result.hpp +++ b/include/boost/leaf/result.hpp @@ -339,6 +339,25 @@ class BOOST_LEAF_SYMBOL_VISIBLE BOOST_LEAF_ATTRIBUTE_NODISCARD result what_ = move_from(std::move(x)); } + template + void print_error_result(std::basic_ostream & os) const + { + result_discriminant const what = what_; + BOOST_LEAF_ASSERT(what.kind() != result_discriminant::val); + error_id const err_id = what.get_error_id(); + os << "Error serial #" << err_id; + if( what.kind() == result_discriminant::err_id_capture_list ) + { +#if BOOST_LEAF_CFG_CAPTURE + char const * prefix = "\nCaptured:"; + cap_.print(os, err_id, prefix); + os << "\n"; +#else + BOOST_LEAF_ASSERT(0); // Possible ODR violation. +#endif + } + } + public: using value_type = T; @@ -584,31 +603,13 @@ class BOOST_LEAF_SYMBOL_VISIBLE BOOST_LEAF_ATTRIBUTE_NODISCARD result #endif } - template - void print( std::basic_ostream & os ) const - { - result_discriminant const what = what_; - if( what.kind() == result_discriminant::val ) - leaf_detail::print_result_value(os, value()); - else - { - error_id const err_id = what.get_error_id(); - os << "Error ID " << err_id; - if( what.kind() == result_discriminant::err_id_capture_list ) - { -#if BOOST_LEAF_CFG_CAPTURE - cap_.print(os, err_id.value(), ". Captured error objects:\n"); -#else - BOOST_LEAF_ASSERT(0); // Possible ODR violation. -#endif - } - } - } - template friend std::ostream & operator<<( std::basic_ostream & os, result const & r ) { - r.print(os); + if( r.what_.kind() == result_discriminant::val ) + leaf_detail::print_result_value(os, r.value()); + else + r.print_error_result(os); return os; } }; @@ -704,18 +705,12 @@ class BOOST_LEAF_SYMBOL_VISIBLE BOOST_LEAF_ATTRIBUTE_NODISCARD result: } template - void print( std::basic_ostream & os ) const + friend std::ostream & operator<<( std::basic_ostream & os, result const & r ) { - if( what_.kind() == result_discriminant::val ) + if( r ) os << "No error"; else - os << *static_cast(this); - } - - template - friend std::ostream & operator<<( std::basic_ostream & os, result const & r ) - { - r.print(os); + r.print_error_result(os); return os; } diff --git a/meson.build b/meson.build index 6524f605..2e990e63 100644 --- a/meson.build +++ b/meson.build @@ -9,6 +9,7 @@ option_leaf_hpp = get_option('leaf_hpp') option_boost = get_option('leaf_boost_examples') option_lua = get_option('leaf_lua_examples') option_diagnostics = get_option('leaf_diagnostics') +option_capture = get_option('leaf_capture') option_exceptions = (get_option('cpp_eh')!='none') option_enable_unit_tests = get_option('leaf_enable_unit_tests') option_enable_examples = get_option('leaf_enable_examples') @@ -93,7 +94,10 @@ if option_lua dep_lua = subproject('lua').get_variable('all') endif -defines = [ '-DBOOST_LEAF_CFG_DIAGNOSTICS=' + option_diagnostics.to_string() ] +defines = [ + '-DBOOST_LEAF_CFG_DIAGNOSTICS=' + option_diagnostics.to_string(), + '-DBOOST_LEAF_CFG_CAPTURE=' + option_capture.to_string() +] if option_embedded defines += '-DBOOST_LEAF_EMBEDDED' diff --git a/meson_options.txt b/meson_options.txt index 66ddd1a8..de865fa5 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -2,6 +2,7 @@ option('leaf_hpp',type:'boolean',value:false,description:'Unit tests #include #endif +#include + #include "lightweight_test.hpp" namespace leaf = boost::leaf; -enum class enum_class_payload +enum class enum_class { - value + enum0, + enum1 }; template @@ -37,108 +40,156 @@ struct my_exception: { char const * what() const noexcept { - return "my_exception"; + return "my_exception what"; } }; -struct printable_payload +struct printable_value { - friend std::ostream & operator<<( std::ostream & os, printable_payload const & ) + friend std::ostream & operator<<( std::ostream & os, printable_value const & ) { - return os << "printed printable_payload"; + return os << "printed printable_value"; } }; -struct non_printable_payload +struct non_printable_value { }; -struct printable_info_printable_payload +struct printable_info_printable_value { - printable_payload value; + printable_value value; - friend std::ostream & operator<<( std::ostream & os, printable_info_printable_payload const & x ) + friend std::ostream & operator<<( std::ostream & os, printable_info_printable_value const & x ) { - return os << "*** printable_info_printable_payload " << x.value << " ***"; + return os << x.value; } }; -struct printable_info_non_printable_payload +struct printable_info_non_printable_value { - non_printable_payload value; + non_printable_value value; - friend std::ostream & operator<<( std::ostream & os, printable_info_non_printable_payload const & ) + friend std::ostream & operator<<( std::ostream & os, printable_info_non_printable_value const & ) { - return os << "*** printable_info_non_printable_payload ***"; + return os << "*** printable_info non_printable_value ***"; } }; -class non_printable_info_printable_payload +class non_printable_info_printable_value { public: - printable_payload value; + printable_value value; }; -struct non_printable_info_non_printable_payload +struct non_printable_info_non_printable_value { - non_printable_payload value; + non_printable_value value; }; -struct hidden_printable_info_printable_payload +struct hidden_printable_info_printable_value { - printable_payload value; + printable_value value; - friend std::ostream & operator<<( std::ostream & os, hidden_printable_info_printable_payload const & x ) + friend std::ostream & operator<<( std::ostream & os, hidden_printable_info_printable_value const & x ) { - return os << "*** hidden_printable_info_printable_payload " << x.value << " ***"; + return os << x.value << " ***"; } }; -struct hidden_non_printable_info_printable_payload +struct hidden_non_printable_info_printable_value { - printable_payload value; + printable_value value; }; namespace boost { namespace leaf { -template <> struct show_in_diagnostics: std::false_type { }; -template <> struct show_in_diagnostics: std::false_type { }; +template <> struct show_in_diagnostics: std::false_type { }; +template <> struct show_in_diagnostics: std::false_type { }; } } +#if BOOST_LEAF_CFG_STD_STRING +namespace +{ + void remove_value(std::string & s, std::string const & name) + { + auto s1 = s.find(name); + if( s1 == s.npos ) + return; + auto s2 = s.find("\n\t", s1 + name.size()); + if( s1 == s.npos ) + return; + s.replace(s1 + name.size(), s2 - s1 - name.size(), ""); + } + + 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: "); + } + + bool cmp(std::string a, std::string const & b) noexcept + { + remove_variance(a); + auto i = a.begin(); + auto j = b.begin(); + for( auto e = i + std::min(a.size(), b.size()); i != e; ++i, ++j ) + if( *i != *j ) + { + std::cout << + "a =\n----\n" << a << "----\n\n" + "b =\n----\n" << b << "----\n\n" + "Difference immediately after:\n" << std::string(a.begin(), i) << '\n'; + return false; + } + return i == a.end() && j == b.end(); + } +} +#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" + int main() { + std::cout << __LINE__ << " ---- result / error_info\n"; leaf::try_handle_all( []() -> leaf::result { return BOOST_LEAF_NEW_ERROR( - printable_info_printable_payload(), - printable_info_non_printable_payload(), - non_printable_info_printable_payload(), - non_printable_info_non_printable_payload(), - hidden_printable_info_printable_payload(), - hidden_non_printable_info_printable_payload(), - enum_class_payload{}, + 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} ); }, []( leaf::e_source_location, - printable_info_printable_payload, - printable_info_non_printable_payload, - non_printable_info_printable_payload, - non_printable_info_non_printable_payload, - hidden_printable_info_printable_payload, - hidden_non_printable_info_printable_payload, - enum_class_payload, + 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_STRINfG +#if BOOST_LEAF_CFG_STD_STRING std::ostringstream st; st << unmatched; std::string s = st.str(); std::cout << s << std::endl; - BOOST_TEST_NE(s.find("Error ID: "), s.npos); + BOOST_TEST(cmp(s, + "Error serial #1\n" + )); + #endif }, []() @@ -146,29 +197,29 @@ int main() BOOST_ERROR("Bad error dispatch"); } ); - std::cout << __LINE__ << " ---- diagnostic_info\n"; + std::cout << __LINE__ << " ---- result / diagnostic_info\n"; leaf::try_handle_all( []() -> leaf::result { return BOOST_LEAF_NEW_ERROR( - printable_info_printable_payload(), - printable_info_non_printable_payload(), - non_printable_info_printable_payload(), - non_printable_info_non_printable_payload(), - hidden_printable_info_printable_payload(), - hidden_non_printable_info_printable_payload(), - enum_class_payload{}, + 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} ); }, []( leaf::e_source_location, - printable_info_printable_payload, - printable_info_non_printable_payload, - non_printable_info_printable_payload, - non_printable_info_non_printable_payload, - hidden_printable_info_printable_payload, - hidden_non_printable_info_printable_payload, - enum_class_payload, + 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::diagnostic_info const & unmatched ) { @@ -177,23 +228,23 @@ int main() st << unmatched; std::string s = st.str(); std::cout << s << std::endl; - BOOST_TEST_NE(s.find("Error ID: "), s.npos); if( BOOST_LEAF_CFG_DIAGNOSTICS ) - { - BOOST_TEST_NE(s.find("e_source_location"), s.npos); - BOOST_TEST_NE(s.find("*** printable_info_printable_payload printed printable_payload ***"), s.npos); - BOOST_TEST_NE(s.find("*** printable_info_non_printable_payload ***"), s.npos); - BOOST_TEST_NE(s.find(": printed printable_payload"), s.npos); - BOOST_TEST_NE(s.find(": {not printable}"), s.npos); - std::size_t hidden1 = s.find(": {hidden by show_in_diagnostics}"); - std::size_t hidden2 = s.find(": {hidden by show_in_diagnostics}", hidden1 + 1); - BOOST_TEST_NE(hidden1, s.npos); - BOOST_TEST_NE(hidden2, s.npos); - BOOST_TEST_NE(hidden1, hidden2); - BOOST_TEST_NE(s.find("enum_class_payload"), s.npos); - } + 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" + )); else - BOOST_TEST_NE(s.find("diagnostic_info not available due to BOOST_LEAF_CFG_DIAGNOSTICS=0"), s.npos); + BOOST_TEST(cmp(s, + "Error serial #2" + BOOST_LEAF_DIAGNOSTIC_INFO_NO_BOOST_LEAF_CFG_DIAGNOSTICS + )); #endif }, []() @@ -201,31 +252,31 @@ int main() BOOST_ERROR("Bad error dispatch"); } ); - std::cout << __LINE__ << " ---- diagnostic_details\n"; + std::cout << __LINE__ << " ---- result / diagnostic_details\n"; leaf::try_handle_all( []() -> leaf::result { return BOOST_LEAF_NEW_ERROR( - printable_info_printable_payload(), - printable_info_non_printable_payload(), - non_printable_info_printable_payload(), - non_printable_info_non_printable_payload(), - hidden_printable_info_printable_payload(), - hidden_non_printable_info_printable_payload(), + 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(), unexpected_test<1>{1}, unexpected_test<2>{2}, - enum_class_payload{}, + enum_class::enum0, leaf::e_errno{ENOENT} ); }, []( leaf::e_source_location, - printable_info_printable_payload, - printable_info_non_printable_payload, - non_printable_info_printable_payload, - non_printable_info_non_printable_payload, - hidden_printable_info_printable_payload, - hidden_non_printable_info_printable_payload, - enum_class_payload, + 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::diagnostic_details const & di ) { @@ -234,33 +285,95 @@ int main() st << di; std::string s = st.str(); std::cout << s << std::endl; - BOOST_TEST_NE(s.find("Error ID: "), s.npos); if( BOOST_LEAF_CFG_DIAGNOSTICS ) - { - BOOST_TEST_NE(s.find("e_source_location"), s.npos); - BOOST_TEST_NE(s.find("*** printable_info_printable_payload printed printable_payload ***"), s.npos); - BOOST_TEST_NE(s.find("*** printable_info_non_printable_payload ***"), s.npos); - BOOST_TEST_NE(s.find(": printed printable_payload"), s.npos); - BOOST_TEST_NE(s.find(": {not printable}"), s.npos); - std::size_t hidden1 = s.find(": {hidden by show_in_diagnostics}"); - std::size_t hidden2 = s.find(": {hidden by show_in_diagnostics}", hidden1 + 1); - BOOST_TEST_NE(hidden1, s.npos); - BOOST_TEST_NE(hidden2, s.npos); - BOOST_TEST_NE(hidden1, hidden2); - BOOST_TEST_NE(s.find("enum_class"), s.npos); - BOOST_TEST_EQ(s.find("dynamic_allocator"), s.npos); if( BOOST_LEAF_CFG_CAPTURE ) - { - BOOST_TEST_NE(s.find("unexpected_test<1>"), s.npos); - BOOST_TEST_NE(s.find("unexpected_test<2>"), s.npos); - BOOST_TEST_NE(s.find(": 1"), s.npos); - BOOST_TEST_NE(s.find(": 2"), s.npos); - } + 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" + )); else - BOOST_TEST_NE(s.find("diagnostic_details not available due to BOOST_LEAF_CFG_CAPTURE=0"), s.npos); - } + 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\"" + BOOST_LEAF_DIAGNOSTIC_DETAILS_NO_BOOST_LEAF_CFG_CAPTURE + )); + else + BOOST_TEST(cmp(s, + "Error serial #3" + BOOST_LEAF_DIAGNOSTIC_DETAILS_NO_BOOST_LEAF_CFG_DIAGNOSTICS + )); +#endif + }, + []() + { + BOOST_ERROR("Bad error dispatch"); + } ); + + std::cout << __LINE__ << " ---- result / diagnostic_details / nothing caught\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(), + unexpected_test<1>{1}, + unexpected_test<2>{2}, + enum_class::enum0, + leaf::e_errno{ENOENT} ); + }, + []( leaf::diagnostic_details const & di ) + { +#if BOOST_LEAF_CFG_STD_STRING + std::ostringstream st; + st << di; + std::string s = st.str(); + std::cout << s << std::endl; + 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: " + )); + else + BOOST_TEST(cmp(s, + "Error serial #4" + BOOST_LEAF_DIAGNOSTIC_DETAILS_NO_BOOST_LEAF_CFG_CAPTURE + )); else - BOOST_TEST_NE(s.find("diagnostic_details not available due to BOOST_LEAF_CFG_DIAGNOSTICS=0"), s.npos); + BOOST_TEST(cmp(s, + "Error serial #4" + BOOST_LEAF_DIAGNOSTIC_DETAILS_NO_BOOST_LEAF_CFG_DIAGNOSTICS + )); #endif }, []() @@ -272,29 +385,29 @@ int main() #ifndef BOOST_LEAF_NO_EXCEPTIONS - std::cout << __LINE__ << " ---- error_info\n"; + std::cout << __LINE__ << " ---- exception / error_info\n"; leaf::try_catch( [] { BOOST_LEAF_THROW_EXCEPTION( my_exception(), - printable_info_printable_payload(), - printable_info_non_printable_payload(), - non_printable_info_printable_payload(), - non_printable_info_non_printable_payload(), - hidden_printable_info_printable_payload(), - hidden_non_printable_info_printable_payload(), - enum_class_payload{}, + 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} ); }, []( leaf::e_source_location, - printable_info_printable_payload, - printable_info_non_printable_payload, - non_printable_info_printable_payload, - non_printable_info_non_printable_payload, - hidden_printable_info_printable_payload, - hidden_non_printable_info_printable_payload, - enum_class_payload, + 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 ) { @@ -303,37 +416,38 @@ int main() st << unmatched; std::string s = st.str(); std::cout << s << std::endl; - if( BOOST_LEAF_CFG_DIAGNOSTICS ) - { - BOOST_TEST_NE(s.find("Exception dynamic type: "), s.npos); - BOOST_TEST_NE(s.find("std::exception::what(): my_exception"), s.npos); - } + BOOST_TEST(cmp(s, + "Error serial #5\n" + "Caught C++ exception:" + "\n\tType: " + "\n\tstd::exception::what(): my_exception what\n" + )); #endif } ); - std::cout << __LINE__ << " ---- diagnostic_info\n"; + std::cout << __LINE__ << " ---- exception / diagnostic_info\n"; leaf::try_catch( [] { BOOST_LEAF_THROW_EXCEPTION( my_exception(), - printable_info_printable_payload(), - printable_info_non_printable_payload(), - non_printable_info_printable_payload(), - non_printable_info_non_printable_payload(), - hidden_printable_info_printable_payload(), - hidden_non_printable_info_printable_payload(), - enum_class_payload{}, + 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} ); }, []( leaf::e_source_location, - printable_info_printable_payload, - printable_info_non_printable_payload, - non_printable_info_printable_payload, - non_printable_info_non_printable_payload, - hidden_printable_info_printable_payload, - hidden_non_printable_info_printable_payload, - enum_class_payload, + 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::diagnostic_info const & unmatched ) { @@ -342,53 +456,56 @@ int main() st << unmatched; std::string s = st.str(); std::cout << s << std::endl; - BOOST_TEST_NE(s.find("Error ID: "), s.npos); - BOOST_TEST_NE(s.find("Exception dynamic type: "), s.npos); - BOOST_TEST_NE(s.find("std::exception::what(): my_exception"), s.npos); if( BOOST_LEAF_CFG_DIAGNOSTICS ) - { - BOOST_TEST_NE(s.find("e_source_location"), s.npos); - BOOST_TEST_NE(s.find("*** printable_info_printable_payload printed printable_payload ***"), s.npos); - BOOST_TEST_NE(s.find("*** printable_info_non_printable_payload ***"), s.npos); - BOOST_TEST_NE(s.find(": printed printable_payload"), s.npos); - BOOST_TEST_NE(s.find(": {not printable}"), s.npos); - std::size_t hidden1 = s.find(": {hidden by show_in_diagnostics}"); - std::size_t hidden2 = s.find(": {hidden by show_in_diagnostics}", hidden1 + 1); - BOOST_TEST_NE(hidden1, s.npos); - BOOST_TEST_NE(hidden2, s.npos); - BOOST_TEST_NE(hidden1, hidden2); - BOOST_TEST_NE(s.find("enum_class_payload"), s.npos); - } + 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: 0" + "\n\tboost::leaf::e_errno: 2, \"No such file or directory\"\n" + )); else - BOOST_TEST_NE(s.find("diagnostic_info not available"), s.npos); + BOOST_TEST(cmp(s, + "Error serial #7\n" + "Caught C++ exception:" + "\n\tType: " + "\n\tstd::exception::what(): my_exception what" + BOOST_LEAF_DIAGNOSTIC_INFO_NO_BOOST_LEAF_CFG_DIAGNOSTICS + )); #endif } ); - std::cout << __LINE__ << " ---- diagnostic_details\n"; + std::cout << __LINE__ << " ---- exception / diagnostic_details\n"; leaf::try_catch( [] { BOOST_LEAF_THROW_EXCEPTION( my_exception(), - printable_info_printable_payload(), - printable_info_non_printable_payload(), - non_printable_info_printable_payload(), - non_printable_info_non_printable_payload(), - hidden_printable_info_printable_payload(), - hidden_non_printable_info_printable_payload(), - enum_class_payload{}, + 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, unexpected_test<1>{1}, unexpected_test<2>{2}, leaf::e_errno{ENOENT} ); }, []( leaf::e_source_location, - printable_info_printable_payload, - printable_info_non_printable_payload, - non_printable_info_printable_payload, - non_printable_info_non_printable_payload, - hidden_printable_info_printable_payload, - hidden_non_printable_info_printable_payload, - enum_class_payload, + 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::diagnostic_details const & di ) { @@ -397,35 +514,107 @@ int main() st << di; std::string s = st.str(); std::cout << s << std::endl; - BOOST_TEST_NE(s.find("Error ID: "), s.npos); - BOOST_TEST_NE(s.find("Exception dynamic type: "), s.npos); - BOOST_TEST_NE(s.find("std::exception::what(): my_exception"), s.npos); if( BOOST_LEAF_CFG_DIAGNOSTICS ) - { - BOOST_TEST_NE(s.find("e_source_location"), s.npos); - BOOST_TEST_NE(s.find("*** printable_info_printable_payload printed printable_payload ***"), s.npos); - BOOST_TEST_NE(s.find("*** printable_info_non_printable_payload ***"), s.npos); - BOOST_TEST_NE(s.find(": printed printable_payload"), s.npos); - BOOST_TEST_NE(s.find(": {not printable}"), s.npos); - std::size_t hidden1 = s.find(": {hidden by show_in_diagnostics}"); - std::size_t hidden2 = s.find(": {hidden by show_in_diagnostics}", hidden1 + 1); - BOOST_TEST_NE(hidden1, s.npos); - BOOST_TEST_NE(hidden2, s.npos); - BOOST_TEST_NE(hidden1, hidden2); - BOOST_TEST_NE(s.find("enum_class_payload"), s.npos); - BOOST_TEST_EQ(s.find("dynamic_allocator"), s.npos); if( BOOST_LEAF_CFG_CAPTURE ) - { - BOOST_TEST_NE(s.find("unexpected_test<1>"), s.npos); - BOOST_TEST_NE(s.find("unexpected_test<2>"), s.npos); - BOOST_TEST_NE(s.find(": 1"), s.npos); - BOOST_TEST_NE(s.find(": 2"), s.npos); - } + BOOST_TEST(cmp(s, + "Error serial #9\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" + )); else - BOOST_TEST_NE(s.find("diagnostic_details not available due to BOOST_LEAF_CFG_CAPTURE=0"), s.npos); - } + BOOST_TEST(cmp(s, + "Error serial #9\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\"" + BOOST_LEAF_DIAGNOSTIC_DETAILS_NO_BOOST_LEAF_CFG_CAPTURE + )); + else + BOOST_TEST(cmp(s, + "Error serial #9\n" + "Caught C++ exception:" + "\n\tType: " + "\n\tstd::exception::what(): my_exception what" + BOOST_LEAF_DIAGNOSTIC_DETAILS_NO_BOOST_LEAF_CFG_DIAGNOSTICS + )); +#endif + } ); + + std::cout << __LINE__ << " ---- exception / diagnostic_details / nothing caught\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, + unexpected_test<1>{1}, + unexpected_test<2>{2}, + leaf::e_errno{ENOENT} ); + }, + []( leaf::diagnostic_details const & di ) + { +#if BOOST_LEAF_CFG_STD_STRING + std::ostringstream st; + st << di; + std::string s = st.str(); + std::cout << s << std::endl; + if( BOOST_LEAF_CFG_DIAGNOSTICS ) + if( BOOST_LEAF_CFG_CAPTURE ) + BOOST_TEST(cmp(s, + "Error serial #11\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: " + )); + else + BOOST_TEST(cmp(s, + "Error serial #11\n" + "Caught C++ exception:" + "\n\tType: " + "\n\tstd::exception::what(): my_exception what" + BOOST_LEAF_DIAGNOSTIC_DETAILS_NO_BOOST_LEAF_CFG_CAPTURE + )); else - BOOST_TEST_NE(s.find("diagnostic_details not available due to BOOST_LEAF_CFG_DIAGNOSTICS=0"), s.npos); + BOOST_TEST(cmp(s, + "Error serial #11\n" + "Caught C++ exception:" + "\n\tType: " + "\n\tstd::exception::what(): my_exception what" + BOOST_LEAF_DIAGNOSTIC_DETAILS_NO_BOOST_LEAF_CFG_DIAGNOSTICS + )); #endif } ); diff --git a/test/error_id_test.cpp b/test/error_id_test.cpp index ce4e2609..2f704d4a 100644 --- a/test/error_id_test.cpp +++ b/test/error_id_test.cpp @@ -56,7 +56,7 @@ int main() BOOST_TEST(!e1); BOOST_TEST_EQ(e1.value(), 0); BOOST_TEST(e2); - BOOST_TEST_EQ(e2.value(), 1); + BOOST_TEST_EQ(e2.value(), 5); BOOST_TEST(!(e1==e2)); BOOST_TEST(e1!=e2); BOOST_TEST(e1 ) { - BOOST_TEST_EQ(err.error().value(), 1); + BOOST_TEST_EQ(err.error().value(), 5); return 1; }, []( info<2> ) @@ -97,7 +97,7 @@ int main() }, []( leaf::error_info const & err, info<2>, info<3> ) { - BOOST_TEST_EQ(err.error().value(), 9); + BOOST_TEST_EQ(err.error().value(), 13); return 2; }, []( info<1>, info<2> ) @@ -114,7 +114,7 @@ int main() }, []( leaf::error_info const & err, info<1> ) { - BOOST_TEST_EQ(err.error().value(), 17); + BOOST_TEST_EQ(err.error().value(), 21); return 1; }, []( info<2> ) @@ -139,7 +139,7 @@ int main() }, []( leaf::error_info const & err, info<2>, info<3> ) { - BOOST_TEST_EQ(err.error().value(), 21); + BOOST_TEST_EQ(err.error().value(), 25); return 2; }, []( info<1>, info<2> ) diff --git a/test/parse_name_test.cpp b/test/parse_name_test.cpp index 71447f45..0ec422da 100644 --- a/test/parse_name_test.cpp +++ b/test/parse_name_test.cpp @@ -26,6 +26,10 @@ namespace leaf_test template struct struct_template2 { }; } +namespace boost { namespace leaf { + struct in_namespace_boost_leaf { }; +} } + class class_ { }; struct struct_ { }; enum enum_ { }; @@ -39,7 +43,7 @@ namespace template void test_name(std::string const & correct) { - leaf::parsed_name pn = leaf::parse_name(); + auto pn = leaf::leaf_detail::parse_name(); BOOST_TEST(pn.parse_success()); BOOST_TEST_EQ(std::string(pn.name, pn.len), correct); } @@ -47,6 +51,8 @@ namespace int main() { + test_name("boost::leaf::in_namespace_boost_leaf"); + test_name("leaf_test::class_"); test_name("leaf_test::struct_"); test_name("leaf_test::enum_"); diff --git a/test/print_test.cpp b/test/print_test.cpp index 07cdaba4..342ce75f 100644 --- a/test/print_test.cpp +++ b/test/print_test.cpp @@ -34,7 +34,7 @@ struct c0 { friend std::ostream & operator<<( std::ostream & os, c0 const & ) { - return os << "c0"; + return os << "info"; } }; @@ -42,9 +42,9 @@ struct c1 { int value; - friend std::ostream & operator<<( std::ostream & os, c1 const & ) + friend std::ostream & operator<<( std::ostream & os, c1 const & x ) { - return os << "c1"; + return os << "value " << x.value; } }; @@ -53,9 +53,9 @@ struct c2 int value; }; -std::ostream & operator<<( std::ostream & os, c2 const & ) +std::ostream & operator<<( std::ostream & os, c2 const & x ) { - return os << "c2"; + return os << "value " << x.value; } struct c3 @@ -70,59 +70,58 @@ struct c4 }; template -bool check( T const & x, char const * sub ) +std::string print(T const & x, char const * prefix, char const * delimiter) { using namespace leaf::leaf_detail; std::ostringstream s; - diagnostic::print(s,x); + diagnostic::print(s, prefix, delimiter, x); std::string q = s.str(); - std::cout << "LINE " << Line << ": " << q << std::endl; - return q.find(sub)!=q.npos; + std::cout << "[LINE " << Line << "] " << q << '\n'; + return q; } struct my_exception: std::exception { - char const * what() const noexcept override { return "my_exception_what"; } + char const * what() const noexcept override { return "my_exception what"; } }; int main() { - BOOST_TEST(check<__LINE__>(c0{ },"c0")); - BOOST_TEST(check<__LINE__>(c1{42},"c1")); { - c1 x; - c1 & y = x; - BOOST_TEST(check<__LINE__>(x,"c1")); - BOOST_TEST(check<__LINE__>(y,"c1")); + 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); } - BOOST_TEST(check<__LINE__>(c2{42},"c2")); { - c2 x = {42}; - c2 & y = x; - BOOST_TEST(check<__LINE__>(x,"c2")); - BOOST_TEST(check<__LINE__>(y,"c2")); + 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); } - BOOST_TEST(check<__LINE__>(c3{42},"c3")); - BOOST_TEST(check<__LINE__>(c3{42},"42")); { - c3 x = {42}; - c3 & y = x; - BOOST_TEST(check<__LINE__>(x,"c3")); - BOOST_TEST(check<__LINE__>(x,"42")); - BOOST_TEST(check<__LINE__>(y,"c3")); - BOOST_TEST(check<__LINE__>(y,"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); } - BOOST_TEST(check<__LINE__>(c4(),"c4")); - BOOST_TEST(check<__LINE__>(c4(),"{not printable}")); { - c4 x; - c4 & y = x; - BOOST_TEST(check<__LINE__>(x,"c4")); - BOOST_TEST(check<__LINE__>(x,"{not printable}")); - BOOST_TEST(check<__LINE__>(y,"c4")); - BOOST_TEST(check<__LINE__>(y,"{not printable}")); + 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__>(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__>(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); } - BOOST_TEST(check<__LINE__>(my_exception{}, "std::exception::what(): my_exception_what")); return boost::report_errors(); } diff --git a/test/result_print_test.cpp b/test/result_print_test.cpp index 789bd5a8..3ce3313d 100644 --- a/test/result_print_test.cpp +++ b/test/result_print_test.cpp @@ -83,7 +83,7 @@ int main() std::cout << s << std::endl; leaf::error_id err = r.error(); if( BOOST_LEAF_CFG_DIAGNOSTICS ) - BOOST_TEST_EQ(s, "Error ID " + std::to_string(err.value())); + BOOST_TEST_EQ(s, "Error serial #" + std::to_string(err.value()/4)); #endif } @@ -100,11 +100,11 @@ int main() std::string s = ss.str(); std::cout << s << std::endl; leaf::error_id err = r.error(); - BOOST_TEST_NE(s.find("Error ID " + std::to_string(err.value())), s.npos); + BOOST_TEST_NE(s.find("Error serial #" + std::to_string(err.value()/4)), s.npos); if( BOOST_LEAF_CFG_DIAGNOSTICS ) { - BOOST_TEST_NE(s.find("Captured error objects"), s.npos); - BOOST_TEST_NE(s.find("e_err"), s.npos); + BOOST_TEST_NE(s.find("Captured:"), s.npos); + BOOST_TEST_NE(s.find("e_err: e_err"), s.npos); } #endif } diff --git a/test/try_catch_error_id_test.cpp b/test/try_catch_error_id_test.cpp index fa83568c..d561ec98 100644 --- a/test/try_catch_error_id_test.cpp +++ b/test/try_catch_error_id_test.cpp @@ -42,7 +42,7 @@ int main() }, []( my_error const &, leaf::catch_ id ) { - BOOST_TEST(dynamic_cast(&id.matched)!=0 && dynamic_cast(&id.matched)->value()==1); + BOOST_TEST(dynamic_cast(&id.matched)!=0 && dynamic_cast(&id.matched)->value()==5); return 1; }, []