emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Mehmet Tekman <mtekman89@gmail.com>
To: Ihor Radchenko <yantar92@posteo.net>
Cc: emacs-orgmode@gnu.org
Subject: Re: [ANN] lisp/ob-tangle-sync.el
Date: Wed, 17 May 2023 15:45:33 +0200	[thread overview]
Message-ID: <87a5y3vzpe.fsf@gmail.com> (raw)
In-Reply-To: <87leho3y0n.fsf@localhost> (Ihor Radchenko's message of "Tue, 16 May 2023 18:57:12 +0000")

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

Hello again,

Ihor Radchenko <yantar92@posteo.net> writes:

>>> I recommend trying various edge cases with your patch.
>>> In particular:
>>>
>>> 1. Testing exclusive group inheritance when we inherit a header arg
>>>    value that matches :any:
>>>
>>>    #+PROPERTIES: header-args :tangle "foo.txt"
>>>    #+begin_src ... :tangle no
>>>
>>>    #+PROPERTIES: header-args :tangle no
>>>    #+begin_src ... :tangle "foo.txt"
>>>
>>>    #+PROPERTIES: header-args :tangle no
>>>    * Heading
>>>
>>>    :PROPERTIES:
>>>    :header-args: :tangle "foo.txt"
>>>    :END:
>>>    #+begin_src ... :tangle yes
>> ...
>>> I feel that the following code is not reliable when we inherit exact and
>>> :any exclusive group members in alternations.
>>
>> Ah, hmm - can you give me an example here? I thought the idea was that
>> an :any string would only be invokable once for a given header
>> parameter.
>
> See the above 3 examples: (1) "foo.txt" shadowed by "no"; (2) "no"
> shadowed by "foo.txt"; (3) "no" shadowed by "foo.txt" then shadowed by
> "yes".
>
> You can also consider "foo.txt" shadowed by "bar.txt" and other
> variations.

I've created a small patch that contains a single ert test function that
checks an example org file I made (based on the above as well as my own
toy file) to try to validate the `org-babel-merge-params' rewrite.

I've attached it below in case you want to test it...

...but there were a few cases where I wasn't entirely sure what the
result of the merge was supposed to be:

For example, a document with:

> #+TITLE: Header tests
> #+PROPERTY: header-args :tangle /tmp/default_tangle.txt
> 
> * Inherit tangle header from document
> 
> #+begin_src conf
>   (:tangle . /tmp/default_tangle.txt)
> #+end_src

I would expect the output of:

    (assoc :tangle (nth 2 (org-babel-get-src-block-info)))

within that block to evaluate to the contents written in that
block. Instead it evaluates to `(:tangle . no)' when run in a vanilla
Emacs. Is this expected?


Another example:

> * Header args overwritten by local header
> :PROPERTIES:
> :header-args: :tangle "foo.txt"
> :END:
> #+begin_src :tangle yes
>    (:tangle . foo.txt)
> #+end_src
>
> ** Inherited header
> 
> #+begin_src :tangle "file with spaces.txt"
>   (:tangle . "file with spaces.txt")
> #+end_src

The first block correctly gives "foo.txt" under vanilla Emacs, but the
second block also gives "foo.txt". Is this expected behaviour?


Best,
Mehmet


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: test org file and associated ert test function --]
[-- Type: text/x-patch, Size: 7406 bytes --]

From 2f040db1197f835262d32e7ced857f2a47dd8ca8 Mon Sep 17 00:00:00 2001
From: MT <mtekman89@gmail.com>
Date: Wed, 17 May 2023 13:16:08 +0200
Subject: [PATCH 4/4] * testing/examples/header_test.org: New example test file

  Contains several source blocks with document, heading, block header
  arguments

* testing/lisp/test-ob.el (test-ob/merge-params): New test function
for `org-babel-merge-params' validation.

  This function takes a list of all the ID properties for each of the
  blocks in `header_test.org', along with a symbol or list of header
  properties to test against.  The expected value is written within
  the block contents.
---
 testing/examples/header_test.org | 127 +++++++++++++++++++++++++++++++
 testing/lisp/test-ob.el          |  44 +++++++++++
 2 files changed, 171 insertions(+)
 create mode 100644 testing/examples/header_test.org

