emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Test failure due to LANG
@ 2023-04-22  7:11 Axel Kielhorn
  2023-04-22  9:51 ` Ruijie Yu via General discussions about Org-mode.
  2023-04-22 12:35 ` Ihor Radchenko
  0 siblings, 2 replies; 34+ messages in thread
From: Axel Kielhorn @ 2023-04-22  7:11 UTC (permalink / raw)
  To: Org-Mode Mailing List

Hello!

I’m building org with LANG=de.
As a result I get two failed tests:

   FAILED  test-org-clock/clock-drawer-dwim  ((should (equal "*
Foo\n:LOGBOOK:\nCLOCK: [2022-11-03 Thu 06:00]--[2022-11-03 Thu 06:01] =>
0:01\n:END:\n" (org-test-with-temp-text "* Foo\n:LOGBOOK:\n<point>CLOCK:
[2022-11-03 ??? 06:00]--[2022-11-03 ??? 06:01] =>  0:01\n:END:\n"
(org-ctrl-c-ctrl-c) (buffer-string)))) :form (equal "*
Foo\n:LOGBOOK:\nCLOCK: [2022-11-03 Thu 06:00]--[2022-11-03 Thu 06:01] =>
0:01\n:END:\n" #("* Foo\n:LOGBOOK:\nCLOCK: [2022-11-03 Do
06:00]--[2022-11-03 Do 06:01] =>  0:01\n:END:\n" 0 2 (face org-level-1) 2 5
(face org-level-1) 6 15 (face org-drawer font-lock-fontified t) 16 22 (face
org-special-keyword) 44 67 (mouse-face highlight keymap (keymap (follow-link
. mouse-face) (mouse-3 . org-find-file-at-mouse) (mouse-2 .
org-open-at-mouse)) face org-date) 77 82 (face org-drawer
font-lock-fontified t))) :value nil :explanation 
(arrays-of-different-length 85 83 

"* Foo\n:LOGBOOK:\nCLOCK: [2022-11-03 Thu 06:00]--[2022-11-03 Thu 06:01] =>  0:01\n:END:\n" #(
"* Foo\n:LOGBOOK:\nCLOCK: [2022-11-03 Do 06:00]--[2022-11-03 Do 06:01] =>  0:01\n:END:\n" 

0 2 (face org-level-1) 2 5 (face org-level-1) 6 15 (face org-drawer font-lock-fontified t) 16 22 (face org-special-keyword) 44 67 (mouse-face highlight keymap (keymap (follow-link . mouse-face) (mouse-3 . org-find-file-at-mouse) (mouse-2 . org-open-at-mouse)) face org-date) 77 82 (face org-drawer font-lock-fontified t)) first-mismatch-at 35))

   FAILED  test-org-clok/org-clock-timestamps-change  ((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)))) :form (equal "CLOCK: [2023-02-19 Sun 21:30]--[2023-02-19
Sun 23:35] =>  2:05" #("CLOCK: [2023-02-19 So 21:30]--[2023-02-19 So 23:35]
=>  2:05" 0 6 (face org-special-keyword) 28 51 (mouse-face highlight keymap
(keymap (follow-link . mouse-face) (mouse-3 . org-find-file-at-mouse)
(mouse-2 . org-open-at-mouse)) face org-date))) :value nil :explanation
(arrays-of-different-length 62 60 

"CLOCK: [2023-02-19 Sun 21:30]--[2023-02-19 Sun 23:35] =>  2:05" #(
"CLOCK: [2023-02-19 So 21:30]--[2023-02-19 So 23:35] =>  2:05" 

0 6 (face org-special-keyword) 28 51 (mouse-face highlight keymap (keymap (follow-link . mouse-face) (mouse-3 . org-find-file-at-mouse) (mouse-2 . org-open-at-mouse)) face org-date)) first-mismatch-at 20))

When I build with LANG=C, these tests pass.

I’m using macOS 11.7 on intel, but that shouldn’t affect these two fails.

Greetings Axel

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: Test failure due to LANG
  2023-04-22  7:11 Test failure due to LANG Axel Kielhorn
@ 2023-04-22  9:51 ` Ruijie Yu via General discussions about Org-mode.
  2023-04-22 10:15   ` Ruijie Yu via General discussions about Org-mode.
  2023-04-22 12:35 ` Ihor Radchenko
  1 sibling, 1 reply; 34+ messages in thread
From: Ruijie Yu via General discussions about Org-mode. @ 2023-04-22  9:51 UTC (permalink / raw)
  To: Axel Kielhorn; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1119 bytes --]


Axel Kielhorn <org-mode@axelkielhorn.de> writes:

> Hello!
>
> I’m building org with LANG=de.
> As a result I get two failed tests:

Reproducible using "LANG=zh_CN.UTF-8".  In fact, I got more failed tests
in my testing.  I think the OP's two test failures are due to hardcoded
English expected result, whereas the additional test failures on my
testing are probably due to the fact that each Chinese character is as
wide as two latin letters, which catches some testing code offguard.

Here are the test names that failed unexpectedly for me.  All the
"should"'s and "should-not"'s are in the attachment below.

--8<---------------cut here---------------start------------->8---
8 unexpected results:
   FAILED  test-org-clock/clock-drawer-dwim
   FAILED  test-org-clock/clocktable/lang
   FAILED  test-org-clok/org-clock-timestamps-change
   FAILED  test-org-colview/columns-width
   FAILED  test-org/add-planning-info
   FAILED  test-org/clone-with-time-shift
   FAILED  test-org/deadline
   FAILED  test-org/schedule
--8<---------------cut here---------------end--------------->8---


[-- Attachment #2: lang.txt --]
[-- Type: text/plain, Size: 7282 bytes --]

8 unexpected results:
   FAILED  test-org-clock/clock-drawer-dwim  ((should (equal "* Foo\n:LOGBOOK:\nCLOCK: [2022-11-03 Thu 06:00]--[2022-11-03 Thu 06:01] =>  0:01\n:END:\n" (org-test-with-temp-text "* Foo\n:LOGBOOK:\n<point>CLOCK: [2022-11-03 ??? 06:00]--[2022-11-03 ??? 06:01] =>  0:01\n:END:\n" (org-ctrl-c-ctrl-c) (buffer-string)))) :form (equal "* Foo\n:LOGBOOK:\nCLOCK: [2022-11-03 Thu 06:00]--[2022-11-03 Thu 06:01] =>  0:01\n:END:\n" #("* Foo\n:LOGBOOK:\nCLOCK: [2022-11-03 四 06:00]--[2022-11-03 四 06:01] =>  0:01\n:END:\n" 0 2 (face org-level-1) 2 5 (face org-level-1) 6 15 (font-lock-fontified t face org-drawer) 16 22 (face org-special-keyword) 43 65 (face org-date keymap (keymap (follow-link . mouse-face) (mouse-3 . org-find-file-at-mouse) (mouse-2 . org-open-at-mouse)) mouse-face highlight) 75 80 (font-lock-fontified t face org-drawer))) :value nil :explanation (arrays-of-different-length 85 81 "* Foo\n:LOGBOOK:\nCLOCK: [2022-11-03 Thu 06:00]--[2022-11-03 Thu 06:01] =>  0:01\n:END:\n" #("* Foo\n:LOGBOOK:\nCLOCK: [2022-11-03 四 06:00]--[2022-11-03 四 06:01] =>  0:01\n:END:\n" 0 2 (face org-level-1) 2 5 (face org-level-1) 6 15 (font-lock-fontified t face org-drawer) 16 22 (face org-special-keyword) 43 65 (face org-date keymap (keymap (follow-link . mouse-face) (mouse-3 . org-find-file-at-mouse) (mouse-2 . org-open-at-mouse)) mouse-face highlight) 75 80 (font-lock-fontified t face org-drawer)) first-mismatch-at 35))
   FAILED  test-org-clock/clocktable/lang  ((should (equal "| En-tête        | Durée   |\n|----------------+---------|\n| *Durée totale* | *26:00* |\n|----------------+---------|\n| Foo            | 26:00   |" (org-test-with-temp-text "* Foo\n  CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00" (test-org-clock-clocktable-contents ":maxlevel 1 :lang fr")))) :form (equal "| En-tête        | Durée   |\n|----------------+---------|\n| *Durée totale* | *26:00* |\n|----------------+---------|\n| Foo            | 26:00   |" "| En-tête        | Durée  |\n|-----------------+---------|\n| *Durée totale* | *26:00* |\n|-----------------+---------|\n| Foo             | 26:00   |") :value nil :explanation (arrays-of-different-length 144 146 "| En-tête        | Durée   |\n|----------------+---------|\n| *Durée totale* | *26:00* |\n|----------------+---------|\n| Foo            | 26:00   |" "| En-tête        | Durée  |\n|-----------------+---------|\n| *Durée totale* | *26:00* |\n|-----------------+---------|\n| Foo             | 26:00   |" first-mismatch-at 26))
   FAILED  test-org-clok/org-clock-timestamps-change  ((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)))) :form (equal "CLOCK: [2023-02-19 Sun 21:30]--[2023-02-19 Sun 23:35] =>  2:05" #("CLOCK: [2023-02-19 日 21:30]--[2023-02-19 日 23:35] =>  2:05" 0 6 (face org-special-keyword) 27 49 (face org-date keymap (keymap (follow-link . mouse-face) (mouse-3 . org-find-file-at-mouse) (mouse-2 . org-open-at-mouse)) mouse-face highlight))) :value nil :explanation (arrays-of-different-length 62 58 "CLOCK: [2023-02-19 Sun 21:30]--[2023-02-19 Sun 23:35] =>  2:05" #("CLOCK: [2023-02-19 日 21:30]--[2023-02-19 日 23:35] =>  2:05" 0 6 (face org-special-keyword) 27 49 (face org-date keymap (keymap (follow-link . mouse-face) (mouse-3 . org-find-file-at-mouse) (mouse-2 . org-open-at-mouse)) mouse-face highlight)) first-mismatch-at 19))
   FAILED  test-org-colview/columns-width  ((should (equal "1234… |" (org-test-with-temp-text "* H\n:PROPERTIES:\n:P: 123456\n:END:" (let (... ...) (org-columns)) (org-trim (get-char-property ... ...))))) :form (equal "1234… |" "1234  |") :value nil :explanation (array-elt 4 (different-atoms (8230 "#x2026" "?…") (32 "#x20" "? "))))
   FAILED  test-org/add-planning-info  ((should (equal "* H\n  DEADLINE: <2015-06-25>\nParagraph" (org-test-with-temp-text "* H\nParagraph<point>" (let (...) (org-add-planning-info ... "<2015-06-25 Thu>")) (replace-regexp-in-string "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))) :form (equal "* H\n  DEADLINE: <2015-06-25>\nParagraph" #("* H\n  DEADLINE: <2015-06-25 四>\nParagraph" 0 2 (face org-level-1) 2 30 (face org-level-1))) :value nil :explanation (arrays-of-different-length 38 40 "* H\n  DEADLINE: <2015-06-25>\nParagraph" #("* H\n  DEADLINE: <2015-06-25 四>\nParagraph" 0 2 (face org-level-1) 2 30 (face org-level-1)) first-mismatch-at 27))
   FAILED  test-org/clone-with-time-shift  ((should (equal "* H1\n<2015-06-21>\n* H1\n<2015-06-23>\n" (org-test-with-temp-text "* H1\n<2015-06-21 Sun>" (org-clone-subtree-with-time-shift 1 "+2d") (replace-regexp-in-string "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string) nil nil 1)))) :form (equal "* H1\n<2015-06-21>\n* H1\n<2015-06-23>\n" #("* H1\n<2015-06-21>\n* H1\n<2015-06-23 二>\n" 0 2 (face org-level-1) 2 4 (face org-level-1) 5 16 (face org-date keymap (keymap (follow-link . mouse-face) (mouse-3 . org-find-file-at-mouse) (mouse-2 . org-open-at-mouse)) mouse-face highlight) 16 17 (face org-date rear-nonsticky (mouse-face highlight keymap invisible intangible help-echo org-linked-text htmlize-link) keymap (keymap (follow-link . mouse-face) (mouse-3 . org-find-file-at-mouse) (mouse-2 . org-open-at-mouse)) mouse-face highlight) 18 20 (face org-level-1) 20 22 (face org-level-1))) :value nil :explanation (arrays-of-different-length 36 38 "* H1\n<2015-06-21>\n* H1\n<2015-06-23>\n" #("* H1\n<2015-06-21>\n* H1\n<2015-06-23 二>\n" 0 2 (face org-level-1) 2 4 (face org-level-1) 5 16 (face org-date keymap (keymap (follow-link . mouse-face) (mouse-3 . org-find-file-at-mouse) (mouse-2 . org-open-at-mouse)) mouse-face highlight) 16 17 (face org-date rear-nonsticky (mouse-face highlight keymap invisible intangible help-echo org-linked-text htmlize-link) keymap (keymap (follow-link . mouse-face) (mouse-3 . org-find-file-at-mouse) (mouse-2 . org-open-at-mouse)) mouse-face highlight) 18 20 (face org-level-1) 20 22 (face org-level-1)) first-mismatch-at 34))
   FAILED  test-org/deadline  ((should (equal "* H\nDEADLINE: <2012-03-29>" (org-test-with-temp-text "* H" (let (... ...) (org-deadline nil "<2012-03-29 Tue>")) (replace-regexp-in-string "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))) :form (equal "* H\nDEADLINE: <2012-03-29>" #("* H\nDEADLINE: <2012-03-29 四>" 0 2 (face org-level-1) 2 28 (face org-level-1))) :value nil :explanation (arrays-of-different-length 26 28 "* H\nDEADLINE: <2012-03-29>" #("* H\nDEADLINE: <2012-03-29 四>" 0 2 (face org-level-1) 2 28 (face org-level-1)) first-mismatch-at 25))
   FAILED  test-org/schedule  ((should (equal "* H\nSCHEDULED: <2012-03-29>" (org-test-with-temp-text "* H" (let (... ...) (org-schedule nil "<2012-03-29 Tue>")) (replace-regexp-in-string "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))) :form (equal "* H\nSCHEDULED: <2012-03-29>" #("* H\nSCHEDULED: <2012-03-29 四>" 0 2 (face org-level-1) 2 29 (face org-level-1))) :value nil :explanation (arrays-of-different-length 27 29 "* H\nSCHEDULED: <2012-03-29>" #("* H\nSCHEDULED: <2012-03-29 四>" 0 2 (face org-level-1) 2 29 (face org-level-1)) first-mismatch-at 26))

[-- Attachment #3: Type: text/plain, Size: 2936 bytes --]


>    FAILED  test-org-clock/clock-drawer-dwim  ((should (equal "*
> Foo\n:LOGBOOK:\nCLOCK: [2022-11-03 Thu 06:00]--[2022-11-03 Thu 06:01] =>
> 0:01\n:END:\n" (org-test-with-temp-text "* Foo\n:LOGBOOK:\n<point>CLOCK:
> [2022-11-03 ??? 06:00]--[2022-11-03 ??? 06:01] =>  0:01\n:END:\n"
> (org-ctrl-c-ctrl-c) (buffer-string)))) :form (equal "*
> Foo\n:LOGBOOK:\nCLOCK: [2022-11-03 Thu 06:00]--[2022-11-03 Thu 06:01] =>
> 0:01\n:END:\n" #("* Foo\n:LOGBOOK:\nCLOCK: [2022-11-03 Do
> 06:00]--[2022-11-03 Do 06:01] =>  0:01\n:END:\n" 0 2 (face org-level-1) 2 5
> (face org-level-1) 6 15 (face org-drawer font-lock-fontified t) 16 22 (face
> org-special-keyword) 44 67 (mouse-face highlight keymap (keymap (follow-link
> . mouse-face) (mouse-3 . org-find-file-at-mouse) (mouse-2 .
> org-open-at-mouse)) face org-date) 77 82 (face org-drawer
> font-lock-fontified t))) :value nil :explanation 
> (arrays-of-different-length 85 83 
>
> "* Foo\n:LOGBOOK:\nCLOCK: [2022-11-03 Thu 06:00]--[2022-11-03 Thu 06:01] =>  0:01\n:END:\n" #(
> "* Foo\n:LOGBOOK:\nCLOCK: [2022-11-03 Do 06:00]--[2022-11-03 Do 06:01] =>  0:01\n:END:\n" 
>
> 0 2 (face org-level-1) 2 5 (face org-level-1) 6 15 (face org-drawer
> font-lock-fontified t) 16 22 (face org-special-keyword) 44 67 (mouse-face
> highlight keymap (keymap (follow-link . mouse-face) (mouse-3
> . org-find-file-at-mouse) (mouse-2 . org-open-at-mouse)) face org-date) 77 82
> (face org-drawer font-lock-fontified t)) first-mismatch-at 35))
>
>    FAILED  test-org-clok/org-clock-timestamps-change  ((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)))) :form (equal "CLOCK: [2023-02-19 Sun 21:30]--[2023-02-19
> Sun 23:35] =>  2:05" #("CLOCK: [2023-02-19 So 21:30]--[2023-02-19 So 23:35]
> =>  2:05" 0 6 (face org-special-keyword) 28 51 (mouse-face highlight keymap
> (keymap (follow-link . mouse-face) (mouse-3 . org-find-file-at-mouse)
> (mouse-2 . org-open-at-mouse)) face org-date))) :value nil :explanation
> (arrays-of-different-length 62 60 
>
> "CLOCK: [2023-02-19 Sun 21:30]--[2023-02-19 Sun 23:35] =>  2:05" #(
> "CLOCK: [2023-02-19 So 21:30]--[2023-02-19 So 23:35] =>  2:05" 
>
> 0 6 (face org-special-keyword) 28 51 (mouse-face highlight keymap (keymap
> (follow-link . mouse-face) (mouse-3 . org-find-file-at-mouse) (mouse-2
> . org-open-at-mouse)) face org-date)) first-mismatch-at 20))
>
> When I build with LANG=C, these tests pass.
>
> I’m using macOS 11.7 on intel, but that shouldn’t affect these two fails.

For me, I have a month-old Emacs master, with an up-to-date orgmode.git.

> Greetings Axel

-- 
Best,


RY

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

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: Test failure due to LANG
  2023-04-22  9:51 ` Ruijie Yu via General discussions about Org-mode.
