diff options
| author | Stefan Boberg <[email protected]> | 2023-11-21 13:42:53 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-11-21 13:42:53 +0100 |
| commit | 3369e345678aaa4199b76a099c750ed00754c548 (patch) | |
| tree | 6d202aeb7d312acddd6c9da58b8d1993a3adfffc /src/zencore/zencore.cpp | |
| parent | fix bad merge (diff) | |
| download | zen-3369e345678aaa4199b76a099c750ed00754c548.tar.xz zen-3369e345678aaa4199b76a099c750ed00754c548.zip | |
basic ZEN_ASSERT_FORMAT implementation (#556)
includes porting some compact binary builder code to use it since it had vestiges of the UE-side asserts
Diffstat (limited to 'src/zencore/zencore.cpp')
| -rw-r--r-- | src/zencore/zencore.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/zencore/zencore.cpp b/src/zencore/zencore.cpp index 5406af097..eed903f54 100644 --- a/src/zencore/zencore.cpp +++ b/src/zencore/zencore.cpp @@ -10,6 +10,7 @@ # include <pthread.h> #endif +#include <zencore/assertfmt.h> #include <zencore/blake3.h> #include <zencore/compactbinary.h> #include <zencore/compactbinarybuilder.h> @@ -34,6 +35,22 @@ #include <zencore/uid.h> #include <zencore/workthreadpool.h> +#include <fmt/format.h> + +namespace zen::assert { + +void +ExecAssertFmt(const char* Filename, int LineNumber, const char* FunctionName, std::string_view Format, fmt::format_args Args) +{ + fmt::basic_memory_buffer<char, 1024> Message; + fmt::vformat_to(fmt::appender(Message), Format, Args); + Message.push_back('\0'); + + AssertImpl::ExecAssert(Filename, LineNumber, FunctionName, Message.data()); +} + +} // namespace zen::assert + namespace zen { void refcount_forcelink(); @@ -144,6 +161,8 @@ zencore_forcelinktests() namespace zen { +TEST_SUITE_BEGIN("core.assert"); + TEST_CASE("Assert.Default") { bool A = true; @@ -151,6 +170,13 @@ TEST_CASE("Assert.Default") CHECK_THROWS_WITH(ZEN_ASSERT(A == B), "A == B"); } +TEST_CASE("Assert.Format") +{ + bool A = true; + bool B = false; + CHECK_THROWS_WITH(ZEN_ASSERT_FORMAT(A == B, "{} == {}", A, B), "assert(A == B) failed: true == false"); +} + TEST_CASE("Assert.Custom") { struct MyAssertImpl : AssertImpl @@ -185,6 +211,7 @@ TEST_CASE("Assert.Custom") CHECK(strcmp(MyAssert.Message, "A == B") == 0); } +TEST_SUITE_END(); #endif } // namespace zen |