From 3369e345678aaa4199b76a099c750ed00754c548 Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Tue, 21 Nov 2023 13:42:53 +0100 Subject: 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 --- src/zencore/zencore.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/zencore/zencore.cpp') 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 #endif +#include #include #include #include @@ -34,6 +35,22 @@ #include #include +#include + +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 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 -- cgit v1.2.3