From 79284b25994d90149f4a9a5286ec739770db94ea Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Tue, 17 Dec 2024 19:18:21 -0700 Subject: libmisc: Rework how test-intercepts work --- libmisc/tests/test_log.c | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) (limited to 'libmisc/tests/test_log.c') diff --git a/libmisc/tests/test_log.c b/libmisc/tests/test_log.c index 286738d..e819c09 100644 --- a/libmisc/tests/test_log.c +++ b/libmisc/tests/test_log.c @@ -13,36 +13,43 @@ #define LOG_NAME FROBNICATE #include +#include + #include "test.h" /* Intercept output ***********************************************************/ static char *log_output = NULL; -int vprintf(const char *format, va_list ap) { - return vasprintf(&log_output, format, ap); +int __lm_printf(const char *format, ...) { + va_list va; + va_start(va, format); + int ret = vasprintf(&log_output, format, va); + va_end(va); + return ret; } /* Actual tests ***************************************************************/ -#define should_print(_exp, cmd) do { \ - char *exp = _exp; \ - test_assert(!log_output); \ - cmd; \ - if (!exp) \ - test_assert(!log_output); \ - else \ - if (!(log_output != NULL && \ - strcmp(log_output, exp) == 0)) { \ - printf("exp = \"%s\"\n" \ - "act = \"%s\"\n", \ - exp, log_output); \ - test_assert(0); \ - } \ - if (log_output) { \ - free(log_output); \ - log_output = NULL; \ - } \ +#define should_print(_exp, cmd) do { \ + char *exp = _exp; \ + test_assert(!log_output); \ + cmd; \ + if (!exp) \ + test_assert(!log_output); \ + else { \ + test_assert(log_output); \ + if (strcmp(log_output, exp)) { \ + printf("exp = \"%s\"\n" \ + "act = \"%s\"\n", \ + exp, log_output); \ + test_assert(0); \ + } \ + } \ + if (log_output) { \ + free(log_output); \ + log_output = NULL; \ + } \ } while (0) int main() { -- cgit v1.2.3-2-g168b From 1aecc70750ee6ce9c96ebf3e6b4a7fb322ff8ca3 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Tue, 17 Dec 2024 19:18:21 -0700 Subject: Build the full matrix of CMAKE_BUILD_TYPE --- libmisc/tests/test_log.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libmisc/tests/test_log.c') diff --git a/libmisc/tests/test_log.c b/libmisc/tests/test_log.c index e819c09..49a76ca 100644 --- a/libmisc/tests/test_log.c +++ b/libmisc/tests/test_log.c @@ -57,6 +57,7 @@ int main() { errorf("val=%d", 42)); should_print("info : FROBNICATE: val=0\n", infof("val=%d", 0)); +#ifndef NDEBUG #define CONFIG_FROBNICATE_DEBUG 1 should_print("debug: FROBNICATE: val=-2\n", debugf("val=%d", -2)); @@ -64,5 +65,6 @@ int main() { #define CONFIG_FROBNICATE_DEBUG 0 should_print(NULL, debugf("val=%d", -2)); +#endif return 0; } -- cgit v1.2.3-2-g168b