@ 2023-04-22 10:15   ` Ruijie Yu via General discussions about Org-mode.
  2023-04-22 12:37     ` Ruijie Yu via General discussions about Org-mode.
  0 siblings, 1 reply; 34+ messages in thread
From: Ruijie Yu via General discussions about Org-mode. @ 2023-04-22 10:15 UTC (permalink / raw)
  To: Ruijie Yu; +Cc: Axel Kielhorn, emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1383 bytes --]


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

> Axel Kielhorn <org-mode@axelkielhorn.de> writes:
>
>> Hello!
>>
>> I’m building org with LANG=de.
>> As a result I get two failed tests:
>
> Reproducible using "LANG=zh_CN.UTF-8".  In fact, I got more failed tests
> in my testing.  I think the OP's two test failures are due to hardcoded
> English expected result, whereas the additional test failures on my
> testing are probably due to the fact that each Chinese character is as
> wide as two latin letters, which catches some testing code offguard.
>
> Here are the test names that failed unexpectedly for me.  All the
> "should"'s and "should-not"'s are in the attachment below.
>
> --8<---------------cut here---------------start------------->8---
> 8 unexpected results:
>    FAILED  test-org-clock/clock-drawer-dwim
>    FAILED  test-org-clock/clocktable/lang
>    FAILED  test-org-clok/org-clock-timestamps-change
>    FAILED  test-org-colview/columns-width
>    FAILED  test-org/add-planning-info
>    FAILED  test-org/clone-with-time-shift
>    FAILED  test-org/deadline
>    FAILED  test-org/schedule
> --8<---------------cut here---------------end--------------->8---
>
> [3. text/plain; lang.txt]...

Update: interestingly, there is one test error when setting
"LANG=en_US.UTF-8" or "LANG=C".


