From aed711f260b7214e7264df63e3154f4a75e5c5e5 Mon Sep 17 00:00:00 2001 From: Ruijie Yu 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 | 23 +++++++++++++ 2 files changed, 57 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 22: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: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 23: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 22: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: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 23: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: 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..a303bec90 100644 --- a/testing/org-test.el +++ b/testing/org-test.el @@ -547,6 +547,29 @@ 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 + (seq-map (apply-partially #'format-time-string "%a") + org-test-day-of-weeks-seconds) + "Abbreviated names of days of week.") + +(defconst org-test-day-of-weeks-full + (seq-map (apply-partially #'format-time-string "%A") + org-test-day-of-weeks-seconds) + "Full names for days of week.") + + + (provide 'org-test) ;;; org-test.el ends here -- 2.40.0