Improve assertion logging

This commit is contained in:
Piotr Wójcik 2025-04-18 00:40:59 +02:00
commit 92ca481915
2 changed files with 5 additions and 4 deletions

View file

@ -5,11 +5,11 @@
TEST (assert_DeathTest, debug_assert)
{
debug_assert (true);
ASSERT_DEATH (debug_assert (false), ".*Assertion \\(false\\) failed.*");
ASSERT_DEATH (debug_assert (false, "test"), ".*Assertion `false` failed: test.*");
}
TEST (assert_DeathTest, release_assert)
{
release_assert (true);
ASSERT_DEATH (release_assert (false), ".*Assertion \\(false\\) failed.*");
ASSERT_DEATH (release_assert (false, "test"), ".*Assertion `false` failed: test.*");
}

View file

@ -14,11 +14,12 @@
void assert_internal (char const * check_expr, char const * func, char const * file, unsigned int line, bool is_release_assert, std::string_view error_msg)
{
std::stringstream ss;
ss << "Assertion (" << check_expr << ") failed";
ss << "Assertion `" << check_expr << "` failed";
if (!error_msg.empty ())
{
ss << ": " << error_msg << "\n";
ss << ": " << error_msg;
}
ss << "\n";
ss << file << ":" << line << " [" << func << "]"
<< "'\n";