[-- Attachment #2: lang-en-us-utf8.txt --]
[-- Type: text/plain, Size: 1162 bytes --]

1 unexpected results:
   FAILED  test-org-clock/clocktable/lang  ((should (equal "| En-tête        | Durée   |\n|----------------+---------|\n| *Durée totale* | *26:00* |\n|----------------+---------|\n| Foo            | 26:00   |" (org-test-with-temp-text "* Foo\n  CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00" (test-org-clock-clocktable-contents ":maxlevel 1 :lang fr")))) :form (equal "| En-tête        | Durée   |\n|----------------+---------|\n| *Durée totale* | *26:00* |\n|----------------+---------|\n| Foo            | 26:00   |" "| En-tête        | Durée |\n|---------------------+------------|\n| *Durée totale* | *26:00*    |\n|---------------------+------------|\n| Foo                 | 26:00      |") :value nil :explanation (arrays-of-different-length 144 169 "| En-tête        | Durée   |\n|----------------+---------|\n| *Durée totale* | *26:00* |\n|----------------+---------|\n| Foo            | 26:00   |" "| En-tête        | Durée |\n|---------------------+------------|\n| *Durée totale* | *26:00*    |\n|---------------------+------------|\n| Foo                 | 26:00      |" first-mismatch-at 25))

[-- Attachment #3: Type: text/plain, Size: 75 bytes --]


And, two somewhat different test errors when setting "LANG=fr_FR.UTF-8".


[-- Attachment #4: lang-fr-fr-utf8.txt --]
[-- Type: text/plain, Size: 1531 bytes --]

2 unexpected results:
   FAILED  test-org-clock/clock-drawer-dwim  ((should (equal "* Foo\n:LOGBOOK:\nCLOCK: [2022-11-03 Thu 06:00]--[2022-11-03 Thu 06:01] =>  0:01\n:END:\n" (org-test-with-temp-text "* Foo\n:LOGBOOK:\n<point>CLOCK: [2022-11-03 ??? 06:00]--[2022-11-03 ??? 06:01] =>  0:01\n:END:\n" (org-ctrl-c-ctrl-c) (buffer-string)))) :form (equal "* Foo\n:LOGBOOK:\nCLOCK: [2022-11-03 Thu 06:00]--[2022-11-03 Thu 06:01] =>  0:01\n:END:\n" #("* Foo\n:LOGBOOK:\nCLOCK: [2022-11-03 jeu. 06:00]--[2022-11-03 jeu. 06:01] =>  0:01\n:END:\n" 0 2 (face org-level-1) 2 5 (face org-level-1) 6 15 (font-lock-fontified t face org-drawer) 16 22 (face org-special-keyword) 46 71 (face org-date keymap (keymap (follow-link . mouse-face) (mouse-3 . org-find-file-at-mouse) (mouse-2 . org-open-at-mouse)) mouse-face highlight) 81 86 (font-lock-fontified t face org-drawer))) :value nil :explanation (arrays-of-different-length 85 87 "* Foo\n:LOGBOOK:\nCLOCK: [2022-11-03 Thu 06:00]--[2022-11-03 Thu 06:01] =>  0:01\n:END:\n" #("* Foo\n:LOGBOOK:\nCLOCK: [2022-11-03 jeu. 06:00]--[2022-11-03 jeu. 06:01] =>  0:01\n:END:\n" 0 2 (face org-level-1) 2 5 (face org-level-1) 6 15 (font-lock-fontified t face org-drawer) 16 22 (face org-special-keyword) 46 71 (face org-date keymap (keymap (follow-link . mouse-face) (mouse-3 . org-find-file-at-mouse) (mouse-2 . org-open-at-mouse)) mouse-face highlight) 81 86 (font-lock-fontified t face org-drawer)) first-mismatch-at 35))
   FAILED  test-org-clok/org-clock-timestamps-change  "Not at a timestamp"

[-- Attachment #5: Type: text/plain, Size: 134 bytes --]


-- 
Best,


RY

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

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: Test failure due to LANG
  2023-04-22  7:11 Test failure due to LANG Axel Kielhorn
  2023-04-22  9:51 ` Ruijie Yu via General discussions about Org-mode.
@ 2023-04-22 12:35 ` Ihor Radchenko
  2023-04-22 13:00   ` Ruijie Yu via General discussions about Org-mode.
                     ` (2 more replies)
  1 sibling, 3 replies; 34+ messages in thread
From: Ihor Radchenko @ 2023-04-22 12:35 UTC (permalink / raw)
  To: Axel Kielhorn; +Cc: Org-Mode Mailing List

Axel Kielhorn <org-mode@axelkielhorn.de> writes:

> I’m building org with LANG=de.
> As a result I get two failed tests:
>
> ...
> "* Foo\n:LOGBOOK:\nCLOCK: [2022-11-03 Thu 06:00]--[2022-11-03 Thu 06:01] =>  0:01\n:END:\n" #(
> "* Foo\n:LOGBOOK:\nCLOCK: [2022-11-03 Do 06:00]--[2022-11-03 Do 06:01] =>  0:01\n:END:\n" 
> ...
> "CLOCK: [2023-02-19 Sun 21:30]--[2023-02-19 Sun 23:35] =>  2:05" #(
> "CLOCK: [2023-02-19 So 21:30]--[2023-02-19 So 23:35] =>  2:05" 

I guess we can explicitly specify LANG in these tests.
Though I am not 100% how because I cannot reproduce on my Linux.

May you try

(with-environment-variables (("LANG" "de"))
  (format-time-string "%A"))
(with-environment-variables (("LANG" "en"))
  (format-time-string "%A"))

and report the output?
(For me, it is all same...)

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: Test failure due to LANG
  2023-04-22 10:15   ` Ruijie Yu via General discussions about Org-mode.
@ 2023-04-22 12:37     ` Ruijie Yu via General discussions about Org-mode.
  2023-04-22 13:01       ` [DRAFT PATCH v2] Decouple LANG= and testing (was: Test failure due to LANG) Ruijie Yu via General discussions about Org-mode.
  2023-04-22 14:28       ` Test failure due to LANG Axel Kielhorn
  0 siblings, 2 replies; 34+ messages in thread
From: Ruijie Yu via General discussions about Org-mode. @ 2023-04-22 12:37 UTC (permalink / raw)
  To: Ruijie Yu; +Cc: Axel Kielhorn, emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1760 bytes --]


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

> Ruijie Yu via "General discussions about Org-mode." <emacs-orgmode@gnu.org> writes:
>
>> Axel Kielhorn <org-mode@axelkielhorn.de> writes:
>>
>>> Hello!
>>>
>>> I’m building org with LANG=de.
>>> As a result I get two failed tests:
>>
>> Reproducible using "LANG=zh_CN.UTF-8".  In fact, I got more failed tests
>> in my testing.  I think the OP's two test failures are due to hardcoded
>> English expected result, whereas the additional test failures on my
>> testing are probably due to the fact that each Chinese character is as
>> wide as two latin letters, which catches some testing code offguard.
>>
>> Here are the test names that failed unexpectedly for me.  All the
>> "should"'s and "should-not"'s are in the attachment below.
>>
>> --8<---------------cut here---------------start------------->8---
>> 8 unexpected results:
>>    FAILED  test-org-clock/clock-drawer-dwim
>>    FAILED  test-org-clock/clocktable/lang
>>    FAILED  test-org-clok/org-clock-timestamps-change
>>    FAILED  test-org-colview/columns-width
>>    FAILED  test-org/add-planning-info
>>    FAILED  test-org/clone-with-time-shift
>>    FAILED  test-org/deadline
>>    FAILED  test-org/schedule
>> --8<---------------cut here---------------end--------------->8---
>>
>> [3. text/plain; lang.txt]...
>
> Update: interestingly, there is one test error when setting
> "LANG=en_US.UTF-8" or "LANG=C".
>
> [2. text/plain; lang-en-us-utf8.txt]...
>
>
> And, two somewhat different test errors when setting "LANG=fr_FR.UTF-8".
>
> [4. text/plain; lang-fr-fr-utf8.txt]...

Axel, does this patch fix test-org-clock/clock-drawer-dwim on your
system?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-testing-lisp-test-org-clock.el.patch --]
[-- Type: text/x-patch, Size: 1050 bytes --]

From e223381ca670f99e6f6d69a7920923e2ad5ea91c Mon Sep 17 00:00:00 2001
From: Ruijie Yu <ruijie@netyu.xyz>
Date: Sat, 22 Apr 2023 20:36:18 +0800
Subject: [PATCH] * testing/lisp/test-org-clock.el

Avoid hard-coded values where locales play a significant role.
---
 testing/lisp/test-org-clock.el | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/testing/lisp/test-org-clock.el b/testing/lisp/test-org-clock.el
index 7d8123e1f..3f587ce05 100644
--- a/testing/lisp/test-org-clock.el
+++ b/testing/lisp/test-org-clock.el
@@ -299,11 +299,12 @@ the buffer."
 
 (ert-deftest test-org-clock/clock-drawer-dwim ()
   "Test DWIM update of days for clocks in logbook drawers."
-  (should (equal "* Foo
+  (should (equal (let ((thu (format-time-string "%a" 1000)))
+                   (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:
-"
+" thu thu))
          (org-test-with-temp-text
              "* Foo
 :LOGBOOK:
-- 
2.40.0


[-- Attachment #3: Type: text/plain, Size: 134 bytes --]


-- 
Best,


RY

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

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* Re: Test failure due to LANG
  2023-04-22 12:35 ` Ihor Radchenko
@ 2023-04-22 13:00   ` Ruijie Yu via General discussions about Org-mode.
  2023-04-22 14:21   ` Max Nikulin
  2023-04-22 14:36   ` Axel Kielhorn
  2 siblings, 0 replies; 34+ messages in thread
From: Ruijie Yu via General discussions about Org-mode. @ 2023-04-22 13:00 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Axel Kielhorn, emacs-orgmode


Ihor Radchenko <yantar92@posteo.net> writes:

> Axel Kielhorn <org-mode@axelkielhorn.de> writes:
>
>> I’m building org with LANG=de.
>> As a result I get two failed tests:
>>
>> ...
>> "* Foo\n:LOGBOOK:\nCLOCK: [2022-11-03 Thu 06:00]--[2022-11-03 Thu 06:01] =>  0:01\n:END:\n" #(
>> "* Foo\n:LOGBOOK:\nCLOCK: [2022-11-03 Do 06:00]--[2022-11-03 Do 06:01] =>  0:01\n:END:\n" 
>> ...
>> "CLOCK: [2023-02-19 Sun 21:30]--[2023-02-19 Sun 23:35] =>  2:05" #(
>> "CLOCK: [2023-02-19 So 21:30]--[2023-02-19 So 23:35] =>  2:05" 
>
> I guess we can explicitly specify LANG in these tests.
> Though I am not 100% how because I cannot reproduce on my Linux.
>
> May you try
>
> (with-environment-variables (("LANG" "de"))
>   (format-time-string "%A"))
> (with-environment-variables (("LANG" "en"))
>   (format-time-string "%A"))
>
> and report the output?
> (For me, it is all same...)

I think it is still important to try different locales, like the test
failures I found using zh_CN.UTF-8 (in the other subthread) which would
not be uncovered if you only assume one single locale.  I am working on
a patch that would hopefully help in this regard, which I will post
under the other subthread.

-- 
Best,


RY

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


^ permalink raw reply	[flat|nested] 34+ messages in thread

* [DRAFT PATCH v2] Decouple LANG= and testing (was: Test failure due to LANG)
  2023-04-22 12:37     ` Ruijie Yu via General discussions about Org-mode.
@ 2023-04-22 13:01       ` Ruijie Yu via General discussions about Org-mode.
  2023-04-22 13:51         ` Ruijie Yu via General discussions about Org-mode.
  2023-04-22 14:50         ` Axel Kielhorn
  2023-04-22 14:28       ` Test failure due to LANG Axel Kielhorn
  1 sibling, 2 replies; 34+ messages in thread
From: Ruijie Yu via General discussions about Org-mode. @ 2023-04-22 13:01 UTC (permalink / raw)
  To: Ruijie Yu; +Cc: Axel Kielhorn, emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 2201 bytes --]


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

> Ruijie Yu via "General discussions about Org-mode." <emacs-orgmode@gnu.org> writes:
>
>> Ruijie Yu via "General discussions about Org-mode." <emacs-orgmode@gnu.org> writes:
>>
>>> Axel Kielhorn <org-mode@axelkielhorn.de> writes:
>>>
>>>> Hello!
>>>>
>>>> I’m building org with LANG=de.
>>>> As a result I get two failed tests:
>>>
>>> Reproducible using "LANG=zh_CN.UTF-8".  In fact, I got more failed tests
>>> in my testing.  I think the OP's two test failures are due to hardcoded
>>> English expected result, whereas the additional test failures on my
>>> testing are probably due to the fact that each Chinese character is as
>>> wide as two latin letters, which catches some testing code offguard.
>>>
>>> Here are the test names that failed unexpectedly for me.  All the
>>> "should"'s and "should-not"'s are in the attachment below.
>>>
>>> --8<---------------cut here---------------start------------->8---
>>> 8 unexpected results:
>>>    FAILED  test-org-clock/clock-drawer-dwim
>>>    FAILED  test-org-clock/clocktable/lang
>>>    FAILED  test-org-clok/org-clock-timestamps-change
>>>    FAILED  test-org-colview/columns-width
>>>    FAILED  test-org/add-planning-info
>>>    FAILED  test-org/clone-with-time-shift
>>>    FAILED  test-org/deadline
>>>    FAILED  test-org/schedule
>>> --8<---------------cut here---------------end--------------->8---
>>>
>>> [3. text/plain; lang.txt]...
>>
>> Update: interestingly, there is one test error when setting
>> "LANG=en_US.UTF-8" or "LANG=C".
>>
>> [2. text/plain; lang-en-us-utf8.txt]...
>>
>>
>> And, two somewhat different test errors when setting "LANG=fr_FR.UTF-8".
>>
>> [4. text/plain; lang-fr-fr-utf8.txt]...
>
> Axel, does this patch fix test-org-clock/clock-drawer-dwim on your
> system?
>
> [2. text/x-patch; 0001-testing-lisp-test-org-clock.el.patch]...

Here is an updated patch (replacing the first iteration).  This should
hopefully fix both test failures that Axel found.  Once this is
confirmed good, I will look at the test failures of the other languages
to see what I can do.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-DRAFT-Fix-dependence-on-locale-in-org-testing-facili.patch --]
[-- Type: text/x-patch, Size: 5115 bytes --]

From aed711f260b7214e7264df63e3154f4a75e5c5e5 Mon Sep 17 00:00:00 2001
From: Ruijie Yu <ruijie@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            | 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 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))))))
 
 \f
 ;;; 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))))))
 
 \f
 ;;; 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


[-- Attachment #3: Type: text/plain, Size: 134 bytes --]


-- 
Best,


RY

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

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* Re: [DRAFT PATCH v2] Decouple LANG= and testing (was: Test failure due to LANG)
  2023-04-22 13:01       ` [DRAFT PATCH v2] Decouple LANG= and testing (was: Test failure due to LANG) Ruijie Yu via General discussions about Org-mode.
@ 2023-04-22 13:51         ` Ruijie Yu via General discussions about Org-mode.
  2023-04-23 10:54           ` Ihor Radchenko
  2023-04-22 14:50         ` Axel Kielhorn
  1 sibling, 1 reply; 34+ messages in thread
From: Ruijie Yu via General discussions about Org-mode. @ 2023-04-22 13:51 UTC (permalink / raw)
  To: Ruijie Yu; +Cc: Axel Kielhorn, emacs-orgmode


Ruijie Yu <ruijie@netyu.xyz> writes:

> Here is an updated patch (replacing the first iteration).  This should
> hopefully fix both test failures that Axel found.  Once this is
> confirmed good, I will look at the test failures of the other languages
> to see what I can do.
>
> [2. text/x-patch; 0001-DRAFT-Fix-dependence-on-locale-in-org-testing-facili.patch]...

More updates.

First, I noticed that `test-org-clock/clocktable/lang' may fail
depending on the value of `org-hide-emphasis-markers'.

Second, `org-columns--overlay-text' has a problem where

    (format "%-5.5s |" "1234…")

returns different results for different locales, causing
`test-org-colview/columns-width' to break.  I stepped over the test and
found that everything, including `org-columns-add-ellipses', works fine
until we hit the `format'.

Okay, digging into these issues took me some effort so I might just call
it a day for now.  Will continue looking into it within 48 hours,
though.

-- 
Best,


RY

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


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: Test failure due to LANG
  2023-04-22 12:35 ` Ihor Radchenko
  2023-04-22 13:00   ` Ruijie Yu via General discussions about Org-mode.
@ 2023-04-22 14:21   ` Max Nikulin
  2023-04-22 14:35     ` Ihor Radchenko
  2023-04-22 14:40     ` Axel Kielhorn
  2023-04-22 14:36   ` Axel Kielhorn
  2 siblings, 2 replies; 34+ messages in thread
From: Max Nikulin @ 2023-04-22 14:21 UTC (permalink / raw)
  To: emacs-orgmode

On 22/04/2023 19:35, Ihor Radchenko wrote:
> Axel Kielhorn writes:
>> "* Foo\n:LOGBOOK:\nCLOCK: [2022-11-03 Thu 06:00]--[2022-11-03 Thu 06:01] =>  0:01\n:END:\n" #(
>> "* Foo\n:LOGBOOK:\nCLOCK: [2022-11-03 Do 06:00]--[2022-11-03 Do 06:01] =>  0:01\n:END:\n"
> 
> (with-environment-variables (("LANG" "de"))
>    (format-time-string "%A"))
> (with-environment-variables (("LANG" "en"))
>    (format-time-string "%A"))

("LC_TIME" "de_DE.UTF-8")

Since it is related to dates or even "LC_ALL". E.g. Ubuntu installer may 
configure LC_TIME overriding LANG. Some users may have LC_ALL that 
overrides specific LC_* variable and LANG.




^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: Test failure due to LANG
  2023-04-22 12:37     ` Ruijie Yu via General discussions about Org-mode.
  2023-04-22 13:01       ` [DRAFT PATCH v2] Decouple LANG= and testing (was: Test failure due to LANG) Ruijie Yu via General discussions about Org-mode.
@ 2023-04-22 14:28       ` Axel Kielhorn
  1 sibling, 0 replies; 34+ messages in thread
From: Axel Kielhorn @ 2023-04-22 14:28 UTC (permalink / raw)
  To: Org-Mode Mailing List


> Am 22.04.2023 um 14:37 schrieb Ruijie Yu <ruijie@netyu.xyz>:
> 
> 
> 
> Axel, does this patch fix test-org-clock/clock-drawer-dwim on your
> system?
> 
> <0001-testing-lisp-test-org-clock.el.patch>

Yes it does, thanks.

Axel



^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: Test failure due to LANG
  2023-04-22 14:21   ` Max Nikulin
@ 2023-04-22 14:35     ` Ihor Radchenko
  2023-04-22 14:40     ` Axel Kielhorn
  1 sibling, 0 replies; 34+ messages in thread
From: Ihor Radchenko @ 2023-04-22 14:35 UTC (permalink / raw)
  To: Max Nikulin; +Cc: emacs-orgmode

Max Nikulin <manikulin@gmail.com> writes:

>> (with-environment-variables (("LANG" "de"))
>>    (format-time-string "%A"))
>> (with-environment-variables (("LANG" "en"))
>>    (format-time-string "%A"))
>
> ("LC_TIME" "de_DE.UTF-8")
>
> Since it is related to dates or even "LC_ALL". E.g. Ubuntu installer may 
> configure LC_TIME overriding LANG. Some users may have LC_ALL that 
> overrides specific LC_* variable and LANG.

I guess it will also depend on whether the requested locales are
generated. I only generated "en" on my system, so even setting LC_TIME
will change nothing for me as the only available locale is used
regardless.

I now think that overriding the locale is not reliable in practice.
Ruijie's idea may be better.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: Test failure due to LANG
  2023-04-22 12:35 ` Ihor Radchenko
  2023-04-22 13:00   ` Ruijie Yu via General discussions about Org-mode.
  2023-04-22 14:21   ` Max Nikulin
@ 2023-04-22 14:36   ` Axel Kielhorn
  2 siblings, 0 replies; 34+ messages in thread
From: Axel Kielhorn @ 2023-04-22 14:36 UTC (permalink / raw)
  To: Org-Mode Mailing List



> Am 22.04.2023 um 14:35 schrieb Ihor Radchenko <yantar92@posteo.net>:
> 
> 
> (with-environment-variables (("LANG" "de"))
>  (format-time-string "%A"))
> (with-environment-variables (("LANG" "en"))
>  (format-time-string "%A“))

When I start Emacs from a shell with LANG=de I get „Samstag“ in both cases.
When I start with LANG=C I get „Saturday“ in both cases.

Axel

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: Test failure due to LANG
  2023-04-22 14:21   ` Max Nikulin
  2023-04-22 14:35     ` Ihor Radchenko
@ 2023-04-22 14:40     ` Axel Kielhorn
  2023-04-22 16:14       ` Max Nikulin
  1 sibling, 1 reply; 34+ messages in thread
From: Axel Kielhorn @ 2023-04-22 14:40 UTC (permalink / raw)
  To: Org-Mode Mailing List



> Am 22.04.2023 um 16:21 schrieb Max Nikulin <manikulin@gmail.com>:
> 
> On 22/04/2023 19:35, Ihor Radchenko wrote:
>> Axel Kielhorn writes:
>>> "* Foo\n:LOGBOOK:\nCLOCK: [2022-11-03 Thu 06:00]--[2022-11-03 Thu 06:01] =>  0:01\n:END:\n" #(
>>> "* Foo\n:LOGBOOK:\nCLOCK: [2022-11-03 Do 06:00]--[2022-11-03 Do 06:01] =>  0:01\n:END:\n"
>> (with-environment-variables (("LANG" "de"))
>>   (format-time-string "%A"))
>> (with-environment-variables (("LANG" "en"))
>>   (format-time-string "%A"))
> 
> ("LC_TIME" "de_DE.UTF-8")
> 
> Since it is related to dates or even "LC_ALL". E.g. Ubuntu installer may configure LC_TIME overriding LANG. Some users may have LC_ALL that overrides specific LC_* variable and LANG.

(with-environment-variables (("LC_TIME" "de_DE.UTF-8"))
 (format-time-string "%A“))

Still results in „Saturday“ when I start emacs from a shell with LANG=C.

Axel

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [DRAFT PATCH v2] Decouple LANG= and testing (was: Test failure due to LANG)
  2023-04-22 13:01       ` [DRAFT PATCH v2] Decouple LANG= and testing (was: Test failure due to LANG) Ruijie Yu via General discussions about Org-mode.
  2023-04-22 13:51         ` Ruijie Yu via General discussions about Org-mode.
@ 2023-04-22 14:50         ` Axel Kielhorn
  2023-04-22 15:03           ` Ruijie Yu via General discussions about Org-mode.
  1 sibling, 1 reply; 34+ messages in thread
From: Axel Kielhorn @ 2023-04-22 14:50 UTC (permalink / raw)
  To: Org-Mode Mailing List



> Am 22.04.2023 um 15:01 schrieb Ruijie Yu via General discussions about Org-mode. <emacs-orgmode@gnu.org>:
> 
> 
> Ruijie Yu via "General discussions about Org-mode." <emacs-orgmode@gnu.org> writes:
> 
>> Ruijie Yu via "General discussions about Org-mode." <emacs-orgmode@gnu.org> writes:
>> 
>>> Ruijie Yu via "General discussions about Org-mode." <emacs-orgmode@gnu.org> writes:
>>> 
>>>> Axel Kielhorn <org-mode@axelkielhorn.de> writes:
>>>> 
>>>>> Hello!
>>>>> 
>>>>> I’m building org with LANG=de.
>>>>> As a result I get two failed tests:
>>>> 
>>>> Reproducible using "LANG=zh_CN.UTF-8".  In fact, I got more failed tests
>>>> in my testing.  I think the OP's two test failures are due to hardcoded
>>>> English expected result, whereas the additional test failures on my
>>>> testing are probably due to the fact that each Chinese character is as
>>>> wide as two latin letters, which catches some testing code offguard.
>>>> 
>>>> Here are the test names that failed unexpectedly for me.  All the
>>>> "should"'s and "should-not"'s are in the attachment below.
>>>> 
>>>> --8<---------------cut here---------------start------------->8---
>>>> 8 unexpected results:
>>>>   FAILED  test-org-clock/clock-drawer-dwim
>>>>   FAILED  test-org-clock/clocktable/lang
>>>>   FAILED  test-org-clok/org-clock-timestamps-change
>>>>   FAILED  test-org-colview/columns-width
>>>>   FAILED  test-org/add-planning-info
>>>>   FAILED  test-org/clone-with-time-shift
>>>>   FAILED  test-org/deadline
>>>>   FAILED  test-org/schedule
>>>> --8<---------------cut here---------------end--------------->8---
>>>> 
>>>> [3. text/plain; lang.txt]...
>>> 
>>> Update: interestingly, there is one test error when setting
>>> "LANG=en_US.UTF-8" or "LANG=C".
>>> 
>>> [2. text/plain; lang-en-us-utf8.txt]...
>>> 
>>> 
>>> And, two somewhat different test errors when setting "LANG=fr_FR.UTF-8".
>>> 
>>> [4. text/plain; lang-fr-fr-utf8.txt]...
>> 
>> Axel, does this patch fix test-org-clock/clock-drawer-dwim on your
>> system?
>> 
>> [2. text/x-patch; 0001-testing-lisp-test-org-clock.el.patch]...
> 
> Here is an updated patch (replacing the first iteration).  This should
> hopefully fix both test failures that Axel found.  Once this is
> confirmed good, I will look at the test failures of the other languages
> to see what I can do.
> 
> <0001-DRAFT-Fix-dependence-on-locale-in-org-testing-facili.patch>


With this patch I get:
   FAILED  test-org-clock/clock-drawer-dwim  arrayp
   FAILED  test-org-clok/org-clock-timestamps-change  arrayp

Axel



^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [DRAFT PATCH v2] Decouple LANG= and testing (was: Test failure due to LANG)
  2023-04-22 14:50         ` Axel Kielhorn
@ 2023-04-22 15:03           ` Ruijie Yu via General discussions about Org-mode.
  2023-04-23  1:47             ` [DRAFT PATCH v3] " Ruijie Yu via General discussions about Org-mode.
  0 siblings, 1 reply; 34+ messages in thread
From: Ruijie Yu via General discussions about Org-mode. @ 2023-04-22 15:03 UTC (permalink / raw)
  To: Axel Kielhorn; +Cc: emacs-orgmode


Axel Kielhorn <org-mode@axelkielhorn.de> writes:

>> Am 22.04.2023 um 15:01 schrieb Ruijie Yu via General discussions about Org-mode. <emacs-orgmode@gnu.org>:
>> 
>> 
>> Ruijie Yu via "General discussions about Org-mode." <emacs-orgmode@gnu.org> writes:
>> 
>>> Ruijie Yu via "General discussions about Org-mode." <emacs-orgmode@gnu.org> writes:
>>> 
>>>> Ruijie Yu via "General discussions about Org-mode." <emacs-orgmode@gnu.org> writes:
>>>> 
>>>>> Axel Kielhorn <org-mode@axelkielhorn.de> writes:
>>>>> 
>>>>>> Hello!
>>>>>> 
>>>>>> I’m building org with LANG=de.
>>>>>> As a result I get two failed tests:
>>>>> 
>>>>> Reproducible using "LANG=zh_CN.UTF-8".  In fact, I got more failed tests
>>>>> in my testing.  I think the OP's two test failures are due to hardcoded
>>>>> English expected result, whereas the additional test failures on my
>>>>> testing are probably due to the fact that each Chinese character is as
>>>>> wide as two latin letters, which catches some testing code offguard.
>>>>> 
>>>>> Here are the test names that failed unexpectedly for me.  All the
>>>>> "should"'s and "should-not"'s are in the attachment below.
>>>>> 
>>>>> --8<---------------cut here---------------start------------->8---
>>>>> 8 unexpected results:
>>>>>   FAILED  test-org-clock/clock-drawer-dwim
>>>>>   FAILED  test-org-clock/clocktable/lang
>>>>>   FAILED  test-org-clok/org-clock-timestamps-change
>>>>>   FAILED  test-org-colview/columns-width
>>>>>   FAILED  test-org/add-planning-info
>>>>>   FAILED  test-org/clone-with-time-shift
>>>>>   FAILED  test-org/deadline
>>>>>   FAILED  test-org/schedule
>>>>> --8<---------------cut here---------------end--------------->8---
>>>>> 
>>>>> [3. text/plain; lang.txt]...
>>>> 
>>>> Update: interestingly, there is one test error when setting
>>>> "LANG=en_US.UTF-8" or "LANG=C".
>>>> 
>>>> [2. text/plain; lang-en-us-utf8.txt]...
>>>> 
>>>> 
>>>> And, two somewhat different test errors when setting "LANG=fr_FR.UTF-8".
>>>> 
>>>> [4. text/plain; lang-fr-fr-utf8.txt]...
>>> 
>>> Axel, does this patch fix test-org-clock/clock-drawer-dwim on your
>>> system?
>>> 
>>> [2. text/x-patch; 0001-testing-lisp-test-org-clock.el.patch]...
>> 
>> Here is an updated patch (replacing the first iteration).  This should
>> hopefully fix both test failures that Axel found.  Once this is
>> confirmed good, I will look at the test failures of the other languages
>> to see what I can do.
>> 
>> <0001-DRAFT-Fix-dependence-on-locale-in-org-testing-facili.patch>
>
>
> 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.


-- 
Best,


RY

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


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: Test failure due to LANG
  2023-04-22 14:40     ` Axel Kielhorn
@ 2023-04-22 16:14       ` Max Nikulin
  0 siblings, 0 replies; 34+ messages in thread
From: Max Nikulin @ 2023-04-22 16:14 UTC (permalink / raw)
  To: emacs-orgmode

On 22/04/2023 21:40, Axel Kielhorn wrote:
> (with-environment-variables (("LC_TIME" "de_DE.UTF-8"))
>   (format-time-string "%A“))
> 
> Still results in „Saturday“ when I start emacs from a shell with LANG=C.

Changing environment variable while process is running is not enough. 
There is a dedicated function

     (set-locale-environment "POSIX")

I suppose, forcing "C.UTF-8" should work for tests.



^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [DRAFT PATCH v3] Decouple LANG= and testing (was: Test failure due to LANG)
  2023-04-22 15:03           ` Ruijie Yu via General discussions about Org-mode.
@ 2023-04-23  1:47             ` Ruijie Yu via General discussions about Org-mode.
  2023-04-23  5:36               ` Axel Kielhorn
  0 siblings, 1 reply; 34+ messages in thread
From: Ruijie Yu via General discussions about Org-mode. @ 2023-04-23  1:47 UTC (permalink / raw)
  To: Axel Kielhorn; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 437 bytes --]


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

> Axel Kielhorn <org-mode@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?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-DRAFT-Fix-dependence-on-locale-in-org-testing-facili.patch --]
[-- Type: text/x-patch, Size: 5276 bytes --]

From 7621108e377c71cf083389e7bdb6f9d76cd07461 Mon Sep 17 00:00:00 2001
From: Ruijie Yu <ruijie@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))))))
 
 \f
 ;;; 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))))))
 
 \f
 ;;; 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


[-- Attachment #3: Type: text/plain, Size: 134 bytes --]


-- 
Best,


RY

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

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* Re: [DRAFT PATCH v3] Decouple LANG= and testing (was: Test failure due to LANG)
  2023-04-23  1:47             ` [DRAFT PATCH v3] " Ruijie Yu via General discussions about Org-mode.
@ 2023-04-23  5:36               ` Axel Kielhorn
  2023-04-23  6:46                 ` [DRAFT PATCH v4] " Ruijie Yu via General discussions about Org-mode.
  0 siblings, 1 reply; 34+ messages in thread
From: Axel Kielhorn @ 2023-04-23  5:36 UTC (permalink / raw)
  To: Org-Mode Mailing List



> Am 23.04.2023 um 03:47 schrieb Ruijie Yu via General discussions about Org-mode. <emacs-orgmode@gnu.org>:
> 
> 
> Ruijie Yu via "General discussions about Org-mode." <emacs-orgmode@gnu.org> writes:
> 
>> Axel Kielhorn <org-mode@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?
> 
> <0001-DRAFT-Fix-dependence-on-locale-in-org-testing-facili.patch>

This works for me, thanks.

Axel



^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [DRAFT PATCH v4] Decouple LANG= and testing (was: Test failure due to LANG)
  2023-04-23  5:36               ` Axel Kielhorn
@ 2023-04-23  6:46                 ` Ruijie Yu via General discussions about Org-mode.
  2023-04-23 11:17                   ` Ihor Radchenko
  0 siblings, 1 reply; 34+ messages in thread
From: Ruijie Yu via General discussions about Org-mode. @ 2023-04-23  6:46 UTC (permalink / raw)
  To: Axel Kielhorn; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 2670 bytes --]


Axel Kielhorn <org-mode@axelkielhorn.de> writes:

>> Am 23.04.2023 um 03:47 schrieb Ruijie Yu via General discussions about Org-mode. <emacs-orgmode@gnu.org>:
>> 
>> 
>> Ruijie Yu via "General discussions about Org-mode." <emacs-orgmode@gnu.org> writes:
>> 
>>> Axel Kielhorn <org-mode@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?
>> 
>> <0001-DRAFT-Fix-dependence-on-locale-in-org-testing-facili.patch>
>
> This works for me, thanks.
>
> Axel

Thank you for confirming that it works.

The following is an update of my progress trying to fix all issues I
found when I tested against different $LANG values.

I was able to iron out most of the errors found in my testing on
zh_CN.UTF-8.  The amount of unexpected failures went down from 8 to 2.

I also noticed that new errors are introduced in LANG=fr_FR.UTF-8 (was
1, now 5), so I will take a look at that for the next iteration.

Something very troublesome for me is `test-org-clock/clocktable/lang' on
zh_CN.UTF-8.  What I noticed is that when I run this test in batch mode
(one of the two methods below), it fails:

$ LANG=zh_CN.UTF-8 make test
$ LANG=zh_CN.UTF-8 emacs -Q -nw -batch \
                   -L lisp -L testing/lisp \
                   -l ert \
                   -l testing/org-test.el \
                   -l testing/lisp/test-org-clock.el \
                   -f ert-run-tests-batch-and-exit

Whereas when I run it interactively, it succeeds:

$ LANG=zh_CN.UTF-8 emacs -Q -nw \
                   -L lisp -L testing/lisp \
                   -l ert \
                   -l testing/org-test.el \
                   -l testing/lisp/test-org-clock.el

    M-x ert-i test-org-clock/clocktable/lang RET

Not sure what to make of it just yet.

The other failure I got in zh_CN.UTF-8 is
`test-org-colview/columns-width', as I mentioned somewhere up-thread.
It is caused by this s-exp:

    (format "%-5.5s |" "1234…")

which returns "1234… |" when locale is en_US.UTF-8 or fr_FR.UTF-8, and
"1234 |" when locale is zh_CN.UTF-8 or ja_JA.UTF-8.

I think it might be due to the "perceived width" of the ellipsis, or
something?

Anyways, this is enough progress for now.  Here is the 4th iteration.
Note the very big rx regexp, where I asked in another thread whether my
understanding of a timestamp is complete.  Thanks.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-DRAFT-Fix-dependence-on-locale-in-org-testing-facili.patch --]
[-- Type: text/x-patch, Size: 24735 bytes --]

From d8525132d3f90623a6e8c732bd2a580ba23a2156 Mon Sep 17 00:00:00 2001
From: Ruijie Yu <ruijie@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.el org-test-timestamp-regexp: make a comprehensive
timestamp regexp for testing.
(test-org/clone-with-time-shift): (test-org/add-planning-info):
(test-org/deadline): (test-org/schedule): replace the regexps which try to match
the DoW string in a timestamp into using `org-test-timestamp-regexp'.
---
 testing/lisp/test-org-clock.el |  62 +++++----
 testing/lisp/test-org.el       | 231 +++++++++++++++++----------------
 testing/org-test.el            |  25 ++++
 3 files changed, 177 insertions(+), 141 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))))))
 
 \f
 ;;; 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))))))
 
 \f
 ;;; Clocktable
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index d7c801fe5..cc06322f3 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -29,6 +29,65 @@
 (require 'org-refile)
 (require 'org-agenda)
 
+\f
+;;; Regexps
+
+(defconst org-test-timestamp-regexp
+  (rx (any ?\< ?\[)                     ; < or [
+      (group-n 200                      ; YEAR-MONTH-DATE
+        (group-n 100 (= 4 digit)) ?-
+        (group-n 101 (= 2 digit)) ?-
+        (group-n 102 (= 2 digit)))
+      (group-n 210                      ; SPC DOW
+        " " (group-n 110 bow (+ letter) eow))
+      (opt                              ; SPC HOUR:MINUTE
+       (group-n 221
+         " "
+         (group-n 220
+           (group-n 120 (= 2 digit)) ?:
+           (group-n 121 (= 2 digit)))))
+      (opt                              ; repeater: +{1,2}AMOUNTunit
+       (group-n 232
+         " "
+         (group-n 231
+           (group-n 132 (** 1 2 ?+))
+           (group-n 230
+             (group-n 130 (+ digit))
+             (group-n 131 (any "hdmwy"))))))
+      (opt                              ; warning period: -AMOUNTunit
+       (group-n 242
+         " "
+         (group-n 241
+           ?-
+           (group-n 240
+             (group-n 140 (+ digit))
+             (group-n 141 (any "hdmwy"))))))
+      (any ?\> ?\]))
+  "A (hopefully) comprehensive timestamp regexp.
+Each individual component is contained in a group, described below.
+
+- 100: year
+- 101: month
+- 102: day-of-month
+- 110: day-of-week
+- 120: hour (if available)
+- 121: minute (if available)
+- 130: the repeater amount (if available)
+- 131: the repeater unit (if available)
+- 132: the repeater \"+\" or \"++\" (if available)
+- 140: the warning period amount (if available)
+- 141: the warning period unit (if available)
+- 200: full year-month-date portion
+- 210: day-of-week including preceding space
+- 220: full time (hour:minute) portion
+- 221: full time portion including preceding space
+- 230: repeater amount + unit
+- 231: repeater, with preceding \"+\" or \"++\"
+- 232: repeater, with preceding \" +\" or \" ++\"
+- 240: warning period amount + unit
+- 241: warning period with \"-\"
+- 242: warning period with \" -\"")
+
 \f
 ;;; Helpers
 
@@ -43,6 +102,13 @@
              ,@body)
              (setenv "TZ" ,tz-saved)))))
 
+(defun org-test-drop-dow-from-timestamp ()
+  "Drop dow from timestamps for testing within a buffer.
+Return the buffer string."
+  (replace-regexp-in-string
+   org-test-timestamp-regexp ""
+   (buffer-string) nil nil 210))
+
 \f
 ;;; Comments
 
@@ -2015,9 +2081,7 @@ CLOCK: [2022-09-17 sam. 11:00]--[2022-09-17 sam. 11:46] =>  0:46"
 "
 	  (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
 	    (org-clone-subtree-with-time-shift 1 "+2d")
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
-	     nil nil 1))))
+            (org-test-drop-dow-from-timestamp))))
   ;; Clone repeating once.
   (should
    (equal "\
@@ -2027,9 +2091,7 @@ CLOCK: [2022-09-17 sam. 11:00]--[2022-09-17 sam. 11:46] =>  0:46"
 "
 	  (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
 	    (org-clone-subtree-with-time-shift 1 "+2d")
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
-	     nil nil 1))))
+            (org-test-drop-dow-from-timestamp))))
   ;; Clone repeating once in backward.
   (should
    (equal "\
@@ -2039,9 +2101,7 @@ CLOCK: [2022-09-17 sam. 11:00]--[2022-09-17 sam. 11:46] =>  0:46"
 "
 	  (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
 	    (org-clone-subtree-with-time-shift 1 "-2d")
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
-	     nil nil 1))))
+            (org-test-drop-dow-from-timestamp))))
   ;; Clone non-repeating zero times.
   (should
    (equal "\
@@ -2049,9 +2109,7 @@ CLOCK: [2022-09-17 sam. 11:00]--[2022-09-17 sam. 11:46] =>  0:46"
 "
 	  (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
 	    (org-clone-subtree-with-time-shift 0 "+2d")
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
-	     nil nil 1))))
+            (org-test-drop-dow-from-timestamp))))
   ;; Clone repeating "zero" times.
   (should
    (equal "\
@@ -2060,9 +2118,7 @@ CLOCK: [2022-09-17 sam. 11:00]--[2022-09-17 sam. 11:46] =>  0:46"
 "
 	  (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
 	    (org-clone-subtree-with-time-shift 0 "+2d")
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
-	     nil nil 1))))
+            (org-test-drop-dow-from-timestamp))))
   ;; Clone with blank SHIFT argument.
   (should
    (string-prefix-p
@@ -2098,10 +2154,7 @@ CLOCK: [2022-09-17 sam. 11:00]--[2022-09-17 sam. 11:46] =>  0:46"
 "
           (org-test-with-temp-text "* H1\n<2015-06-21 Sun 20:00>"
             (org-clone-subtree-with-time-shift 2 "+3h")
-            (replace-regexp-in-string
-             "\\( [.A-Za-z]+\\)\\( [0-9][0-9]:[0-9][0-9]\\)?>" ""
-             (buffer-substring-no-properties (point-min) (point-max))
-             nil nil 1))))
+            (org-test-drop-dow-from-timestamp))))
   (should
    (equal "\
 * H1\n<2015-06-21 20:00>
@@ -2109,10 +2162,7 @@ CLOCK: [2022-09-17 sam. 11:00]--[2022-09-17 sam. 11:46] =>  0:46"
 "
           (org-test-with-temp-text "* H1\n<2015-06-21 Sun 20:00>"
             (org-clone-subtree-with-time-shift 1 "-2h")
-            (replace-regexp-in-string
-             "\\( [.A-Za-z]+\\)\\( [0-9][0-9]:[0-9][0-9]\\)?>" ""
-             (buffer-substring-no-properties (point-min) (point-max))
-             nil nil 1)))))
+            (org-test-drop-dow-from-timestamp)))))
 
 \f
 ;;; Fixed-Width Areas