diff --git a/testing/examples/header_test.org b/testing/examples/header_test.org
new file mode 100644
index 000000000..9a33661be
--- /dev/null
+++ b/testing/examples/header_test.org
@@ -0,0 +1,127 @@
+#+TITLE: Header tests
+#+PROPERTY: header-args :tangle /tmp/default_tangle.txt
+
+The text contents in each block are tested against the output of
+=(assoc <prop> (nth 2 (org-babel-get-src-block-info)))=
+
+Multiple header properties can be tested by separating each property
+output with a **newline followed by exactly two spaces**.
+
+* Inherit tangle header from document
+:PROPERTIES:
+:ID:       a41c3238-f457-4769-b10b-8d50e9d386a1
+:END:
+
+#+begin_src conf
+  (:tangle . /tmp/default_tangle.txt)
+#+end_src
+
+* Inherit tangle header but use local sync action
+:PROPERTIES:
+:ID:       debf7bf8-e5eb-412d-9127-57950a27c390
+:END:
+
+#+begin_src conf :tangle skip
+  (:tangle . /tmp/default_tangle.txt skip)
+#+end_src
+
+* Use local tangle file and sync action
+:PROPERTIES:
+:ID:       1ca658c1-0dfd-42a5-bbe3-305582deeb00
+:END:
++ Ignore document header completely.
+#+begin_src conf :tangle randomfile sync
+  (:tangle . randomfile sync)
+#+end_src
+
+* Use local tangle file and sync action 2
+:PROPERTIES:
+:header-args: :tangle "newfile.txt" import
+:END:
+** Subheading
+:PROPERTIES:
+:ID:       602503b8-6657-49c6-9cac-7edac396f725
+:END:
++ Ignore document header and parent header completely.
+#+begin_src conf :tangle randomfile sync
+  (:tangle . randomfile sync)
+#+end_src
+
+
+* Test tangle and results param together
+:PROPERTIES:
+:ID:       4fb9938c-aec0-479f-bbc6-6b7a4228d9c2
+:END:
+#+begin_src conf  :tangle randomfile
+  (:tangle . randomfile)
+  (:results . replace)
+#+end_src
+
+* Inherit the tangle file name, take the last sync action
+:PROPERTIES:
+:ID:       7a98b56d-e59f-426d-bd58-f93bb22cf57b
+:END:
++ Ignores import
+#+begin_src conf  :tangle import export
+  (:tangle . /tmp/default_tangle.txt export)
+#+end_src
+
+* Take the last local tangle file name and the last sync action
+:PROPERTIES:
+:ID:       cd85e03a-1a4c-45d5-ac33-90d96999b665
+:END:
++ Ignores fname1 and sync
+#+begin_src conf  :tangle fname1 fname2 sync export
+  (:tangle . fname2 export)
+#+end_src
+
+* Merge document results param and local results param
+:PROPERTIES:
+:ID:       f4e4e422-029b-4ef7-b594-cd70cff2d943
+:END:
+
+#+begin_src sh :results file wrap
+  (:results . wrap file replace)
+  (:exports . code)
+#+end_src
+
+* All tangle headers should be ignored (ITS FAILING HERE)
+:PROPERTIES:
+:ID:       9715d355-009c-4188-8b97-bcbebaeee86f
+:END:
+
+#+begin_src conf :tangle no
+  (:tangle . no)
+#+end_src
+
+* Tangle filename ignores document and heading args, inherits heading exports
+:PROPERTIES:
+:ID:       1a3b5565-27b5-450e-a2c5-7f95a8142f3b
+:header-args: :tangle no :exports verbatim
+:END:
+
+#+begin_src conf :tangle "foo.txt" :comments link
+  (:tangle . foo.txt)
+  (:exports . verbatim code)
+  (:comments . link)
+#+end_src
+
+* Heading tangle parameter is not overwritten by local "yes"
+:PROPERTIES:
+:ID:       fe54b2be-d9f1-40b4-83df-49501e69d083
+:header-args: :tangle "foo.txt"
+:END:
+#+begin_src :tangle yes
+   (:tangle . foo.txt)
+#+end_src
+
+** Local tangle filename with spaces overwrites parent foo.txt
+:PROPERTIES:
+:ID:       ab8af294-c586-4ec8-9f45-3c3baaeb184d
+:END:
++ The expected hierarchy is =/tmp/default_tangle.txt= is supplanted by
+  =foo.txt= which is supplanted by =file with spaces.txt=
+
+#+begin_src :tangle "file with spaces.txt"
+   (:tangle . "file with spaces.txt")
+#+end_src
diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el
index c8dbd44f4..e05dd083a 100644
--- a/testing/lisp/test-ob.el
+++ b/testing/lisp/test-ob.el
@@ -314,6 +314,50 @@ this is simple"
     (org-babel-next-src-block)
     (should (= 14 (org-babel-execute-src-block)))))
 
