Skip to content

Commit

Permalink
Added all configurations to diagnostics_test1.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
zajo committed Sep 2, 2024
1 parent 42b85ca commit 5f10a8e
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 63 deletions.
6 changes: 3 additions & 3 deletions include/boost/leaf/diagnostics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class diagnostic_info: public error_info
template <class CharT, class Traits>
friend std::ostream & operator<<( std::basic_ostream<CharT, Traits> & os, diagnostic_info const & x )
{
return os << "diagnostic_info not available due to BOOST_LEAF_CFG_DIAGNOSTICS=0.\n" << static_cast<error_info const &>(x);
return os << static_cast<error_info const &>(x) << "boost::leaf::diagnostic_info N/A due to BOOST_LEAF_CFG_DIAGNOSTICS=0\n";
}
};

Expand Down Expand Up @@ -216,7 +216,7 @@ class diagnostic_details: public diagnostic_info
template <class CharT, class Traits>
friend std::ostream & operator<<( std::basic_ostream<CharT, Traits> & 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<diagnostic_info const &>(x);
return os << static_cast<diagnostic_info const &>(x) << "boost::leaf::diagnostic_details N/A due to BOOST_LEAF_CFG_CAPTURE=0\n";
}
};

Expand Down Expand Up @@ -260,7 +260,7 @@ class diagnostic_details: public diagnostic_info
template <class CharT, class Traits>
friend std::ostream & operator<<( std::basic_ostream<CharT, Traits> & 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<error_info const &>(x);
return os << "boost::leaf::diagnostic_details N/A due to BOOST_LEAF_CFG_DIAGNOSTICS=0\n";
}
};

Expand Down
4 changes: 3 additions & 1 deletion include/boost/leaf/handle_errors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,15 @@ class BOOST_LEAF_SYMBOL_VISIBLE error_info
void print(std::basic_ostream<CharT, Traits> & os) const
{
os << "Error serial #" << err_id_;
#if BOOST_LEAF_CFG_DIAGNOSTICS && !defined(BOOST_LEAF_NO_EXCEPTIONS)
#ifndef BOOST_LEAF_NO_EXCEPTIONS
if( ex_ )
{
os << "\nCaught C++ exception:\n\tType: ";
#if BOOST_LEAF_CFG_DIAGNOSTICS
if( auto eb = dynamic_cast<leaf_detail::exception_base const *>(ex_) )
eb->print_type_name(os);
else
#endif
leaf_detail::demangle_and_print(os, typeid(*ex_).name());
os << "\n\tstd::exception::what(): " << ex_->what();
}
Expand Down
210 changes: 151 additions & 59 deletions test/diagnostics_test1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,25 +112,29 @@ template <> struct show_in_diagnostics<hidden_non_printable_info_printable_value
#if BOOST_LEAF_CFG_STD_STRING
namespace
{
std::string remove_variance(std::string s)
void remove_value(std::string & s, std::string const & name)
{
s.erase(std::remove(s.begin(), s.end(), '\r'), s.end());
std::string loc = "boost::leaf::e_source_location: ";
auto s1 = s.find(loc);
auto s1 = s.find(name);
if( s1 == s.npos )
return s;
auto s2 = s.find("\n\t", s1);
return;
auto s2 = s.find("\n\t", s1 + name.size());
if( s1 == s.npos )
return s;
s.replace(s1 + loc.size(), s2 - s1 - loc.size(), "<removed variance>");
return s;
return;
s.replace(s1 + name.size(), s2 - s1 - name.size(), "<removed variance>");
}

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 b) noexcept
bool cmp(std::string a, std::string const & b) noexcept
{
a = remove_variance(a);
b = remove_variance(b);
auto i = a.begin(), j = b.begin();
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 )
{
Expand All @@ -142,6 +146,10 @@ namespace
}
#endif

#define BOOST_LEAF_DIAGNOSTIC_INFO_NO_BOOST_LEAF_CFG_CAPTURE "boost::leaf::diagnostic_info N/A due to BOOST_LEAF_CFG_DIAGNOSTICS=0\n"
#define BOOST_LEAF_DIAGNOSTIC_DETAILS_NO_BOOST_LEAF_CFG_CAPTURE "boost::leaf::diagnostic_details N/A due to BOOST_LEAF_CFG_CAPTURE=0\n"
#define BOOST_LEAF_DIAGNOSTIC_DETAILS_NO_BOOST_LEAF_CFG_DIAGNOSTICS "boost::leaf::diagnostic_details N/A due to BOOST_LEAF_CFG_DIAGNOSTICS=0\n"

int main()
{
std::cout << __LINE__ << " ---- result / error_info\n";
Expand Down Expand Up @@ -229,6 +237,11 @@ int main()
"\n\tenum_class: 1"
"\n\tboost::leaf::e_errno: 2, \"No such file or directory\"\n"
));
else
BOOST_TEST(cmp(s,
"Error serial #2\n"
BOOST_LEAF_DIAGNOSTIC_INFO_NO_BOOST_LEAF_CFG_CAPTURE
));
#endif
},
[]()
Expand Down Expand Up @@ -270,19 +283,38 @@ int main()
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 #3\n"
"Caught:"
"\n\tboost::leaf::e_source_location: <removed variance>"
"\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(cmp(s,
"Error serial #3\n"
"Caught:"
"\n\tboost::leaf::e_source_location: <removed variance>"
"\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"
BOOST_LEAF_DIAGNOSTIC_DETAILS_NO_BOOST_LEAF_CFG_CAPTURE
));
else
BOOST_TEST(cmp(s,
"Error serial #3\n"
"Caught:"
"\n\tboost::leaf::e_source_location: <removed variance>"
"\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"
BOOST_LEAF_DIAGNOSTIC_DETAILS_NO_BOOST_LEAF_CFG_DIAGNOSTICS
));
#endif
},
Expand Down Expand Up @@ -315,18 +347,29 @@ int main()
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: <removed variance>"
));
else
BOOST_TEST(cmp(s,
"Error serial #4\n"
BOOST_LEAF_DIAGNOSTIC_INFO_NO_BOOST_LEAF_CFG_CAPTURE
));
else
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: <removed variance>"
BOOST_LEAF_DIAGNOSTIC_DETAILS_NO_BOOST_LEAF_CFG_DIAGNOSTICS
));
#endif
},
Expand Down Expand Up @@ -373,7 +416,7 @@ int main()
BOOST_TEST(cmp(s,
"Error serial #5\n"
"Caught C++ exception:"
"\n\tType: my_exception"
"\n\tType: <removed variance>"
"\n\tstd::exception::what(): my_exception what\n"
));
#endif
Expand Down Expand Up @@ -414,7 +457,7 @@ int main()
BOOST_TEST(cmp(s,
"Error serial #7\n"
"Caught C++ exception:"
"\n\tType: my_exception"
"\n\tType: <removed variance>"
"\n\tstd::exception::what(): my_exception what"
"\n\tboost::leaf::e_source_location: <removed variance>"
"\n\tprintable_info_printable_value: printed printable_value"
Expand All @@ -424,6 +467,14 @@ int main()
"\n\tenum_class: 0"
"\n\tboost::leaf::e_errno: 2, \"No such file or directory\"\n"
));
else
BOOST_TEST(cmp(s,
"Error serial #7\n"
"Caught C++ exception:"
"\n\tType: <removed variance>"
"\n\tstd::exception::what(): my_exception what"
BOOST_LEAF_DIAGNOSTIC_INFO_NO_BOOST_LEAF_CFG_CAPTURE
));
#endif
} );