@@ -5629,18 +5679,14 @@ Text.
 	  (org-test-with-temp-text "* H\nParagraph<point>"
 	    (let ((org-adapt-indentation t))
 	      (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string)
-	     nil nil 1))))
+            (org-test-drop-dow-from-timestamp))))
   ;; Create deadline when `org-adapt-indentation' is nil.
   (should
    (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
 	  (org-test-with-temp-text "* H\nParagraph<point>"
 	    (let ((org-adapt-indentation nil))
 	      (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string)
-	     nil nil 1))))
+            (org-test-drop-dow-from-timestamp))))
   ;; Update deadline when `org-adapt-indentation' is non-nil.
   (should
    (equal "* H\n  DEADLINE: <2015-06-25>\nParagraph"
@@ -5650,9 +5696,7 @@ Text.
 Paragraph<point>"
 	    (let ((org-adapt-indentation t))
 	      (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string)
-	     nil nil 1))))
+            (org-test-drop-dow-from-timestamp))))
   ;; Update deadline when `org-adapt-indentation' is nil.
   (should
    (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
@@ -5662,27 +5706,21 @@ DEADLINE: <2015-06-24 Wed>
 Paragraph<point>"
 	    (let ((org-adapt-indentation nil))
 	      (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string)
-	     nil nil 1))))
+            (org-test-drop-dow-from-timestamp))))
   ;; Schedule when `org-adapt-indentation' is non-nil.
   (should
    (equal "* H\n  SCHEDULED: <2015-06-25>\nParagraph"
 	  (org-test-with-temp-text "* H\nParagraph<point>"
 	    (let ((org-adapt-indentation t))
 	      (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string)
-	     nil nil 1))))
+            (org-test-drop-dow-from-timestamp))))
   ;; Schedule when `org-adapt-indentation' is nil.
   (should
    (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
 	  (org-test-with-temp-text "* H\nParagraph<point>"
 	    (let ((org-adapt-indentation nil))
 	      (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string)
-	     nil nil 1))))
+            (org-test-drop-dow-from-timestamp))))
   ;; Add deadline when scheduled.
   (should
    (equal "\
@@ -5695,9 +5733,7 @@ Paragraph"
 Paragraph<point>"
 	    (let ((org-adapt-indentation t))
 	      (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string)
-	     nil nil 1))))
+            (org-test-drop-dow-from-timestamp))))
   ;; Remove middle entry.
   (should
    (equal "\
@@ -5710,9 +5746,7 @@ Paragraph"
 Paragraph<point>"
 	    (let ((org-adapt-indentation t))
 	      (org-add-planning-info nil nil 'deadline))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
-	     nil nil 1))))
+            (org-test-drop-dow-from-timestamp))))
   ;; Remove last entry and then middle entry (order should not
   ;; matter).
   (should
@@ -5726,9 +5760,7 @@ Paragraph"
 Paragraph<point>"
 	    (let ((org-adapt-indentation t))
 	      (org-add-planning-info nil nil 'scheduled 'deadline))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
-	     nil nil 1))))
+            (org-test-drop-dow-from-timestamp))))
   ;; Remove closed when `org-adapt-indentation' is non-nil.
   (should
    (equal "* H\n  DEADLINE: <2015-06-25>\nParagraph"
@@ -5738,9 +5770,7 @@ Paragraph<point>"
 Paragraph<point>"
 	    (let ((org-adapt-indentation t))
 	      (org-add-planning-info nil nil 'closed))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string)
-	     nil nil 1))))
+            (org-test-drop-dow-from-timestamp))))
   (should
    (equal "* H\n  Paragraph"
 	  (org-test-with-temp-text "\
@@ -5749,9 +5779,7 @@ Paragraph<point>"
   Paragraph<point>"
 	    (let ((org-adapt-indentation t))
 	      (org-add-planning-info nil nil 'closed))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string)
-	     nil nil 1))))
+            (org-test-drop-dow-from-timestamp))))
   ;; Remove closed when `org-adapt-indentation' is nil.
   (should
    (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
@@ -5761,9 +5789,7 @@ CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
 Paragraph<point>"
 	    (let ((org-adapt-indentation nil))
 	      (org-add-planning-info nil nil 'closed))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string)
-	     nil nil 1))))
+            (org-test-drop-dow-from-timestamp))))
   (should
    (equal "* H\nParagraph"
 	  (org-test-with-temp-text "\
@@ -5772,9 +5798,7 @@ Paragraph<point>"
 Paragraph<point>"
 	    (let ((org-adapt-indentation nil))
 	      (org-add-planning-info nil nil 'closed))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string)
-	     nil nil 1))))
+            (org-test-drop-dow-from-timestamp))))
   ;; Remove closed entry and delete empty line.
   (should
    (equal "\
@@ -5786,9 +5810,7 @@ Paragraph"
 Paragraph<point>"
 	    (let ((org-adapt-indentation t))
 	      (org-add-planning-info nil nil 'closed))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string)
-	     nil nil 1))))
+            (org-test-drop-dow-from-timestamp))))
   ;; Remove one entry and update another.
   (should
    (equal "* H\n  DEADLINE: <2015-06-25>\nParagraph"
@@ -5798,9 +5820,7 @@ Paragraph<point>"
 Paragraph<point>"
 	    (let ((org-adapt-indentation t))
 	      (org-add-planning-info 'deadline "<2015-06-25 Thu>" 'scheduled))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string)
-	     nil nil 1)))))
+            (org-test-drop-dow-from-timestamp)))))
 
 (ert-deftest test-org/deadline ()
   "Test `org-deadline' specifications."
