Merge branch 'maint'
[org-mode.git] / testing / lisp / test-ob.el
blob7035e678d2110cfd9d243322a841daff81e29cf6
1 ;;; test-ob.el --- tests for ob.el
3 ;; Copyright (c) 2010-2015 Eric Schulte
4 ;; Authors: Eric Schulte, Martyn Jago
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 ;;; Code:
23 (ert-deftest test-ob/indented-cached-org-bracket-link ()
24 "When the result of a source block is a cached indented link it
25 should still return the link."
26 (should
27 (let ((default-directory temporary-file-directory))
28 (org-test-with-temp-text
30 * Test
31 #+<point>BEGIN_SRC emacs-lisp :file test.txt :cache yes
32 (message \"test\")
33 #+END_SRC"
34 ;; Execute twice as the first time creates the cache.
35 (org-babel-execute-src-block)
36 (string= (expand-file-name "test.txt")
37 (org-babel-execute-src-block))))))
39 (ert-deftest test-ob/multi-line-header-regexp ()
40 (should(equal "^[ \t]*#\\+headers?:[ \t]*\\([^\n]*\\)$"
41 org-babel-multi-line-header-regexp))
42 ;;TODO can be optimised - and what about blah4 blah5 blah6?
43 (should (string-match
44 org-babel-multi-line-header-regexp
45 " \t #+headers: blah1 blah2 blah3 \t\n\t\n blah4 blah5 blah6 \n"))
46 (should
47 (equal
48 "blah1 blah2 blah3 \t"
49 (match-string
51 " \t #+headers: blah1 blah2 blah3 \t\n\t\n blah4 blah5 blah6 \n")))
53 ;;TODO Check - should this fail?
54 (should
55 (not (org-test-string-exact-match
56 org-babel-multi-line-header-regexp
57 " \t #+headers : blah1 blah2 blah3 \t\n\t\n blah4 blah5 blah6 \n"))))
59 (ert-deftest test-ob/src-block-regexp ()
60 (let ((test-block
61 (concat
62 "#+begin_src language -n-r-a-b -c :argument-1 yes :argument-2 no\n"
63 "echo this is a test\n"
64 "echo Currently in ' $PWD\n"
65 "#+end_src"))
66 (language "language")
67 (flags "-n-r-a-b -c ")
68 (arguments ":argument-1 yes :argument-2 no")
69 (body "echo this is a test\necho Currently in ' $PWD\n"))
70 (should (string-match org-babel-src-block-regexp test-block))
71 (should (string-match org-babel-src-block-regexp (upcase test-block)))
72 (should (equal language (match-string 2 test-block)))
73 ;;TODO Consider refactoring
74 (should (equal flags (match-string 3 test-block)))
75 (should (equal arguments (match-string 4 test-block)))
76 (should (equal body (match-string 5 test-block)))
77 ;;no switches
78 (should (org-test-string-exact-match
79 org-babel-src-block-regexp
80 (replace-regexp-in-string flags "" test-block)))
81 ;;no header arguments
82 (should (org-test-string-exact-match
83 org-babel-src-block-regexp
84 (replace-regexp-in-string arguments "" test-block)))
85 ;; should be valid with no body
86 (should (org-test-string-exact-match
87 org-babel-src-block-regexp
88 (replace-regexp-in-string body "" test-block)))))
90 (ert-deftest test-ob/default-inline-header-args ()
91 (should(equal
92 '((:session . "none")
93 (:results . "replace")
94 (:exports . "results")
95 (:hlines . "yes"))
96 org-babel-default-inline-header-args)))
98 (ert-deftest ob-test/org-babel-combine-header-arg-lists ()
99 (let ((results (org-babel-combine-header-arg-lists
100 '((foo . :any)
101 (bar)
102 (baz . ((foo bar) (baz)))
103 (qux . ((foo bar baz qux)))
104 (quux . ((foo bar))))
105 '((bar)
106 (baz . ((baz)))
107 (quux . :any)))))
108 (dolist (pair '((foo . :any)
109 (bar)
110 (baz . ((baz)))
111 (quux . :any)
112 (qux . ((foo bar baz qux)))))
113 (should (equal (cdr pair)
114 (cdr (assoc (car pair) results)))))))
116 ;;; ob-get-src-block-info
117 (ert-deftest test-ob/get-src-block-info-language ()
118 (org-test-at-marker nil org-test-file-ob-anchor
119 (let ((info (org-babel-get-src-block-info)))
120 (should (string= "emacs-lisp" (nth 0 info))))))
122 (ert-deftest test-ob/get-src-block-info-body ()
123 (org-test-at-marker nil org-test-file-ob-anchor
124 (let ((info (org-babel-get-src-block-info)))
125 (should (string-match (regexp-quote org-test-file-ob-anchor)
126 (nth 1 info))))))
128 (ert-deftest test-ob/get-src-block-info-tangle ()
129 (org-test-at-marker nil org-test-file-ob-anchor
130 (let ((info (org-babel-get-src-block-info)))
131 (should (string= "no" (cdr (assq :tangle (nth 2 info))))))))
133 (ert-deftest test-ob/elisp-in-header-arguments ()
134 "Test execution of elisp forms in header arguments."
135 (org-test-with-temp-text-in-file "
137 * elisp forms in header arguments
138 :PROPERTIES:
139 :header-args: :var prop = (* 7 6)
140 :END:
141 #+begin_src emacs-lisp
142 prop
143 #+end_src"
144 (goto-char (point-min))
145 (org-babel-next-src-block)
146 (should (= 42 (org-babel-execute-src-block)))))
148 (ert-deftest test-ob/simple-named-code-block ()
149 "Test that simple named code blocks can be evaluated."
150 (org-test-with-temp-text-in-file "
152 #+name: i-have-a-name
153 #+begin_src emacs-lisp
155 #+end_src"
156 (org-babel-next-src-block 1)
157 (should (= 42 (org-babel-execute-src-block)))))
159 (ert-deftest test-ob/simple-variable-resolution ()
160 "Test that simple variable resolution is working."
161 (org-test-with-temp-text-in-file "
163 #+name: four
164 #+begin_src emacs-lisp
165 (list 1 2 3 4)
166 #+end_src
168 #+begin_src emacs-lisp :var four=four
169 (length four)
170 #+end_src"
172 (org-babel-next-src-block 2)
173 (should (= 4 (org-babel-execute-src-block)))
174 (forward-line 5)
175 (should (string= ": 4" (buffer-substring
176 (point-at-bol)
177 (point-at-eol))))))
179 (ert-deftest test-ob/multi-line-header-arguments ()
180 "Test that multi-line header arguments and can be read."
181 (org-test-with-temp-text-in-file "
183 #+headers: :var letters='(a b c d e f g)
184 #+begin_src emacs-lisp :var numbers='(1 2 3 4 5 6 7)
185 (require 'cl-lib)
186 (cl-map 'list #'list numbers letters)
187 #+end_src"
188 (org-babel-next-src-block)
189 (let ((results (org-babel-execute-src-block)))
190 (should (eq 'a (cadr (assoc 1 results))))
191 (should (eq 'd (cadr (assoc 4 results)))))))
193 (ert-deftest test-ob/parse-header-args ()
194 (org-test-with-temp-text-in-file "
196 #+begin_src example-lang :session :results output :var num=9
197 the body
198 #+end_src"
200 (org-babel-next-src-block)
201 (let* ((info (org-babel-get-src-block-info))
202 (params (nth 2 info)))
203 (message "%S" params)
204 (should (equal "example-lang" (nth 0 info)))
205 (should (string= "the body" (org-trim (nth 1 info))))
206 (should-not (member '(:session\ \ \ \ ) params))
207 (should (equal '(:session) (assq :session params)))
208 (should (equal '(:result-type . output) (assq :result-type params)))
209 (should (equal '(num . 9) (cdr (assq :var params)))))))
211 (ert-deftest test-ob/parse-header-args2 ()
212 (org-test-with-temp-text-in-file "
214 * resolving sub-trees as references
216 #+begin_src emacs-lisp :var text=d4faa7b3-072b-4dcf-813c-dd7141c633f3
217 (length text)
218 #+end_src
220 #+begin_src org :noweb yes
221 <<simple-subtree>>
222 <<d4faa7b3-072b-4dcf-813c-dd7141c633f3>>
223 #+end_src
225 ** simple subtree with custom ID
226 :PROPERTIES:
227 :CUSTOM_ID: simple-subtree
228 :END:
229 this is simple"
231 (should (string-match (regexp-quote "this is simple")
232 (org-babel-ref-resolve "simple-subtree")))
233 (org-babel-next-src-block)
234 (should (= 14 (org-babel-execute-src-block)))))
236 (ert-deftest test-ob/inline-src-blocks ()
237 (should
238 (= 1
239 (org-test-with-temp-text
240 "In the middle <point>src_emacs-lisp{(+ 0 1)} of a line"
241 (org-babel-execute-src-block))))
242 (should
243 (= 2
244 (org-test-with-temp-text
245 "One at the end of a line: <point>src_emacs-lisp{(+ 1 1)}"
246 (org-babel-execute-src-block))))
247 (should
248 (= 3
249 (org-test-with-temp-text
250 "src_emacs-lisp{(+ 2 1)} at the beginning of a line."
251 (org-babel-execute-src-block))))
252 (should
253 (= 4
254 (org-test-with-temp-text
255 "In the middle <point>src_emacs-lisp[:results silent\
256 :exports code]{(+ 3 1)} of a line"
257 (org-babel-execute-src-block))))
258 (should
259 (= 5
260 (org-test-with-temp-text
261 "One at the end of a line: <point>src_emacs-lisp[:results silent\
262 :exports code]{(+ 4 1)}"
263 (org-babel-execute-src-block))))
264 (should
265 (= 6
266 (org-test-with-temp-text
267 "src_emacs-lisp[:results silent :exports code]{(+ 5 1)}\
268 at the beginning of a line."
269 (org-babel-execute-src-block))))
270 (should
271 (= 7
272 (org-test-with-temp-text
273 "One also evaluated: <point>src_emacs-lisp[:exports both\
274 :results silent]{(+ 6 1)}"
275 (org-babel-execute-src-block)))))
277 (ert-deftest test-ob/inline-src_blk-default-results-replace-line-1 ()
278 (let ((test-line "src_sh{echo 1}")
279 (org-babel-inline-result-wrap "=%s="))
280 ;; src_ at bol line 1...
281 (org-test-with-temp-text
282 test-line
283 (goto-char (point-min)) (org-babel-execute-maybe)
284 (should (string=
285 (concat test-line " {{{results(=1=)}}}")
286 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
287 (forward-char) (org-babel-execute-maybe)
288 (should (string=
289 (concat test-line " {{{results(=1=)}}}")
290 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
291 (re-search-forward "{{{")
292 ;;(should-error (org-ctrl-c-ctrl-c))
293 (backward-char 4) ;; last char of block body
294 (org-babel-execute-maybe)
295 (should (string=
296 (concat test-line " {{{results(=1=)}}}")
297 (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
298 ;; src_ follows space line 1...
299 (let ((test-line " src_emacs-lisp{ 1 }"))
300 (org-test-with-temp-text
301 test-line
302 (should-error (org-ctrl-c-ctrl-c))
303 (forward-char) (org-babel-execute-maybe)
304 (should (string=
305 (concat test-line " {{{results(=1=)}}}")
306 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
307 (re-search-forward "{ 1 ") (org-babel-execute-maybe)
308 (should (string=
309 (concat test-line " {{{results(=1=)}}}")
310 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
311 (forward-char 6)
312 (should-error (org-ctrl-c-ctrl-c))))
313 ;; Results on a subsequent line are replaced.
314 (should
315 (equal
316 "src_emacs-lisp{(+ 1 2)}\n {{{results(=3=)}}}"
317 (org-test-with-temp-text "src_emacs-lisp{(+ 1 2)}\n {{{results(=2=)}}}"
318 (let ((org-babel-inline-result-wrap "=%s=")) (org-babel-execute-maybe))
319 (buffer-string))))
320 ;; Also handle results at the beginning of a line.
321 (should
322 (equal
323 "src_emacs-lisp{(+ 1 2)}\n{{{results(=3=)}}}"
324 (org-test-with-temp-text "src_emacs-lisp{(+ 1 2)}\n{{{results(=2=)}}}"
325 (let ((org-babel-inline-result-wrap "=%s=")) (org-babel-execute-maybe))
326 (buffer-string))))))
328 (ert-deftest test-ob/inline-src_blk-default-results-replace-line-2 ()
329 ;; src_ at bol line 2...
330 (let ((test-line " src_emacs-lisp{ \"x\" }")
331 (org-babel-inline-result-wrap "=%s="))
332 (org-test-with-temp-text
333 (concat "\n" test-line)
334 (should-error (org-ctrl-c-ctrl-c))
335 (goto-char (point-min))
336 (should-error (org-ctrl-c-ctrl-c))
337 (forward-line)
338 (should-error (org-ctrl-c-ctrl-c))
339 (forward-char) (org-babel-execute-maybe)
340 (should (string=
341 (concat test-line " {{{results(=x=)}}}")
342 (buffer-substring-no-properties
343 (point-at-bol) (point-at-eol))))))
344 (let ((test-line "Some text prior to block src_emacs-lisp{ \"y\" }")
345 (org-babel-inline-result-wrap "=%s="))
346 (org-test-with-temp-text
347 test-line
348 (goto-char (point-max))
349 (insert (concat "\n" test-line " end"))
350 (re-search-backward "src") (org-babel-execute-maybe)
351 (should (string=
352 (concat test-line " {{{results(=y=)}}} end")
353 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
354 (re-search-forward "\" ") (org-babel-execute-maybe)
355 (should (string=
356 (concat test-line " {{{results(=y=)}}} end")
357 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
358 (forward-char 3)
359 (should-error (org-ctrl-c-ctrl-c)))))
361 (ert-deftest test-ob/inline-src_blk-manual-results-replace ()
362 (let ((test-line " src_emacs-lisp[:results replace]{ \"x\" }")
363 (org-babel-inline-result-wrap "=%s="))
364 (org-test-with-temp-text
365 (concat "\n" test-line)
366 (should-error (org-ctrl-c-ctrl-c))
367 (goto-char (point-max))
368 (org-babel-execute-maybe)
369 (beginning-of-line)
370 (should-error (org-ctrl-c-ctrl-c))
371 (forward-char) (org-babel-execute-maybe)
372 (should (string=
373 (concat test-line " {{{results(=x=)}}}")
374 (buffer-substring-no-properties
375 (point-at-bol) (point-at-eol))))))
376 (let ((test-line (concat " Some text prior to block "
377 "src_emacs-lisp[:results replace]{ \"y\" }"))
378 (org-babel-inline-result-wrap "=%s="))
379 (org-test-with-temp-text test-line
380 (goto-char (point-max))
381 (insert (concat "\n" test-line " end"))
382 (re-search-backward "src") (org-babel-execute-maybe)
383 (should (string=
384 (concat test-line " {{{results(=y=)}}} end")
385 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
386 (re-search-forward "\" ") (org-babel-execute-maybe)
387 (should (string=
388 (concat test-line " {{{results(=y=)}}} end")
389 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
390 (forward-char 3)
391 (should-error (org-ctrl-c-ctrl-c)))))
393 (ert-deftest test-ob/inline-src_blk-results-silent ()
394 (let ((test-line "src_emacs-lisp[ :results silent ]{ \"x\" }"))
395 (org-test-with-temp-text test-line
396 (org-babel-execute-maybe)
397 (should (string= test-line
398 (buffer-substring-no-properties
399 (point-at-bol) (point-at-eol))))))
400 (let ((test-line (concat " Some text prior to block src_emacs-lisp"
401 "[ :results silent ]{ \"y\" }")))
402 (org-test-with-temp-text
403 test-line
404 (goto-char (point-max))
405 (insert (concat "\n" test-line " end"))
406 (re-search-backward "src_") (org-babel-execute-maybe)
407 (should (string= (concat test-line " end")
408 (buffer-substring-no-properties
409 (point-at-bol) (point-at-eol))))
410 (re-search-forward "\" ") (org-babel-execute-maybe)
411 (should (string= (concat test-line " end")
412 (buffer-substring-no-properties
413 (point-at-bol) (point-at-eol))))
414 (forward-char 2)
415 (should-error (org-ctrl-c-ctrl-c)))))
417 (ert-deftest test-ob/inline-src_blk-results-raw ()
418 (let ((test-line "src_emacs-lisp[ :results raw ]{ \"x\" }"))
419 (org-test-with-temp-text test-line
420 (org-babel-execute-maybe)
421 (should (string= (concat test-line " x")
422 (buffer-string)))))
423 (let ((test-line (concat " Some text prior to block "
424 "src_emacs-lisp[ :results raw ]{ \"the\" }")))
425 (org-test-with-temp-text (concat test-line " end")
426 (re-search-forward "src_") (org-babel-execute-maybe)
427 (should (string= (concat test-line " the end")
428 (buffer-substring-no-properties
429 (point-at-bol) (point-at-eol))))
430 (re-search-forward "\" ") (org-babel-execute-maybe)
431 (should (string= (concat test-line " the the end")
432 (buffer-substring-no-properties
433 (point-at-bol) (point-at-eol))))
434 (forward-char 2)
435 (should-error (org-ctrl-c-ctrl-c)))))
437 (ert-deftest test-ob/inline-src_blk-results-file ()
438 (let ((test-line "src_emacs-lisp[ :results file ]{ \"~/test-file\" }"))
439 (org-test-with-temp-text
440 test-line
441 (org-babel-execute-maybe)
442 (should (string= (concat test-line " {{{results([[file:~/test-file]])}}}")
443 (buffer-substring-no-properties
444 (point-min) (point-max)))))))
446 (ert-deftest test-ob/inline-src_blk-results-scalar ()
447 (let ((test-line "src_emacs-lisp[ :results scalar ]{ \"x\" }")
448 (org-babel-inline-result-wrap "=%s="))
449 (org-test-with-temp-text
450 test-line
451 (org-babel-execute-maybe)
452 (should (string= (concat test-line " {{{results(=\"x\"=)}}}")
453 (buffer-substring-no-properties
454 (point-min) (point-max)))))))
456 (ert-deftest test-ob/inline-src_blk-results-verbatim ()
457 (let ((test-line "src_emacs-lisp[ :results verbatim ]{ \"x\" }")
458 (org-babel-inline-result-wrap "=%s="))
459 (org-test-with-temp-text
460 test-line
461 (org-babel-execute-maybe)
462 (should (string= (concat test-line " {{{results(=\"x\"=)}}}")
463 (buffer-substring-no-properties
464 (point-min) (point-max)))))))
466 (ert-deftest test-ob/combining-scalar-and-raw-result-types ()
467 (org-test-with-temp-text-in-file "
469 #+begin_src sh :results scalar
470 echo \"[[file:./cv.cls]]\"
471 #+end_src
473 #+name:
474 : [[file:./cv.cls]]
476 #+begin_src sh :results raw scalar
477 echo \"[[file:./cv.cls]]\"
478 #+end_src
480 (cl-flet ((next-result ()
481 (org-babel-next-src-block)
482 (org-babel-execute-src-block)
483 (goto-char (org-babel-where-is-src-block-result))
484 (forward-line 1)))
485 (goto-char (point-min))
486 (next-result)
487 (should (eq (org-element-type (org-element-at-point)) 'fixed-width))
488 (next-result)
489 (should-not
490 (eq (org-element-type (org-element-at-point)) 'fixed-width)))))
492 (ert-deftest test-ob/no-defaut-value-for-var ()
493 "Test that the absence of a default value for a variable DOES THROW
494 a proper error."
495 (org-test-at-id "f2df5ba6-75fa-4e6b-8441-65ed84963627"
496 (org-babel-next-src-block)
497 (let ((err
498 (should-error (org-babel-execute-src-block) :type 'error)))
499 (should
500 (equal
501 '(error
502 "Variable \"x\" must be assigned a default value")
503 err)))))
505 (ert-deftest test-ob/just-one-results-block ()
506 "Test that evaluating two times the same code block does not result in a
507 duplicate results block."
508 (org-test-with-temp-text "#+begin_src sh\necho Hello\n#+end_src\n"
509 (org-babel-execute-src-block)
510 (org-babel-execute-src-block) ; second code block execution
511 (should (search-forward "Hello")) ; the string inside the source code block
512 (should (search-forward "Hello")) ; the same string in the results block
513 (should-error (search-forward "Hello"))))
515 (ert-deftest test-ob/nested-code-block ()
516 "Test nested code blocks inside code blocks don't cause problems."
517 (should
518 (string= "#+begin_src emacs-lisp\n 'foo\n#+end_src"
519 (org-test-with-temp-text "#+begin_src org :results silent
520 ,#+begin_src emacs-lisp
521 'foo
522 ,#+end_src
523 #+end_src"
524 (let ((org-edit-src-content-indentation 2)
525 (org-src-preserve-indentation nil))
526 (org-babel-execute-src-block))))))
528 (ert-deftest test-ob/partial-nested-code-block ()
529 "Test nested code blocks inside code blocks don't cause problems."
530 (org-test-with-temp-text "#+begin_src org :results silent
531 ,#+begin_src emacs-lisp
532 #+end_src"
533 (should (string= "#+begin_src emacs-lisp" (org-babel-execute-src-block)))))
535 (ert-deftest test-ob/does-not-replace-a-block-with-the-results ()
536 (org-test-with-temp-text "#+NAME: foo
537 #+BEGIN_SRC emacs-lisp
538 'foo
539 #+END_SRC\n"
540 (org-babel-next-src-block 1)
541 (should (eq 'foo (org-babel-execute-src-block)))
542 (goto-char (point-min))
543 (org-babel-next-src-block 1)
544 (should (looking-at org-babel-src-block-regexp))))
546 (ert-deftest test-ob/catches-all-references ()
547 (org-test-with-temp-text "
548 #+NAME: literal-example
549 #+BEGIN_EXAMPLE
550 A literal example
551 on two lines
552 #+END_EXAMPLE
554 #+NAME: read-literal-example
555 #+BEGIN_SRC emacs-lisp :var x=literal-example
556 (concatenate 'string x \" for me.\")
557 #+END_SRC"
558 (org-babel-next-src-block 1)
559 (should (string= (org-babel-execute-src-block)
560 "A literal example\non two lines\n for me."))))
562 (ert-deftest test-ob/ignore-reference-in-commented-headings ()
563 (should
564 (= 2
565 (org-test-with-temp-text
567 * COMMENT H1
568 #+NAME: n
571 * H2
572 #+NAME: n
575 * Code
577 <point>#+BEGIN_SRC emacs-lisp :var x=n
579 #+END_SRC"
580 (org-babel-execute-src-block)))))
582 (ert-deftest test-ob/do-not-resolve-to-partial-names-data ()
583 (org-test-with-temp-text "
584 #+name: base_plus
585 | 1 |
586 | 2 |
588 #+name: base
589 | 3 |
590 | 4 |
592 #+begin_src emacs-lisp :var x=base
594 #+end_src"
595 (org-babel-next-src-block 1)
596 (should (equal (org-babel-execute-src-block) '((3) (4))))))
598 (ert-deftest test-ob/do-not-resolve-to-partial-names-code ()
599 (org-test-with-temp-text "
600 #+name: base_plus
601 #+begin_src emacs-lisp
602 'bar
603 #+end_src
605 #+name: base
606 #+begin_src emacs-lisp
607 'foo
608 #+end_src
610 #+begin_src emacs-lisp :var x=base
612 #+end_src"
613 (org-babel-next-src-block 3)
614 (should (equal (org-babel-execute-src-block) "foo"))))
616 (ert-deftest test-ob/allow-spaces-around-=-in-var-specs ()
617 (org-test-with-temp-text "#+begin_src emacs-lisp :var a = 1 b = 2 c= 3 d =4
618 (+ a b c d)
619 #+end_src
621 (should (= 10 (org-babel-execute-src-block)))))
623 (ert-deftest test-ob/org-babel-update-intermediate ()
624 (org-test-with-temp-text "#+name: foo
625 #+begin_src emacs-lisp
627 #+end_src
629 #+results: foo
632 #+begin_src emacs-lisp :var it=foo
633 (+ it 1)
634 #+end_src"
635 (let ((org-babel-update-intermediate nil))
636 (goto-char (point-min))
637 (org-babel-next-src-block 2)
638 (should (= 3 (org-babel-execute-src-block)))
639 (goto-char (point-min))
640 (forward-line 6)
641 (should (looking-at ": 4")))
642 (let ((org-babel-update-intermediate t))
643 (goto-char (point-min))
644 (org-babel-next-src-block 2)
645 (should (= 3 (org-babel-execute-src-block)))
646 (goto-char (point-min))
647 (forward-line 6)
648 (should (looking-at ": 2")))))
650 (ert-deftest test-ob/eval-header-argument ()
651 (cl-flet ((check-eval (eval runp)
652 (org-test-with-temp-text (format "#+begin_src emacs-lisp :eval %s
653 (setq foo :evald)
654 #+end_src" eval)
655 (let ((foo :not-run))
656 (if runp
657 (progn (should (org-babel-execute-src-block))
658 (should (eq foo :evald)))
659 (progn (should-not (org-babel-execute-src-block))
660 (should-not (eq foo :evald))))))))
661 (check-eval "never" nil)
662 (check-eval "no" nil)
663 (check-eval "never-export" t)
664 (check-eval "no-export" t)
665 (let ((org-babel-exp-reference-buffer (current-buffer)))
666 (check-eval "never" nil)
667 (check-eval "no" nil)
668 (check-eval "never-export" nil)
669 (check-eval "no-export" nil))))
671 (ert-deftest test-ob/noweb-expansion-1 ()
672 (org-test-with-temp-text "#+begin_src sh :results output :tangle yes
673 <<foo>>
674 #+end_src
676 #+name: foo
677 #+begin_src sh
679 #+end_src"
680 (should (string= (org-babel-expand-noweb-references) "bar"))))
682 (ert-deftest test-ob/noweb-expansion-2 ()
683 (org-test-with-temp-text "#+begin_src sh :results output :tangle yes
684 <<foo>>
685 #+end_src
687 #+begin_src sh :noweb-ref foo :noweb-sep \"\"
689 #+end_src
691 #+begin_src sh :noweb-ref foo :noweb-sep \"\"
693 #+end_src"
694 (should (string= (org-babel-expand-noweb-references) "barbaz"))))
696 (ert-deftest test-ob/splitting-variable-lists-in-references ()
697 (org-test-with-temp-text ""
698 (should (= 1 (length (org-babel-ref-split-args
699 "a=\"this, no work\""))))
700 (should (= 2 (length (org-babel-ref-split-args
701 "a=\"this, no work\", b=1"))))))
703 (ert-deftest test-ob/balanced-split ()
704 "Test `org-babel-balanced-split' specifications."
705 (should (equal
706 '(":a 1" "b [2 3]" "c (4 :d (5 6))")
707 (org-babel-balanced-split ":a 1 :b [2 3] :c (4 :d (5 6))"
708 '((32 9) . 58))))
709 ;; Handle un-balanced parens.
710 (should
711 (equal '(":foo ((6)" "bar 1")
712 (org-babel-balanced-split ":foo ((6) :bar 1" '((32 9) . 58))))
713 (should
714 (equal '(":foo \"(foo\"" "bar 2")
715 (org-babel-balanced-split ":foo \"(foo\" :bar 2" '((32 9) . 58))))
716 ;; Handle un-balanced quotes.
717 (should
718 (equal '(":foo \"1" "bar 3")
719 (org-babel-balanced-split ":foo \"1 :bar 3" '((32 9) . 58))))
720 ;; Handle empty string.
721 (should
722 (equal '(":foo \"\"")
723 (org-babel-balanced-split ":foo \"\"" '((32 9) . 58))))
724 ;; Handle control characters within double quotes.
725 (should
726 (equal '(":foo \"\\n\"")
727 (org-babel-balanced-split ":foo \"\\n\"" '((32 9) . 58)))))
729 (ert-deftest test-ob/commented-last-block-line-no-var ()
730 (org-test-with-temp-text-in-file "
731 #+begin_src emacs-lisp
733 #+end_src"
734 (org-babel-next-src-block)
735 (org-babel-execute-maybe)
736 (should (re-search-forward "\\#\\+results:" nil t))
737 (forward-line)
738 (should
739 (string=
741 (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
742 (org-test-with-temp-text-in-file "
743 #+begin_src emacs-lisp
744 \"some text\";;
745 #+end_src"
746 (org-babel-next-src-block)
747 (org-babel-execute-maybe)
748 (should (re-search-forward "\\#\\+results:" nil t))
749 (forward-line)
750 (should
751 (string=
752 ": some text"
753 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
755 (ert-deftest test-ob/commented-last-block-line-with-var ()
756 (org-test-with-temp-text-in-file "
757 #+begin_src emacs-lisp :var a=1
759 #+end_src"
760 (org-babel-next-src-block)
761 (org-babel-execute-maybe)
762 (re-search-forward "\\#\\+results:" nil t)
763 (forward-line)
764 (should (string=
766 (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
767 (org-test-with-temp-text-in-file "
768 #+begin_src emacs-lisp :var a=2
770 #+end_src"
771 (org-babel-next-src-block)
772 (org-babel-execute-maybe)
773 (re-search-forward "\\#\\+results:" nil t)
774 (forward-line)
775 (should (string=
776 ": 2"
777 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
779 (ert-deftest test-ob/org-babel-insert-result ()
780 "Test `org-babel-insert-result' specifications."
781 ;; Do not error when output is an improper list.
782 (should
783 (org-test-with-temp-text
785 <point>#+BEGIN_SRC emacs-lisp
786 '((1 . nil) (2 . 3))
787 #+END_SRC
789 (org-babel-execute-maybe) t))
790 ;; Escape headlines when producing an example block.
791 (should
792 (string-match-p
793 ",\\* Not an headline"
794 (org-test-with-temp-text
796 <point>#+BEGIN_SRC emacs-lisp
797 \"* Not an headline\"
798 #+END_SRC
800 (let ((org-babel-min-lines-for-block-output 1)) (org-babel-execute-maybe))
801 (buffer-string))))
802 ;; Escape special syntax in example blocks.
803 (should
804 (string-match-p
805 ",#\\+END_SRC"
806 (org-test-with-temp-text
808 <point>#+BEGIN_SRC emacs-lisp
809 \"#+END_SRC\"
810 #+END_SRC
812 (let ((org-babel-min-lines-for-block-output 1)) (org-babel-execute-maybe))
813 (buffer-string))))
814 ;; No escaping is done with other blocks or raw type.
815 (should-not
816 (string-match-p
817 ",\\* Not an headline"
818 (org-test-with-temp-text
820 <point>#+BEGIN_SRC emacs-lisp
821 \"* Not an headline\"
822 #+END_SRC
824 (let ((org-babel-min-lines-for-block-output 10))
825 (org-babel-execute-maybe))
826 (buffer-string))))
827 (should-not
828 (string-match-p
829 ",\\* Not an headline"
830 (org-test-with-temp-text
832 <point>#+BEGIN_SRC emacs-lisp :results raw
833 \"* Not an headline\"
834 #+END_SRC
836 (org-babel-execute-maybe)
837 (buffer-string))))
838 (should-not
839 (string-match-p
840 ",\\* Not an headline"
841 (org-test-with-temp-text
843 <point>#+BEGIN_SRC emacs-lisp :results drawer
844 \"* Not an headline\"
845 #+END_SRC
847 (org-babel-execute-maybe)
848 (buffer-string)))))
850 (ert-deftest test-ob/remove-inline-result ()
851 "Test `org-babel-remove-inline-result' honors whitespace."
852 (let*
853 ((inline-sb "src_emacs-lisp{(+ 1 2)}")
854 (inline-res " {{{results(=3=)}}}")
855 (inline-sb-dot (concat inline-sb "."))
856 (inline-sb-res-dot (concat inline-sb inline-res ".")))
857 (org-test-with-temp-text
858 ;; Insert inline_src_block followed by dot.
859 inline-sb-dot
860 ;; Insert result before dot.
861 (org-babel-execute-maybe)
862 (should (string= inline-sb-res-dot
863 (buffer-substring-no-properties
864 (point-at-bol) (point-at-eol))))
865 ;; Delete whitespace and result.
866 (org-babel-remove-inline-result)
867 (should (string= inline-sb-dot
868 (buffer-substring-no-properties
869 (point-at-bol) (point-at-eol))))
870 ;; Add whitespace and result before dot.
871 (search-forward inline-sb)
872 (insert " " inline-res)
873 (goto-char (point-at-bol))
874 ;; Remove whitespace and result.
875 (org-babel-remove-inline-result)
876 (should (string= inline-sb-dot
877 (buffer-substring-no-properties
878 (point-at-bol) (point-at-eol))))
879 ;; Add whitespace before dot.
880 (search-forward inline-sb)
881 (insert " ")
882 (goto-char (point-at-bol))
883 ;; Add result before whitespace.
884 (org-babel-execute-maybe)
885 ;; Remove result - leave trailing whitespace and dot.
886 (org-babel-remove-inline-result)
887 (should (string= (concat inline-sb " .")
888 (buffer-substring-no-properties
889 (point-at-bol) (point-at-eol)))))))
891 (ert-deftest test-ob/org-babel-remove-result--results-default ()
892 "Test `org-babel-remove-result' with default :results."
893 (mapcar (lambda (language)
894 (test-ob-verify-result-and-removed-result
895 "\n"
896 (concat
897 "* org-babel-remove-result
898 #+begin_src " language "
899 #+end_src
901 * next heading")))
902 '("sh" "emacs-lisp")))
904 (ert-deftest test-ob/org-babel-results-indented-wrap ()
905 "Ensure that wrapped results are inserted correction when indented.
906 If not inserted correctly then the second evaluation will fail
907 trying to find the :END: marker."
908 (org-test-with-temp-text
909 "- indented
910 #+begin_src sh :results file wrap
911 echo test.txt
912 #+end_src"
913 (org-babel-next-src-block 1)
914 (org-babel-execute-src-block)
915 (org-babel-execute-src-block)))
917 (ert-deftest test-ob/file-desc-header-argument ()
918 "Test that the :file-desc header argument is used."
919 (org-test-with-temp-text "#+begin_src emacs-lisp :results file :file-desc bar
920 \"foo\"
921 #+end_src
923 #+begin_src emacs-lisp :results file :file-desc
924 \"foo\"
925 #+end_src"
926 (org-babel-execute-src-block)
927 (org-babel-next-src-block 1)
928 (org-babel-execute-src-block)
929 (goto-char (point-min))
930 (should (search-forward "[[file:foo][bar]]" nil t))
931 (should (search-forward "[[file:foo][foo]]" nil t))))
933 (ert-deftest test-ob/inline-src_blk-preceded-punct-preceded-by-point ()
934 (let ((test-line ".src_emacs-lisp[ :results verbatim ]{ \"x\" }")
935 (org-babel-inline-result-wrap "=%s="))
936 (org-test-with-temp-text
937 test-line
938 (forward-char 1)
939 (org-babel-execute-maybe)
940 (should (re-search-forward "=\"x\"=" nil t))
941 (forward-line))))
943 (ert-deftest test-ob/commented-last-block-line-with-var ()
944 (org-test-with-temp-text-in-file "
945 #+begin_src emacs-lisp :var a=1
947 #+end_src"
948 (org-babel-next-src-block)
949 (org-babel-execute-maybe)
950 (re-search-forward "\\#\\+results:" nil t)
951 (forward-line)
952 (should (string=
954 (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
955 (org-test-with-temp-text-in-file "
956 #+begin_src emacs-lisp :var a=2
958 #+end_src"
959 (org-babel-next-src-block)
960 (org-babel-execute-maybe)
961 (re-search-forward "\\#\\+results:" nil t)
962 (forward-line)
963 (should (string=
964 ": 2"
965 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
967 (defun test-ob-verify-result-and-removed-result (result buffer-text)
968 "Test helper function to test `org-babel-remove-result'.
969 A temp buffer is populated with BUFFER-TEXT, the first block is executed,
970 and the result of execution is verified against RESULT.
972 The block is actually executed /twice/ to ensure result
973 replacement happens correctly."
974 (org-test-with-temp-text
975 buffer-text
976 (org-babel-next-src-block) (org-babel-execute-maybe) (org-babel-execute-maybe)
977 (should (re-search-forward "\\#\\+results:" nil t))
978 (forward-line)
979 (should (string= result
980 (buffer-substring-no-properties
981 (point-at-bol)
982 (- (point-max) 16))))
983 (org-babel-previous-src-block) (org-babel-remove-result)
984 (should (string= buffer-text
985 (buffer-substring-no-properties
986 (point-min) (point-max))))))
988 (ert-deftest test-ob/org-babel-remove-result--results-list ()
989 "Test `org-babel-remove-result' with :results list."
990 (test-ob-verify-result-and-removed-result
991 "- 1
994 - (quote (4 5))"
996 "* org-babel-remove-result
997 #+begin_src emacs-lisp :results list
998 '(1 2 3 '(4 5))
999 #+end_src
1001 * next heading"))
1003 (ert-deftest test-ob/org-babel-remove-result--results-wrap ()
1004 "Test `org-babel-remove-result' with :results wrap."
1005 (test-ob-verify-result-and-removed-result
1006 ":RESULTS:
1007 hello there
1008 :END:"
1010 "* org-babel-remove-result
1012 #+begin_src emacs-lisp :results wrap
1013 \"hello there\"
1014 #+end_src
1016 * next heading"))
1018 (ert-deftest test-ob/org-babel-remove-result--results-org ()
1019 "Test `org-babel-remove-result' with :results org."
1020 (test-ob-verify-result-and-removed-result
1021 "#+BEGIN_SRC org
1022 ,* heading
1023 ,** subheading
1024 content
1025 #+END_SRC"
1027 "* org-babel-remove-result
1028 #+begin_src emacs-lisp :results org
1029 \"* heading
1030 ,** subheading
1031 content\"
1032 #+end_src
1034 * next heading"))
1036 (ert-deftest test-ob/org-babel-remove-result--results-html ()
1037 "Test `org-babel-remove-result' with :results html."
1038 (test-ob-verify-result-and-removed-result
1039 "#+BEGIN_EXPORT html
1040 <head><body></body></head>
1041 #+END_EXPORT"
1043 "* org-babel-remove-result
1044 #+begin_src emacs-lisp :results html
1045 \"<head><body></body></head>\"
1046 #+end_src
1048 * next heading"))
1050 (ert-deftest test-ob/org-babel-remove-result--results-latex ()
1051 "Test `org-babel-remove-result' with :results latex."
1052 (test-ob-verify-result-and-removed-result
1053 "#+BEGIN_EXPORT latex
1054 Line 1
1055 Line 2
1056 Line 3
1057 #+END_EXPORT"
1059 "* org-babel-remove-result
1060 #+begin_src emacs-lisp :results latex
1061 \"Line 1
1062 Line 2
1063 Line 3\"
1064 #+end_src
1066 * next heading"))
1068 (ert-deftest test-ob/org-babel-remove-result--results-code ()
1069 "Test `org-babel-remove-result' with :results code."
1071 (test-ob-verify-result-and-removed-result
1072 "#+BEGIN_SRC emacs-lisp
1073 \"I am working!\"
1074 #+END_SRC"
1076 "* org-babel-remove-result
1077 #+begin_src emacs-lisp :results code
1078 (message \"I am working!\")
1079 #+end_src
1081 * next heading"))
1083 (ert-deftest test-ob/org-babel-remove-result--results-pp ()
1084 "Test `org-babel-remove-result' with :results pp."
1085 (test-ob-verify-result-and-removed-result
1086 ": \"I /am/ working!\""
1088 "* org-babel-remove-result
1089 #+begin_src emacs-lisp :results pp
1090 \"I /am/ working!\")
1091 #+end_src
1093 * next heading"))
1095 (ert-deftest test-ob/org-babel-remove-result--no-blank-line ()
1096 "Test `org-babel-remove-result' without blank line between code and results."
1097 (should
1098 (equal "
1099 #+begin_src emacs-lisp
1100 (+ 1 1)
1101 #+end_src
1102 #+results:
1104 * next heading"
1105 (org-test-with-temp-text
1107 <point>#+begin_src emacs-lisp
1108 (+ 1 1)
1109 #+end_src
1110 #+results:
1112 * next heading"
1113 (org-babel-execute-maybe)
1114 (buffer-string)))))
1116 (ert-deftest test-ob/results-do-not-replace-code-blocks ()
1117 (org-test-with-temp-text "Block two has a space after the name.
1119 #+name: foo
1120 #+begin_src emacs-lisp
1122 #+end_src
1124 #+name: foo
1125 #+begin_src emacs-lisp
1127 #+end_src
1129 #+name: foo
1130 #+begin_src emacs-lisp
1132 #+end_src
1134 #+RESULTS: foo
1135 : foo
1137 (dolist (num '(1 2 3))
1138 ;; execute the block
1139 (goto-char (point-min))
1140 (org-babel-next-src-block num) (org-babel-execute-src-block)
1141 ;; check the results
1142 (goto-char (point-max))
1143 (move-beginning-of-line 0)
1144 (should (looking-at (format ": %d" num))))))
1146 (ert-deftest test-ob/blocks-with-spaces ()
1147 "Test expansion of blocks followed by blank lines."
1148 ;; Preserve number of blank lines after block.
1149 (should
1150 (equal "#+BEGIN_SRC emacs-lisp
1151 \(+ 1 2)
1152 #+END_SRC
1154 #+RESULTS:
1155 : 3\n\n\n"
1156 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp
1157 \(+ 1 2)
1158 #+END_SRC\n\n\n"
1159 (let ((org-babel-next-src-block "RESULTS"))
1160 (org-babel-execute-src-block))
1161 (buffer-string))))
1162 ;; Do not add spurious blank lines after results.
1163 (should
1164 (equal
1166 - item 1
1168 #+begin_src emacs-lisp
1170 #+end_src
1172 #+RESULTS:
1175 - item 2"
1176 (org-test-with-temp-text "
1177 - item 1
1179 #+begin_src emacs-lisp<point>
1181 #+end_src
1183 - item 2"
1184 (org-babel-execute-src-block)
1185 (buffer-string))))
1186 (should
1187 (equal
1189 - item 1
1191 #+begin_src emacs-lisp
1193 #+end_src
1195 #+RESULTS:
1198 - item 2"
1199 (org-test-with-temp-text "
1200 - item 1
1202 #+begin_src emacs-lisp<point>
1204 #+end_src
1206 #+RESULTS:
1209 - item 2"
1210 (org-babel-execute-src-block)
1211 (buffer-string)))))
1213 (ert-deftest test-ob/results-in-narrowed-buffer ()
1214 "Test block execution in a narrowed buffer."
1215 ;; If results don't exist, they should be inserted in visible part
1216 ;; of the buffer.
1217 (should
1218 (equal
1219 "#+BEGIN_SRC emacs-lisp\n(+ 1 2)\n#+END_SRC\n\n#+RESULTS:\n: 3"
1220 (org-test-with-temp-text
1221 "#+BEGIN_SRC emacs-lisp\n(+ 1 2)\n#+END_SRC\n\nParagraph"
1222 (narrow-to-region (point) (save-excursion (forward-line 3) (point)))
1223 (let ((org-babel-results-keyword "RESULTS"))
1224 (org-babel-execute-src-block))
1225 (org-trim (buffer-string)))))
1226 (should
1227 (equal
1228 "#+NAME: test\n#+BEGIN_SRC emacs-lisp\n(+ 1 2)\n#+END_SRC\n\n#+RESULTS: test\n: 3"
1229 (org-test-with-temp-text
1230 "#+NAME: test\n#+BEGIN_SRC emacs-lisp\n(+ 1 2)\n#+END_SRC\n\nParagraph"
1231 (narrow-to-region (point) (save-excursion (forward-line 4) (point)))
1232 (let ((org-babel-results-keyword "RESULTS"))
1233 (org-babel-execute-src-block))
1234 (org-trim (buffer-string)))))
1235 ;; Results in visible part of buffer, should be updated here.
1236 (should
1237 (equal
1238 "#+NAME: test
1239 #+BEGIN_SRC emacs-lisp
1240 \(+ 1 2)
1241 #+END_SRC
1243 #+RESULTS: test
1244 : 3"
1245 (org-test-with-temp-text
1246 "#+NAME: test
1247 #+BEGIN_SRC emacs-lisp
1248 \(+ 1 2)
1249 #+END_SRC
1251 #+RESULTS: test
1253 <point>
1254 Paragraph"
1255 (narrow-to-region (point-min) (point))
1256 (goto-char (point-min))
1257 (let ((org-babel-results-keyword "RESULTS"))
1258 (org-babel-execute-src-block))
1259 (org-trim (buffer-string)))))
1260 ;; Results in invisible part of buffer, should be updated there.
1261 (org-test-with-temp-text
1262 "#+NAME: test
1263 #+BEGIN_SRC emacs-lisp
1264 \(+ 1 2)
1265 #+END_SRC
1267 #+RESULTS: test
1270 Paragraph"
1271 (narrow-to-region (point) (save-excursion (forward-line 4) (point)))
1272 (let ((org-babel-results-keyword "RESULTS"))
1273 (org-babel-execute-src-block))
1274 (should-not (re-search-forward "^#\\+RESULTS:" nil t))
1275 (widen)
1276 (should (re-search-forward "^: 3" nil t))))
1278 (ert-deftest test-ob/specific-colnames ()
1279 "Test passing specific column names."
1280 (should
1281 (equal "#+name: input-table
1282 | id | var1 |
1283 |----+------|
1284 | 1 | bar |
1285 | 2 | baz |
1287 #+begin_src sh :var data=input-table :exports results :colnames '(Rev Author)
1288 echo \"$data\"
1289 #+end_src
1291 #+RESULTS:
1292 | Rev | Author |
1293 |-----+--------|
1294 | 1 | bar |
1295 | 2 | baz |
1297 (org-test-with-temp-text
1298 "#+name: input-table
1299 | id | var1 |
1300 |----+------|
1301 | 1 | bar |
1302 | 2 | baz |
1304 #+begin_src sh :var data=input-table :exports results :colnames '(Rev Author)
1305 echo \"$data\"
1306 #+end_src
1308 ;; we should find a code block
1309 (should (re-search-forward org-babel-src-block-regexp nil t))
1310 (goto-char (match-beginning 0))
1311 ;; now that we've located the code block, it may be evaluated
1312 (let ((org-babel-execute-src-block "RESULTS"))
1313 (org-babel-execute-src-block))
1314 (buffer-string)))))
1316 (ert-deftest test-ob/location-of-header-arg-eval ()
1317 "Test location of header argument evaluation."
1318 (org-test-with-temp-text "
1319 #+name: top-block
1320 #+begin_src emacs-lisp :var pt=(point)
1322 #+end_src
1324 #+name: bottom-block
1325 #+begin_src emacs-lisp :var pt=top-block()
1327 #+end_src
1329 ;; the value of the second block should be greater than the first
1330 (should
1331 (< (progn (re-search-forward org-babel-src-block-regexp nil t)
1332 (goto-char (match-beginning 0))
1333 (prog1 (save-match-data (org-babel-execute-src-block))
1334 (goto-char (match-end 0))))
1335 (progn (re-search-forward org-babel-src-block-regexp nil t)
1336 (goto-char (match-beginning 0))
1337 (org-babel-execute-src-block))))))
1339 (ert-deftest test-ob/preserve-results-indentation ()
1340 "Preserve indentation when executing a src block."
1341 (should
1342 (equal
1343 '(2 2)
1344 (org-test-with-temp-text " #+begin_src emacs-lisp\n(+ 1 1)\n #+end_src"
1345 (org-babel-execute-src-block)
1346 (let ((case-fold-search t)) (search-forward "RESULTS"))
1347 (list (org-get-indentation)
1348 (progn (forward-line) (org-get-indentation))))))
1349 (should
1350 (equal
1351 '(2 2)
1352 (org-test-with-temp-text
1353 " #+name: block\n #+begin_src emacs-lisp\n(+ 1 1)\n #+end_src"
1354 (org-babel-execute-src-block)
1355 (let ((case-fold-search t)) (search-forward "RESULTS"))
1356 (list (org-get-indentation)
1357 (progn (forward-line) (org-get-indentation))))))
1358 ;; Don't get fooled by TAB-based indentation.
1359 (should
1360 (equal
1361 '(6 6)
1362 (org-test-with-temp-text
1363 "\t #+begin_src emacs-lisp\n\t (+ 1 1)\n\t #+end_src"
1364 (setq tab-width 4)
1365 (org-babel-execute-src-block)
1366 (let ((case-fold-search t)) (search-forward "RESULTS"))
1367 (list (org-get-indentation)
1368 (progn (forward-line) (org-get-indentation))))))
1369 ;; Properly indent examplified blocks.
1370 (should
1371 (equal
1372 " #+begin_example
1383 #+end_example
1385 (org-test-with-temp-text
1386 " #+begin_src emacs-lisp :results output
1387 (dotimes (i 10) (princ i) (princ \"\\n\"))
1388 #+end_src"
1389 (org-babel-execute-src-block)
1390 (search-forward "begin_example")
1391 (downcase
1392 (buffer-substring-no-properties (line-beginning-position)
1393 (point-max))))))
1394 ;; Properly indent "org" blocks.
1395 (should
1396 (equal
1397 " #+begin_src org
1408 #+end_src
1410 (org-test-with-temp-text
1411 " #+begin_src emacs-lisp :results output org
1412 (dotimes (i 10) (princ i) (princ \"\\n\"))
1413 #+end_src"
1414 (org-babel-execute-src-block)
1415 (search-forward "begin_src org")
1416 (downcase
1417 (buffer-substring-no-properties (line-beginning-position)
1418 (point-max)))))))
1420 (ert-deftest test-ob/safe-header-args ()
1421 "Detect safe and unsafe header args."
1422 (let ((safe-args '((:cache . "foo")
1423 (:results . "output")
1424 (:eval . "never")
1425 (:eval . "query")))
1426 (unsafe-args '((:eval . "yes")
1427 (:results . "output file")
1428 (:foo . "bar")))
1429 (malformed-args '((bar . "foo")
1430 ("foo" . "bar")
1431 :foo))
1432 (safe-p (org-babel-header-args-safe-fn org-babel-safe-header-args)))
1433 (dolist (arg safe-args)
1434 (should (org-babel-one-header-arg-safe-p arg org-babel-safe-header-args)))
1435 (dolist (arg unsafe-args)
1436 (should (not (org-babel-one-header-arg-safe-p arg org-babel-safe-header-args))))
1437 (dolist (arg malformed-args)
1438 (should (not (org-babel-one-header-arg-safe-p arg org-babel-safe-header-args))))
1439 (should (not (funcall safe-p (append safe-args unsafe-args))))))
1441 (ert-deftest test-ob/noweb-expansions-in-cache ()
1442 "Ensure that noweb expansions are expanded before caching."
1443 (let ((noweb-expansions-in-cache-var 0))
1444 (org-test-with-temp-text "
1445 #+name: foo
1446 #+begin_src emacs-lisp
1447 \"I said\"
1448 #+end_src
1450 #+name: bar
1451 #+begin_src emacs-lisp :noweb yes :cache yes
1452 (setq noweb-expansions-in-cache-var
1453 (+ 1 noweb-expansions-in-cache-var))
1454 (concat <<foo>> \" check noweb expansions\")
1455 #+end_src
1457 ;; run the second block to create the cache
1458 (goto-char (point-min))
1459 (re-search-forward (regexp-quote "#+name: bar"))
1460 (should (string= "I said check noweb expansions"
1461 (org-babel-execute-src-block)))
1462 (should (= noweb-expansions-in-cache-var 1))
1463 ;; change the value of the first block
1464 (goto-char (point-min))
1465 (re-search-forward (regexp-quote "said"))
1466 (goto-char (match-beginning 0))
1467 (insert "haven't ")
1468 (re-search-forward (regexp-quote "#+name: bar"))
1469 (should (string= "I haven't said check noweb expansions"
1470 (org-babel-execute-src-block)))
1471 (should (= noweb-expansions-in-cache-var 2)))))
1473 (ert-deftest test-ob/file-ext-and-output-dir ()
1474 (org-test-at-id "93573e1d-6486-442e-b6d0-3fedbdc37c9b"
1475 (org-babel-next-src-block)
1476 (should (equal "file-ext-basic.txt"
1477 (cdr (assq :file (nth 2 (org-babel-get-src-block-info t))))))
1478 (org-babel-next-src-block)
1479 (should (equal "foo/file-ext-dir-relative.txt"
1480 (cdr (assq :file (nth 2 (org-babel-get-src-block-info t))))))
1481 (org-babel-next-src-block)
1482 (should (equal "foo/file-ext-dir-relative-slash.txt"
1483 (cdr (assq :file (nth 2 (org-babel-get-src-block-info t))))))
1484 (org-babel-next-src-block)
1485 (should (equal "/tmp/file-ext-dir-absolute.txt"
1486 (cdr (assq :file (nth 2 (org-babel-get-src-block-info t))))))
1487 (org-babel-next-src-block)
1488 (should (equal "foo.bar"
1489 (cdr (assq :file (nth 2 (org-babel-get-src-block-info t))))))
1490 (org-babel-next-src-block)
1491 (should (equal "xxx/foo.bar"
1492 (cdr (assq :file (nth 2 (org-babel-get-src-block-info t))))))
1495 (ert-deftest test-ob/script-escape ()
1496 ;; Delimited lists of numbers
1497 (should (equal '(1 2 3)
1498 (org-babel-script-escape "[1 2 3]")))
1499 (should (equal '(1 2 3)
1500 (org-babel-script-escape "{1 2 3}")))
1501 (should (equal '(1 2 3)
1502 (org-babel-script-escape "(1 2 3)")))
1503 ;; Delimited lists of double-quoted strings
1504 (should (equal '("foo" "bar")
1505 (org-babel-script-escape "(\"foo\" \"bar\")")))
1506 (should (equal '("foo" "bar")
1507 (org-babel-script-escape "[\"foo\" \"bar\"]")))
1508 (should (equal '("foo" "bar")
1509 (org-babel-script-escape "{\"foo\" \"bar\"}")))
1510 ;; ... with commas
1511 (should (equal '("foo" "bar")
1512 (org-babel-script-escape "(\"foo\", \"bar\")")))
1513 (should (equal '("foo" "bar")
1514 (org-babel-script-escape "[\"foo\", \"bar\"]")))
1515 (should (equal '("foo" "bar")
1516 (org-babel-script-escape "{\"foo\", \"bar\"}")))
1517 ;; Delimited lists of single-quoted strings
1518 (should (equal '("foo" "bar")
1519 (org-babel-script-escape "('foo' 'bar')")))
1520 (should (equal '("foo" "bar")
1521 (org-babel-script-escape "['foo' 'bar']")))
1522 (should (equal '("foo" "bar")
1523 (org-babel-script-escape "{'foo' 'bar'}")))
1524 ;; ... with commas
1525 (should (equal '("foo" "bar")
1526 (org-babel-script-escape "('foo', 'bar')")))
1527 (should (equal '("foo" "bar")
1528 (org-babel-script-escape "['foo', 'bar']")))
1529 (should (equal '("foo" "bar")
1530 (org-babel-script-escape "{'foo', 'bar'}")))
1531 ;; Single quoted strings
1532 (should (equal "foo"
1533 (org-babel-script-escape "'foo'")))
1534 ;; ... with internal double quote
1535 (should (equal "foo\"bar"
1536 (org-babel-script-escape "'foo\"bar'")))
1537 ;; ... with internal backslash
1538 (should (equal "foo\\bar"
1539 (org-babel-script-escape "'foo\\bar'")))
1540 ;; ... with internal escaped backslash
1541 (should (equal "foo\\bar"
1542 (org-babel-script-escape "'foo\\\\bar'")))
1543 ;; ... with internal backslash-double quote
1544 (should (equal "foo\\\"bar"
1545 (org-babel-script-escape "'foo\\\"bar'")))
1546 ;; ... with internal escaped backslash-double quote
1547 (should (equal "foo\\\"bar"
1548 (org-babel-script-escape "'foo\\\\\"bar'")))
1549 ;; ... with internal escaped single quote
1550 (should (equal "foo'bar"
1551 (org-babel-script-escape "'foo\\'bar'")))
1552 ;; ... with internal escaped backslash-escaped single quote
1553 (should (equal "foo\\'bar"
1554 (org-babel-script-escape "'foo\\\\\\'bar'")))
1555 ;; Double quoted strings
1556 (should (equal "foo"
1557 (org-babel-script-escape "\"foo\"")))
1558 ;; ... with internal single quote
1559 (should (equal "foo'bar"
1560 (org-babel-script-escape "\"foo'bar\"")))
1561 ;; ... with internal backslash
1562 (should (equal "foo\\bar"
1563 (org-babel-script-escape "\"foo\\bar\"")))
1564 ;; ... with internal escaped backslash
1565 (should (equal "foo\\bar"
1566 (org-babel-script-escape "\"foo\\\\bar\"")))
1567 ;; ... with internal backslash-single quote
1568 (should (equal "foo\\'bar"
1569 (org-babel-script-escape "\"foo\\'bar\"")))
1570 ;; ... with internal escaped backslash-single quote
1571 (should (equal "foo\\'bar"
1572 (org-babel-script-escape "\"foo\\\\'bar\"")))
1573 ;; ... with internal escaped double quote
1574 (should (equal "foo\"bar"
1575 (org-babel-script-escape "\"foo\\\"bar\"")))
1576 ;; ... with internal escaped backslash-escaped double quote
1577 (should (equal "foo\\\"bar"
1578 (org-babel-script-escape "\"foo\\\\\\\"bar\""))))
1580 (ert-deftest test-ob/process-params-no-duplicates ()
1581 (should
1582 (equal (org-babel-process-params '((:colname-names)
1583 (:rowname-names)
1584 (:result-params)
1585 (:result-type)
1586 (:var . "\"foo\"")))
1587 '((:var)
1588 (:colname-names)
1589 (:rowname-names)
1590 (:result-params)
1591 (:result-type . value)))))
1593 (defun org-test-babel-confirm-evaluate (eval-value)
1594 (org-test-with-temp-text (format "#+begin_src emacs-lisp :eval %s
1596 #+end_src" eval-value)
1597 (goto-char (point-min))
1598 (let ((info (org-babel-get-src-block-info)))
1599 (org-babel-check-confirm-evaluate info))))
1601 (ert-deftest test-ob/check-eval ()
1602 (let ((org-confirm-babel-evaluate t))
1603 ;; Non-export tests
1604 (dolist (pair '(("no" . nil)
1605 ("never" . nil)
1606 ("query" . query)
1607 ("yes" . query)))
1608 (should (eq (org-test-babel-confirm-evaluate (car pair)) (cdr pair))))
1609 ;; Export tests
1610 (let ((org-babel-exp-reference-buffer t))
1611 (dolist (pair '(("no" . nil)
1612 ("never" . nil)
1613 ("query" . query)
1614 ("yes" . query)
1615 ("never-export" . nil)
1616 ("no-export" . nil)
1617 ("query-export" . query)))
1618 (message (car pair))
1619 (should (eq (org-test-babel-confirm-evaluate (car pair)) (cdr pair))))))
1620 (let ((org-confirm-babel-evaluate nil))
1621 ;; Non-export tests
1622 (dolist (pair '(("no" . nil)
1623 ("never" . nil)
1624 ("query" . query)
1625 ("yes" . t)))
1626 (should (eq (org-test-babel-confirm-evaluate (car pair)) (cdr pair))))
1627 ;; Export tests
1628 (let ((org-babel-exp-reference-buffer t))
1629 (dolist (pair '(("no" . nil)
1630 ("never" . nil)
1631 ("query" . query)
1632 ("yes" . t)
1633 ("never-export" . nil)
1634 ("no-export" . nil)
1635 ("query-export" . query)))
1636 (message (car pair))
1637 (should (eq (org-test-babel-confirm-evaluate (car pair)) (cdr pair)))))))
1639 (defun org-test-ob/update-block-body ()
1640 "Test `org-babel-update-block-body' specifications."
1641 (should
1642 (equal "#+begin_src elisp\n 2\n#+end_src"
1643 (let ((org-edit-src-content-indentation 2))
1644 (org-test-with-temp-text "#+begin_src elisp\n(+ 1 1)\n#+end_src"
1645 (org-babel-update-block-body "2")
1646 (buffer-string)))))
1647 ;; Preserve block indentation.
1648 (should
1649 (equal " #+begin_src elisp\n 2\n #+end_src"
1650 (let ((org-edit-src-content-indentation 1))
1651 (org-test-with-temp-text
1652 " #+begin_src elisp\n (+ 1 1)\n #+end_src"
1653 (org-babel-update-block-body "2")
1654 (buffer-string)))))
1655 ;; Ignore NEW-BODY global indentation.
1656 (should
1657 (equal "#+begin_src elisp\n 2\n#+end_src"
1658 (let ((org-edit-src-content-indentation 2))
1659 (org-test-with-temp-text "#+begin_src elisp\n(+ 1 1)\n#+end_src"
1660 (org-babel-update-block-body " 2")
1661 (buffer-string)))))
1662 ;; When indentation should be preserved ignore the two rules above.
1663 (should
1664 (equal " #+begin_src elisp\n2\n #+end_src"
1665 (let ((org-edit-src-content-indentation 1)
1666 (org-src-preserve-indentation t))
1667 (org-test-with-temp-text
1668 " #+begin_src elisp\n (+ 1 1)\n #+end_src"
1669 (org-babel-update-block-body "2")
1670 (buffer-string)))))
1671 (should
1672 (equal " #+begin_src elisp -i\n2\n #+end_src"
1673 (let ((org-edit-src-content-indentation 1))
1674 (org-test-with-temp-text
1675 " #+begin_src elisp -i\n (+ 1 1)\n #+end_src"
1676 (org-babel-update-block-body "2")
1677 (buffer-string)))))
1678 (should
1679 (equal "#+begin_src elisp\n 2\n#+end_src"
1680 (let ((org-edit-src-content-indentation 2)
1681 (org-src-preserve-indentation t))
1682 (org-test-with-temp-text "#+begin_src elisp\n(+ 1 1)\n#+end_src"
1683 (org-babel-update-block-body " 2")
1684 (buffer-string)))))
1685 (should
1686 (equal "#+begin_src elisp -i\n 2\n#+end_src"
1687 (let ((org-edit-src-content-indentation 2)
1688 (org-src-preserve-indentation t))
1689 (org-test-with-temp-text "#+begin_src elisp -i\n(+ 1 1)\n#+end_src"
1690 (org-babel-update-block-body " 2")
1691 (buffer-string))))))
1693 (ert-deftest test-ob/find-named-result ()
1694 "Test `org-babel-find-named-result' specifications."
1695 (should
1696 (= 1
1697 (org-test-with-temp-text "#+results: foo\n: result"
1698 (org-babel-find-named-result "foo"))))
1699 (should-not
1700 (org-test-with-temp-text "#+results: foo\n: result"
1701 (org-babel-find-named-result "bar")))
1702 (should-not
1703 (org-test-with-temp-text "#+results: foobar\n: result"
1704 (org-babel-find-named-result "foo")))
1705 ;; Search is case insensitive.
1706 (should
1707 (org-test-with-temp-text "#+RESULTS: FOO\n: result"
1708 (org-babel-find-named-result "foo")))
1709 ;; Handle hash in results keyword.
1710 (should
1711 (org-test-with-temp-text "#+results[hash]: FOO\n: result"
1712 (org-babel-find-named-result "foo")))
1713 ;; Accept orphaned affiliated keywords.
1714 (should
1715 (org-test-with-temp-text "#+results: foo"
1716 (org-babel-find-named-result "foo"))))
1718 (ert-deftest test-ob/where-is-src-block-result ()
1719 "Test `org-babel-where-is-src-block-result' specifications."
1720 ;; Find anonymous results.
1721 (should
1722 (equal "#+RESULTS:"
1723 (org-test-with-temp-text
1724 "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC\n\n#+RESULTS:\n: 2"
1725 (goto-char (org-babel-where-is-src-block-result))
1726 (buffer-substring-no-properties (point) (line-end-position)))))
1727 ;; Find named results. Those have priority over anonymous ones.
1728 (should
1729 (equal "#+RESULTS: example"
1730 (org-test-with-temp-text
1732 <point>#+NAME: example
1733 #+BEGIN_SRC emacs-lisp
1734 \(+ 1 1)
1735 #+END_SRC
1737 #+RESULTS: example
1738 : 2"
1739 (goto-char (org-babel-where-is-src-block-result))
1740 (buffer-substring-no-properties (point) (line-end-position)))))
1741 (should
1742 (equal "#+RESULTS: example"
1743 (org-test-with-temp-text
1745 <point>#+NAME: example
1746 #+BEGIN_SRC emacs-lisp
1747 \(+ 1 1)
1748 #+END_SRC
1750 #+RESULTS:
1751 : fake
1753 #+RESULTS: example
1754 : 2"
1755 (goto-char (org-babel-where-is-src-block-result))
1756 (buffer-substring-no-properties (point) (line-end-position)))))
1757 ;; Return nil when no result is found.
1758 (should-not
1759 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
1760 (org-babel-where-is-src-block-result)))
1761 (should-not
1762 (org-test-with-temp-text
1763 "- item\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC\n\n"
1764 (org-babel-where-is-src-block-result)))
1765 ;; When optional argument INSERT is non-nil, add RESULTS keyword
1766 ;; whenever no RESULTS can be found.
1767 (should
1768 (equal
1769 "#+RESULTS:"
1770 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
1771 (let ((org-babel-results-keyword "RESULTS"))
1772 (goto-char (org-babel-where-is-src-block-result t)))
1773 (buffer-substring-no-properties (point) (line-end-position)))))
1774 ;; Insert a named RESULTS keyword if possible.
1775 (should
1776 (equal
1777 "#+RESULTS: e"
1778 (org-test-with-temp-text
1779 "#+NAME: e\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
1780 (let ((org-babel-results-keyword "RESULTS"))
1781 (goto-char (org-babel-where-is-src-block-result t)))
1782 (buffer-substring-no-properties (point) (line-end-position)))))
1783 ;; When optional argument HASH is provided, clear RESULTS keyword
1784 ;; and related contents if they do not match it.
1785 (should
1786 (equal
1787 "#+RESULTS[bbbb]:"
1788 (org-test-with-temp-text
1789 "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC\n\n#+RESULTS[aaaa]:\n: 3"
1790 (let ((org-babel-results-keyword "RESULTS"))
1791 (goto-char (org-babel-where-is-src-block-result nil nil "bbbb")))
1792 (org-trim (buffer-substring-no-properties (point) (point-max))))))
1793 (should
1794 (equal
1795 "#+RESULTS[bbbb]:"
1796 (org-test-with-temp-text
1797 "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC\n\n#+RESULTS[aaaa]:"
1798 (let ((org-babel-results-keyword "RESULTS"))
1799 (goto-char (org-babel-where-is-src-block-result nil nil "bbbb")))
1800 (org-trim (buffer-substring-no-properties (point) (point-max))))))
1801 ;; Handle hashes with times.
1802 (should
1803 (equal
1804 "#+RESULTS[<2014-03-04 00:41:10> bbbb]:"
1805 (org-test-with-temp-text
1807 <point>#+BEGIN_SRC emacs-lisp
1808 \(+ 1 1)
1809 #+END_SRC
1811 #+RESULTS[<2012-03-29 16:40:12> aaaa]:"
1812 (let ((org-babel-results-keyword "RESULTS")
1813 (org-babel-hash-show-time t))
1814 (cl-letf (((symbol-function 'format-time-string)
1815 (lambda (&rest _) "<2014-03-04 00:41:10>")))
1816 (goto-char (org-babel-where-is-src-block-result nil nil "bbbb"))
1817 (org-trim (buffer-substring-no-properties (point) (point-max))))))))
1818 (should
1819 (equal
1820 "#+RESULTS[<2012-03-29 16:40:12> aaaa]:"
1821 (org-test-with-temp-text
1823 <point>#+BEGIN_SRC emacs-lisp
1824 \(+ 1 1)
1825 #+END_SRC
1827 #+RESULTS[<2012-03-29 16:40:12> aaaa]:"
1828 (let ((org-babel-results-keyword "RESULTS")
1829 (org-babel-hash-show-time t))
1830 (cl-letf (((symbol-function 'format-time-string)
1831 (lambda (&rest _) "<2014-03-04 00:41:10>")))
1832 (goto-char (org-babel-where-is-src-block-result nil nil "aaaa"))
1833 (org-trim (buffer-substring-no-properties (point) (point-max))))))))
1834 ;; RESULTS keyword may not be the last affiliated keyword.
1835 (should
1836 (equal
1837 "#+RESULTS[bbbb]:"
1838 (org-test-with-temp-text
1840 <point>#+BEGIN_SRC emacs-lisp
1841 \(+ 1 1)
1842 #+END_SRC
1844 #+RESULTS[aaaa]:
1845 #+NAME: e
1846 : 3"
1847 (let ((org-babel-results-keyword "RESULTS"))
1848 (goto-char (org-babel-where-is-src-block-result nil nil "bbbb")))
1849 (org-trim (buffer-substring-no-properties (point) (point-max))))))
1850 ;; HASH does nothing if no RESULTS can be found. However, if INSERT
1851 ;; is also non-nil, RESULTS keyword is inserted along with the
1852 ;; expected hash.
1853 (should
1854 (equal
1855 "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
1856 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
1857 (org-babel-where-is-src-block-result nil nil "bbbb")
1858 (buffer-string))))
1859 (should
1860 (equal
1861 "#+RESULTS[bbbb]:"
1862 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
1863 (let ((org-babel-results-keyword "RESULTS"))
1864 (goto-char (org-babel-where-is-src-block-result t nil "bbbb")))
1865 (org-trim (buffer-substring-no-properties (point) (point-max)))))))
1867 (ert-deftest test-ob/goto-named-src-block ()
1868 "Test interactive use of `org-babel-goto-named-src-block'."
1869 (org-test-with-temp-text-in-file
1871 #+NAME: abc
1872 #+BEGIN_SRC emacs-lisp :results value
1873 (1+ 1)
1874 #+END_SRC
1875 #+CALL: abc( lorem() ) :results raw :wrap EXAMPLE
1876 #+BEGIN_SRC emacs-lisp
1877 <<abc>>
1878 #+END_SRC
1880 #+RESULTS: abc
1883 ;; non-existent name
1884 (should-not
1885 (execute-kbd-macro "\M-xorg-babel-goto-named-src-block\nno-name\n"))
1886 ;; correct name
1887 (execute-kbd-macro "\M-xorg-babel-goto-named-src-block\nabc\n")
1888 (should (= 14 (point)))
1889 ;; call line - autocompletion
1890 (forward-line 3)
1891 (execute-kbd-macro "\M-xorg-babel-goto-named-src-block\n\n")
1892 (should (= 14 (point)))
1893 ;; noweb reference - autocompletion
1894 (forward-line 5)
1895 (execute-kbd-macro "\M-xorg-babel-goto-named-src-block\n\n")
1896 (should (= 14 (point)))
1897 ;; at symbol - autocompletion
1898 (forward-line 7)
1899 (execute-kbd-macro "\M-xorg-babel-goto-named-src-block\n\n")
1900 (should (= 14 (point)))
1901 ;; in results - autocompletion
1902 (forward-line 8)
1903 (execute-kbd-macro "\M-xorg-babel-goto-named-src-block\n\n")
1904 (should (= 14 (point)))
1905 (forward-line 9)
1906 (execute-kbd-macro "\M-xorg-babel-goto-named-src-block\n\n")
1907 (should (= 14 (point)))))
1909 (ert-deftest test-ob/evaluate-body-with-coderefs ()
1910 (should
1911 (= 2
1912 (org-test-with-temp-text
1913 "#+begin_src emacs-lisp -l \"#(ref:%s)\"\n2 #(ref:foo)\n#+end_src"
1914 (org-babel-execute-src-block))))
1915 (should
1916 (= 3
1917 (org-test-with-temp-text
1918 "#+begin_src emacs-lisp\n3 #(ref:foo)\n#+end_src"
1919 (let ((org-coderef-label-format "#(ref:%s)"))
1920 (org-babel-execute-src-block))))))
1922 (provide 'test-ob)
1924 ;;; test-ob ends here