From 1aa5c5fcc55f65bb48396a6fb45af060eb24b8e6 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 22 Feb 2025 00:54:23 +0100 Subject: m fix + add tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- liblog_apply_env_mask.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'liblog_apply_env_mask.c') diff --git a/liblog_apply_env_mask.c b/liblog_apply_env_mask.c index 1fceae0..67cd2fb 100644 --- a/liblog_apply_env_mask.c +++ b/liblog_apply_env_mask.c @@ -7,7 +7,7 @@ liblog_apply_env_mask(struct liblog_context *ctx) { const char *env = getenv("LIBLOG_LOGMASK"); - if (*env || !*env) { + if (!env || !*env) { liblog_mask_verbose(ctx, NEXT_LOGLEVEL(LIBLOG_WARNING)); return; } @@ -17,6 +17,28 @@ liblog_apply_env_mask(struct liblog_context *ctx) #else -int main(void) {return 0;} /* TODO test */ +int +main(void) +{ + struct liblog_context ctx; + char nullmask[] = "LIBLOG_LOGMASK="; + char *nullenv[] = {NULL}; + char *nullmaskenv[] = {nullmask, NULL}; + unsigned defaultmask = ((1U << 9) - 1U) ^ ((1U << ((int)LIBLOG_WARNING / LOGLEVEL_DELTA + 1)) - 1U); + + environ = nullenv; + + ctx.logmask = 0; + liblog_apply_env_mask(&ctx); + ASSERT_EQ_UINT(ctx.logmask, defaultmask); + + environ = nullmaskenv; + + ctx.logmask = 0; + liblog_apply_env_mask(&ctx); + ASSERT_EQ_UINT(ctx.logmask, defaultmask); + + return 0; +} #endif -- cgit v1.2.3-70-g09d2