aboutsummaryrefslogtreecommitdiffstats
path: root/util/generic/yexception_ut.cpp
diff options
context:
space:
mode:
authorsvkrasnov <svkrasnov@yandex-team.ru>2022-02-18 00:11:31 +0300
committersvkrasnov <svkrasnov@yandex-team.ru>2022-02-18 00:11:31 +0300
commit5d9b03f7d5e4d38860ff05886839b0224222da3e (patch)
tree85920b5ab330a7d9dab3ad6bf5c75d54d08a8bd1 /util/generic/yexception_ut.cpp
parent59b572e5c9c4932e5d976212fc0ef905b1ec75b4 (diff)
downloadydb-5d9b03f7d5e4d38860ff05886839b0224222da3e.tar.gz
IGNIETFERRO-1975, BIGRT-39 [RESUBMIT]: add TBackTrace::FromCurrentException() to CurrentExceptionMessage()
ref:8d5b72512d2b80cfd1ae859a4175cc92cf32a99a
Diffstat (limited to 'util/generic/yexception_ut.cpp')
-rw-r--r--util/generic/yexception_ut.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/util/generic/yexception_ut.cpp b/util/generic/yexception_ut.cpp
index cb3e29fed84..771ae2a9ca2 100644
--- a/util/generic/yexception_ut.cpp
+++ b/util/generic/yexception_ut.cpp
@@ -15,6 +15,7 @@ static inline void Throw2DontMove() {
#include <util/random/mersenne.h>
#include <util/stream/output.h>
#include <util/string/subst.h>
+#include <util/string/split.h>
#include "yexception_ut.h"
#include "bt_exception.h"
@@ -48,6 +49,8 @@ class TExceptionTest: public TTestBase {
UNIT_TEST(TestBackTrace)
UNIT_TEST(TestEnsureWithBackTrace1)
UNIT_TEST(TestEnsureWithBackTrace2)
+ UNIT_TEST(TestCurrentExceptionMessageWithLIBUNWIND)
+ UNIT_TEST(TestCurrentExceptionMessageWithInvalidBacktraceFormatter)
UNIT_TEST(TestRethrowAppend)
UNIT_TEST(TestMacroOverload)
UNIT_TEST(TestMessageCrop)
@@ -128,6 +131,48 @@ private:
UNIT_ASSERT(false);
}
+ inline void TestCurrentExceptionMessageWithLIBUNWIND() {
+#ifdef _YNDX_LIBUNWIND_ENABLE_EXCEPTION_BACKTRACE
+ try {
+ throw std::logic_error("some exception"); // is instance of std::exception
+ UNIT_ASSERT(false);
+ } catch (...) {
+ TString exceptionMessage = CurrentExceptionMessage();
+ UNIT_ASSERT(exceptionMessage.Contains("(std::logic_error) some exception"));
+ TVector<TString> backtraceStrs = StringSplitter(exceptionMessage).Split('\n');
+ UNIT_ASSERT(backtraceStrs.size() > 1);
+ }
+#endif
+ }
+
+ inline void TestCurrentExceptionMessageWithInvalidBacktraceFormatter() {
+#ifdef _YNDX_LIBUNWIND_ENABLE_EXCEPTION_BACKTRACE
+ auto invalidFormatter = [](IOutputStream*, void* const*, size_t) {
+ Throw2DontMove();
+ };
+ SetFormatBackTraceFn(invalidFormatter);
+
+ try {
+ Throw1DontMove();
+ UNIT_ASSERT(false);
+ } catch (...) {
+ TString expected = "Failed to print backtrace: (yexception) "
+ "util/generic/yexception_ut.cpp:8: 1 qw 12.1\n"
+ "(yexception) util/generic/yexception_ut.cpp:4: blabla";
+ UNIT_ASSERT_EQUAL(CurrentExceptionMessage(), expected);
+ }
+ try {
+ throw std::logic_error("std exception");
+ UNIT_ASSERT(false);
+ } catch (...) {
+ TString expected = "Failed to print backtrace: (yexception) "
+ "util/generic/yexception_ut.cpp:8: 1 qw 12.1\n"
+ "(std::logic_error) std exception";
+ UNIT_ASSERT_EQUAL(CurrentExceptionMessage(), expected);
+ }
+#endif
+ }
+
inline void TestVirtualInheritance() {
TStringStream ss;