Expand Down Expand Up @@ -461,21 +512,45 @@ int main()
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 #9\n"
"Caught C++ exception:"
"\n\tType: <removed variance>"
"\n\tstd::exception::what(): my_exception what"
"\n\tboost::leaf::e_source_location: <removed variance>"
"\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(cmp(s,
"Error serial #9\n"
"Caught C++ exception:"
"\n\tType: <removed variance>"
"\n\tstd::exception::what(): my_exception what"
"\n\tboost::leaf::e_source_location: <removed variance>"
"\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"
BOOST_LEAF_DIAGNOSTIC_DETAILS_NO_BOOST_LEAF_CFG_CAPTURE
));
else
BOOST_TEST(cmp(s,
"Error serial #9\n"
"Caught C++ exception:"
"\n\tType: my_exception"
"\n\tType: <removed variance>"
"\n\tstd::exception::what(): my_exception what"
"\n\tboost::leaf::e_source_location: <removed variance>"
"\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"
BOOST_LEAF_DIAGNOSTIC_DETAILS_NO_BOOST_LEAF_CFG_DIAGNOSTICS
));
#endif
} );
Expand Down Expand Up @@ -504,21 +579,38 @@ int main()
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: <removed variance>"
"\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: <removed variance>"
));
else
BOOST_TEST(cmp(s,
"Error serial #11\n"
"Caught C++ exception:"
"\n\tType: <removed variance>"
"\n\tstd::exception::what(): my_exception what"
BOOST_LEAF_DIAGNOSTIC_DETAILS_NO_BOOST_LEAF_CFG_CAPTURE
));
else
BOOST_TEST(cmp(s,
"Error serial #11\n"
"Caught C++ exception:"
"\n\tType: my_exception"
"\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: <removed variance>"
"\n\tType: <removed variance>"
"\n\tstd::exception::what(): my_exception what"
BOOST_LEAF_DIAGNOSTIC_DETAILS_NO_BOOST_LEAF_CFG_DIAGNOSTICS
));
#endif
} );
Expand Down

0 comments on commit 5f10a8e

Please sign in to comment.