1 ;;; test-ob-lob.el --- test for ob-lob.el
3 ;; Copyright (c) 2010-2015, 2019 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 (eval-and-compile (require 'cl-lib
))
27 "library-of-babel.org"
35 (or load-file-name buffer-file-name
)))))))
37 (ert-deftest test-ob-lob
/ingest
()
38 "Test the ingestion of an Org file."
39 (should (< 0 (org-babel-lob-ingest
40 (expand-file-name "babel.org" org-test-example-dir
)))))
42 (ert-deftest test-ob-lob
/call-with-header-arguments
()
43 "Test the evaluation of a library of babel #+call: line."
44 (cl-letf (((symbol-function 'org-babel-insert-result
)
45 (symbol-function 'ignore
)))
46 (let ((org-babel-library-of-babel
47 (org-test-with-temp-text-in-file
50 #+begin_src emacs-lisp :var input=\"echo'd\"
55 #+begin_src emacs-lisp :var a=0 :var b=0
58 (org-babel-lob-ingest)
59 org-babel-library-of-babel
)))
60 (org-test-at-id "fab7e291-fde6-45fc-bf6e-a485b8bca2f0"
61 (move-beginning-of-line 1)
63 (message (buffer-substring (point-at-bol) (point-at-eol)))
65 (string= "testing" (org-babel-execute-src-block
66 nil
(org-babel-lob-get-info))))
69 (string= "testing" (caar (org-babel-execute-src-block
70 nil
(org-babel-lob-get-info)))))
73 (string= "testing" (org-babel-execute-src-block
74 nil
(org-babel-lob-get-info))))
77 (string= "testing" (caar (org-babel-execute-src-block
78 nil
(org-babel-lob-get-info)))))
81 (string= "testing" (org-babel-execute-src-block
82 nil
(org-babel-lob-get-info))))
85 (string= "testing" (caar (org-babel-execute-src-block
86 nil
(org-babel-lob-get-info)))))
87 (forward-line 1) (beginning-of-line) (forward-char 27)
89 (string= "testing" (org-babel-execute-src-block
90 nil
(org-babel-lob-get-info))))
91 (forward-line 1) (beginning-of-line) (forward-char 27)
93 (string= "testing" (caar (org-babel-execute-src-block
94 nil
(org-babel-lob-get-info)))))
95 (forward-line 1) (beginning-of-line)
97 (= 4 (org-babel-execute-src-block nil
(org-babel-lob-get-info))))
100 (string= "testing" (org-babel-execute-src-block
101 nil
(org-babel-lob-get-info))))
103 (should (string= "123" (org-babel-execute-src-block
104 nil
(org-babel-lob-get-info))))))))
106 (ert-deftest test-ob-lob
/export-lob-lines
()
107 "Test the export of a variety of library babel call lines."
108 (let ((org-babel-inline-result-wrap "=%s=")
109 (org-export-use-babel t
))
110 (org-test-at-id "72ddeed3-2d17-4c7f-8192-a575d535d3fc"
111 (org-narrow-to-subtree)
112 (let ((string (org-with-wide-buffer (buffer-string)))
113 (narrowing (list (point-min) (point-max))))
117 (apply #'narrow-to-region narrowing
)
118 (org-babel-exp-process-buffer)
119 (message (buffer-string))
120 (goto-char (point-min))
121 (should (re-search-forward "^: 0" nil t
))
122 (should (re-search-forward "call {{{results(=2=)}}} stuck" nil t
))
123 (should (re-search-forward
124 "exported =call_double(it=2)= because" nil t
))
125 (should (re-search-forward "^{{{results(=6=)}}} because" nil t
))
126 (should (re-search-forward "results 8 should" nil t
))
127 (should (re-search-forward "following 2\\*5={{{results(=10=)}}} should" nil t
)))))))
129 (ert-deftest test-ob-lob
/do-not-eval-lob-lines-in-example-blocks-on-export
()
131 (org-test-with-temp-text-in-file "
136 (should (progn (org-babel-exp-process-buffer) t
))))
138 (ert-deftest test-ob-lob
/caching-call-line
()
139 (let ((temporary-value-for-test 0))
140 (org-test-with-temp-text "
141 #+name: call-line-caching-example
142 #+begin_src emacs-lisp :var bar=\"baz\"
143 (setq temporary-value-for-test (+ 1 temporary-value-for-test))
146 <point>#+call: call-line-caching-example(\"qux\") :cache yes
148 ;; first execution should flip value to t
150 (eq (org-babel-execute-src-block nil
(org-babel-lob-get-info)) 1))
151 ;; if cached, second evaluation will retain the t value
153 (eq (org-babel-execute-src-block nil
(org-babel-lob-get-info)) 1)))))
155 (ert-deftest test-ob-lob
/named-caching-call-line
()
156 (let ((temporary-value-for-test 0))
157 (org-test-with-temp-text "
158 #+name: call-line-caching-example
159 #+begin_src emacs-lisp :var bar=\"baz\"
160 (setq temporary-value-for-test (+ 1 temporary-value-for-test))
163 #+name: call-line-caching-called
164 <point>#+call: call-line-caching-example(\"qux\") :cache yes
166 ;; first execution should flip value to t
168 (eq (org-babel-execute-src-block nil
(org-babel-lob-get-info)) 1))
169 ;; if cached, second evaluation will retain the t value
171 (eq (org-babel-execute-src-block nil
(org-babel-lob-get-info)) 1)))))
173 (ert-deftest test-ob-lob
/assignment-with-newline
()
174 "Test call lines with an argument containing a newline character."
177 (org-test-with-temp-text "
179 #+begin_src emacs-lisp :var x=\"a\"
183 call_test-newline[:eval yes :results raw](\"a\nb\")<point>"
184 (org-babel-execute-src-block nil
(org-babel-lob-get-info))
185 (buffer-substring (point) (point-max)))))
188 (org-test-with-temp-text "
190 #+begin_src emacs-lisp :var x=\"a\"
194 call_test-newline[:eval yes :results raw]('(1\n2))<point>"
195 (org-babel-execute-src-block nil
(org-babel-lob-get-info))
196 (buffer-substring (point) (point-max))))))
198 (ert-deftest test-ob-lob
/external-reference-syntax
()
199 "Test external reference syntax for Babel calls."
202 (org-test-with-temp-text-in-file
203 "#+name: foo\n#+begin_src emacs-lisp\n(+ 1 1)\n#+end_src"
204 (let ((file (buffer-file-name)))
205 (org-test-with-temp-text (format "#+call: %s:foo()" file
)
206 (org-babel-execute-src-block nil
(org-babel-lob-get-info))))))))
208 (ert-deftest test-ob-lob
/call-with-indirection
()
209 "Test calling code with indirection."
212 (org-test-with-temp-text
215 #+begin_src emacs-lisp
222 <point>#+call: bar()"
223 (org-babel-execute-src-block nil
(org-babel-lob-get-info)))))
226 (org-test-with-temp-text
229 #+begin_src emacs-lisp :var x=1
236 <point>#+call: bar(x=5)"
237 (org-babel-execute-src-block nil
(org-babel-lob-get-info)))))
240 (org-test-with-temp-text
243 #+begin_src emacs-lisp :var x=1
250 <point>#+call: bar()"
251 (org-babel-execute-src-block nil
(org-babel-lob-get-info))))))
253 (provide 'test-ob-lob
)
255 ;;; test-ob-lob.el ends here