From f130f5426ecd4edd5596797e0a5721b927f80126 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 30 Mar 2024 13:28:01 -0600 Subject: [PATCH] time_r-tests: skip French tests if no Europe/Paris * tests/test-localtime_r.c (main): * tests/test-localtime_r-mt.c (main): If TZ='Europe/Paris' does not work, skip these tests. --- ChangeLog | 7 +++++++ tests/test-localtime_r-mt.c | 21 +++++++++++++++++++++ tests/test-localtime_r.c | 21 +++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/ChangeLog b/ChangeLog index eab98607a2..ecb4632196 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2024-03-30 Paul Eggert + + time_r-tests: skip French tests if no Europe/Paris + * tests/test-localtime_r.c (main): + * tests/test-localtime_r-mt.c (main): + If TZ='Europe/Paris' does not work, skip these tests. + 2024-03-29 Paul Eggert intprops: pacify GCC < 10 -Wsign-compare diff --git a/tests/test-localtime_r-mt.c b/tests/test-localtime_r-mt.c index ae371a8946..b09e86854f 100644 --- a/tests/test-localtime_r-mt.c +++ b/tests/test-localtime_r-mt.c @@ -107,6 +107,27 @@ main (int argc, char *argv[]) { setenv ("TZ", FRENCH_TZ, 1); + /* Check that this TZ works. */ + { + time_t t = 0; /* 1970-01-01 01:00:00 */ + struct tm *result = localtime (&t); + if (! (result + && result->tm_sec == 0 + && result->tm_min == 0 + && result->tm_hour == 1 + && result->tm_mday == 1 + && result->tm_mon == 1 - 1 + && result->tm_year == 1970 - 1900 + && result->tm_wday == 4 + && result->tm_yday == 0 + && result->tm_isdst == 0)) + { + fputs ("Skipping test: TZ='Europe/Paris' is not Paris time\n", + stderr); + return 77; + } + } + /* Create the threads. */ gl_thread_create (thread1_func, NULL); gl_thread_create (thread2_func, NULL); diff --git a/tests/test-localtime_r.c b/tests/test-localtime_r.c index 70ec3b5d4f..6b3da1af19 100644 --- a/tests/test-localtime_r.c +++ b/tests/test-localtime_r.c @@ -43,6 +43,27 @@ main (void) { setenv ("TZ", FRENCH_TZ, 1); + /* Check that this TZ works. */ + { + time_t t = 0; /* 1970-01-01 01:00:00 */ + struct tm *result = localtime (&t); + if (! (result + && result->tm_sec == 0 + && result->tm_min == 0 + && result->tm_hour == 1 + && result->tm_mday == 1 + && result->tm_mon == 1 - 1 + && result->tm_year == 1970 - 1900 + && result->tm_wday == 4 + && result->tm_yday == 0 + && result->tm_isdst == 0)) + { + fputs ("Skipping test: TZ='Europe/Paris' is not Paris time\n", + stderr); + return 77; + } + } + /* Note: The result->tm_gmtoff values and the result->tm_zone values are the same (3600, "CET" or 7200, "CEST") across all tested platforms: glibc, musl, macOS, FreeBSD, NetBSD, OpenBSD, Minix, Cygwin, Android. */ -- 2.44.0