Skip to content

Commit

Permalink
chore: update stacktrace print format
Browse files Browse the repository at this point in the history
  • Loading branch information
DNKpp committed Jan 31, 2025
1 parent b4467a7 commit 81225ef
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion include/mimic++/Stacktrace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,12 @@ namespace mimicpp::stacktrace::detail
{
assert(index < stacktrace.size() && "Index out of bounds.");

out = format::format_to(std::move(out), "`");
out = print_path(std::move(out), stacktrace.source_file(index));
out = format::format_to(std::move(out), "`");
out = format::format_to(
std::move(out),
"[{}], {}",
"#L{}, `{}`",
stacktrace.source_line(index),
stacktrace.description(index));

Expand Down
6 changes: 3 additions & 3 deletions test/custom-stacktrace-tests/Printing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ TEST_CASE(
const auto text = mimicpp::print(stacktrace);
REQUIRE_THAT(
text,
Catch::Matchers::Equals("#0 test.cpp[1337], Hello, World!\n"));
Catch::Matchers::Equals("#0 `test.cpp`#L1337, `Hello, World!`\n"));
}

SECTION("When stacktrace contains multiple entries.")
Expand All @@ -79,7 +79,7 @@ TEST_CASE(
REQUIRE_THAT(
text,
Catch::Matchers::Equals(
"#0 other-test.cpp[42], Hello, mimic++!\n"
"#1 test.cpp[1337], Hello, World!\n"));
"#0 `other-test.cpp`#L42, `Hello, mimic++!`\n"
"#1 `test.cpp`#L1337, `Hello, World!`\n"));
}
}
4 changes: 3 additions & 1 deletion test/unit-tests/Stacktrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,12 @@ TEST_CASE(

const std::string pattern = format::format(
R"((?:#\d+ )" // always starts with the entry index
"`"
R"((?:\/?)" // may begin with a /
R"((?:(?:\d|\w|_|-|\+|\*|\.)+(?:\\|\/))*)" // arbitrary times `dir/`
R"((?:\d|\w|_|-|\+|\*|\.)+)?)" // file name; sometimes there is no file, so the whole path may be empty
R"((?:\[\d+\],.+?\n)){{{}}})", // other stuff
"`"
R"((?:#L\d+, `.*`\n)){{{}}})", // other stuff
size);
REQUIRE_THAT(
mimicpp::print(stacktrace),
Expand Down

0 comments on commit 81225ef

Please sign in to comment.