From 4459b8b3aa9d73895391785a99dcc87134e80601 Mon Sep 17 00:00:00 2001 From: Albert Cervin Date: Tue, 17 Sep 2024 08:47:03 +0200 Subject: More lsp support This makes the LSP support complete for now: - Completion - Diagnostics - Goto implementation/declaration - Rename - Documentation - Find references --- test/assert.c | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) (limited to 'test/assert.c') diff --git a/test/assert.c b/test/assert.c index b252d36..2fa8a89 100644 --- a/test/assert.c +++ b/test/assert.c @@ -1,20 +1,47 @@ #include "assert.h" #include +#include #include #include #include -void assert(bool cond, const char *cond_str, const char *file, int line, - const char *msg) { +static void assert_internal(bool cond, const char *cond_str, const char *file, + int line, const char *msg, va_list args) { if (!cond) { - printf("\n%s:%d: assert failed (%s): %s\n", file, line, cond_str, msg); + va_list args2; + va_copy(args2, args); + + ssize_t res = vsnprintf(NULL, 0, msg, args); + char *buf = (char *)msg; + + if (res != -1) { + buf = malloc(res + 1); + vsnprintf(buf, res + 1, msg, args2); + } + + va_end(args); + + printf("\n%s:%d: assert failed (%s): %s\n", file, line, cond_str, buf); + + if (buf != msg) { + free(buf); + } raise(SIGABRT); } } +void assert(bool cond, const char *cond_str, const char *file, int line, + const char *msg, ...) { + va_list args; + va_start(args, msg); + assert_internal(cond, cond_str, file, line, msg, args); +} + void assert_streq(const char *left, const char *right, const char *file, - int line, const char *msg) { - assert(strcmp(left, right) == 0, " == ", file, - line, msg); + int line, const char *msg, ...) { + va_list args; + va_start(args, msg); + assert_internal(strcmp(left, right) == 0, " == ", + file, line, msg, args); } -- cgit v1.2.3