diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el index c8dbd44f4..2b9326865 100644 --- a/testing/lisp/test-ob.el +++ b/testing/lisp/test-ob.el @@ -314,6 +314,151 @@ 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 +in each test. 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 ((test-the-result + (lambda (test-prop) + (org-babel-next-src-block) + (org-set-regexps-and-options) + (string= + (if (string= "symbol" (type-of test-prop)) + (format "%s" (assoc test-prop (nth 2 (org-babel-get-src-block-info)))) + (mapconcat + (lambda (x) (format "%s" (assoc x (nth 2 (org-babel-get-src-block-info))))) + test-prop "\n ")) ;; newline with exactly two spaces. + (string-trim (org-element-property :value (org-element-at-point))))))) + (should ;; 1. inherit-document-header-args + (org-test-with-temp-text + "\ +#+PROPERTY: header-args :tangle /tmp/default_tangle.txt +* One +#+begin_src conf + (:tangle . /tmp/default_tangle.txt) +#+end_src" + (funcall test-the-result :tangle))) + (should ;; 2. inherit-document-header-with-local-sync-action + (org-test-with-temp-text + "\ +#+PROPERTY: header-args :tangle /tmp/default_tangle.txt +* One +#+begin_src conf :tangle skip + (:tangle . /tmp/default_tangle.txt skip) +#+end_src" + (funcall test-the-result :tangle))) + (should ;; 3. override-document-header-with-local-tfile + (org-test-with-temp-text + "\ +#+PROPERTY: header-args :tangle /tmp/default_tangle.txt +* One +#+begin_src conf :tangle randomfile sync + (:tangle . randomfile sync) +#+end_src" + (funcall test-the-result :tangle))) + (should ;; 4. override-document-and-parent-header-with-local-tfile-and-action + (org-test-with-temp-text + "\ +#+PROPERTY: header-args :tangle /tmp/default_tangle.txt +* One +:PROPERTIES: +:header-args: :tangle \"newfile.txt\" import +:END: +** Two +#+begin_src conf :tangle randomfile sync + (:tangle . randomfile sync) +#+end_src" + (funcall test-the-result :tangle))) + (should ;; 5. test-tangle-and-default-results-param-together + (org-test-with-temp-text + "\ +* One +#+begin_src conf :tangle randomfile + (:tangle . randomfile) + (:results . replace) +#+end_src" + (funcall test-the-result '(:tangle :results)))) + (should ;; 6. inherit-document-tfile-take-only-last-local-sync-action + (org-test-with-temp-text + "\ +#+PROPERTY: header-args :tangle /tmp/default_tangle.txt +* One +#+begin_src conf :tangle import export + (:tangle . /tmp/default_tangle.txt export) +#+end_src" + (funcall test-the-result :tangle))) + (should ;; 7. ignore-document-header-take-last-tfile-and-sync-action + (org-test-with-temp-text + "\ +#+PROPERTY: header-args :tangle /tmp/default_tangle.txt +* One +#+begin_src conf :tangle fname1 fname2 sync export + (:tangle . fname2 export) +#+end_src" + (funcall test-the-result :tangle))) + (should ;; 8. test-results-and-exports + (org-test-with-temp-text + "\ +* One +#+begin_src sh :results file wrap + (:results . wrap file replace) + (:exports . code) +#+end_src" + (funcall test-the-result '(:results :exports)))) + (should-not ;; 9. do-not-tangle-this-block -- + ;; THIS SHOULD NOT FAIL WITH NEW MERGE FUNCTION. + (org-test-with-temp-text + "\ +#+PROPERTY: header-args :tangle /tmp/default_tangle.txt +* One +#+begin_src conf :tangle no + (:tangle . no) +#+end_src" + (funcall test-the-result :tangle))) + (should ;; 10. test-tangle-exports-and-comments + (org-test-with-temp-text + "\ +#+PROPERTY: header-args :tangle /tmp/default_tangle.txt +* One +:PROPERTIES: +: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" + (funcall test-the-result '(:tangle :exports :comments)))) + (should ;; 11. override-document-and-heading-tfile-with-yes + (org-test-with-temp-text + "\ +#+PROPERTY: header-args :tangle /tmp/default_tangle.txt +* One +:PROPERTIES: +:header-args: :tangle \"foo.txt\" +:END: +#+begin_src conf :tangle yes + (:tangle . foo.txt) +#+end_src" + (funcall test-the-result :tangle))) + (should-not ;; 12. tangle-file-with-spaces + ;; THIS SHOULD NOT FAIL WITH NEW MERGE FUNCTION. + (org-test-with-temp-text + "\ +* One +:PROPERTIES: +:header-args: :tangle \"foo.txt\" +:END: +** Two +#+begin_src conf :tangle \"file with spaces.txt\" + (:tangle . \"file with spaces.txt\") +#+end_src" + (funcall test-the-result :tangle))))) + (ert-deftest test-ob/inline-src-blocks () (should (= 1