[ox/std] Add print of assert condition to assert output

This commit is contained in:
Gary Talent 2022-01-26 21:14:11 -06:00
parent 4a9b0e5dc3
commit 2d429d30a3
2 changed files with 8 additions and 8 deletions

View File

@ -17,12 +17,12 @@
namespace ox {
void assertFunc([[maybe_unused]]const char *file, [[maybe_unused]]int line, [[maybe_unused]]bool pass, [[maybe_unused]]const char *msg) noexcept {
void assertFunc([[maybe_unused]]const char *file, [[maybe_unused]]int line, [[maybe_unused]]bool pass, [[maybe_unused]]const char *assertTxt, [[maybe_unused]]const char *msg) noexcept {
if (!pass) {
#if defined(OX_USE_STDLIB)
std::cerr << "\033[31;1;1mASSERT FAILURE:\033[0m (" << file << ':' << line << "): " << msg << std::endl;
std::cerr << "\033[31;1;1mASSERT FAILURE:\033[0m " << assertTxt << " [" << file << ':' << line << "]: " << msg << std::endl;
printStackTrace(2);
oxTrace("assert").del("") << "Failed assert: " << msg << " (" << file << ":" << line << ")";
oxTrace("assert").del("") << "Failed assert: " << msg << " (" << assertTxt << ") " << " [" << file << ":" << line << "]";
std::abort();
#else
panic(file, line, msg);
@ -30,7 +30,7 @@ void assertFunc([[maybe_unused]]const char *file, [[maybe_unused]]int line, [[ma
}
}
void assertFunc(const char *file, int line, const Error &err, const char *assertMsg) noexcept {
void assertFunc(const char *file, int line, const Error &err, const char*, const char *assertMsg) noexcept {
if (err) {
#if defined(OX_USE_STDLIB)
std::cerr << "\033[31;1;1mASSERT FAILURE:\033[0m (" << file << ':' << line << "): " << assertMsg << '\n';
@ -42,7 +42,7 @@ void assertFunc(const char *file, int line, const Error &err, const char *assert
std::cerr << "\tError Location:\t" << err.file << ':' << err.line << '\n';
}
printStackTrace(2);
oxTrace("panic").del("") << "Panic: " << assertMsg << " (" << file << ":" << line << ")";
oxTrace("panic").del("") << "Panic: " << assertMsg << " [" << file << ":" << line << "]";
std::abort();
#else
panic(file, line, assertMsg);

View File

@ -19,9 +19,9 @@
namespace ox {
void assertFunc(const char *file, int line, bool pass, const char *msg) noexcept;
void assertFunc(const char *file, int line, bool pass, const char *assertTxt, const char *msg) noexcept;
void assertFunc(const char *file, int line, const Error &err, const char *msg) noexcept;
void assertFunc(const char *file, int line, const Error &err, const char *assertTxt, const char *msg) noexcept;
void panic([[maybe_unused]]const char *file, [[maybe_unused]]int line, [[maybe_unused]]const char *msg, [[maybe_unused]]const Error &err = OxError(0)) noexcept;
@ -29,7 +29,7 @@ void panic([[maybe_unused]]const char *file, [[maybe_unused]]int line, [[maybe_u
#define oxPanic(errCode, msg) ox::panic(__FILE__, __LINE__, msg, errCode)
#ifndef NDEBUG
#define oxAssert(pass, msg) ox::assertFunc(__FILE__, __LINE__, pass, msg)
#define oxAssert(pass, msg) ox::assertFunc(__FILE__, __LINE__, pass, #pass, msg)
#else
inline void oxAssert(bool, const char*) {}
inline void oxAssert(ox::Error, const char*) {}