@@ -5811,18 +5831,14 @@ Paragraph<point>"
 	    (let ((org-adapt-indentation nil)
 		  (org-last-inserted-timestamp nil))
 	      (org-deadline nil "<2012-03-29 Tue>"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string)
-	     nil nil 1))))
+            (org-test-drop-dow-from-timestamp))))
   (should
    (equal "* H\nDEADLINE: <2014-03-04>"
 	  (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
 	    (let ((org-adapt-indentation nil)
 		  (org-last-inserted-timestamp nil))
 	      (org-deadline nil "<2014-03-04 Thu>"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string)
-	     nil nil 1))))
+            (org-test-drop-dow-from-timestamp))))
   ;; Accept delta time, e.g., "+2d".
   (should
    (equal "* H\nDEADLINE: <2015-03-04>"
@@ -5831,8 +5847,7 @@ Paragraph<point>"
 	      (let ((org-adapt-indentation nil)
 		    (org-last-inserted-timestamp nil))
 		(org-deadline nil "+1y"))
-	      (replace-regexp-in-string
-	       "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
+              (org-test-drop-dow-from-timestamp)))))
   ;; Preserve repeater.
   (should
    (equal "* H\nDEADLINE: <2012-03-29 +2y>"
@@ -5840,8 +5855,7 @@ Paragraph<point>"
 	    (let ((org-adapt-indentation nil)
 		  (org-last-inserted-timestamp nil))
 	      (org-deadline nil "<2012-03-29 Tue +2y>"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
+            (org-test-drop-dow-from-timestamp))))
   ;; Preserve warning period.
   (should
    (equal "* H\nDEADLINE: <2021-07-20 -1d>"
@@ -5849,16 +5863,14 @@ Paragraph<point>"
 	    (let ((org-adapt-indentation nil)
 		  (org-last-inserted-timestamp nil))
 	      (org-deadline nil "<2021-07-20 Tue -1d>"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
+            (org-test-drop-dow-from-timestamp))))
   (should
    (equal "* H\nDEADLINE: <2021-07-20 +1m -3d>"
 	  (org-test-with-temp-text "* H"
 	    (let ((org-adapt-indentation nil)
 		  (org-last-inserted-timestamp nil))
 	      (org-deadline nil "<2021-07-20 Tue +1m -3d>"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
+            (org-test-drop-dow-from-timestamp))))
   ;; Remove CLOSED keyword, if any.
   (should
    (equal "* H\nDEADLINE: <2012-03-29>"
@@ -5866,8 +5878,7 @@ Paragraph<point>"
 	    (let ((org-adapt-indentation nil)
 		  (org-last-inserted-timestamp nil))
 	      (org-deadline nil "<2012-03-29 Tue>"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
+            (org-test-drop-dow-from-timestamp))))
   ;; With C-u argument, remove DEADLINE keyword.
   (should
    (equal "* H\n"
@@ -5916,8 +5927,7 @@ Paragraph<point>"
 	      (push-mark (point) t t)
 	      (goto-char (point-max))
 	      (org-deadline nil "2012-03-29"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
+            (org-test-drop-dow-from-timestamp))))
   (should-not
    (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
 	  (org-test-with-temp-text "* H1\n* H2"
@@ -5928,8 +5938,7 @@ Paragraph<point>"
 	      (push-mark (point) t t)
 	      (goto-char (point-max))
 	      (org-deadline nil "2012-03-29"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
+            (org-test-drop-dow-from-timestamp)))))
 
 (ert-deftest test-org/schedule ()
   "Test `org-schedule' specifications."
@@ -5940,18 +5949,14 @@ Paragraph<point>"
 	    (let ((org-adapt-indentation nil)
 		  (org-last-inserted-timestamp nil))
 	      (org-schedule nil "<2012-03-29 Tue>"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string)
-	     nil nil 1))))
+            (org-test-drop-dow-from-timestamp))))
   (should
    (equal "* H\nSCHEDULED: <2014-03-04>"
 	  (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
 	    (let ((org-adapt-indentation nil)
 		  (org-last-inserted-timestamp nil))
 	      (org-schedule nil "<2014-03-04 Thu>"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string)
-	     nil nil 1))))
+            (org-test-drop-dow-from-timestamp))))
   ;; Accept delta time, e.g., "+2d".
   (should
    (equal "* H\nSCHEDULED: <2015-03-04>"
@@ -5960,8 +5965,7 @@ Paragraph<point>"
 	      (let ((org-adapt-indentation nil)
 		    (org-last-inserted-timestamp nil))
 		(org-schedule nil "+1y"))
-	      (replace-regexp-in-string
-	       "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
+              (org-test-drop-dow-from-timestamp)))))
   ;; Preserve repeater.
   (should
    (equal "* H\nSCHEDULED: <2012-03-29 +2y>"
@@ -5969,8 +5973,7 @@ Paragraph<point>"
 	    (let ((org-adapt-indentation nil)
 		  (org-last-inserted-timestamp nil))
 	      (org-schedule nil "<2012-03-29 Tue +2y>"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
+            (org-test-drop-dow-from-timestamp))))
   ;; Remove CLOSED keyword, if any.
   (should
    (equal "* H\nSCHEDULED: <2012-03-29>"
@@ -5978,8 +5981,7 @@ Paragraph<point>"
 	    (let ((org-adapt-indentation nil)
 		  (org-last-inserted-timestamp nil))
 	      (org-schedule nil "<2012-03-29 Tue>"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
+            (org-test-drop-dow-from-timestamp))))
   ;; With C-u argument, remove SCHEDULED keyword.
   (should
    (equal "* H\n"
@@ -6028,8 +6030,7 @@ Paragraph<point>"
 	      (push-mark (point) t t)
 	      (goto-char (point-max))
 	      (org-schedule nil "2012-03-29"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
+            (org-test-drop-dow-from-timestamp))))
   (should-not
    (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
 	  (org-test-with-temp-text "* H1\n* H2"
@@ -6040,17 +6041,21 @@ Paragraph<point>"
 	      (push-mark (point) t t)
 	      (goto-char (point-max))
 	      (org-schedule nil "2012-03-29"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
-  (should
-   ;; check if a repeater survives re-scheduling.
-   (string-match-p
-    "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
-    (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
-			     (let ((org-adapt-indentation nil)
-				   (org-last-inserted-timestamp nil))
-			       (org-schedule nil "2017-02-01"))
-			     (buffer-string)))))
+            (org-test-drop-dow-from-timestamp))))
+     ;; check if a repeater survives re-scheduling.
+  (save-match-data
+    (let* ((org-adapt-indentation nil)
+           (org-last-inserted-timestamp nil)
+           (s (org-test-with-temp-text
+                  "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
+                (org-schedule nil "2017-02-01")
+                (buffer-string))))
+      (should
+       (string-match
+        (rx "* H\nSCHEDULED: " (regexp org-test-timestamp-regexp) ?\n)
+        s))
+      (should (equal "2017-02-01" (match-string 200 s)))
+      (should (equal "++7d" (match-string 231 s))))))
 
 \f
 ;;; Property API
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


[-- Attachment #3: Type: text/plain, Size: 134 bytes --]


-- 
Best,


RY

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

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* Re: [DRAFT PATCH v2] Decouple LANG= and testing (was: Test failure due to LANG)
  2023-04-22 13:51         ` Ruijie Yu via General discussions about Org-mode.
@ 2023-04-23 10:54           ` Ihor Radchenko
       [not found]             ` <sdvjzy2rhne.fsf@netyu.xyz>
  0 siblings, 1 reply; 34+ messages in thread
From: Ihor Radchenko @ 2023-04-23 10:54 UTC (permalink / raw)
  To: Ruijie Yu via General discussions about Org-mode.
  Cc: Ruijie Yu, Axel Kielhorn

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

> Second, `org-columns--overlay-text' has a problem where
>
>     (format "%-5.5s |" "1234…")
>
> returns different results for different locales, causing
> `test-org-colview/columns-width' to break.

What are these different results?

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [DRAFT PATCH v4] Decouple LANG= and testing (was: Test failure due to LANG)
  2023-04-23  6:46                 ` [DRAFT PATCH v4] " Ruijie Yu via General discussions about Org-mode.
@ 2023-04-23 11:17                   ` Ihor Radchenko
  2023-04-23 13:57                     ` Ruijie Yu via General discussions about Org-mode.
  0 siblings, 1 reply; 34+ messages in thread
From: Ihor Radchenko @ 2023-04-23 11:17 UTC (permalink / raw)
  To: Ruijie Yu; +Cc: Axel Kielhorn, emacs-orgmode

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

> Something very troublesome for me is `test-org-clock/clocktable/lang' on
> zh_CN.UTF-8.  What I noticed is that when I run this test in batch mode
> (one of the two methods below), it fails:

Well. Batch and non-batch modes are not the same, especially wrt display
things. And the differences are not consistent for different Emacs
versions. This only happens for weird edge cases though. (Or when
displaying images).

> +(defconst org-test-timestamp-regexp

I recommend `org-element-timestamp-parser' for analysis.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [DRAFT PATCH v2] Decouple LANG= and testing (was: Test failure due to LANG)
       [not found]             ` <sdvjzy2rhne.fsf@netyu.xyz>
@ 2023-04-23 11:19               ` Ihor Radchenko
  2023-04-23 14:30                 ` Ruijie Yu via General discussions about Org-mode.
  0 siblings, 1 reply; 34+ messages in thread
From: Ihor Radchenko @ 2023-04-23 11:19 UTC (permalink / raw)
  To: Ruijie Yu; +Cc: Axel Kielhorn, emacs-orgmode

Ruijie Yu <ruijie@netyu.xyz> writes:

>>>     (format "%-5.5s |" "1234…")
>>>
>>> returns different results for different locales, causing
>>> `test-org-colview/columns-width' to break.
>>
>> What are these different results?
>
> In CJK locales such as zh_CN and ja_JA, the ellipsis character is
> truncated, and replaced by a space.
>
> I reported to Emacs devs a few minutes ago because I wanted to
> understand how `format' decide the ellipsis is a two-unit wide character
> in CJK locales.  I also wasn't sure if that is an Emacs bug or an Org
> one, and their response would help a lot.

For future reference:
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=63029

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [DRAFT PATCH v4] Decouple LANG= and testing (was: Test failure due to LANG)
  2023-04-23 11:17                   ` Ihor Radchenko
@ 2023-04-23 13:57                     ` Ruijie Yu via General discussions about Org-mode.
  2023-04-23 15:07                       ` Ihor Radchenko
  0 siblings, 1 reply; 34+ messages in thread
From: Ruijie Yu via General discussions about Org-mode. @ 2023-04-23 13:57 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Axel Kielhorn, emacs-orgmode


Ihor Radchenko <yantar92@posteo.net> writes:

> Ruijie Yu via "General discussions about Org-mode."
> <emacs-orgmode@gnu.org> writes:
>
>> Something very troublesome for me is `test-org-clock/clocktable/lang' on
>> zh_CN.UTF-8.  What I noticed is that when I run this test in batch mode
>> (one of the two methods below), it fails:
>
> Well. Batch and non-batch modes are not the same, especially wrt display
> things. And the differences are not consistent for different Emacs
> versions. This only happens for weird edge cases though. (Or when
> displaying images).

Hmm.  I guess I won't be trying to fix this particular issue then -- it
is a bit beyond my knowledge.  Thanks for explaining it.

>> +(defconst org-test-timestamp-regexp
>
> I recommend `org-element-timestamp-parser' for analysis.

Thanks for pointing that out!  I didn't realize it was there.  Although,
I don't think I can use this function as-is, nor its internal regexps:
all the relevant tests where I used `org-test-timestamp-regexp' tried to
remove the day-of-week part.  So I would need to know the region for the
day-of-week portion.  At the moment, I can't think of anything other
than making a group for DoW, and removing wrapping `save-match-data' in
`org-element-timestamp-parser' -- which is why I had those convoluted
group numbers in my `org-test-timestamp-regexp' for all portions that
one may ever want to use, hoping that nobody goes beyond defining 100
groups.

I also don't know if it is viable to integrate my full-of-`rx' and
full-of-`group-n' regexp expression into the 10s of different internal
constants representing different possible components of a timestamp.

Alternatively (and I say this very hesitantly), we could try to rewrite
all the involved tests so that we don't need to try to remove DoW from
the timestamp.  But, I haven't figured out how to do all of them (they
are also of different styles, some with repeater, some with warning
period, some are bare, etc), and there are -- I think -- around 40 of
them that needs changing.

-- 
Best,


RY

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


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [DRAFT PATCH v2] Decouple LANG= and testing (was: Test failure due to LANG)
  2023-04-23 11:19               ` Ihor Radchenko
@ 2023-04-23 14:30                 ` Ruijie Yu via General discussions about Org-mode.
  2023-04-23 15:03                   ` Ihor Radchenko
  0 siblings, 1 reply; 34+ messages in thread
From: Ruijie Yu via General discussions about Org-mode. @ 2023-04-23 14:30 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Axel Kielhorn, emacs-orgmode


Ihor Radchenko <yantar92@posteo.net> writes:

> Ruijie Yu <ruijie@netyu.xyz> writes:
>
>>>>     (format "%-5.5s |" "1234…")
>>>>
>>>> returns different results for different locales, causing
>>>> `test-org-colview/columns-width' to break.
>>>
>>> What are these different results?
>>
>> In CJK locales such as zh_CN and ja_JA, the ellipsis character is
>> truncated, and replaced by a space.
>>
>> I reported to Emacs devs a few minutes ago because I wanted to
>> understand how `format' decide the ellipsis is a two-unit wide character
>> in CJK locales.  I also wasn't sure if that is an Emacs bug or an Org
>> one, and their response would help a lot.
>
> For future reference:
> https://debbugs.gnu.org/cgi/bugreport.cgi?bug=63029

From my understanding of Eli's response, org-colview is at fault here, by
calling `length' instead of `string-width' in
`org-columns-add-ellipses'.  Changing this function call might be all it
needs to fix the colview test failure?

-- 
Best,


RY

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


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [DRAFT PATCH v2] Decouple LANG= and testing (was: Test failure due to LANG)
  2023-04-23 14:30                 ` Ruijie Yu via General discussions about Org-mode.
@ 2023-04-23 15:03                   ` Ihor Radchenko
  2023-04-23 15:15                     ` Ruijie Yu via General discussions about Org-mode.
  0 siblings, 1 reply; 34+ messages in thread
From: Ihor Radchenko @ 2023-04-23 15:03 UTC (permalink / raw)
  To: Ruijie Yu; +Cc: Axel Kielhorn, emacs-orgmode

Ruijie Yu <ruijie@netyu.xyz> writes:

>> https://debbugs.gnu.org/cgi/bugreport.cgi?bug=63029
>
> From my understanding of Eli's response, org-colview is at fault here, by
> calling `length' instead of `string-width' in
> `org-columns-add-ellipses'.  Changing this function call might be all it
> needs to fix the colview test failure?

This is tricky because string width may be different depending on
in-buffer settings, fonts used, etc.

We can try to be a tiny little bit more accurate using
`truncate-string-to-width', `string-width', or `org-string-width'.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [DRAFT PATCH v4] Decouple LANG= and testing (was: Test failure due to LANG)
  2023-04-23 13:57                     ` Ruijie Yu via General discussions about Org-mode.
@ 2023-04-23 15:07                       ` Ihor Radchenko
  2023-04-25  8:02                         ` [DRAFT PATCH v5] " Ruijie Yu via General discussions about Org-mode.
  0 siblings, 1 reply; 34+ messages in thread
From: Ihor Radchenko @ 2023-04-23 15:07 UTC (permalink / raw)
  To: Ruijie Yu; +Cc: Axel Kielhorn, emacs-orgmode

Ruijie Yu <ruijie@netyu.xyz> writes:

>> I recommend `org-element-timestamp-parser' for analysis.
>
> Thanks for pointing that out!  I didn't realize it was there.  Although,
> I don't think I can use this function as-is, nor its internal regexps:
> all the relevant tests where I used `org-test-timestamp-regexp' tried to
> remove the day-of-week part.  So I would need to know the region for the
> day-of-week portion.  At the moment, I can't think of anything other
> than making a group for DoW, and removing wrapping `save-match-data' in
> `org-element-timestamp-parser' -- which is why I had those convoluted
> group numbers in my `org-test-timestamp-regexp' for all portions that
> one may ever want to use, hoping that nobody goes beyond defining 100
> groups.

(let ((org-time-stamp-formats '("%Y-%m-%d" . "%Y-%m-%d %H:%M")))
     (org-element-timestamp-interpreter timestamp nil))

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [DRAFT PATCH v2] Decouple LANG= and testing (was: Test failure due to LANG)
  2023-04-23 15:03                   ` Ihor Radchenko
@ 2023-04-23 15:15                     ` Ruijie Yu via General discussions about Org-mode.
  2023-04-25 10:11                       ` Ihor Radchenko
  0 siblings, 1 reply; 34+ messages in thread
From: Ruijie Yu via General discussions about Org-mode. @ 2023-04-23 15:15 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Axel Kielhorn, emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 871 bytes --]


Ihor Radchenko <yantar92@posteo.net> writes:

> Ruijie Yu <ruijie@netyu.xyz> writes:
>
>>> https://debbugs.gnu.org/cgi/bugreport.cgi?bug=63029
>>
>> From my understanding of Eli's response, org-colview is at fault here, by
>> calling `length' instead of `string-width' in
>> `org-columns-add-ellipses'.  Changing this function call might be all it
>> needs to fix the colview test failure?
>
> This is tricky because string width may be different depending on
> in-buffer settings, fonts used, etc.
>
> We can try to be a tiny little bit more accurate using
> `truncate-string-to-width', `string-width', or `org-string-width'.

Just had a try at this, fully untested code (other than starting a
LANG=zh_CN.UTF-8 Emacs session and running this substring function to
see its effects).  It is a bit too late for me now, so I'll call it a
day (literally) for coding today.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: org-colview.diff --]
[-- Type: text/x-patch, Size: 1722 bytes --]

diff --git a/lisp/org-colview.el b/lisp/org-colview.el
index 92a3b473d..e8106f9cd 100644
--- a/lisp/org-colview.el
+++ b/lisp/org-colview.el
@@ -452,14 +452,30 @@ DATELINE is non-nil when the face used should be
 	    "Type \\<org-columns-map>`\\[org-columns-edit-value]' \
 to edit property")))))))
 
+(defun org-columns--substring-below-width (string start width)
+  "Similar to `substring', but use `string-width' to check width.
+The returned value is a substring of STRING, starting at START,
+and is the largest possible substring whose width does not exceed
+WIDTH."
+  (let ((end (min (+ start width) (length string))) res)
+    (while (and end (>= end start))
+      (let* ((curr (string-width string start end))
+             (excess (- curr width)))
+        (if (cl-plusp excess)
+            (cl-decf end (max 1 (/ excess 2)))
+          (setq res (substring string start end) end nil))))
+    res))
+
 (defun org-columns-add-ellipses (string width)
   "Truncate STRING with WIDTH characters, with ellipses."
   (cond
-   ((<= (length string) width) string)
-   ((<= width (length org-columns-ellipses))
-    (substring org-columns-ellipses 0 width))
-   (t (concat (substring string 0 (- width (length org-columns-ellipses)))
-	      org-columns-ellipses))))
+   ((<= (string-width string) width) string)
+   ((<= width (string-width org-columns-ellipses))
+    (org-columns--substring-below-width org-columns-ellipses 0 width))
+   (t (concat
+       (org-columns--substring-below-width
+        string 0 (- width (length org-columns-ellipses)))
+       org-columns-ellipses))))
 
 (defvar org-columns-full-header-line-format nil
   "The full header line format, will be shifted by horizontal scrolling." )

