Ruijie Yu via "General discussions about Org-mode." <emacs-orgmode@gnu.org> 
writes:

> Axel Kielhorn <org-m...@axelkielhorn.de> writes:
>
>> With this patch I get:
>>    FAILED  test-org-clock/clock-drawer-dwim  arrayp
>>    FAILED  test-org-clok/org-clock-timestamps-change  arrayp
>>
>> Axel
>
> Thanks for testing.  Will take a look tomorrow.

Apparently `seq-map' does not preserve the type of its input.  This
patch be good then?

>From 7621108e377c71cf083389e7bdb6f9d76cd07461 Mon Sep 17 00:00:00 2001
From: Ruijie Yu <rui...@netyu.xyz>
Date: Sat, 22 Apr 2023 20:36:18 +0800
Subject: [PATCH] [DRAFT] Fix dependence on locale in org testing facilities

* testing/org-test.el org-test-day-of-weeks-seconds: add values of
seconds that yield different days of week (by trial-and-error).
org-test-day-of-weeks-abbrev: add a vector of abbreviated DoW
names for testing.
org-test-day-of-weeks-full: add a vector of full DoW names for
testing.

* testing/lisp/test-org-clock.el
(test-org-clok/org-clock-timestamps-change):
(test-org-clock/clock-drawer-dwim): make use of the pre-generated
DoW names in the testing to remove assumptions on LANG=C.
---
 testing/lisp/test-org-clock.el | 62 +++++++++++++++++++---------------
 testing/org-test.el            | 25 ++++++++++++++
 2 files changed, 59 insertions(+), 28 deletions(-)

diff --git a/testing/lisp/test-org-clock.el b/testing/lisp/test-org-clock.el
index 7d8123e1f..4d9306619 100644
--- a/testing/lisp/test-org-clock.el
+++ b/testing/lisp/test-org-clock.el
@@ -91,27 +91,32 @@ the buffer."
 
 (ert-deftest test-org-clok/org-clock-timestamps-change ()
   "Test `org-clock-timestamps-change' specifications."
-  (should
-   (equal
-    "CLOCK: [2023-02-19 Sun 21:30]--[2023-02-19 Sun 23:35] =>  2:05"
-    (org-test-with-temp-text
-        "CLOCK: [2023-02-19 Sun 2<point>2:30]--[2023-02-20 Mon 00:35] =>  2:05"
-      (org-clock-timestamps-change 'down 1)
-      (buffer-string))))
-  (should
-   (equal
-    "CLOCK: [2023-02-20 Mon 00:00]--[2023-02-20 Mon 00:40] =>  0:40"
-    (org-test-with-temp-text
-        "CLOCK: [2023-02-19 Sun 23:<point>55]--[2023-02-20 Mon 00:35] =>  0:40"
-      (org-clock-timestamps-change 'up 1)
-      (buffer-string))))
-  (should
-   (equal
-    "CLOCK: [2023-02-20 Mon 00:30]--[2023-02-20 Mon 01:35] =>  1:05"
-    (org-test-with-temp-text
-        "CLOCK: [2023-02-19 Sun 2<point>3:30]--[2023-02-20 Mon 00:35] =>  1:05"
-      (org-clock-timestamps-change 'up 1)
-      (buffer-string)))))
+  (let ((sun (aref org-test-day-of-weeks-abbrev 0))
+        (mon (aref org-test-day-of-weeks-abbrev 1)))
+    (should
+     (equal
+      (format "CLOCK: [2023-02-19 %s 21:30]--[2023-02-19 %s 23:35] =>  2:05"
+              sun sun)
+      (org-test-with-temp-text
+          "CLOCK: [2023-02-19 Sun 2<point>2:30]--[2023-02-20 Mon 00:35] =>  2:05"
+        (org-clock-timestamps-change 'down 1)
+        (buffer-string))))
+    (should
+     (equal
+      (format "CLOCK: [2023-02-20 %s 00:00]--[2023-02-20 %s 00:40] =>  0:40"
+              mon mon)
+      (org-test-with-temp-text
+          "CLOCK: [2023-02-19 Sun 23:<point>55]--[2023-02-20 Mon 00:35] =>  0:40"
+        (org-clock-timestamps-change 'up 1)
+        (buffer-string))))
+    (should
+     (equal
+      (format "CLOCK: [2023-02-20 %s 00:30]--[2023-02-20 %s 01:35] =>  1:05"
+              mon mon)
+      (org-test-with-temp-text
+          "CLOCK: [2023-02-19 Sun 2<point>3:30]--[2023-02-20 Mon 00:35] =>  1:05"
+        (org-clock-timestamps-change 'up 1)
+        (buffer-string))))))
 
 
 ;;; Clock drawer
@@ -299,19 +304,20 @@ the buffer."
 
 (ert-deftest test-org-clock/clock-drawer-dwim ()
   "Test DWIM update of days for clocks in logbook drawers."
-  (should (equal "* Foo
+  (let ((thu (aref org-test-day-of-weeks-abbrev 4)))
+    (should (equal (format "* Foo
 :LOGBOOK:
-CLOCK: [2022-11-03 Thu 06:00]--[2022-11-03 Thu 06:01] =>  0:01
+CLOCK: [2022-11-03 %s 06:00]--[2022-11-03 %s 06:01] =>  0:01
 :END:
-"
-         (org-test-with-temp-text
-             "* Foo
+" thu thu)
+                   (org-test-with-temp-text
+                       "* Foo
 :LOGBOOK:
 <point>CLOCK: [2022-11-03 ??? 06:00]--[2022-11-03 ??? 06:01] =>  0:01
 :END:
 "
-           (org-ctrl-c-ctrl-c)
-           (buffer-string)))))
+                     (org-ctrl-c-ctrl-c)
+                     (buffer-string))))))
 
 
 ;;; Clocktable
diff --git a/testing/org-test.el b/testing/org-test.el
index 22ac60670..ced281e23 100644
--- a/testing/org-test.el
+++ b/testing/org-test.el
@@ -547,6 +547,31 @@ TIME can be a non-nil Lisp time value, or a string specifying a date and time."
        ,@body)
      (nreverse messages)))
 
+(defconst org-test-day-of-weeks-seconds
+  [121223891                            ; Sun
+   30000000                             ; Mon
+   2222222                              ; Tue
+   500000                               ; Wed
+   1000                                 ; Thu
+   89173                                ; Fri
+   666666666]                           ; Sat
+  "Epoch seconds for generating days of week strings.
+Starts at Sunday, ends at Saturday.")
+
+(defconst org-test-day-of-weeks-abbrev
+  (apply #'vector
+         (seq-map (apply-partially #'format-time-string "%a")
+                  org-test-day-of-weeks-seconds))
+  "Vector of abbreviated names of days of week.
+See `org-test-day-of-weeks-seconds'.")
+
+(defconst org-test-day-of-weeks-full
+  (apply #'vector
+         (seq-map (apply-partially #'format-time-string "%A")
+                  org-test-day-of-weeks-seconds))
+  "Vector of full names for days of week.
+See `org-test-day-of-weeks-seconds'.")
+
 (provide 'org-test)
 
 ;;; org-test.el ends here
-- 
2.40.0

-- 
Best,


RY

[Please note that this mail might go to spam due to some
misconfiguration in my mail server -- still investigating.]

Reply via email to