Better handling for Exception stack trace testing.
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
5ac7654be1
commit
1dee4cd4a8
|
@ -18,26 +18,37 @@ namespace ArbUt {
|
||||||
|
|
||||||
[[nodiscard]] const char* what() const _GLIBCXX_TXN_SAFE_DYN _GLIBCXX_NOTHROW override { return _msg.c_str(); }
|
[[nodiscard]] const char* what() const _GLIBCXX_TXN_SAFE_DYN _GLIBCXX_NOTHROW override { return _msg.c_str(); }
|
||||||
|
|
||||||
[[nodiscard]] std::string GetStacktrace(size_t depth = 6) const {
|
[[nodiscard]] std::string GetStacktrace(size_t depth = 6, bool include_addr = true) const {
|
||||||
backward::TraceResolver tr;
|
backward::TraceResolver tr;
|
||||||
tr.load_stacktrace(_stack);
|
tr.load_stacktrace(_stack);
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
for (size_t i = 3; i < _stack.size() && i < depth + 3; ++i) {
|
for (size_t i = 3; i < _stack.size() && i < depth + 3; ++i) {
|
||||||
backward::ResolvedTrace trace = tr.resolve(_stack[i]);
|
backward::ResolvedTrace trace = tr.resolve(_stack[i]);
|
||||||
if (trace.source.filename.empty()){
|
if (trace.source.filename.empty()) {
|
||||||
|
auto objectName =
|
||||||
|
(strrchr(trace.object_filename.c_str(), '/') ? strrchr(trace.object_filename.c_str(), '/') + 1
|
||||||
|
: trace.object_filename.c_str());
|
||||||
|
auto function = trace.object_function;
|
||||||
|
if (function.length() > 70) {
|
||||||
|
function = function.substr(0, 67);
|
||||||
|
function += "...";
|
||||||
|
}
|
||||||
|
ss << objectName;
|
||||||
|
if (include_addr){
|
||||||
|
ss << "[" << trace.addr << "]";
|
||||||
|
}
|
||||||
|
ss << " " << function << std::endl;
|
||||||
|
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
auto fileName =
|
auto fileName =
|
||||||
(strrchr(trace.source.filename.c_str(), '/') ? strrchr(trace.source.filename.c_str(), '/') + 1
|
(strrchr(trace.source.filename.c_str(), '/') ? strrchr(trace.source.filename.c_str(), '/') + 1
|
||||||
: trace.source.filename.c_str());
|
: trace.source.filename.c_str());
|
||||||
auto function = trace.object_function;
|
auto function = trace.object_function;
|
||||||
if (function.length() > 70){
|
if (function.length() > 70) {
|
||||||
function = function.substr(0, 67);
|
function = function.substr(0, 67);
|
||||||
function += "...";
|
function += "...";
|
||||||
}
|
}
|
||||||
ss << fileName << "[" << trace.source.line << "] " << function << std::endl;
|
ss << fileName << "[" << trace.source.line << "] " << function << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ss.str();
|
return ss.str();
|
||||||
|
|
|
@ -8,8 +8,13 @@ TEST_CASE("Throw exception, get stack trace") {
|
||||||
throw ArbUt::Exception("foobar");
|
throw ArbUt::Exception("foobar");
|
||||||
}
|
}
|
||||||
catch (const ArbUt::Exception& e) {
|
catch (const ArbUt::Exception& e) {
|
||||||
|
#ifndef NDEBUG
|
||||||
REQUIRE(e.GetStacktrace(1) ==
|
REQUIRE(e.GetStacktrace(1) ==
|
||||||
"ExceptionTests.cpp[8] ____C_A_T_C_H____T_E_S_T____0()\n");
|
"ExceptionTests.cpp[8] ____C_A_T_C_H____T_E_S_T____0()\n");
|
||||||
|
#else
|
||||||
|
REQUIRE(e.GetStacktrace(1, false) ==
|
||||||
|
"ArbutilsTests Catch::RunContext::runTest(Catch::TestCase const&)\n");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue