Subject: bug#70070: FAIL: test-localtime_r

From: Paul Eggert <[email-masked]>
Date: Sat, 30 Mar 2024 13:31:53 -0600

On 3/29/24 08:15, Andreas Schwab wrote:
> On Mär 29 2024, Bruno Haible wrote:
> 
>> Yes. And make sure that it has a time zone database installed at all.
> 
> Why? That doesn't make any sense.

Although Andreas is not clear, perhaps he is alluding to the fact that 
Gnulib's localtime_r tests assume that TZ='Europe/Paris' stands for 
Paris time. POSIX doesn't guarantee this, so the implication is that the 
tests should be skipped when Europe/Paris does not work.

I installed the attached to do that. I don't know whether this will fix 
Andreas's problem, whatever it is.

From f130f5426ecd4edd5596797e0a5721b927f80126 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
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  <[email-masked]>
+
+	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  <[email-masked]>
 
 	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