]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: unset TZ before timezone-sensitive unit tests are run
authorLuca Boccassi <bluca@debian.org>
Fri, 26 Jan 2024 00:22:38 +0000 (00:22 +0000)
committerLuca Boccassi <bluca@debian.org>
Fri, 26 Jan 2024 00:22:38 +0000 (00:22 +0000)
Some tests have hard-coded results that need to match, and change if
the caller has a timezone set via the TZ= environment variable, as it
is the case during reproducible build tests. Unset it.

src/test/test-calendarspec.c
src/test/test-date.c
src/test/test-time-util.c

index db64142f01cbbcd2912c8241fa2e20cef8b34951..18a0f8f8bfdf93d8400e18bb26918fed282fc289 100644 (file)
@@ -254,4 +254,11 @@ TEST(calendar_spec_from_string) {
         assert_se(calendar_spec_from_string("*:4,30:*\n", &c) == -EINVAL);
 }
 
-DEFINE_TEST_MAIN(LOG_INFO);
+static int intro(void) {
+        /* Tests have hard-coded results that do not expect a specific timezone to be set by the caller */
+        assert_se(unsetenv("TZ") >= 0);
+
+        return EXIT_SUCCESS;
+}
+
+DEFINE_TEST_MAIN_WITH_INTRO(LOG_INFO, intro);
index a7058a33d4241de3704bd15f51579cc5bb70dea2..162ac342f50bb787debbd64ffd8c05f95aed868a 100644 (file)
@@ -62,6 +62,9 @@ static void test_one_noutc(const char *p) {
 }
 
 int main(int argc, char *argv[]) {
+        /* Tests have hard-coded results that do not expect a specific timezone to be set by the caller */
+        assert_se(unsetenv("TZ") >= 0);
+
         test_setup_logging(LOG_DEBUG);
 
         test_one("17:41");
index d29afa38dd29a2dcea5dae4a48273081087e2f1b..9ce014dc9e3cbe432daf5ae6695d92e55ad80cce 100644 (file)
@@ -1171,6 +1171,9 @@ TEST(timezone_offset_change) {
 }
 
 static int intro(void) {
+        /* Tests have hard-coded results that do not expect a specific timezone to be set by the caller */
+        assert_se(unsetenv("TZ") >= 0);
+
         log_info("realtime=" USEC_FMT "\n"
                  "monotonic=" USEC_FMT "\n"
                  "boottime=" USEC_FMT "\n",