[-- Attachment #3: Type: text/plain, Size: 134 bytes --]


-- 
Best,


RY

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

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* Re: [DRAFT PATCH v5] Decouple LANG= and testing (was: Test failure due to LANG)
  2023-04-23 15:07                       ` Ihor Radchenko
@ 2023-04-25  8:02                         ` Ruijie Yu via General discussions about Org-mode.
  2023-04-25 15:19                           ` [DRAFT PATCH v6] " Ruijie Yu via General discussions about Org-mode.
  2023-04-26  8:44                           ` [DRAFT PATCH v5] " Ihor Radchenko
  0 siblings, 2 replies; 34+ messages in thread
From: Ruijie Yu via General discussions about Org-mode. @ 2023-04-25  8:02 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Axel Kielhorn, emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1175 bytes --]


Ihor Radchenko <yantar92@posteo.net> writes:

> (let ((org-time-stamp-formats '("%Y-%m-%d" . "%Y-%m-%d %H:%M")))
>      (org-element-timestamp-interpreter timestamp nil))

Thanks for the pointer.  I have made this into a macro and redid my
changes accordingly.  Please also let me know if more work should be
dedicated to avoid code duplication in tests (I see a lot of duplication
in the portions I touched in testing/lisp/test-org.el).

What currently still fails unexpectedly:

zh_CN.UTF-8:
    test-org-clock/clocktable/lang
    - This test only fails in batch mode, as I mentioned up-thread.  I
      might try to convert this into a test that expects failure
      depending on whether Emacs is in batch mode.
    test-org-colview/columns-width
    - This patch did not attempt to fix it.  I posted a diff file under
      v2 (not included in this patch), but that didn't work either.

ja_JA.UTF-8:
    test-org-colview/columns-width
    - See above.

fr_FR.UTF-8:
    test-org-clok/org-clock-timestamps-change
    - This is tracked in the other thread I created, and won't be fixed
      by this patch.

en_US.UTF-8 and de_DE.UTF-8:
    No unexpected test failures.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-DRAFT-Fix-dependence-on-locale-in-org-testing-facili.patch --]
[-- Type: text/x-patch, Size: 33280 bytes --]

From d17e33802b0e53af131a2ab3f44d9ee3ecfb2a59 Mon Sep 17 00:00:00 2001
From: Ruijie Yu <ruijie@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-clock/clock-drawer-dwim): make use of the pre-generated
DoW names in the testing to remove assumptions on LANG=C.
(test-org-clock/org-clock-timestamps-change): renamed from
test-org-clok/org-clock-timestamps-change; used DoW pre-generated
names.

* testing/lisp/test-org.el (org-test-with-result):
(org-test-without-dow): add two macros to combat the 40-time
repetition of "do not add day-of-week, do something, and return
buffer string".
(test-org/clone-with-time-shift): (test-org/add-planning-info):
(test-org/deadline): (test-org/schedule): rewrite the
day-of-week-removal portion to avoid generating day-of-week names
altogether, using the new macro `org-test-without-dow'.
---
 testing/lisp/test-org-clock.el |  64 ++---
 testing/lisp/test-org.el       | 415 +++++++++++++++------------------
 testing/org-test.el            |  25 ++
 3 files changed, 250 insertions(+), 254 deletions(-)

diff --git a/testing/lisp/test-org-clock.el b/testing/lisp/test-org-clock.el
index 7d8123e1f..d4beb76e0 100644
--- a/testing/lisp/test-org-clock.el
+++ b/testing/lisp/test-org-clock.el
@@ -89,29 +89,34 @@ the buffer."
     ;; Remove clocktable.
     (delete-region (point) (search-forward "#+END:\n"))))
 
-(ert-deftest test-org-clok/org-clock-timestamps-change ()
+(ert-deftest test-org-clock/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))))))
 
 \f
 ;;; 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))))))
 
 \f
 ;;; Clocktable
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index d7c801fe5..e5581f140 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -43,6 +43,40 @@
              ,@body)
              (setenv "TZ" ,tz-saved)))))
 
+(defmacro org-test-with-result (result &rest body)
+  "Evaluate BODY, and return buffer content based on RESULT.
+RESULT is an sexp, and is processed according to the following
+rules.
+
+If RESULT is the quoted symbol `buffer', return buffer string.
+
+If RESULT is the quoted symbol `buffer-no-properties', return
+buffer string with no properties.
+
+If RESULT is a positive integer, return the RESULT-th line of the
+buffer.
+
+Otherwise, evaluate RESULT as an sexp and return its result."
+  (declare (indent 1))
+  `(progn ,@body
+          ,(pcase result
+             (''buffer-no-properties
+              '(buffer-substring-no-properties
+                (point-min) (point-max)))
+             (''buffer '(buffer-string))
+             ((and (pred numberp) (pred cl-plusp))
+              `(buffer-substring (line-beginning-position ,result)
+                                 (line-end-position ,result)))
+             (_ result))))
+
+(defmacro org-test-without-dow (result &rest body)
+  "Eval BODY skipping day-of-week in timestamps.
+See `org-test-with-result' for RESULT and the return value."
+  (declare (indent 1))
+  `(let ((org-time-stamp-formats '("%Y-%m-%d" . "%Y-%m-%d %H:%M")))
+     ;; ,(macroexpand-1 `(org-test-with-result ,result ,@body))
+     (org-test-with-result ,result ,@body)))
+
 \f
 ;;; Comments
 
@@ -2013,11 +2047,9 @@ CLOCK: [2022-09-17 sam. 11:00]--[2022-09-17 sam. 11:46] =>  0:46"
 * H1\n<2015-06-21>
 * H1\n<2015-06-23>
 "
-	  (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
-	    (org-clone-subtree-with-time-shift 1 "+2d")
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
-	     nil nil 1))))
+          (org-test-with-temp-text "* H1\n<2015-06-21>"
+            (org-test-without-dow 'buffer
+              (org-clone-subtree-with-time-shift 1 "+2d")))))
   ;; Clone repeating once.
   (should
    (equal "\
@@ -2025,11 +2057,9 @@ CLOCK: [2022-09-17 sam. 11:00]--[2022-09-17 sam. 11:46] =>  0:46"
 * H1\n<2015-06-23>
 * H1\n<2015-06-25 +1w>
 "
-	  (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
-	    (org-clone-subtree-with-time-shift 1 "+2d")
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
-	     nil nil 1))))
+          (org-test-with-temp-text "* H1\n<2015-06-21 +1w>"
+            (org-test-without-dow 'buffer
+              (org-clone-subtree-with-time-shift 1 "+2d")))))
   ;; Clone repeating once in backward.
   (should
    (equal "\
@@ -2037,58 +2067,49 @@ CLOCK: [2022-09-17 sam. 11:00]--[2022-09-17 sam. 11:46] =>  0:46"
 * H1\n<2015-06-19>
 * H1\n<2015-06-17 +1w>
 "
-	  (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
-	    (org-clone-subtree-with-time-shift 1 "-2d")
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
-	     nil nil 1))))
+          (org-test-with-temp-text "* H1\n<2015-06-21 +1w>"
+            (org-test-without-dow 'buffer
+              (org-clone-subtree-with-time-shift 1 "-2d")))))
   ;; Clone non-repeating zero times.
   (should
    (equal "\
 * H1\n<2015-06-21>
 "
-	  (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
-	    (org-clone-subtree-with-time-shift 0 "+2d")
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
-	     nil nil 1))))
+          (org-test-with-temp-text "* H1\n<2015-06-21>"
+            (org-test-without-dow 'buffer
+              (org-clone-subtree-with-time-shift 0 "+2d")))))
   ;; Clone repeating "zero" times.
   (should
    (equal "\
 * H1\n<2015-06-21>
 * H1\n<2015-06-23 +1w>
 "
-	  (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
-	    (org-clone-subtree-with-time-shift 0 "+2d")
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
-	     nil nil 1))))
+          (org-test-with-temp-text "* H1\n<2015-06-21 +1w>"
+            (org-test-without-dow 'buffer
+              (org-clone-subtree-with-time-shift 0 "+2d")))))
   ;; Clone with blank SHIFT argument.
   (should
    (string-prefix-p
     "* H <2012-03-29"
     (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
-      (org-clone-subtree-with-time-shift 1 "")
-      (buffer-substring-no-properties (line-beginning-position 2)
-				      (line-end-position 2)))))
+      (org-test-without-dow 2
+        (org-clone-subtree-with-time-shift 1 "")))))
   ;; Find time stamps before point.  If SHIFT is not specified, ask
   ;; for a time shift.
   (should
    (string-prefix-p
     "* H <2012-03-30"
     (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
-      (org-clone-subtree-with-time-shift 1 "+1d")
-      (buffer-substring-no-properties (line-beginning-position 2)
-				      (line-end-position 2)))))
+      (org-test-without-dow 2
+        (org-clone-subtree-with-time-shift 1 "+1d")))))
   (should
    (string-prefix-p
     "* H <2014-03-05"
     (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
       (cl-letf (((symbol-function 'read-from-minibuffer)
-		 (lambda (&rest _args) "+1d")))
-	(org-clone-subtree-with-time-shift 1))
-      (buffer-substring-no-properties (line-beginning-position 2)
-				      (line-end-position 2)))))
+                 (lambda (&rest _args) "+1d")))
+        (org-test-without-dow 2
+          (org-clone-subtree-with-time-shift 1))))))
   ;; Hour shift.
   (should
    (equal "\
@@ -2096,23 +2117,17 @@ CLOCK: [2022-09-17 sam. 11:00]--[2022-09-17 sam. 11:46] =>  0:46"
 * H1\n<2015-06-21 23:00>
 * H1\n<2015-06-22 02:00>
 "
-          (org-test-with-temp-text "* H1\n<2015-06-21 Sun 20:00>"
-            (org-clone-subtree-with-time-shift 2 "+3h")
-            (replace-regexp-in-string
-             "\\( [.A-Za-z]+\\)\\( [0-9][0-9]:[0-9][0-9]\\)?>" ""
-             (buffer-substring-no-properties (point-min) (point-max))
-             nil nil 1))))
+          (org-test-with-temp-text "* H1\n<2015-06-21 20:00>"
+            (org-test-without-dow 'buffer
+              (org-clone-subtree-with-time-shift 2 "+3h")))))
   (should
    (equal "\
 * H1\n<2015-06-21 20:00>
 * H1\n<2015-06-21 18:00>
 "
-          (org-test-with-temp-text "* H1\n<2015-06-21 Sun 20:00>"
-            (org-clone-subtree-with-time-shift 1 "-2h")
-            (replace-regexp-in-string
-             "\\( [.A-Za-z]+\\)\\( [0-9][0-9]:[0-9][0-9]\\)?>" ""
-             (buffer-substring-no-properties (point-min) (point-max))
-             nil nil 1)))))
+          (org-test-with-temp-text "* H1\n<2015-06-21 20:00>"
+            (org-test-without-dow 'buffer
+              (org-clone-subtree-with-time-shift 1 "-2h"))))))
 
 \f
 ;;; Fixed-Width Areas
