diff --git a/Tests/assert.cpp b/Tests/assert.cpp index 3929583..ee606f3 100644 --- a/Tests/assert.cpp +++ b/Tests/assert.cpp @@ -5,14 +5,14 @@ #include #ifdef NDEBUG -# undef NDEBUG -# define NDEBUG_WAS_SET +#undef NDEBUG +#define NDEBUG_WAS_SET #endif #include "utility_assert.hpp" #ifdef NDEBUG_WAS_SET -# define NDEBUG +#define NDEBUG #endif namespace @@ -20,12 +20,12 @@ namespace bool assert_flag = false; -void assertCallback(const char*, const int) +void assertCallback(const char*, const char*, const int) { assert_flag = true; } -} +}// namespace TEST_CASE("Assert debug without NDEBUG gets triggered if check is false.", "[utility],[assert]") { diff --git a/Tests/assert_ndebug.cpp b/Tests/assert_ndebug.cpp index f130c25..e921a1c 100644 --- a/Tests/assert_ndebug.cpp +++ b/Tests/assert_ndebug.cpp @@ -5,14 +5,14 @@ #include #ifndef NDEBUG -# define NDEBUG -# define NDEBUG_WAS_NOT_DEFINED +#define NDEBUG +#define NDEBUG_WAS_NOT_DEFINED #endif #include "utility_assert.hpp" #ifdef NDEBUG_WAS_NOT_DEFINED -# undef NDEBUG +#undef NDEBUG #endif namespace @@ -20,12 +20,12 @@ namespace bool assert_flag = false; -void assertCallback(const char*, const int) +void assertCallback(const char*, const char*, const int) { assert_flag = true; } -} +}// namespace TEST_CASE("Assert debug with NDEBUG is a null-opt.", "[utility],[assert]") { diff --git a/Utility/Inc/utility_assert.hpp b/Utility/Inc/utility_assert.hpp index 89c1998..a292dc4 100644 --- a/Utility/Inc/utility_assert.hpp +++ b/Utility/Inc/utility_assert.hpp @@ -8,26 +8,26 @@ namespace Utility::Assert::Detail { -void assertImpl(const bool expr, const char* file, const int line); +void assertImpl(const char* expression, const char* file, const int line); } #ifndef NDEBUG -# define SKULLC_ASSERT_DEBUG(e) Utility::Assert::Detail::assertImpl(e, __FILE__, __LINE__) +#define SKULLC_ASSERT_DEBUG(e) (!(e) ? Utility::Assert::Detail::assertImpl(#e, __FILE__, __LINE__) : ((void) 0)) #else -# define SKULLC_ASSERT_DEBUG(e) +#define SKULLC_ASSERT_DEBUG(e) #endif -#define SKULLC_ASSERT_SAFE(e) Utility::Assert::Detail::assertImpl(e, __FILE__, __LINE__) +#define SKULLC_ASSERT_SAFE(e) (!(e) ? Utility::Assert::Detail::assertImpl(#e, __FILE__, __LINE__) : ((void) 0)) namespace Utility::Assert { -using assert_cb = void (*)(const char* file, const int line); +using assert_cb = void (*)(const char* expression, const char* file, const int line); void setHandler(assert_cb callback); assert_cb getHandler(); -} +}// namespace Utility::Assert -#endif // SKULLC_UTILITY_ASSERT_HPP_ +#endif// SKULLC_UTILITY_ASSERT_HPP_ diff --git a/Utility/Src/utility_assert.cpp b/Utility/Src/utility_assert.cpp index 6527a3e..4f6eb6f 100644 --- a/Utility/Src/utility_assert.cpp +++ b/Utility/Src/utility_assert.cpp @@ -19,18 +19,15 @@ namespace Utility::Assert namespace Detail { -void assertImpl(const bool expr, const char* file, const int line) +void assertImpl(const char* expression, const char* file, const int line) { - if (!expr) - { - if (INSTALLED_HANDLER) - INSTALLED_HANDLER(file, line); - else - std::terminate(); - } + if (INSTALLED_HANDLER) + INSTALLED_HANDLER(expression, file, line); + else + std::terminate(); } -} +}// namespace Detail void setHandler(assert_cb callback) { @@ -42,4 +39,4 @@ assert_cb getHandler() return INSTALLED_HANDLER; } -} +}// namespace Utility::Assert