From 4d5ad9d951299c905453ac8e3769dc82b0a09fb4 Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Wed, 24 Nov 2021 18:45:16 +0100 Subject: [PATCH] test-time-util: Properly restore TZ variable The test fails to call tzset() after unsetting TZ variable, which could break other tests. Also, let's be nicer and actually restore the TZ to its original value. --- src/test/test-time-util.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/test/test-time-util.c b/src/test/test-time-util.c index 53f81145017..0992a316598 100644 --- a/src/test/test-time-util.c +++ b/src/test/test-time-util.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "env-util.h" #include "random-util.h" #include "serialize.h" #include "string-util.h" @@ -570,6 +571,8 @@ static void test_usec_shift_clock(void) { static void test_in_utc_timezone(void) { log_info("/* %s */", __func__); + const char *tz = getenv("TZ"); + assert_se(setenv("TZ", ":UTC", 1) >= 0); assert_se(in_utc_timezone()); assert_se(streq(tzname[0], "UTC")); @@ -582,7 +585,8 @@ static void test_in_utc_timezone(void) { assert_se(streq(tzname[0], "CET")); assert_se(streq(tzname[1], "CEST")); - assert_se(unsetenv("TZ") == 0); + assert_se(set_unset_env("TZ", tz, true) == 0); + tzset(); } static void test_map_clock_usec(void) { -- 2.47.3