From fc25e0f0f7f99dcecb382ebce3a66c7cc72fc463 Mon Sep 17 00:00:00 2001 From: Pierre Le Marre Date: Mon, 26 Jun 2023 12:19:49 +0200 Subject: [PATCH] Test(compose): fix assumption on environment variables The test `test_from_locale` fails when there is a user-defined compose file, e.g. ~/.XCompose. Indeed, the function `xkb_compose_table_new_from_locale` use various environment variables to determine the location of the compose file. Ensure no environment variables but the required ones are set, in order to have robust tests. --- test/compose.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/compose.c b/test/compose.c index 07914fe..1e85cbd 100644 --- a/test/compose.c +++ b/test/compose.c @@ -588,6 +588,22 @@ main(int argc, char *argv[]) ctx = test_get_context(CONTEXT_NO_FLAG); assert(ctx); + /* + * Ensure no environment variables but “top_srcdir” is set. This ensures + * that user Compose file paths are unset before the tests and set + * explicitely when necessary. + */ +#ifdef __linux__ + const char *srcdir = getenv("top_srcdir"); + clearenv(); + setenv("top_srcdir", srcdir, 1); +#else + unsetenv("XCOMPOSEFILE"); + unsetenv("XDG_CONFIG_HOME"); + unsetenv("HOME"); + unsetenv("XLOCALEDIR"); +#endif + test_seqs(ctx); test_conflicting(ctx); test_XCOMPOSEFILE(ctx);