Update copyright years.
[org-mode.git] / testing / lisp / test-ob-tangle.el
blob8a8e2bef8c4157be9508cbadefbd05a53b85af34
1 ;;; test-ob-tangle.el --- tests for ob-tangle.el
3 ;; Copyright (c) 2010-2014 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/>.
21 ;;; Comments:
23 ;; Template test file for Org-mode tests
26 ;;; Code:
28 ;; TODO
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)
40 ;; (buffer-string))))
41 ;; (flet ((exp-p (arg)
42 ;; (and
43 ;; (string-match
44 ;; (format "noweb-%s-start\\([^\000]*\\)noweb-%s-end" arg arg)
45 ;; tang)
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)
56 (org-babel-tangle)
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"
62 (let ((tangled
63 "df|sed '1d'|awk '{print $5 \" \" $6}'|sort -n |tail -1|awk '{print $2}'"))
64 (org-narrow-to-subtree)
65 (org-babel-tangle)
66 (with-temp-buffer
67 (insert-file-contents "babel.sh")
68 (goto-char (point-min))
69 (should (re-search-forward (regexp-quote tangled) nil t)))
70 (delete-file "babel.sh"))))
72 (ert-deftest ob-tangle/expand-headers-as-noweb-references ()
73 "Test that references to headers are expanded during noweb expansion."
74 (org-test-at-id "2409e8ba-7b5f-4678-8888-e48aa02d8cb4"
75 (org-babel-next-src-block 2)
76 (let ((expanded (org-babel-expand-noweb-references)))
77 (should (string-match (regexp-quote "simple") expanded))
78 (should (string-match (regexp-quote "length 14") expanded)))))
80 (provide 'test-ob-tangle)
82 ;;; test-ob-tangle.el ends here