+(ert-deftest test-ob/merge-params ()
+  "Test the output of merging multiple header parameters.  The
+expected output is given in the contents of the source code block
+at each header.  The desired test header parameters are given
+either as a symbol or a list in the `idtest-alist' variable.
+Multiple header parameters must be separated by a newline and
+exactly two spaces in the block contents."
+  (let ((idtest-alist '(("a41c3238-f457-4769-b10b-8d50e9d386a1" . :tangle)
+                        ("debf7bf8-e5eb-412d-9127-57950a27c390" . :tangle)
+                        ("1ca658c1-0dfd-42a5-bbe3-305582deeb00" . :tangle)
+                        ("602503b8-6657-49c6-9cac-7edac396f725" . :tangle)
+                        ("4fb9938c-aec0-479f-bbc6-6b7a4228d9c2" . (:tangle :results))
+                        ("7a98b56d-e59f-426d-bd58-f93bb22cf57b" . :tangle)
+                        ("cd85e03a-1a4c-45d5-ac33-90d96999b665" . :tangle)
+                        ("f4e4e422-029b-4ef7-b594-cd70cff2d943" . (:results :exports))
+                        ("9715d355-009c-4188-8b97-bcbebaeee86f" . :tangle)
+                        ("1a3b5565-27b5-450e-a2c5-7f95a8142f3b" . (:tangle :exports :comments))
+                        ("fe54b2be-d9f1-40b4-83df-49501e69d083" . :tangle)
+                        ("ab8af294-c586-4ec8-9f45-3c3baaeb184d" . :tangle)))
+        buffer
+        failed-ids)
+    (unwind-protect
+        (org-test-in-example-file (expand-file-name "header_test.org" org-test-example-dir)
+          (setq buffer (current-buffer))
+          (dolist (testpair idtest-alist)
+            (let ((id (car testpair))
+                  (prop (cdr testpair)))
+              (org-test-at-id id)
+              (org-babel-next-src-block)
+              (unless (string=
+                       (if (string= "symbol" (type-of prop))
+                           (format "%s" (assoc prop
+                                               (nth 2 (org-babel-get-src-block-info))))
+                         (mapconcat (lambda (x) (format "%s"
+                                                   (assoc x
+                                                          (nth 2 (org-babel-get-src-block-info)))))
+                                    prop "\n  ")) ;; newline with exactly two spaces.
+                       (string-trim (org-element-property :value (org-element-at-point))))
+                (push id failed-ids))))
+          (kill-buffer buffer)
+          (if failed-ids
+              (user-error "%d Failed Blocks: %s" (length failed-ids) failed-ids))
+          (should (= 0 (length failed-ids) ))))))
+
 (ert-deftest test-ob/inline-src-blocks ()
   (should
    (= 1
-- 
2.40.1


  reply	other threads:[~2023-05-17 13:47 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-26 14:48 [ANN] lisp/ob-tangle-sync.el Mehmet Tekman
2023-04-26 16:43 ` John Wiegley
2023-04-26 18:43   ` Mehmet Tekman
2023-04-27  2:55 ` Ruijie Yu via General discussions about Org-mode.
2023-04-27  6:27   ` Mehmet Tekman
2023-04-28 10:57     ` Ruijie Yu via General discussions about Org-mode.
2023-04-28 11:28       ` Mehmet Tekman
2023-05-02 20:43         ` Mehmet Tekman
2023-05-03  2:31           ` Ruijie Yu via General discussions about Org-mode.
2023-05-03  7:53             ` Mehmet Tekman
2023-05-03  8:34               ` Mehmet Tekman
2023-05-03  8:44                 ` Ihor Radchenko
2023-05-03 11:43           ` Ihor Radchenko
2023-05-03 13:54             ` Mehmet Tekman
2023-05-03 18:06               ` Ihor Radchenko
2023-05-03 15:05             ` Mehmet Tekman
2023-05-03 15:21               ` Ihor Radchenko
     [not found]                 ` <87lei577g4.fsf@gmail.com>
     [not found]                   ` <87lei5v1fg.fsf@localhost>
     [not found]                     ` <87fs8duyae.fsf@localhost>
2023-05-09 14:03                       ` Mehmet Tekman
2023-05-10  9:46                         ` Ihor Radchenko
2023-05-10 11:06                           ` mtekman89
2023-05-10 11:32                             ` Ihor Radchenko
2023-05-10 16:20                               ` Mehmet Tekman
2023-05-12 12:33                                 ` Ihor Radchenko
2023-05-16 12:49                                   ` Mehmet Tekman
2023-05-16 18:57                                     ` Ihor Radchenko
2023-05-17 13:45                                       ` Mehmet Tekman [this message]
2023-05-18 10:30                                         ` Ihor Radchenko
2023-05-19  7:10                                           ` Mehmet Tekman
2023-07-15 12:38                                             ` Ihor Radchenko
2023-07-16  9:42                                               ` Mehmet Tekman
2023-07-17 11:29                                                 ` Mehmet Tekman
2023-07-18  8:47                                                   ` Ihor Radchenko
2023-07-21  8:48                                                     ` Mehmet Tekman
2023-07-22  8:02                                                       ` Ihor Radchenko
2023-07-25 11:19                                                         ` Mehmet Tekman
2023-07-25 16:19                                                           ` Ihor Radchenko
2023-07-31 13:41                                                             ` Mehmet Tekman
2023-07-31 16:38                                                               ` Ihor Radchenko
2023-07-31 20:11                                                                 ` Mehmet Tekman
2023-08-01  7:54                                                                   ` Ihor Radchenko
2023-08-01  8:49                                                                     ` Mehmet Tekman
2023-08-01  9:30                                                                       ` Ihor Radchenko
2023-08-01 18:19                                                                         ` Bastien Guerry
2023-08-02  7:29                                                                           ` Ihor Radchenko
2023-08-02 14:46                                                                   ` Mehmet Tekman
2023-08-03  6:32                                                                     ` Mehmet Tekman
2023-08-03  7:35                                                                     ` Ihor Radchenko
2023-08-03  8:08                                                                       ` Mehmet Tekman
2023-08-03  8:16                                                                         ` Ihor Radchenko
     [not found]                                                                           ` <CAHHeYzL6Z5_gGbTUrNzKDh5swgCSQiYsSj3Cs0gFy_d=eXbSBA@mail.gmail.com>
     [not found]                                                                             ` <87o7jo1q2s.fsf@localhost>
2023-08-03  8:46                                                                               ` Mehmet Tekman
2023-08-04  7:41                                                                                 ` Mehmet Tekman
2023-08-04  8:09                                                                                   ` Ihor Radchenko
2023-08-04 13:14                                                                                     ` Mehmet Tekman
2023-08-04 16:34                                                                                       ` Mehmet Tekman
2023-08-06  9:07                                                                                         ` Ihor Radchenko
2023-08-08 19:41                                                                                           ` Mehmet Tekman
2023-08-08 19:51                                                                                             ` Ihor Radchenko
2023-08-08 20:04                                                                                               ` Mehmet Tekman
2023-08-09  8:04                                                                                                 ` Ihor Radchenko
2023-08-05  8:48                                                                                       ` Ihor Radchenko
2023-08-05 22:54                                                                                         ` Mehmet Tekman
2023-11-10  9:41                                                                                           ` Ihor Radchenko
2023-11-10  9:53                                                                                             ` Mehmet Tekman
2023-12-11 13:40                                                                                               ` Ihor Radchenko
2023-12-11 14:28                                                                                                 ` Mehmet Tekman
2023-04-27 12:02 ` Ihor Radchenko
2023-04-27 13:01   ` Mehmet Tekman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a5y3vzpe.fsf@gmail.com \
    --to=mtekman89@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=yantar92@posteo.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).