testing/*: Inline result tests modified to follow current schema
[org-mode/org-kjn.git] / testing / lisp / test-ob-lob.el
blobe8d2468734974d41de4b2248638037dceb25a0c9
1 ;;; test-ob-lob.el --- test for ob-lob.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/>.
22 ;;; Tests
23 (org-babel-lob-ingest
24 (expand-file-name
25 "library-of-babel.org"
26 (expand-file-name
27 "doc"
28 (expand-file-name
29 ".."
30 (expand-file-name
31 ".."
32 (file-name-directory
33 (or load-file-name buffer-file-name)))))))
35 (ert-deftest test-ob-lob/ingest ()
36 "Test the ingestion of an org-mode file."
37 (should (< 0 (org-babel-lob-ingest
38 (expand-file-name "babel.org" org-test-example-dir)))))
40 (ert-deftest test-ob-lob/call-with-header-arguments ()
41 "Test the evaluation of a library of babel #+call: line."
42 (letf (((symbol-function 'org-babel-insert-result)
43 (symbol-function 'ignore)))
44 (org-test-at-id "fab7e291-fde6-45fc-bf6e-a485b8bca2f0"
45 (move-beginning-of-line 1)
46 (forward-line 6)
47 (message (buffer-substring (point-at-bol) (point-at-eol)))
48 (should (string= "testing" (org-babel-lob-execute
49 (org-babel-lob-get-info))))
50 (forward-line 1)
51 (should (string= "testing" (caar (org-babel-lob-execute
52 (org-babel-lob-get-info)))))
53 (forward-line 1)
54 (should (string= "testing" (org-babel-lob-execute
55 (org-babel-lob-get-info))))
56 (forward-line 1)
57 (should (string= "testing" (caar (org-babel-lob-execute
58 (org-babel-lob-get-info)))))
59 (forward-line 1)
60 (should (string= "testing" (org-babel-lob-execute
61 (org-babel-lob-get-info))))
62 (forward-line 1)
63 (should (string= "testing" (caar (org-babel-lob-execute
64 (org-babel-lob-get-info)))))
65 (forward-line 1) (beginning-of-line) (forward-char 27)
66 (should (string= "testing" (org-babel-lob-execute
67 (org-babel-lob-get-info))))
68 (forward-line 1) (beginning-of-line) (forward-char 27)
69 (should (string= "testing" (caar (org-babel-lob-execute
70 (org-babel-lob-get-info)))))
71 (forward-line 1) (beginning-of-line)
72 (should (= 4 (org-babel-lob-execute (org-babel-lob-get-info))))
73 (forward-line 1)
74 (should (string= "testing" (org-babel-lob-execute
75 (org-babel-lob-get-info))))
76 (forward-line 1)
77 (should (string= "123" (org-babel-lob-execute (org-babel-lob-get-info)))))))
79 (ert-deftest test-ob-lob/export-lob-lines ()
80 "Test the export of a variety of library babel call lines."
81 (let ((org-babel-inline-result-wrap "=%s=")
82 (org-export-babel-evaluate t))
83 (org-test-at-id "72ddeed3-2d17-4c7f-8192-a575d535d3fc"
84 (org-narrow-to-subtree)
85 (let ((buf (current-buffer))
86 (string (buffer-string)))
87 (with-temp-buffer
88 (org-mode)
89 (insert string)
90 (org-babel-exp-process-buffer buf)
91 (message (buffer-string))
92 (goto-char (point-min))
93 (should (re-search-forward "^: 0" nil t))
94 (should (re-search-forward "call {{{results(=2=)}}} stuck" nil t))
95 (should (re-search-forward
96 "exported =call_double(it=2)= because" nil t))
97 (should (re-search-forward "^{{{results(=6=)}}} because" nil t))
98 (should (re-search-forward "results 8 should" nil t))
99 (should (re-search-forward "following 2\\*5={{{results(=10=)}}} should" nil t)))))))
101 (ert-deftest test-ob-lob/do-not-eval-lob-lines-in-example-blocks-on-export ()
102 (require 'ox)
103 (org-test-with-temp-text-in-file "
104 for export
105 #+begin_example
106 #+call: rubbish()
107 #+end_example"
108 (should (progn (org-export-execute-babel-code) t))))
110 (ert-deftest test-ob-lob/caching-call-line ()
111 (let ((temporary-value-for-test 0))
112 (org-test-with-temp-text "
113 #+name: call-line-caching-example
114 #+begin_src emacs-lisp :var bar=\"baz\"
115 (setq temporary-value-for-test (+ 1 temporary-value-for-test))
116 #+end_src
118 #+call: call-line-caching-example(\"qux\") :cache yes
120 (goto-char (point-max)) (forward-line -1)
121 ;; first execution should flip value to t
122 (should (equal (org-babel-lob-execute (org-babel-lob-get-info)) 1))
123 ;; if cached, second evaluation will retain the t value
125 ;; Note: This instance tests for equality with "1". We would
126 ;; prefer if the cached result returned was actually 1, however
127 ;; this is not the current behavior so this test is encoding
128 ;; undesired behavior (because the current goal is simply to see
129 ;; that caching is used on call lines).
131 (should (equal (org-babel-lob-execute (org-babel-lob-get-info)) "1")))))
133 (ert-deftest test-ob-lob/named-caching-call-line ()
134 (let ((temporary-value-for-test 0))
135 (org-test-with-temp-text "
136 #+name: call-line-caching-example
137 #+begin_src emacs-lisp :var bar=\"baz\"
138 (setq temporary-value-for-test (+ 1 temporary-value-for-test))
139 #+end_src
141 #+name: call-line-caching-called
142 #+call: call-line-caching-example(\"qux\") :cache yes
144 (goto-char (point-max)) (forward-line -1)
145 ;; first execution should flip value to t
146 (should (equal (org-babel-lob-execute (org-babel-lob-get-info)) 1))
147 ;; if cached, second evaluation will retain the t value
149 ;; Note: This instance tests for equality with "1". We would
150 ;; prefer if the cached result returned was actually 1, however
151 ;; this is not the current behavior so this test is encoding
152 ;; undesired behavior (because the current goal is simply to see
153 ;; that caching is used on call lines).
155 (should (equal (org-babel-lob-execute (org-babel-lob-get-info)) "1")))))
157 (provide 'test-ob-lob)
159 ;;; test-ob-lob.el ends here