Subject: Re: bug#45819: 28.0.50; time-stamp-tests failures

From: "Basil L. Contovounesios" <[email-masked]>
Date: Tue, 12 Jan 2021 17:11:26 +0000

"Basil L. Contovounesios" <[email-masked]> writes:

> I've been seeing the attached failures in time-stamp-format-am-pm,
> time-stamp-format-ignored-modifiers, and time-stamp-format-string-width
> for a while now.
>
> My guess is that all three are failing because AM/PM format is not
> supported in my locale, and so '%p' returns an empty string, as per
> (info "(libc) Formatting Calendar Time").
>
> Should the tests be changed to just also handle an empty/blank string,

Perhaps something like the attached?

Thanks,

-- 
Basil

>From 39ef99ab39f7421cb515b41a9e8c5999ded1d5c8 Mon Sep 17 00:00:00 2001
From: "Basil L. Contovounesios" <[email-masked]>
Date: Tue, 12 Jan 2021 17:08:27 +0000
Subject: [PATCH] Fix time-stamp-tests for non-AM/PM locales

* test/lisp/time-stamp-tests.el (with-time-stamp-test-env): Add
Edebug spec.
(time-stamp-format-am-pm, time-stamp-format-ignored-modifiers)
(time-stamp-format-string-width): Handle locales which don't support
AM/PM formats and return an empty string instead (bug#45819).
---
 test/lisp/time-stamp-tests.el | 32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)

diff --git a/test/lisp/time-stamp-tests.el b/test/lisp/time-stamp-tests.el
index 81488c3df1..c0c5e6dae5 100644
--- a/test/lisp/time-stamp-tests.el
+++ b/test/lisp/time-stamp-tests.el
@@ -26,7 +26,7 @@
 
 (defmacro with-time-stamp-test-env (&rest body)
   "Evaluate BODY with some standard time-stamp test variables bound."
-  (declare (indent defun))
+  (declare (debug (body)) (indent defun))
   `(let ((user-login-name "test-logname")
          (user-full-name "100%d Tester") ;verify "%" passed unchanged
          (buffer-file-name "/emacs/test/time-stamped-file")
@@ -481,16 +481,17 @@ time-stamp-format-year-4digit
     (should (equal (time-stamp-string "%Y" ref-time1) "2006"))))
 
 (ert-deftest time-stamp-format-am-pm ()
-  "Test time-stamp formats for AM and PM strings."
+  "Test time-stamp formats for AM and PM strings.
+Note that `%P' returns an empty string in some locales."
   (with-time-stamp-test-env
     ;; implemented and documented since 1997
-    (should (equal (time-stamp-string "%#p" ref-time1) "pm"))
-    (should (equal (time-stamp-string "%#p" ref-time3) "am"))
-    (should (equal (time-stamp-string "%P" ref-time1) "PM"))
-    (should (equal (time-stamp-string "%P" ref-time3) "AM"))
+    (should (member (time-stamp-string "%#p" ref-time1) '("" "pm")))
+    (should (member (time-stamp-string "%#p" ref-time3) '("" "am")))
+    (should (member (time-stamp-string "%P" ref-time1) '("" "PM")))
+    (should (member (time-stamp-string "%P" ref-time3) '("" "AM")))
     ;; warned 1997-2019, changed in 2019
-    (should (equal (time-stamp-string "%p" ref-time1) "PM"))
-    (should (equal (time-stamp-string "%p" ref-time3) "AM"))))
+    (should (member (time-stamp-string "%p" ref-time1) '("" "PM")))
+    (should (member (time-stamp-string "%p" ref-time3) '("" "AM")))))
 
 (ert-deftest time-stamp-format-day-number-in-week ()
   "Test time-stamp formats for day number in week."
@@ -565,10 +566,12 @@ time-stamp-format-non-date-conversions
       (should (equal (time-stamp-string "%q" ref-time1) "sysname-no-dots")))))
 
 (ert-deftest time-stamp-format-ignored-modifiers ()
-  "Test additional args allowed (but ignored) to allow for future expansion."
+  "Test additional args allowed (but ignored) to allow for future expansion.
+Note that `%P' returns an empty string in some locales."
   (with-time-stamp-test-env
     ;; allowed modifiers
-    (should (equal (time-stamp-string "%.,@-+_ ^(stuff)P" ref-time3) "AM"))
+    (should (member (time-stamp-string "%.,@-+_ ^(stuff)P" ref-time3)
+                    '("  " "AM")))
     ;; not all punctuation is allowed
     (should-not (equal (time-stamp-string "%&P" ref-time3) "AM"))))
 
@@ -578,13 +581,14 @@ time-stamp-format-non-conversions
     (should (equal (time-stamp-string "No percent" ref-time1) "No percent"))))
 
 (ert-deftest time-stamp-format-string-width ()
-  "Test time-stamp string width modifiers."
+  "Test time-stamp string width modifiers.
+Note that `%P' returns an empty string in some locales."
   (with-time-stamp-test-env
     ;; strings truncate on the right or are blank-padded on the left
     (should (equal (time-stamp-string "%0P" ref-time3) ""))
-    (should (equal (time-stamp-string "%1P" ref-time3) "A"))
-    (should (equal (time-stamp-string "%2P" ref-time3) "AM"))
-    (should (equal (time-stamp-string "%3P" ref-time3) " AM"))
+    (should (member (time-stamp-string "%1P" ref-time3) '(" " "A")))
+    (should (member (time-stamp-string "%2P" ref-time3) '("  " "AM")))
+    (should (member (time-stamp-string "%3P" ref-time3) '("   " " AM")))
     (should (equal (time-stamp-string "%0%" ref-time3) ""))
     (should (equal (time-stamp-string "%1%" ref-time3) "%"))
     (should (equal (time-stamp-string "%2%" ref-time3) " %"))
-- 
2.29.2