1 ;;; test-ob-tangle.el --- tests for ob-tangle.el
3 ;; Copyright (c) 2010-2016 Eric Schulte
4 ;; Authors: Eric Schulte
6 ;; This file is not part of GNU Emacs.
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
23 ;; Template test file for Org tests
29 ;; (ert-deftest ob-tangle/noweb-on-tangle ()
30 ;; "Noweb header arguments tangle correctly.
31 ;; - yes expand on both export and tangle
32 ;; - no expand on neither export or tangle
33 ;; - tangle expand on only tangle not export"
34 ;; (let ((target-file (make-temp-file "ob-tangle-test-")))
35 ;; (org-test-at-id "eb1f6498-5bd9-45e0-9c56-50717053e7b7"
36 ;; (org-narrow-to-subtree)
37 ;; (org-babel-tangle target-file))
38 ;; (let ((tang (with-temp-buffer
39 ;; (insert-file-contents target-file)
41 ;; (flet ((exp-p (arg)
44 ;; (format "noweb-%s-start\\([^\000]*\\)noweb-%s-end" arg arg)
46 ;; (string-match "expanded" (match-string 1 tang)))))
47 ;; (should (exp-p "yes"))
48 ;; (should-not (exp-p "no"))
49 ;; (should (exp-p "tangle"))))))
51 (ert-deftest ob-tangle
/no-excessive-id-insertion-on-tangle
()
52 "Don't add IDs to headings without tangling code blocks."
53 (org-test-at-id "ef06fd7f-012b-4fde-87a2-2ae91504ea7e"
54 (org-babel-next-src-block)
55 (org-narrow-to-subtree)
57 (should (null (org-id-get)))))
59 (ert-deftest ob-tangle
/continued-code-blocks-w-noweb-ref
()
60 "Test that the :noweb-ref header argument is used correctly."
61 (org-test-at-id "54d68d4b-1544-4745-85ab-4f03b3cbd8a0"
63 "df|sed '1d'|awk '{print $5 \" \" $6}'|sort -n |tail -1|awk '{print $2}'"))
64 (org-narrow-to-subtree)
66 (should (unwind-protect
68 (insert-file-contents "babel.sh")
69 (goto-char (point-min))
70 (re-search-forward (regexp-quote tangled
) nil t
))
71 (when (file-exists-p "babel.sh") (delete-file "babel.sh")))))))
73 (ert-deftest ob-tangle
/expand-headers-as-noweb-references
()
74 "Test that references to headers are expanded during noweb expansion."
75 (org-test-at-id "2409e8ba-7b5f-4678-8888-e48aa02d8cb4"
76 (org-babel-next-src-block 2)
77 (let ((expanded (org-babel-expand-noweb-references)))
78 (should (string-match (regexp-quote "simple") expanded
))
79 (should (string-match (regexp-quote "length 14") expanded
)))))
81 (ert-deftest ob-tangle
/comment-links-at-left-margin
()
82 "Test commenting of links at left margin."
85 (regexp-quote "# [[http://orgmode.org][Org mode]]")
86 (org-test-with-temp-text-in-file
87 "[[http://orgmode.org][Org mode]]
88 #+header: :comments org :tangle \"test-ob-tangle.sh\"
93 (progn (org-babel-tangle)
94 (with-temp-buffer (insert-file-contents "test-ob-tangle.sh")
96 (delete-file "test-ob-tangle.sh"))))))
98 (ert-deftest ob-tangle
/comment-links-numbering
()
99 "Test numbering of source blocks when commenting with links."
101 (org-test-with-temp-text-in-file
103 #+header: :tangle \"test-ob-tangle.el\" :comments link
104 #+begin_src emacs-lisp
108 #+header: :tangle \"test-ob-tangle.el\" :comments link
109 #+begin_src emacs-lisp
116 (insert-file-contents "test-ob-tangle.el")
118 (goto-char (point-min))
119 (and (search-forward "[H:1]]" nil t
)
120 (search-forward "[H:2]]" nil t
))))
121 (delete-file "test-ob-tangle.el")))))
123 (ert-deftest ob-tangle
/jump-to-org
()
124 "Test `org-babel-tangle-jump-to-org' specifications."
128 "* H\n#+begin_src emacs-lisp\n1\n#+end_src"
129 (org-test-with-temp-text-in-file
130 "* H\n#+begin_src emacs-lisp\n1\n#+end_src"
131 (let ((file (buffer-file-name)))
132 (org-test-with-temp-text
133 (format ";; [[file:%s][H:1]]\n<point>1\n;; H:1 ends here\n"
134 (file-name-nondirectory file
))
135 (org-babel-tangle-jump-to-org)
137 ;; Multiple blocks in the same section.
141 (org-test-with-temp-text-in-file
146 #+begin_src emacs-lisp
152 #+begin_src emacs-lisp
156 (let ((file (buffer-file-name)))
157 (org-test-with-temp-text
158 (format ";; [[file:%s][H:2]]\n<point>2\n;; H:2 ends here\n"
159 (file-name-nondirectory file
))
160 (org-babel-tangle-jump-to-org)
161 (buffer-substring (line-beginning-position)
162 (line-end-position)))))))
163 ;; Preserve position within the source code.
167 (org-test-with-temp-text-in-file
168 "* H\n#+begin_src emacs-lisp\n(+ 1 1)\n#+end_src"
169 (let ((file (buffer-file-name)))
170 (org-test-with-temp-text
171 (format ";; [[file:%s][H:1]]\n(+ 1 <point>1)\n;; H:1 ends here\n"
172 (file-name-nondirectory file
))
173 (org-babel-tangle-jump-to-org)
174 (buffer-substring-no-properties (point) (line-end-position)))))))
175 ;; Blocks before first heading.
178 "Buffer start\n#+begin_src emacs-lisp\n1\n#+end_src\n* H"
179 (org-test-with-temp-text-in-file
180 "Buffer start\n#+begin_src emacs-lisp\n1\n#+end_src\n* H"
181 (let ((file (buffer-file-name)))
182 (org-test-with-temp-text
183 (format ";; [[file:%s][H:1]]\n<point>1\n;; H:1 ends here\n"
184 (file-name-nondirectory file
))
185 (org-babel-tangle-jump-to-org)
187 ;; Special case: buffer starts with a source block.
190 "#+begin_src emacs-lisp\n1\n#+end_src\n* H"
191 (org-test-with-temp-text-in-file
192 "#+begin_src emacs-lisp\n1\n#+end_src\n* H"
193 (let ((file (buffer-file-name)))
194 (org-test-with-temp-text
195 (format ";; [[file:%s][H:1]]\n<point>1\n;; H:1 ends here\n"
196 (file-name-nondirectory file
))
197 (org-babel-tangle-jump-to-org)
198 (buffer-string)))))))
200 (ert-deftest ob-tangle
/nested-block
()
201 "Test tangling of org file with nested block."
205 ,#+begin_src emacs-lisp
210 (org-test-with-temp-text-in-file
211 "#+header: :tangle \"test-ob-tangle.org\"
214 ,,#+begin_src emacs-lisp
220 (progn (org-babel-tangle)
221 (with-temp-buffer (insert-file-contents "test-ob-tangle.org")
223 (delete-file "test-ob-tangle.org"))))))
225 (provide 'test-ob-tangle
)
227 ;;; test-ob-tangle.el ends here