@@ -5626,21 +5641,17 @@ Text.
   ;; Create deadline when `org-adapt-indentation' is non-nil.
   (should
    (equal "* H\n  DEADLINE: <2015-06-25>\nParagraph"
-	  (org-test-with-temp-text "* H\nParagraph<point>"
-	    (let ((org-adapt-indentation t))
-	      (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string)
-	     nil nil 1))))
+          (org-test-with-temp-text "* H\nParagraph<point>"
+            (let ((org-adapt-indentation t))
+              (org-test-without-dow 'buffer
+                (org-add-planning-info 'deadline "<2015-06-25 Thu>"))))))
   ;; Create deadline when `org-adapt-indentation' is nil.
   (should
    (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
 	  (org-test-with-temp-text "* H\nParagraph<point>"
 	    (let ((org-adapt-indentation nil))
-	      (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string)
-	     nil nil 1))))
+	      (org-test-without-dow 'buffer
+                (org-add-planning-info 'deadline "<2015-06-25 Thu>"))))))
   ;; Update deadline when `org-adapt-indentation' is non-nil.
   (should
    (equal "* H\n  DEADLINE: <2015-06-25>\nParagraph"
@@ -5649,10 +5660,8 @@ Text.
   DEADLINE: <2015-06-24 Wed>
 Paragraph<point>"
 	    (let ((org-adapt-indentation t))
-	      (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string)
-	     nil nil 1))))
+	      (org-test-without-dow 'buffer
+                (org-add-planning-info 'deadline "<2015-06-25 Thu>"))))))
   ;; Update deadline when `org-adapt-indentation' is nil.
   (should
    (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
@@ -5661,28 +5670,22 @@ Paragraph<point>"
 DEADLINE: <2015-06-24 Wed>
 Paragraph<point>"
 	    (let ((org-adapt-indentation nil))
-	      (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string)
-	     nil nil 1))))
+	      (org-test-without-dow 'buffer
+                (org-add-planning-info 'deadline "<2015-06-25 Thu>"))))))
   ;; Schedule when `org-adapt-indentation' is non-nil.
   (should
    (equal "* H\n  SCHEDULED: <2015-06-25>\nParagraph"
 	  (org-test-with-temp-text "* H\nParagraph<point>"
 	    (let ((org-adapt-indentation t))
-	      (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string)
-	     nil nil 1))))
+	      (org-test-without-dow 'buffer
+                (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))))))
   ;; Schedule when `org-adapt-indentation' is nil.
   (should
    (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
 	  (org-test-with-temp-text "* H\nParagraph<point>"
 	    (let ((org-adapt-indentation nil))
-	      (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string)
-	     nil nil 1))))
+	      (org-test-without-dow 'buffer
+                (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))))))
   ;; Add deadline when scheduled.
   (should
    (equal "\
@@ -5691,13 +5694,11 @@ Paragraph<point>"
 Paragraph"
 	  (org-test-with-temp-text "\
 * H
-  SCHEDULED: <2015-06-24 Wed>
+  SCHEDULED: <2015-06-24>
 Paragraph<point>"
 	    (let ((org-adapt-indentation t))
-	      (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string)
-	     nil nil 1))))
+	      (org-test-without-dow 'buffer
+                (org-add-planning-info 'deadline "<2015-06-25 Thu>"))))))
   ;; Remove middle entry.
   (should
    (equal "\
@@ -5706,13 +5707,11 @@ Paragraph<point>"
 Paragraph"
 	  (org-test-with-temp-text "\
 * H
-  CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
+  CLOSED: [2015-06-24] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24>
 Paragraph<point>"
 	    (let ((org-adapt-indentation t))
-	      (org-add-planning-info nil nil 'deadline))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
-	     nil nil 1))))
+	      (org-test-without-dow 'buffer
+                (org-add-planning-info nil nil 'deadline))))))
   ;; Remove last entry and then middle entry (order should not
   ;; matter).
   (should
@@ -5722,25 +5721,21 @@ Paragraph<point>"
 Paragraph"
 	  (org-test-with-temp-text "\
 * H
-  CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
+  CLOSED: [2015-06-24] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
 Paragraph<point>"
 	    (let ((org-adapt-indentation t))
-	      (org-add-planning-info nil nil 'scheduled 'deadline))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
-	     nil nil 1))))
+	      (org-test-without-dow 'buffer
+                (org-add-planning-info nil nil 'scheduled 'deadline))))))
   ;; Remove closed when `org-adapt-indentation' is non-nil.
   (should
    (equal "* H\n  DEADLINE: <2015-06-25>\nParagraph"
 	  (org-test-with-temp-text "\
 * H
-  CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
+  CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25>
 Paragraph<point>"
 	    (let ((org-adapt-indentation t))
-	      (org-add-planning-info nil nil 'closed))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string)
-	     nil nil 1))))
+	      (org-test-without-dow 'buffer
+                (org-add-planning-info nil nil 'closed))))))
   (should
    (equal "* H\n  Paragraph"
 	  (org-test-with-temp-text "\
@@ -5748,22 +5743,18 @@ Paragraph<point>"
   CLOSED: [2015-06-25 Thu]
   Paragraph<point>"
 	    (let ((org-adapt-indentation t))
-	      (org-add-planning-info nil nil 'closed))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string)
-	     nil nil 1))))
+	      (org-test-without-dow 'buffer
+                (org-add-planning-info nil nil 'closed))))))
   ;; Remove closed when `org-adapt-indentation' is nil.
   (should
    (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
 	  (org-test-with-temp-text "\
 * H
-CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
+CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25>
 Paragraph<point>"
 	    (let ((org-adapt-indentation nil))
-	      (org-add-planning-info nil nil 'closed))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string)
-	     nil nil 1))))
+	      (org-test-without-dow 'buffer
+                (org-add-planning-info nil nil 'closed))))))
   (should
    (equal "* H\nParagraph"
 	  (org-test-with-temp-text "\
@@ -5771,10 +5762,8 @@ Paragraph<point>"
   CLOSED: [2015-06-25 Thu]
 Paragraph<point>"
 	    (let ((org-adapt-indentation nil))
-	      (org-add-planning-info nil nil 'closed))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string)
-	     nil nil 1))))
+	      (org-test-without-dow 'buffer
+                (org-add-planning-info nil nil 'closed))))))
   ;; Remove closed entry and delete empty line.
   (should
    (equal "\
@@ -5785,10 +5774,8 @@ Paragraph"
   CLOSED: [2015-06-24 Wed]
 Paragraph<point>"
 	    (let ((org-adapt-indentation t))
-	      (org-add-planning-info nil nil 'closed))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string)
-	     nil nil 1))))
+	      (org-test-without-dow 'buffer
+                (org-add-planning-info nil nil 'closed))))))
   ;; Remove one entry and update another.
   (should
    (equal "* H\n  DEADLINE: <2015-06-25>\nParagraph"
@@ -5797,10 +5784,8 @@ Paragraph<point>"
   SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
 Paragraph<point>"
 	    (let ((org-adapt-indentation t))
-	      (org-add-planning-info 'deadline "<2015-06-25 Thu>" 'scheduled))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string)
-	     nil nil 1)))))
+	      (org-test-without-dow 'buffer
+                (org-add-planning-info 'deadline "<2015-06-25 Thu>" 'scheduled)))))))
 
 (ert-deftest test-org/deadline ()
   "Test `org-deadline' specifications."
@@ -5810,19 +5795,15 @@ Paragraph<point>"
 	  (org-test-with-temp-text "* H"
 	    (let ((org-adapt-indentation nil)
 		  (org-last-inserted-timestamp nil))
-	      (org-deadline nil "<2012-03-29 Tue>"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string)
-	     nil nil 1))))
+	      (org-test-without-dow 'buffer
+                (org-deadline nil "<2012-03-29 Tue>"))))))
   (should
    (equal "* H\nDEADLINE: <2014-03-04>"
 	  (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
 	    (let ((org-adapt-indentation nil)
 		  (org-last-inserted-timestamp nil))
-	      (org-deadline nil "<2014-03-04 Thu>"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string)
-	     nil nil 1))))
+	      (org-test-without-dow 'buffer
+                (org-deadline nil "<2014-03-04 Thu>"))))))
   ;; Accept delta time, e.g., "+2d".
   (should
    (equal "* H\nDEADLINE: <2015-03-04>"
@@ -5830,44 +5811,39 @@ Paragraph<point>"
 	    (org-test-with-temp-text "* H"
 	      (let ((org-adapt-indentation nil)
 		    (org-last-inserted-timestamp nil))
-		(org-deadline nil "+1y"))
-	      (replace-regexp-in-string
-	       "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
+		(org-test-without-dow 'buffer
+                  (org-deadline nil "+1y")))))))
   ;; Preserve repeater.
   (should
    (equal "* H\nDEADLINE: <2012-03-29 +2y>"
 	  (org-test-with-temp-text "* H"
 	    (let ((org-adapt-indentation nil)
 		  (org-last-inserted-timestamp nil))
-	      (org-deadline nil "<2012-03-29 Tue +2y>"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
+	      (org-test-without-dow 'buffer
+                (org-deadline nil "<2012-03-29 Tue +2y>"))))))
   ;; Preserve warning period.
   (should
    (equal "* H\nDEADLINE: <2021-07-20 -1d>"
 	  (org-test-with-temp-text "* H"
 	    (let ((org-adapt-indentation nil)
 		  (org-last-inserted-timestamp nil))
-	      (org-deadline nil "<2021-07-20 Tue -1d>"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
+	      (org-test-without-dow 'buffer
+                (org-deadline nil "<2021-07-20 Tue -1d>"))))))
   (should
    (equal "* H\nDEADLINE: <2021-07-20 +1m -3d>"
 	  (org-test-with-temp-text "* H"
 	    (let ((org-adapt-indentation nil)
 		  (org-last-inserted-timestamp nil))
-	      (org-deadline nil "<2021-07-20 Tue +1m -3d>"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
+	      (org-test-without-dow 'buffer
+                (org-deadline nil "<2021-07-20 Tue +1m -3d>"))))))
   ;; Remove CLOSED keyword, if any.
   (should
    (equal "* H\nDEADLINE: <2012-03-29>"
 	  (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
 	    (let ((org-adapt-indentation nil)
 		  (org-last-inserted-timestamp nil))
-	      (org-deadline nil "<2012-03-29 Tue>"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
+	      (org-test-without-dow 'buffer
+                (org-deadline nil "<2012-03-29 Tue>"))))))
   ;; With C-u argument, remove DEADLINE keyword.
   (should
    (equal "* H\n"
@@ -5912,12 +5888,11 @@ Paragraph<point>"
 	    (let ((org-adapt-indentation nil)
 		  (org-last-inserted-timestamp nil)
 		  (org-loop-over-headlines-in-active-region t))
-	      (transient-mark-mode 1)
+              (transient-mark-mode 1)
 	      (push-mark (point) t t)
 	      (goto-char (point-max))
-	      (org-deadline nil "2012-03-29"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
+              (org-test-without-dow 'buffer
+	        (org-deadline nil "2012-03-29"))))))
   (should-not
    (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
 	  (org-test-with-temp-text "* H1\n* H2"
@@ -5927,130 +5902,120 @@ Paragraph<point>"
 	      (transient-mark-mode 1)
 	      (push-mark (point) t t)
 	      (goto-char (point-max))
-	      (org-deadline nil "2012-03-29"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
+	      (org-test-without-dow 'buffer
+                (org-deadline nil "2012-03-29")))))))
 
 (ert-deftest test-org/schedule ()
   "Test `org-schedule' specifications."
   ;; Insert a new value or replace existing one.
   (should
    (equal "* H\nSCHEDULED: <2012-03-29>"
-	  (org-test-with-temp-text "* H"
-	    (let ((org-adapt-indentation nil)
-		  (org-last-inserted-timestamp nil))
-	      (org-schedule nil "<2012-03-29 Tue>"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string)
-	     nil nil 1))))
+          (org-test-with-temp-text "* H"
+            (let ((org-adapt-indentation nil)
+                  (org-last-inserted-timestamp nil))
+              (org-test-without-dow 'buffer
+                (org-schedule nil "<2012-03-29 Tue>"))))))
   (should
    (equal "* H\nSCHEDULED: <2014-03-04>"
-	  (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
-	    (let ((org-adapt-indentation nil)
-		  (org-last-inserted-timestamp nil))
-	      (org-schedule nil "<2014-03-04 Thu>"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string)
-	     nil nil 1))))
+          (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
+            (let ((org-adapt-indentation nil)
+                  (org-last-inserted-timestamp nil))
+              (org-test-without-dow 'buffer
+                (org-schedule nil "<2014-03-04 Thu>"))))))
   ;; Accept delta time, e.g., "+2d".
   (should
    (equal "* H\nSCHEDULED: <2015-03-04>"
-	  (org-test-at-time "2014-03-04"
-	    (org-test-with-temp-text "* H"
-	      (let ((org-adapt-indentation nil)
-		    (org-last-inserted-timestamp nil))
-		(org-schedule nil "+1y"))
-	      (replace-regexp-in-string
-	       "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
+          (org-test-at-time "2014-03-04"
+            (org-test-with-temp-text "* H"
+              (let ((org-adapt-indentation nil)
+                    (org-last-inserted-timestamp nil))
+                (org-test-without-dow 'buffer
+                  (org-schedule nil "+1y")))))))
   ;; Preserve repeater.
   (should
    (equal "* H\nSCHEDULED: <2012-03-29 +2y>"
-	  (org-test-with-temp-text "* H"
-	    (let ((org-adapt-indentation nil)
-		  (org-last-inserted-timestamp nil))
-	      (org-schedule nil "<2012-03-29 Tue +2y>"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
+          (org-test-with-temp-text "* H"
+            (let ((org-adapt-indentation nil)
+                  (org-last-inserted-timestamp nil))
+              (org-test-without-dow 'buffer
+                (org-schedule nil "<2012-03-29 Tue +2y>"))))))
   ;; Remove CLOSED keyword, if any.
   (should
    (equal "* H\nSCHEDULED: <2012-03-29>"
-	  (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
-	    (let ((org-adapt-indentation nil)
-		  (org-last-inserted-timestamp nil))
-	      (org-schedule nil "<2012-03-29 Tue>"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
+          (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
+            (let ((org-adapt-indentation nil)
+                  (org-last-inserted-timestamp nil))
+              (org-test-without-dow 'buffer
+                (org-schedule nil "<2012-03-29 Tue>"))))))
   ;; With C-u argument, remove SCHEDULED keyword.
   (should
    (equal "* H\n"
-	  (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
-	    (let ((org-adapt-indentation nil)
-		  (org-last-inserted-timestamp nil))
-	      (org-schedule '(4)))
-	    (buffer-string))))
+          (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
+            (let ((org-adapt-indentation nil)
+                  (org-last-inserted-timestamp nil))
+              (org-schedule '(4)))
+            (buffer-string))))
   (should
    (equal "* H"
-	  (org-test-with-temp-text "* H"
-	    (let ((org-adapt-indentation nil)
-		  (org-last-inserted-timestamp nil))
-	      (org-schedule '(4)))
-	    (buffer-string))))
+          (org-test-with-temp-text "* H"
+            (let ((org-adapt-indentation nil)
+                  (org-last-inserted-timestamp nil))
+              (org-schedule '(4)))
+            (buffer-string))))
   ;; With C-u C-u argument, prompt for a delay cookie.
   (should
    (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
-	  (cl-letf (((symbol-function 'org-read-date)
-		     (lambda (&rest _args)
-		       (org-time-string-to-time "2014-03-04"))))
-	    (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
-	      (let ((org-adapt-indentation nil)
-		    (org-last-inserted-timestamp nil))
-		(org-schedule '(16)))
-	      (buffer-string)))))
+          (cl-letf (((symbol-function 'org-read-date)
+                     (lambda (&rest _args)
+                       (org-time-string-to-time "2014-03-04"))))
+            (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
+              (let ((org-adapt-indentation nil)
+                    (org-last-inserted-timestamp nil))
+                (org-schedule '(16)))
+              (buffer-string)))))
   (should-error
    (cl-letf (((symbol-function 'org-read-date)
-	      (lambda (&rest _args)
-		(org-time-string-to-time "2014-03-04"))))
+              (lambda (&rest _args)
+                (org-time-string-to-time "2014-03-04"))))
      (org-test-with-temp-text "* H"
        (let ((org-adapt-indentation nil)
-	     (org-last-inserted-timestamp nil))
-	 (org-schedule '(16)))
+             (org-last-inserted-timestamp nil))
+         (org-schedule '(16)))
        (buffer-string))))
   ;; When a region is active and
   ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
   ;; same value in all headlines in region.
   (should
    (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
-	  (org-test-with-temp-text "* H1\n* H2"
-	    (let ((org-adapt-indentation nil)
-		  (org-last-inserted-timestamp nil)
-		  (org-loop-over-headlines-in-active-region t))
-	      (transient-mark-mode 1)
-	      (push-mark (point) t t)
-	      (goto-char (point-max))
-	      (org-schedule nil "2012-03-29"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
+          (org-test-with-temp-text "* H1\n* H2"
+            (let ((org-adapt-indentation nil)
+                  (org-last-inserted-timestamp nil)
+                  (org-loop-over-headlines-in-active-region t))
+              (transient-mark-mode 1)
+              (push-mark (point) t t)
+              (goto-char (point-max))
+              (org-test-without-dow 'buffer
+                (org-schedule nil "2012-03-29"))))))
   (should-not
    (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
-	  (org-test-with-temp-text "* H1\n* H2"
-	    (let ((org-adapt-indentation nil)
-		  (org-last-inserted-timestamp nil)
-		  (org-loop-over-headlines-in-active-region nil))
-	      (transient-mark-mode 1)
-	      (push-mark (point) t t)
-	      (goto-char (point-max))
-	      (org-schedule nil "2012-03-29"))
-	    (replace-regexp-in-string
-	     "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
+          (org-test-with-temp-text "* H1\n* H2"
+            (let ((org-adapt-indentation nil)
+                  (org-last-inserted-timestamp nil)
+                  (org-loop-over-headlines-in-active-region nil))
+              (transient-mark-mode 1)
+              (push-mark (point) t t)
+              (goto-char (point-max))
+              (org-test-without-dow 'buffer
+                (org-schedule nil "2012-03-29"))))))
   (should
    ;; check if a repeater survives re-scheduling.
-   (string-match-p
-    "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
+   (equal
+    "* H\nSCHEDULED: <2017-02-01 ++7d>\n"
     (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
-			     (let ((org-adapt-indentation nil)
-				   (org-last-inserted-timestamp nil))
-			       (org-schedule nil "2017-02-01"))
-			     (buffer-string)))))
+      (let ((org-adapt-indentation nil)
+            (org-last-inserted-timestamp nil))
+        (org-test-without-dow 'buffer
+          (org-schedule nil "2017-02-01")))))))
 
 \f
 ;;; Property API
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


[-- Attachment #3: Type: text/plain, Size: 299 bytes --]


To summarize, the remaining goal of this patchset is to fix
`test-org-colview/columns-width', and to optionally expect-failure on
`test-org-clock/clocktable/lang'.

-- 
Best,


RY

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

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* Re: [DRAFT PATCH v2] Decouple LANG= and testing (was: Test failure due to LANG)
  2023-04-23 15:15                     ` Ruijie Yu via General discussions about Org-mode.
@ 2023-04-25 10:11                       ` Ihor Radchenko
  2023-04-25 15:14                         ` Ruijie Yu via General discussions about Org-mode.
  0 siblings, 1 reply; 34+ messages in thread
From: Ihor Radchenko @ 2023-04-25 10:11 UTC (permalink / raw)
  To: Ruijie Yu; +Cc: Axel Kielhorn, emacs-orgmode

Ruijie Yu <ruijie@netyu.xyz> writes:

> Just had a try at this, fully untested code (other than starting a
> LANG=zh_CN.UTF-8 Emacs session and running this substring function to
> see its effects).

Thanks!

> +(defun org-columns--substring-below-width (string start width)
> +  "Similar to `substring', but use `string-width' to check width.

This is not really similar to `substring' as `substring' has totally
different third argument.

> +The returned value is a substring of STRING, starting at START,
> +and is the largest possible substring whose width does not exceed
> +WIDTH."
> +  (let ((end (min (+ start width) (length string))) res)
> +    (while (and end (>= end start))
> +      (let* ((curr (string-width string start end))
> +             (excess (- curr width)))
> +        (if (cl-plusp excess)

Why not simply (> excess 0)? `cl-plusp' is a bit confusing - we
generally avoid cl-lib functions unless necessary. (I've never seen
`cl-plusp' used frequently)

>  (defun org-columns-add-ellipses (string width)
>    "Truncate STRING with WIDTH characters, with ellipses."
>    (cond
> -   ((<= (length string) width) string)
> -   ((<= width (length org-columns-ellipses))
> -    (substring org-columns-ellipses 0 width))
> -   (t (concat (substring string 0 (- width (length org-columns-ellipses)))
> -	      org-columns-ellipses))))
> +   ((<= (string-width string) width) string)
> +   ((<= width (string-width org-columns-ellipses))
> +    (org-columns--substring-below-width org-columns-ellipses 0 width))
> +   (t (concat
> +       (org-columns--substring-below-width
> +        string 0 (- width (length org-columns-ellipses)))
> +       org-columns-ellipses))))

It will be best to write dedicated tests here that will clearly indicate
issues when some non-standard LANG environment is used. The current
failure is rather difficult to debug.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [DRAFT PATCH v2] Decouple LANG= and testing (was: Test failure due to LANG)
  2023-04-25 10:11                       ` Ihor Radchenko
@ 2023-04-25 15:14                         ` Ruijie Yu via General discussions about Org-mode.
  0 siblings, 0 replies; 34+ messages in thread
From: Ruijie Yu via General discussions about Org-mode. @ 2023-04-25 15:14 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Axel Kielhorn, emacs-orgmode


Ihor Radchenko <yantar92@posteo.net> writes:

>> +(defun org-columns--substring-below-width (string start width)
>> +  "Similar to `substring', but use `string-width' to check width.
>
> This is not really similar to `substring' as `substring' has totally
> different third argument.

Addressed in v6 -- see my update in the other subthread.

>> +The returned value is a substring of STRING, starting at START,
>> +and is the largest possible substring whose width does not exceed
>> +WIDTH."
>> +  (let ((end (min (+ start width) (length string))) res)
>> +    (while (and end (>= end start))
>> +      (let* ((curr (string-width string start end))
>> +             (excess (- curr width)))
>> +        (if (cl-plusp excess)
>
> Why not simply (> excess 0)? `cl-plusp' is a bit confusing - we
> generally avoid cl-lib functions unless necessary. (I've never seen
> `cl-plusp' used frequently)

Well, one of the courses I took last year used Common Lisp, where plusp
and minusp were largely preferred over (> x 0), hence the habit.  I have
switched over accordingly in v6.

>>  (defun org-columns-add-ellipses (string width)
>>    "Truncate STRING with WIDTH characters, with ellipses."
>>    (cond
>> -   ((<= (length string) width) string)
>> -   ((<= width (length org-columns-ellipses))
>> -    (substring org-columns-ellipses 0 width))
>> -   (t (concat (substring string 0 (- width (length org-columns-ellipses)))
>> -	      org-columns-ellipses))))
>> +   ((<= (string-width string) width) string)
>> +   ((<= width (string-width org-columns-ellipses))
>> +    (org-columns--substring-below-width org-columns-ellipses 0 width))
>> +   (t (concat
>> +       (org-columns--substring-below-width
>> +        string 0 (- width (length org-columns-ellipses)))
>> +       org-columns-ellipses))))
>
> It will be best to write dedicated tests here that will clearly indicate
> issues when some non-standard LANG environment is used. The current
> failure is rather difficult to debug.

Done -- somewhat.  At the time I wrote the tests I misunderstood what
you said, so now we have a test on org-columns--truncate-below-width
(renamed from org-columns--substring-below-width).  I can add a test on
org-columns-add-ellipses as well, if you think it is necessary.  But
probably tomorrow.

-- 
Best,


RY

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


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [DRAFT PATCH v6] Decouple LANG= and testing (was: Test failure due to LANG)
  2023-04-25  8:02                         ` [DRAFT PATCH v5] " Ruijie Yu via General discussions about Org-mode.
@ 2023-04-25 15:19                           ` Ruijie Yu via General discussions about Org-mode.
  2023-04-26  9:05                             ` Ihor Radchenko
  2023-04-26  8:44                           ` [DRAFT PATCH v5] " Ihor Radchenko
  1 sibling, 1 reply; 34+ messages in thread
From: Ruijie Yu via General discussions about Org-mode. @ 2023-04-25 15:19 UTC (permalink / raw)
  To: Ruijie Yu; +Cc: Ihor Radchenko, Axel Kielhorn, emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 2099 bytes --]


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

> Ihor Radchenko <yantar92@posteo.net> writes:
>
>> (let ((org-time-stamp-formats '("%Y-%m-%d" . "%Y-%m-%d %H:%M")))
>>      (org-element-timestamp-interpreter timestamp nil))
>
> Thanks for the pointer.  I have made this into a macro and redid my
> changes accordingly.  Please also let me know if more work should be
> dedicated to avoid code duplication in tests (I see a lot of duplication
> in the portions I touched in testing/lisp/test-org.el).
>
> What currently still fails unexpectedly:
>
> zh_CN.UTF-8:
>     test-org-clock/clocktable/lang
>     - This test only fails in batch mode, as I mentioned up-thread.  I
>       might try to convert this into a test that expects failure
>       depending on whether Emacs is in batch mode.
>     test-org-colview/columns-width
>     - This patch did not attempt to fix it.  I posted a diff file under
>       v2 (not included in this patch), but that didn't work either.
>
> ja_JA.UTF-8:
>     test-org-colview/columns-width
>     - See above.
>
> fr_FR.UTF-8:
>     test-org-clok/org-clock-timestamps-change
>     - This is tracked in the other thread I created, and won't be fixed
>       by this patch.
>
> en_US.UTF-8 and de_DE.UTF-8:
>     No unexpected test failures.
>
> [2. text/x-patch; 0001-DRAFT-Fix-dependence-on-locale-in-org-testing-facili.patch]...
>
>
> To summarize, the remaining goal of this patchset is to fix
> `test-org-colview/columns-width', and to optionally expect-failure on
> `test-org-clock/clocktable/lang'.

Iteration v6.  Everything, other than the French test and the
batch-non-batch Chinese test, now passes.  I'll look up how to determine
whether we are in batch mode or not, and slap that onto the expect tag
for `test-org-clock/clocktable/lang'.  And the French test belongs to
its own thread, so I won't try to fix it here.

V6 has two commits: the first commit is the *exact copy* of v5, and the
second commit tries to fix the zh_CN columns-width code & test.  Hence I
only attach the patch file for the second commit.


[-- Attachment #2: 0002-Let-org-columns-correctly-detect-string-widths-in-co.patch --]
[-- Type: text/x-patch, Size: 4454 bytes --]

From 59cbb93b9fc221bdc8ee708b05943a245c41ad25 Mon Sep 17 00:00:00 2001
From: Ruijie Yu <ruijie@netyu.xyz>
Date: Tue, 25 Apr 2023 22:56:02 +0800
Subject: [PATCH 2/2] Let org-columns correctly detect string-widths in code

TODO: maybe I should also make a test directly on
`org-columns-add-ellipses'.  Will do in next iteration unless
objections.

* lisp/org-colview.el (org-columns--truncate-below-width): add a
helper function that will trim off just enough data from string to
fit into expected width.
(org-columns-add-ellipses): make sure to do truncation correctly
even in CJK locales (where an ellipsis character takes two
spaces).

* testing/lisp/test-org-colview.el
(test-org-colview/substring-below-width): add test to make sure
helper function is correct.
(test-org-colview/columns-width): fix incorrect expectations for
CJK locales about ellipses.
---
 lisp/org-colview.el              | 26 +++++++++++++++++++++-----
 testing/lisp/test-org-colview.el | 19 ++++++++++++++++++-
 2 files changed, 39 insertions(+), 6 deletions(-)

diff --git a/lisp/org-colview.el b/lisp/org-colview.el
index 92a3b473d..6311a9274 100644
--- a/lisp/org-colview.el
+++ b/lisp/org-colview.el
@@ -452,14 +452,30 @@ DATELINE is non-nil when the face used should be
 	    "Type \\<org-columns-map>`\\[org-columns-edit-value]' \
 to edit property")))))))
 
+(defun org-columns--truncate-below-width (string width)
+  "Return a substring of STRING no wider than WIDTH.
+This substring must start at 0, and must be the longest possible
+substring whose `string-width' does not exceed WIDTH."
+  (declare (side-effect-free t))
+  (let ((end (min width (length string))) res)
+    (while (and end (>= end 0))
+      (let* ((curr (string-width string 0 end))
+             (excess (- curr width)))
+        (if (> excess 0)
+            (cl-decf end (max 1 (/ excess 2)))
+          (setq res (substring string 0 end) end nil))))
+    res))
+
 (defun org-columns-add-ellipses (string width)
   "Truncate STRING with WIDTH characters, with ellipses."
   (cond
-   ((<= (length string) width) string)
-   ((<= width (length org-columns-ellipses))
-    (substring org-columns-ellipses 0 width))
-   (t (concat (substring string 0 (- width (length org-columns-ellipses)))
-	      org-columns-ellipses))))
+   ((<= (string-width string) width) string)
+   ((<= width (string-width org-columns-ellipses))
+    (org-columns--truncate-below-width org-columns-ellipses width))
+   (t (concat
+       (org-columns--truncate-below-width
+        string (- width (string-width org-columns-ellipses)))
+       org-columns-ellipses))))
 
 (defvar org-columns-full-header-line-format nil
   "The full header line format, will be shifted by horizontal scrolling." )
diff --git a/testing/lisp/test-org-colview.el b/testing/lisp/test-org-colview.el
index 9daec18e2..b421fdc41 100644
--- a/testing/lisp/test-org-colview.el
+++ b/testing/lisp/test-org-colview.el
@@ -26,6 +26,23 @@
 (require 'org-duration)
 (require 'org-inlinetask)
 
+(ert-deftest test-org-colview/substring-below-width ()
+  "Test `org-columns--truncate-below-width'."
+  (cl-flet ((check (string width expect)
+              (string= expect (org-columns--truncate-below-width
+                               string width))))
+    (if (= (char-width ?…) 2)
+        (progn (should (check "12…" 3 "12"))
+               (should (check "1…2" 1 "1"))
+               (should (check "1…2" 2 "1"))
+               (should (check "1…2" 3 "1…"))
+               (should (check "……………………" 7 "………")))
+      (progn (should (check "12…" 4 "12…"))
+             (should (check "1…2" 1 "1"))
+             (should (check "1…2" 2 "1…"))
+             (should (check "1…2" 3 "1…2"))
+             (should (check "……………………" 7 "…………………"))))))
+
 (ert-deftest test-org-colview/get-format ()
   "Test `org-columns-get-format' specifications."
   ;; Without any clue, use `org-columns-default-format'.
@@ -160,7 +177,7 @@
 	      (org-columns))
 	    (org-trim (get-char-property (point) 'display)))))
   (should
-   (equal "1234… |"
+   (equal (if (= 1 (char-width ?…)) "1234… |" "123… |")
 	  (org-test-with-temp-text "* H\n:PROPERTIES:\n:P: 123456\n:END:"
 	    (let ((org-columns-default-format "%5P")
 		  (org-columns-ellipses "…"))
-- 
2.40.0


[-- Attachment #3: Type: text/plain, Size: 161 bytes --]


Comments welcome, thanks.

-- 
Best,


RY

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

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* Re: [DRAFT PATCH v5] Decouple LANG= and testing (was: Test failure due to LANG)
  2023-04-25  8:02                         ` [DRAFT PATCH v5] " Ruijie Yu via General discussions about Org-mode.
  2023-04-25 15:19                           ` [DRAFT PATCH v6] " Ruijie Yu via General discussions about Org-mode.
@ 2023-04-26  8:44                           ` Ihor Radchenko
  2023-07-17  8:58                             ` Ihor Radchenko
  1 sibling, 1 reply; 34+ messages in thread
From: Ihor Radchenko @ 2023-04-26  8:44 UTC (permalink / raw)
  To: Ruijie Yu; +Cc: Axel Kielhorn, emacs-orgmode

Ruijie Yu <ruijie@netyu.xyz> writes:

> Ihor Radchenko <yantar92@posteo.net> writes:
>
>> (let ((org-time-stamp-formats '("%Y-%m-%d" . "%Y-%m-%d %H:%M")))
>>      (org-element-timestamp-interpreter timestamp nil))
>
> Thanks for the pointer.  I have made this into a macro and redid my
> changes accordingly.  Please also let me know if more work should be
> dedicated to avoid code duplication in tests (I see a lot of duplication
> in the portions I touched in testing/lisp/test-org.el).

Thanks!
Some comments below.

> +(defmacro org-test-with-result (result &rest body)
...
> +             (_ result))))
> +
> +(defmacro org-test-without-dow (result &rest body)
> +  "Eval BODY skipping day-of-week in timestamps.
> +See `org-test-with-result' for RESULT and the return value."
> +  (declare (indent 1))
> +  `(let ((org-time-stamp-formats '("%Y-%m-%d" . "%Y-%m-%d %H:%M")))
> +     ;; ,(macroexpand-1 `(org-test-with-result ,result ,@body))
> +     (org-test-with-result ,result ,@body)))

When reading the test code, this `org-test-without-dow' is quite
confusing - the name suggests "day of week"-related, but RESULTS='buffer
argument is doing something completely different.

IMHO, it would be cleaner to:
1. (let ((org-time-stamp-formats ...)) ...) around the whole test.
2. Use `org-test-with-result' explicitly inside individual test clauses.

> +(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'.")

These constants make it necessary to write incantations like

   (sun (aref org-test-day-of-weeks-abbrev 0))

Why not creating a function like (org-test-translate-dow "Mon")
or (org-test-translate-dow "Monday") that will do the same?
It will be a lot more readable as well. You can then use an alist
instead of vectors.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [DRAFT PATCH v6] Decouple LANG= and testing (was: Test failure due to LANG)
  2023-04-25 15:19                           ` [DRAFT PATCH v6] " Ruijie Yu via General discussions about Org-mode.
@ 2023-04-26  9:05                             ` Ihor Radchenko
  0 siblings, 0 replies; 34+ messages in thread
From: Ihor Radchenko @ 2023-04-26  9:05 UTC (permalink / raw)
  To: Ruijie Yu via General discussions about Org-mode.
  Cc: Ruijie Yu, Axel Kielhorn

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

> Iteration v6.  Everything, other than the French test and the
> batch-non-batch Chinese test, now passes.  I'll look up how to determine
> whether we are in batch mode or not, and slap that onto the expect tag
> for `test-org-clock/clocktable/lang'.  And the French test belongs to
> its own thread, so I won't try to fix it here.

Ideally, we should figure out what is behaving differently in batch mode
and report it upstream. Sometimes, these issues are related to our
misunderstandings of how Emacs works. For example, I had to add
`org-current-text-column' because Org relied on some undocumented (and
changed in recent Emacs versions) behaviour of `current-column'.

> From 59cbb93b9fc221bdc8ee708b05943a245c41ad25 Mon Sep 17 00:00:00 2001
> From: Ruijie Yu <ruijie@netyu.xyz>
> Date: Tue, 25 Apr 2023 22:56:02 +0800
> Subject: [PATCH 2/2] Let org-columns correctly detect string-widths in code

I have no comments on the patch. Looks good to me. Better test coverage
will be also welcome.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [DRAFT PATCH v5] Decouple LANG= and testing (was: Test failure due to LANG)
  2023-04-26  8:44                           ` [DRAFT PATCH v5] " Ihor Radchenko
@ 2023-07-17  8:58                             ` Ihor Radchenko
  0 siblings, 0 replies; 34+ messages in thread
From: Ihor Radchenko @ 2023-07-17  8:58 UTC (permalink / raw)
  To: Ruijie Yu; +Cc: Axel Kielhorn, emacs-orgmode

Ihor Radchenko <yantar92@posteo.net> writes:

> Ruijie Yu <ruijie@netyu.xyz> writes:
>
>> Ihor Radchenko <yantar92@posteo.net> writes:
>>
>>> (let ((org-time-stamp-formats '("%Y-%m-%d" . "%Y-%m-%d %H:%M")))
>>>      (org-element-timestamp-interpreter timestamp nil))
>>
>> Thanks for the pointer.  I have made this into a macro and redid my
>> changes accordingly.  Please also let me know if more work should be
>> dedicated to avoid code duplication in tests (I see a lot of duplication
>> in the portions I touched in testing/lisp/test-org.el).
>
> Thanks!
> Some comments below.

I decided to go ahead and implemented my suggestions myself, after
applying your patches.
Applied, onto main.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=ab9c9732e
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=8739a9578
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=9730f408c
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=26440689a

Note that I am going through this thread after a reminder to re-check
copyright status. I may still miss some of your other patches.
If you have something pending, you can let me know, so that we do not
wait until my previous scheduling triggers.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 34+ messages in thread

end of thread, other threads:[~2023-07-17  8:59 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-22  7:11 Test failure due to LANG Axel Kielhorn
2023-04-22  9:51 ` Ruijie Yu via General discussions about Org-mode.
2023-04-22 10:15   ` Ruijie Yu via General discussions about Org-mode.
2023-04-22 12:37     ` Ruijie Yu via General discussions about Org-mode.
2023-04-22 13:01       ` [DRAFT PATCH v2] Decouple LANG= and testing (was: Test failure due to LANG) Ruijie Yu via General discussions about Org-mode.
2023-04-22 13:51         ` Ruijie Yu via General discussions about Org-mode.
2023-04-23 10:54           ` Ihor Radchenko
     [not found]             ` <sdvjzy2rhne.fsf@netyu.xyz>
2023-04-23 11:19               ` Ihor Radchenko
2023-04-23 14:30                 ` Ruijie Yu via General discussions about Org-mode.
2023-04-23 15:03                   ` Ihor Radchenko
2023-04-23 15:15                     ` Ruijie Yu via General discussions about Org-mode.
2023-04-25 10:11                       ` Ihor Radchenko
2023-04-25 15:14                         ` Ruijie Yu via General discussions about Org-mode.
2023-04-22 14:50         ` Axel Kielhorn
2023-04-22 15:03           ` Ruijie Yu via General discussions about Org-mode.
2023-04-23  1:47             ` [DRAFT PATCH v3] " Ruijie Yu via General discussions about Org-mode.
2023-04-23  5:36               ` Axel Kielhorn
2023-04-23  6:46                 ` [DRAFT PATCH v4] " Ruijie Yu via General discussions about Org-mode.
2023-04-23 11:17                   ` Ihor Radchenko
2023-04-23 13:57                     ` Ruijie Yu via General discussions about Org-mode.
2023-04-23 15:07                       ` Ihor Radchenko
2023-04-25  8:02                         ` [DRAFT PATCH v5] " Ruijie Yu via General discussions about Org-mode.
2023-04-25 15:19                           ` [DRAFT PATCH v6] " Ruijie Yu via General discussions about Org-mode.
2023-04-26  9:05                             ` Ihor Radchenko
2023-04-26  8:44                           ` [DRAFT PATCH v5] " Ihor Radchenko
2023-07-17  8:58                             ` Ihor Radchenko
2023-04-22 14:28       ` Test failure due to LANG Axel Kielhorn
2023-04-22 12:35 ` Ihor Radchenko
2023-04-22 13:00   ` Ruijie Yu via General discussions about Org-mode.
2023-04-22 14:21   ` Max Nikulin
2023-04-22 14:35     ` Ihor Radchenko
2023-04-22 14:40     ` Axel Kielhorn
2023-04-22 16:14       ` Max Nikulin
2023-04-22 14:36   ` Axel Kielhorn

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).