summaryrefslogtreecommitdiffstats
path: root/liblog_apply_env_mask.c
diff options
context:
space:
mode:
authorMattias Andrée <m@maandree.se>2025-02-22 00:54:23 +0100
committerMattias Andrée <m@maandree.se>2025-02-22 00:54:23 +0100
commit1aa5c5fcc55f65bb48396a6fb45af060eb24b8e6 (patch)
tree21d6c69c2f64226e98c28413a8e95534c36f939f /liblog_apply_env_mask.c
parentFix doc style (diff)
downloadliblog-1aa5c5fcc55f65bb48396a6fb45af060eb24b8e6.tar.gz
liblog-1aa5c5fcc55f65bb48396a6fb45af060eb24b8e6.tar.bz2
liblog-1aa5c5fcc55f65bb48396a6fb45af060eb24b8e6.tar.xz
m fix + add testsHEADmaster
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'liblog_apply_env_mask.c')
-rw-r--r--liblog_apply_env_mask.c26
1 files changed, 24 insertions, 2 deletions
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