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/>.
23 (ert-deftest test-org-babel
/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."
27 (let ((default-directory temporary-file-directory
))
28 (org-test-with-temp-text
31 #+<point>BEGIN_SRC emacs-lisp :file test.txt :cache yes
34 ;; Execute twice as the first time creates the cache.
35 (org-babel-execute-src-block)
36 (string= (concat default-directory
"test.txt")
37 (org-babel-execute-src-block))))))
39 (ert-deftest test-org-babel
/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?
44 org-babel-multi-line-header-regexp
45 " \t #+headers: blah1 blah2 blah3 \t\n\t\n blah4 blah5 blah6 \n"))
48 "blah1 blah2 blah3 \t"
51 " \t #+headers: blah1 blah2 blah3 \t\n\t\n blah4 blah5 blah6 \n")))
53 ;;TODO Check - should this fail?
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-org-babel
/src-block-regexp
()
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"
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
)))
78 (should (org-test-string-exact-match
79 org-babel-src-block-regexp
80 (replace-regexp-in-string flags
"" test-block
)))
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-org-babel
/default-inline-header-args
()
93 (:results .
"replace")
94 (:exports .
"results")
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
102 (baz .
((foo bar
) (baz)))
103 (qux .
((foo bar baz qux
)))
104 (quux .
((foo bar
))))
108 (dolist (pair '((foo .
: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-org-babel
/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-org-babel
/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
)
128 (ert-deftest test-org-babel
/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 (assoc :tangle
(nth 2 info
))))))))
133 (ert-deftest test-org-babel
/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
141 #+begin_src emacs-lisp
144 (goto-char (point-min))
145 (org-babel-next-src-block)
146 (let ((info (org-babel-get-src-block-info)))
147 (should (= 42 (org-babel-execute-src-block))))))
149 (ert-deftest test-org-babel
/simple-named-code-block
()
150 "Test that simple named code blocks can be evaluated."
151 (org-test-with-temp-text-in-file "
153 #+name: i-have-a-name
154 #+begin_src emacs-lisp
157 (org-babel-next-src-block 1)
158 (should (= 42 (org-babel-execute-src-block)))))
160 (ert-deftest test-org-babel
/simple-variable-resolution
()
161 "Test that simple variable resolution is working."
162 (org-test-with-temp-text-in-file "
165 #+begin_src emacs-lisp
169 #+begin_src emacs-lisp :var four=four
173 (org-babel-next-src-block 2)
174 (should (= 4 (org-babel-execute-src-block)))
176 (should (string= ": 4" (buffer-substring
180 (ert-deftest test-org-babel
/multi-line-header-arguments
()
181 "Test that multi-line header arguments and can be read."
182 (org-test-with-temp-text-in-file "
184 #+headers: :var letters='(a b c d e f g)
185 #+begin_src emacs-lisp :var numbers='(1 2 3 4 5 6 7)
187 (defalias 'my-map (if (org-version-check \"24.2.50\" \"cl\" :predicate)
190 (my-map 'list #'list numbers letters)
193 (org-babel-next-src-block)
194 (let ((results (org-babel-execute-src-block)))
195 (should(equal 'a
(cadr (assoc 1 results
))))
196 (should(equal 'd
(cadr (assoc 4 results
)))))))
198 (ert-deftest test-org-babel
/parse-header-args
()
199 (org-test-with-temp-text-in-file "
201 #+begin_src example-lang :session :results output :var num=9
205 (org-babel-next-src-block)
206 (let* ((info (org-babel-get-src-block-info))
207 (params (nth 2 info
)))
208 (message "%S" params
)
209 (should (equal "example-lang" (nth 0 info
)))
210 (should (string= "the body" (org-babel-trim (nth 1 info
))))
211 (should-not (member '(:session\ \ \ \
) params
))
212 (should (equal '(:session
) (assoc :session params
)))
213 (should (equal '(:result-type . output
) (assoc :result-type params
)))
214 (should (equal '(num .
9) (cdr (assoc :var params
)))))))
216 (ert-deftest test-org-babel
/parse-header-args2
()
217 (org-test-with-temp-text-in-file "
219 * resolving sub-trees as references
221 #+begin_src emacs-lisp :var text=d4faa7b3-072b-4dcf-813c-dd7141c633f3
225 #+begin_src org :noweb yes
227 <<d4faa7b3-072b-4dcf-813c-dd7141c633f3>>
230 ** simple subtree with custom ID
232 :CUSTOM_ID: simple-subtree
236 (should (string-match (regexp-quote "this is simple")
237 (org-babel-ref-resolve "simple-subtree")))
238 (org-babel-next-src-block)
239 (should (= 14 (org-babel-execute-src-block)))))
241 (ert-deftest test-org-babel
/inline-src-blocks
()
244 (org-test-with-temp-text
245 "In the middle <point>src_emacs-lisp{(+ 0 1)} of a line"
246 (org-babel-execute-src-block))))
249 (org-test-with-temp-text
250 "One at the end of a line: <point>src_emacs-lisp{(+ 1 1)}"
251 (org-babel-execute-src-block))))
254 (org-test-with-temp-text
255 "src_emacs-lisp{(+ 2 1)} at the beginning of a line."
256 (org-babel-execute-src-block))))
259 (org-test-with-temp-text
260 "In the middle <point>src_emacs-lisp[:results silent\
261 :exports code]{(+ 3 1)} of a line"
262 (org-babel-execute-src-block))))
265 (org-test-with-temp-text
266 "One at the end of a line: <point>src_emacs-lisp[:results silent\
267 :exports code]{(+ 4 1)}"
268 (org-babel-execute-src-block))))
271 (org-test-with-temp-text
272 "src_emacs-lisp[:results silent :exports code]{(+ 5 1)}\
273 at the beginning of a line."
274 (org-babel-execute-src-block))))
277 (org-test-with-temp-text
278 "One also evaluated: <point>src_emacs-lisp[:exports both\
279 :results silent]{(+ 6 1)}"
280 (org-babel-execute-src-block)))))
282 (ert-deftest test-org-babel
/org-babel-get-inline-src-block-matches
()
283 (flet ((test-at-id (id)
286 (let ((test-point (point)))
287 (should (fboundp 'org-babel-get-inline-src-block-matches
))
288 (should (re-search-forward "src_" nil t
)) ;; 1
289 (should (org-babel-get-inline-src-block-matches))
290 (should (re-search-forward " b" nil
(point-at-bol))) ;; 1
291 (should-not (org-babel-get-inline-src-block-matches))
292 (should (re-search-forward "in" nil t
)) ;; 2
293 (should-not (org-babel-get-inline-src-block-matches))
294 (should (re-search-forward "echo" nil t
)) ;; 2
295 (should (org-babel-get-inline-src-block-matches))
296 (should (re-search-forward "blocks" nil t
)) ;; 3
297 (backward-char 7) ;; 3
298 (should (org-babel-get-inline-src-block-matches))
300 (should-not (org-babel-get-inline-src-block-matches))
301 (should (re-search-forward ":results" nil t
)) ;; 4
302 (should (org-babel-get-inline-src-block-matches))
304 (should-not (org-babel-get-inline-src-block-matches))))))
305 (test-at-id "0D0983D4-DE33-400A-8A05-A225A567BC74")
306 (test-at-id "d55dada7-de0e-4340-8061-787cccbedee5")))
308 (ert-deftest test-org-babel
/inline-src_blk-default-results-replace-line-1
()
309 (let ((test-line "src_sh{echo 1}")
310 (org-babel-inline-result-wrap "=%s="))
311 ;; src_ at bol line 1...
312 (org-test-with-temp-text
314 (goto-char (point-min)) (org-babel-execute-maybe)
316 (concat test-line
" {{{results(=1=)}}}")
317 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
318 (forward-char) (org-babel-execute-maybe)
320 (concat test-line
" {{{results(=1=)}}}")
321 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
322 (re-search-forward "{{{")
323 ;;(should-error (org-ctrl-c-ctrl-c))
324 (backward-char 4) ;; last char of block body
325 (org-babel-execute-maybe)
327 (concat test-line
" {{{results(=1=)}}}")
328 (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
329 ;; src_ follows space line 1...
330 (let ((test-line " src_emacs-lisp{ 1 }"))
331 (org-test-with-temp-text
333 (should-error (org-ctrl-c-ctrl-c))
334 (forward-char) (org-babel-execute-maybe)
336 (concat test-line
" {{{results(=1=)}}}")
337 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
338 (re-search-forward "{ 1 ") (org-babel-execute-maybe)
340 (concat test-line
" {{{results(=1=)}}}")
341 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
343 (should-error (org-ctrl-c-ctrl-c))
346 (ert-deftest test-org-babel
/inline-src_blk-default-results-replace-line-2
()
347 ;; src_ at bol line 2...
348 (let ((test-line " src_emacs-lisp{ \"x\" }")
349 (org-babel-inline-result-wrap "=%s="))
350 (org-test-with-temp-text
351 (concat "\n" test-line
)
352 (should-error (org-ctrl-c-ctrl-c))
353 (goto-char (point-min))
354 (should-error (org-ctrl-c-ctrl-c))
356 (should-error (org-ctrl-c-ctrl-c))
357 (forward-char) (org-babel-execute-maybe)
359 (concat test-line
" {{{results(=x=)}}}")
360 (buffer-substring-no-properties
361 (point-at-bol) (point-at-eol))))))
362 (let ((test-line "Some text prior to block src_emacs-lisp{ \"y\" }")
363 (org-babel-inline-result-wrap "=%s="))
364 (org-test-with-temp-text
366 (goto-char (point-max))
367 (insert (concat "\n" test-line
" end"))
368 (re-search-backward "src") (org-babel-execute-maybe)
370 (concat test-line
" {{{results(=y=)}}} end")
371 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
372 (re-search-forward "\" ") (org-babel-execute-maybe)
374 (concat test-line
" {{{results(=y=)}}} end")
375 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
377 (should-error (org-ctrl-c-ctrl-c)))))
379 (ert-deftest test-org-babel
/inline-src_blk-manual-results-replace
()
380 (let ((test-line " src_emacs-lisp[:results replace]{ \"x\" }")
381 (org-babel-inline-result-wrap "=%s="))
382 (org-test-with-temp-text
383 (concat "\n" test-line
)
384 (should-error (org-ctrl-c-ctrl-c))
385 (goto-char (point-max))
386 (org-babel-execute-maybe)
388 (should-error (org-ctrl-c-ctrl-c))
389 (forward-char) (org-babel-execute-maybe)
391 (concat test-line
" {{{results(=x=)}}}")
392 (buffer-substring-no-properties
393 (point-at-bol) (point-at-eol))))))
394 (let ((test-line (concat " Some text prior to block "
395 "src_emacs-lisp[:results replace]{ \"y\" }"))
396 (org-babel-inline-result-wrap "=%s="))
397 (org-test-with-temp-text test-line
398 (goto-char (point-max))
399 (insert (concat "\n" test-line
" end"))
400 (re-search-backward "src") (org-babel-execute-maybe)
402 (concat test-line
" {{{results(=y=)}}} end")
403 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
404 (re-search-forward "\" ") (org-babel-execute-maybe)
406 (concat test-line
" {{{results(=y=)}}} end")
407 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
409 (should-error (org-ctrl-c-ctrl-c)))))
411 (ert-deftest test-org-babel
/inline-src_blk-results-silent
()
412 (let ((test-line "src_emacs-lisp[ :results silent ]{ \"x\" }"))
413 (org-test-with-temp-text test-line
414 (org-babel-execute-maybe)
415 (should (string= test-line
416 (buffer-substring-no-properties
417 (point-at-bol) (point-at-eol))))))
418 (let ((test-line (concat " Some text prior to block src_emacs-lisp"
419 "[ :results silent ]{ \"y\" }")))
420 (org-test-with-temp-text
422 (goto-char (point-max))
423 (insert (concat "\n" test-line
" end"))
424 (re-search-backward "src_") (org-babel-execute-maybe)
425 (should (string= (concat test-line
" end")
426 (buffer-substring-no-properties
427 (point-at-bol) (point-at-eol))))
428 (re-search-forward "\" ") (org-babel-execute-maybe)
429 (should (string= (concat test-line
" end")
430 (buffer-substring-no-properties
431 (point-at-bol) (point-at-eol))))
433 (should-error (org-ctrl-c-ctrl-c)))))
435 (ert-deftest test-org-babel
/inline-src_blk-results-raw
()
436 (let ((test-line "src_emacs-lisp[ :results raw ]{ \"x\" }"))
437 (org-test-with-temp-text test-line
438 (org-babel-execute-maybe)
439 (should (string= (concat test-line
" x")
441 (let ((test-line (concat " Some text prior to block "
442 "src_emacs-lisp[ :results raw ]{ \"the\" }")))
443 (org-test-with-temp-text (concat test-line
" end")
444 (re-search-forward "src_") (org-babel-execute-maybe)
445 (should (string= (concat test-line
" the end")
446 (buffer-substring-no-properties
447 (point-at-bol) (point-at-eol))))
448 (re-search-forward "\" ") (org-babel-execute-maybe)
449 (should (string= (concat test-line
" the the end")
450 (buffer-substring-no-properties
451 (point-at-bol) (point-at-eol))))
453 (should-error (org-ctrl-c-ctrl-c)))))
455 (ert-deftest test-org-babel
/inline-src_blk-results-file
()
456 (let ((test-line "src_emacs-lisp[ :results file ]{ \"~/test-file\" }"))
457 (org-test-with-temp-text
459 (org-babel-execute-maybe)
460 (should (string= (concat test-line
" {{{results([[file:~/test-file]])}}}")
461 (buffer-substring-no-properties
462 (point-min) (point-max)))))))
464 (ert-deftest test-org-babel
/inline-src_blk-results-scalar
()
465 (let ((test-line "src_emacs-lisp[ :results scalar ]{ \"x\" }")
466 (org-babel-inline-result-wrap "=%s="))
467 (org-test-with-temp-text
469 (org-babel-execute-maybe)
470 (should (string= (concat test-line
" {{{results(=\"x\"=)}}}")
471 (buffer-substring-no-properties
472 (point-min) (point-max)))))))
474 (ert-deftest test-org-babel
/inline-src_blk-results-verbatim
()
475 (let ((test-line "src_emacs-lisp[ :results verbatim ]{ \"x\" }")
476 (org-babel-inline-result-wrap "=%s="))
477 (org-test-with-temp-text
479 (org-babel-execute-maybe)
480 (should (string= (concat test-line
" {{{results(=\"x\"=)}}}")
481 (buffer-substring-no-properties
482 (point-min) (point-max)))))))
484 (ert-deftest test-org-babel
/combining-scalar-and-raw-result-types
()
485 (org-test-with-temp-text-in-file "
487 #+begin_src sh :results scalar
488 echo \"[[file:./cv.cls]]\"
494 #+begin_src sh :results raw scalar
495 echo \"[[file:./cv.cls]]\"
498 (flet ((next-result ()
499 (org-babel-next-src-block)
500 (org-babel-execute-src-block)
501 (goto-char (org-babel-where-is-src-block-result))
503 (goto-char (point-min))
505 (should (org-babel-in-example-or-verbatim))
507 (should (not (org-babel-in-example-or-verbatim))))))
509 (ert-deftest test-org-babel
/no-defaut-value-for-var
()
510 "Test that the absence of a default value for a variable DOES THROW
512 (org-test-at-id "f2df5ba6-75fa-4e6b-8441-65ed84963627"
513 (org-babel-next-src-block)
515 (should-error (org-babel-execute-src-block) :type
'error
)))
519 "Variable \"x\" must be assigned a default value")
522 (ert-deftest test-org-babel
/just-one-results-block
()
523 "Test that evaluating two times the same code block does not result in a
524 duplicate results block."
525 (org-test-with-temp-text "#+begin_src sh\necho Hello\n#+end_src\n"
526 (org-babel-execute-src-block)
527 (org-babel-execute-src-block) ; second code block execution
528 (should (search-forward "Hello")) ; the string inside the source code block
529 (should (search-forward "Hello")) ; the same string in the results block
530 (should-error (search-forward "Hello"))))
532 (ert-deftest test-org-babel
/nested-code-block
()
533 "Test nested code blocks inside code blocks don't cause problems."
535 (string= "#+begin_src emacs-lisp\n 'foo\n#+end_src"
536 (org-test-with-temp-text "#+begin_src org :results silent
537 ,#+begin_src emacs-lisp
541 (let ((org-edit-src-content-indentation 2)
542 (org-src-preserve-indentation nil
))
543 (org-babel-execute-src-block))))))
545 (ert-deftest test-org-babel
/partial-nested-code-block
()
546 "Test nested code blocks inside code blocks don't cause problems."
547 (org-test-with-temp-text "#+begin_src org :results silent
548 ,#+begin_src emacs-lisp
550 (should (string= "#+begin_src emacs-lisp" (org-babel-execute-src-block)))))
552 (ert-deftest test-ob
/does-not-replace-a-block-with-the-results
()
553 (org-test-with-temp-text "#+NAME: foo
554 #+BEGIN_SRC emacs-lisp
557 (org-babel-next-src-block 1)
558 (should (eq 'foo
(org-babel-execute-src-block)))
559 (goto-char (point-min))
560 (org-babel-next-src-block 1)
561 (should (looking-at org-babel-src-block-regexp
))))
563 (ert-deftest test-ob
/catches-all-references
()
564 (org-test-with-temp-text "
565 #+NAME: literal-example
571 #+NAME: read-literal-example
572 #+BEGIN_SRC emacs-lisp :var x=literal-example
573 (concatenate 'string x \" for me.\")
575 (org-babel-next-src-block 1)
576 (should (string= (org-babel-execute-src-block)
577 "A literal example\non two lines\n for me."))))
579 (ert-deftest test-ob
/ignore-reference-in-commented-headings
()
582 (org-test-with-temp-text
594 <point>#+BEGIN_SRC emacs-lisp :var x=n
597 (org-babel-execute-src-block)))))
599 (ert-deftest test-ob
/do-not-resolve-to-partial-names-data
()
600 (org-test-with-temp-text "
609 #+begin_src emacs-lisp :var x=base
612 (org-babel-next-src-block 1)
613 (should (equal (org-babel-execute-src-block) '((3) (4))))))
615 (ert-deftest test-ob
/do-not-resolve-to-partial-names-code
()
616 (org-test-with-temp-text "
618 #+begin_src emacs-lisp
623 #+begin_src emacs-lisp
627 #+begin_src emacs-lisp :var x=base
630 (org-babel-next-src-block 3)
631 (should (equal (org-babel-execute-src-block) "foo"))))
633 (ert-deftest test-ob
/allow-spaces-around-
=-in-var-specs
()
634 (org-test-with-temp-text "#+begin_src emacs-lisp :var a = 1 b = 2 c= 3 d =4
638 (should (= 10 (org-babel-execute-src-block)))))
640 (ert-deftest test-ob
/org-babel-update-intermediate
()
641 (org-test-with-temp-text "#+name: foo
642 #+begin_src emacs-lisp
649 #+begin_src emacs-lisp :var it=foo
652 (let ((org-babel-update-intermediate nil
))
653 (goto-char (point-min))
654 (org-babel-next-src-block 2)
655 (should (= 3 (org-babel-execute-src-block)))
656 (goto-char (point-min))
658 (should (looking-at ": 4")))
659 (let ((org-babel-update-intermediate t
))
660 (goto-char (point-min))
661 (org-babel-next-src-block 2)
662 (should (= 3 (org-babel-execute-src-block)))
663 (goto-char (point-min))
665 (should (looking-at ": 2")))))
667 (ert-deftest test-ob
/eval-header-argument
()
668 (flet ((check-eval (eval runp
)
669 (org-test-with-temp-text (format "#+begin_src emacs-lisp :eval %s
672 (let ((foo :not-run
))
674 (progn (should (org-babel-execute-src-block))
675 (should (eq foo
:evald
)))
676 (progn (should-not (org-babel-execute-src-block))
677 (should-not (eq foo
:evald
))))))))
678 (check-eval "never" nil
)
679 (check-eval "no" nil
)
680 (check-eval "never-export" t
)
681 (check-eval "no-export" t
)
682 (let ((org-babel-exp-reference-buffer (current-buffer)))
683 (check-eval "never" nil
)
684 (check-eval "no" nil
)
685 (check-eval "never-export" nil
)
686 (check-eval "no-export" nil
))))
688 (ert-deftest test-ob
/noweb-expansion-1
()
689 (org-test-with-temp-text "#+begin_src sh :results output :tangle yes
697 (should (string= (org-babel-expand-noweb-references) "bar"))))
699 (ert-deftest test-ob
/noweb-expansion-2
()
700 (org-test-with-temp-text "#+begin_src sh :results output :tangle yes
705 #+begin_src sh :noweb-sep \"\"
709 #+begin_src sh :noweb-ref foo :noweb-sep \"\"
712 (should (string= (org-babel-expand-noweb-references) "barbaz"))))
714 (ert-deftest test-ob
/splitting-variable-lists-in-references
()
715 (org-test-with-temp-text ""
716 (should (= 1 (length (org-babel-ref-split-args
717 "a=\"this, no work\""))))
718 (should (= 2 (length (org-babel-ref-split-args
719 "a=\"this, no work\", b=1"))))))
721 (ert-deftest test-ob
/org-babel-balanced-split
()
723 '(":a 1" "b [2 3]" "c (4 :d (5 6))")
724 (org-babel-balanced-split ":a 1 :b [2 3] :c (4 :d (5 6))"
727 (ert-deftest test-ob
/commented-last-block-line-no-var
()
728 (org-test-with-temp-text-in-file "
729 #+begin_src emacs-lisp
732 (org-babel-next-src-block)
733 (org-babel-execute-maybe)
734 (should (re-search-forward "\\#\\+results:" nil t
))
739 (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
740 (org-test-with-temp-text-in-file "
741 #+begin_src emacs-lisp
744 (org-babel-next-src-block)
745 (org-babel-execute-maybe)
746 (should (re-search-forward "\\#\\+results:" nil t
))
751 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
753 (ert-deftest test-ob
/commented-last-block-line-with-var
()
754 (org-test-with-temp-text-in-file "
755 #+begin_src emacs-lisp :var a=1
758 (org-babel-next-src-block)
759 (org-babel-execute-maybe)
760 (re-search-forward "\\#\\+results:" nil t
)
764 (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
765 (org-test-with-temp-text-in-file "
766 #+begin_src emacs-lisp :var a=2
769 (org-babel-next-src-block)
770 (org-babel-execute-maybe)
771 (re-search-forward "\\#\\+results:" nil t
)
775 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
777 (ert-deftest test-ob
/org-babel-insert-result--improper-lists
()
778 "Test `org-babel-insert-result' with improper lists."
779 ;; Do not error when output is an improper list.
781 (org-test-with-temp-text
783 <point>#+BEGIN_SRC emacs-lisp
787 (org-babel-execute-maybe) t
)))
789 (ert-deftest test-ob
/remove-inline-result
()
790 "Test `org-babel-remove-inline-result' honors whitespace."
792 ((inline-sb "src_emacs-lisp{(+ 1 2)}")
793 (inline-res " {{{results(=3=)}}}")
794 (inline-sb-dot (concat inline-sb
"."))
795 (inline-sb-res-dot (concat inline-sb inline-res
".")))
796 (org-test-with-temp-text
797 ;; Insert inline_src_block followed by dot.
799 ;; Insert result before dot.
800 (org-babel-execute-maybe)
801 (should (string= inline-sb-res-dot
802 (buffer-substring-no-properties
803 (point-at-bol) (point-at-eol))))
804 ;; Delete whitespace and result.
805 (org-babel-remove-inline-result)
806 (should (string= inline-sb-dot
807 (buffer-substring-no-properties
808 (point-at-bol) (point-at-eol))))
809 ;; Add whitespace and result before dot.
810 (search-forward inline-sb
)
811 (insert " " inline-res
)
812 (goto-char (point-at-bol))
813 ;; Remove whitespace and result.
814 (org-babel-remove-inline-result)
815 (should (string= inline-sb-dot
816 (buffer-substring-no-properties
817 (point-at-bol) (point-at-eol))))
818 ;; Add whitespace before dot.
819 (search-forward inline-sb
)
821 (goto-char (point-at-bol))
822 ;; Add result before whitespace.
823 (org-babel-execute-maybe)
824 ;; Remove result - leave trailing whitespace and dot.
825 (org-babel-remove-inline-result)
826 (should (string= (concat inline-sb
" .")
827 (buffer-substring-no-properties
828 (point-at-bol) (point-at-eol)))))))
830 (defun test-ob-verify-result-and-removed-result (result buffer-text
)
831 "Test helper function to test `org-babel-remove-result'.
832 A temp buffer is populated with BUFFER-TEXT, the first block is executed,
833 and the result of execution is verified against RESULT.
835 The block is actually executed /twice/ to ensure result
836 replacement happens correctly."
837 (org-test-with-temp-text
839 (org-babel-next-src-block) (org-babel-execute-maybe) (org-babel-execute-maybe)
840 (should (re-search-forward "\\#\\+results:" nil t
))
842 (should (string= result
843 (buffer-substring-no-properties
845 (- (point-max) 16))))
846 (org-babel-previous-src-block) (org-babel-remove-result)
847 (should (string= buffer-text
848 (buffer-substring-no-properties
849 (point-min) (point-max))))))
851 (ert-deftest test-ob
/org-babel-remove-result--results-default
()
852 "Test `org-babel-remove-result' with default :results."
853 (mapcar (lambda (language)
854 (test-ob-verify-result-and-removed-result
857 "* org-babel-remove-result
858 #+begin_src " language
"
862 '("sh" "emacs-lisp")))
864 (ert-deftest test-ob
/org-babel-remove-result--results-list
()
865 "Test `org-babel-remove-result' with :results list."
866 (test-ob-verify-result-and-removed-result
872 "* org-babel-remove-result
873 #+begin_src emacs-lisp :results list
879 (ert-deftest test-ob
/org-babel-results-indented-wrap
()
880 "Ensure that wrapped results are inserted correction when indented.
881 If not inserted correctly then the second evaluation will fail
882 trying to find the :END: marker."
883 (org-test-with-temp-text
885 #+begin_src sh :results file wrap
888 (org-babel-next-src-block 1)
889 (org-babel-execute-src-block)
890 (org-babel-execute-src-block)))
892 (ert-deftest test-ob
/file-desc-header-argument
()
893 "Test that the :file-desc header argument is used."
894 (org-test-with-temp-text "#+begin_src emacs-lisp :results file :file-desc bar
898 #+begin_src emacs-lisp :results file :file-desc
901 (org-babel-execute-src-block)
902 (org-babel-next-src-block 1)
903 (org-babel-execute-src-block)
904 (goto-char (point-min))
905 (should (search-forward "[[file:foo][bar]]" nil t
))
906 (should (search-forward "[[file:foo][foo]]" nil t
))))
908 (ert-deftest test-ob
/org-babel-remove-result--results-pp
()
909 "Test `org-babel-remove-result' with :results pp."
910 (test-ob-verify-result-and-removed-result
911 ": \"I /am/ working!\""
913 "* org-babel-remove-result
914 #+begin_src emacs-lisp :results pp
920 (ert-deftest test-org-babel
/inline-src_blk-preceded-punct-preceded-by-point
()
921 (let ((test-line ".src_emacs-lisp[ :results verbatim ]{ \"x\" }")
922 (org-babel-inline-result-wrap "=%s="))
923 (org-test-with-temp-text
926 (org-babel-execute-maybe)
927 (should (re-search-forward "=\"x\"=" nil t
))
930 (ert-deftest test-ob
/commented-last-block-line-with-var
()
931 (org-test-with-temp-text-in-file "
932 #+begin_src emacs-lisp :var a=1
935 (org-babel-next-src-block)
936 (org-babel-execute-maybe)
937 (re-search-forward "\\#\\+results:" nil t
)
941 (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
942 (org-test-with-temp-text-in-file "
943 #+begin_src emacs-lisp :var a=2
946 (org-babel-next-src-block)
947 (org-babel-execute-maybe)
948 (re-search-forward "\\#\\+results:" nil t
)
952 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
954 (defun test-ob-verify-result-and-removed-result (result buffer-text
)
955 "Test helper function to test `org-babel-remove-result'.
956 A temp buffer is populated with BUFFER-TEXT, the first block is executed,
957 and the result of execution is verified against RESULT.
959 The block is actually executed /twice/ to ensure result
960 replacement happens correctly."
961 (org-test-with-temp-text
963 (org-babel-next-src-block) (org-babel-execute-maybe) (org-babel-execute-maybe)
964 (should (re-search-forward "\\#\\+results:" nil t
))
966 (should (string= result
967 (buffer-substring-no-properties
969 (- (point-max) 16))))
970 (org-babel-previous-src-block) (org-babel-remove-result)
971 (should (string= buffer-text
972 (buffer-substring-no-properties
973 (point-min) (point-max))))))
975 (ert-deftest test-ob
/org-babel-remove-result--results-default
()
976 "Test `org-babel-remove-result' with default :results."
977 (mapcar (lambda (language)
978 (test-ob-verify-result-and-removed-result
981 "* org-babel-remove-result
982 #+begin_src " language
"
986 '("sh" "emacs-lisp")))
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
996 "* org-babel-remove-result
997 #+begin_src emacs-lisp :results list
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
1010 "* org-babel-remove-result
1012 #+begin_src emacs-lisp :results wrap
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
1027 "* org-babel-remove-result
1028 #+begin_src emacs-lisp :results org
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>
1043 "* org-babel-remove-result
1044 #+begin_src emacs-lisp :results html
1045 \"<head><body></body></head>\"
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
1059 "* org-babel-remove-result
1060 #+begin_src emacs-lisp :results latex
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
1076 "* org-babel-remove-result
1077 #+begin_src emacs-lisp :results code
1078 (message \"I am working!\")
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!\")
1095 (ert-deftest test-ob
/results-do-not-replace-code-blocks
()
1096 (org-test-with-temp-text "Block two has a space after the name.
1099 #+begin_src emacs-lisp
1104 #+begin_src emacs-lisp
1109 #+begin_src emacs-lisp
1116 (dolist (num '(1 2 3))
1117 ;; execute the block
1118 (goto-char (point-min))
1119 (org-babel-next-src-block num
) (org-babel-execute-src-block)
1120 ;; check the results
1121 (goto-char (point-max))
1122 (move-beginning-of-line 0)
1123 (should (looking-at (format ": %d" num
))))))
1125 (ert-deftest test-ob
/blocks-with-spaces
()
1126 "Test expansion of blocks followed by blank lines."
1128 (equal "#+BEGIN_SRC emacs-lisp
1134 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp
1137 (let ((org-babel-next-src-block "RESULTS"))
1138 (org-babel-execute-src-block))
1141 (ert-deftest test-ob
/results-in-narrowed-buffer
()
1142 "Test block execution in a narrowed buffer."
1143 ;; If results don't exist, they should be inserted in visible part
1147 "#+BEGIN_SRC emacs-lisp\n(+ 1 2)\n#+END_SRC\n\n#+RESULTS:\n: 3"
1148 (org-test-with-temp-text
1149 "#+BEGIN_SRC emacs-lisp\n(+ 1 2)\n#+END_SRC\n\nParagraph"
1150 (narrow-to-region (point) (save-excursion (forward-line 3) (point)))
1151 (let ((org-babel-results-keyword "RESULTS"))
1152 (org-babel-execute-src-block))
1153 (org-trim (buffer-string)))))
1156 "#+NAME: test\n#+BEGIN_SRC emacs-lisp\n(+ 1 2)\n#+END_SRC\n\n#+RESULTS: test\n: 3"
1157 (org-test-with-temp-text
1158 "#+NAME: test\n#+BEGIN_SRC emacs-lisp\n(+ 1 2)\n#+END_SRC\n\nParagraph"
1159 (narrow-to-region (point) (save-excursion (forward-line 4) (point)))
1160 (let ((org-babel-results-keyword "RESULTS"))
1161 (org-babel-execute-src-block))
1162 (org-trim (buffer-string)))))
1163 ;; Results in visible part of buffer, should be updated here.
1167 #+BEGIN_SRC emacs-lisp
1173 (org-test-with-temp-text
1175 #+BEGIN_SRC emacs-lisp
1183 (narrow-to-region (point) (save-excursion (forward-line 7) (point)))
1184 (let ((org-babel-results-keyword "RESULTS"))
1185 (org-babel-execute-src-block))
1186 (org-trim (buffer-string)))))
1187 ;; Results in invisible part of buffer, should be updated there.
1188 (org-test-with-temp-text
1190 #+BEGIN_SRC emacs-lisp
1198 (narrow-to-region (point) (save-excursion (forward-line 4) (point)))
1199 (let ((org-babel-results-keyword "RESULTS"))
1200 (org-babel-execute-src-block))
1201 (should-not (re-search-forward "^#\\+RESULTS:" nil t
))
1203 (should (should (re-search-forward "^: 3" nil t
)))))
1205 (ert-deftest test-ob
/specific-colnames
()
1206 "Test passing specific column names."
1208 (equal "#+name: input-table
1214 #+begin_src sh :var data=input-table :exports results :colnames '(Rev Author)
1225 (org-test-with-temp-text
1226 "#+name: input-table
1232 #+begin_src sh :var data=input-table :exports results :colnames '(Rev Author)
1236 ;; we should find a code block
1237 (should (re-search-forward org-babel-src-block-regexp nil t
))
1238 (goto-char (match-beginning 0))
1239 ;; now that we've located the code block, it may be evaluated
1240 (let ((org-babel-execute-src-block "RESULTS"))
1241 (org-babel-execute-src-block))
1244 (ert-deftest test-ob
/location-of-header-arg-eval
()
1245 "Test location of header argument evaluation."
1246 (org-test-with-temp-text "
1248 #+begin_src emacs-lisp :var pt=(point)
1252 #+name: bottom-block
1253 #+begin_src emacs-lisp :var pt=top-block()
1257 ;; the value of the second block should be greater than the first
1259 (< (progn (re-search-forward org-babel-src-block-regexp nil t
)
1260 (goto-char (match-beginning 0))
1261 (prog1 (save-match-data (org-babel-execute-src-block))
1262 (goto-char (match-end 0))))
1263 (progn (re-search-forward org-babel-src-block-regexp nil t
)
1264 (goto-char (match-beginning 0))
1265 (org-babel-execute-src-block))))))
1267 (ert-deftest test-ob
/preserve-results-indentation
()
1268 "Preserve indentation when executing a src block."
1272 (org-test-with-temp-text " #+begin_src emacs-lisp\n(+ 1 1)\n #+end_src"
1273 (org-babel-execute-src-block)
1274 (let ((case-fold-search t
)) (search-forward "RESULTS"))
1275 (list (org-get-indentation)
1276 (progn (forward-line) (org-get-indentation))))))
1280 (org-test-with-temp-text
1281 " #+name: block\n #+begin_src emacs-lisp\n(+ 1 1)\n #+end_src"
1282 (org-babel-execute-src-block)
1283 (let ((case-fold-search t
)) (search-forward "RESULTS"))
1284 (list (org-get-indentation)
1285 (progn (forward-line) (org-get-indentation))))))
1286 ;; Don't get fooled by TAB-based indentation.
1290 (org-test-with-temp-text
1291 "\t #+begin_src emacs-lisp\n\t (+ 1 1)\n\t #+end_src"
1293 (org-babel-execute-src-block)
1294 (let ((case-fold-search t
)) (search-forward "RESULTS"))
1295 (list (org-get-indentation)
1296 (progn (forward-line) (org-get-indentation)))))))
1298 (ert-deftest test-ob
/safe-header-args
()
1299 "Detect safe and unsafe header args."
1300 (let ((safe-args '((:cache .
"foo")
1301 (:results .
"output")
1304 (unsafe-args '((:eval .
"yes")
1305 (:results .
"output file")
1307 (malformed-args '((bar .
"foo")
1310 (safe-p (org-babel-header-args-safe-fn org-babel-safe-header-args
)))
1311 (dolist (arg safe-args
)
1312 (should (org-babel-one-header-arg-safe-p arg org-babel-safe-header-args
)))
1313 (dolist (arg unsafe-args
)
1314 (should (not (org-babel-one-header-arg-safe-p arg org-babel-safe-header-args
))))
1315 (dolist (arg malformed-args
)
1316 (should (not (org-babel-one-header-arg-safe-p arg org-babel-safe-header-args
))))
1317 (should (not (funcall safe-p
(append safe-args unsafe-args
))))))
1319 (ert-deftest test-ob
/noweb-expansions-in-cache
()
1320 "Ensure that noweb expansions are expanded before caching."
1321 (let ((noweb-expansions-in-cache-var 0))
1322 (org-test-with-temp-text "
1324 #+begin_src emacs-lisp
1329 #+begin_src emacs-lisp :noweb yes :cache yes
1330 (setq noweb-expansions-in-cache-var
1331 (+ 1 noweb-expansions-in-cache-var))
1332 (concat <<foo>> \" check noweb expansions\")
1335 ;; run the second block to create the cache
1336 (goto-char (point-min))
1337 (re-search-forward (regexp-quote "#+name: bar"))
1338 (should (string= "I said check noweb expansions"
1339 (org-babel-execute-src-block)))
1340 (should (= noweb-expansions-in-cache-var
1))
1341 ;; change the value of the first block
1342 (goto-char (point-min))
1343 (re-search-forward (regexp-quote "said"))
1344 (goto-char (match-beginning 0))
1346 (re-search-forward (regexp-quote "#+name: bar"))
1347 (should (string= "I haven't said check noweb expansions"
1348 (org-babel-execute-src-block)))
1349 (should (= noweb-expansions-in-cache-var
2)))))
1351 (ert-deftest test-org-babel
/file-ext-and-output-dir
()
1352 (org-test-at-id "93573e1d-6486-442e-b6d0-3fedbdc37c9b"
1353 (org-babel-next-src-block)
1354 (should (equal "file-ext-basic.txt"
1355 (cdr (assq :file
(nth 2 (org-babel-get-src-block-info t
))))))
1356 (org-babel-next-src-block)
1357 (should (equal "foo/file-ext-dir-relative.txt"
1358 (cdr (assq :file
(nth 2 (org-babel-get-src-block-info t
))))))
1359 (org-babel-next-src-block)
1360 (should (equal "foo/file-ext-dir-relative-slash.txt"
1361 (cdr (assq :file
(nth 2 (org-babel-get-src-block-info t
))))))
1362 (org-babel-next-src-block)
1363 (should (equal "/tmp/file-ext-dir-absolute.txt"
1364 (cdr (assq :file
(nth 2 (org-babel-get-src-block-info t
))))))
1365 (org-babel-next-src-block)
1366 (should (equal "foo.bar"
1367 (cdr (assq :file
(nth 2 (org-babel-get-src-block-info t
))))))
1368 (org-babel-next-src-block)
1369 (should (equal "xxx/foo.bar"
1370 (cdr (assq :file
(nth 2 (org-babel-get-src-block-info t
))))))
1373 (ert-deftest test-org-babel
/script-escape
()
1374 ;; Delimited lists of numbers
1375 (should (equal '(1 2 3)
1376 (org-babel-script-escape "[1 2 3]")))
1377 (should (equal '(1 2 3)
1378 (org-babel-script-escape "{1 2 3}")))
1379 (should (equal '(1 2 3)
1380 (org-babel-script-escape "(1 2 3)")))
1381 ;; Delimited lists of double-quoted strings
1382 (should (equal '("foo" "bar")
1383 (org-babel-script-escape "(\"foo\" \"bar\")")))
1384 (should (equal '("foo" "bar")
1385 (org-babel-script-escape "[\"foo\" \"bar\"]")))
1386 (should (equal '("foo" "bar")
1387 (org-babel-script-escape "{\"foo\" \"bar\"}")))
1389 (should (equal '("foo" "bar")
1390 (org-babel-script-escape "(\"foo\", \"bar\")")))
1391 (should (equal '("foo" "bar")
1392 (org-babel-script-escape "[\"foo\", \"bar\"]")))
1393 (should (equal '("foo" "bar")
1394 (org-babel-script-escape "{\"foo\", \"bar\"}")))
1395 ;; Delimited lists of single-quoted strings
1396 (should (equal '("foo" "bar")
1397 (org-babel-script-escape "('foo' 'bar')")))
1398 (should (equal '("foo" "bar")
1399 (org-babel-script-escape "['foo' 'bar']")))
1400 (should (equal '("foo" "bar")
1401 (org-babel-script-escape "{'foo' 'bar'}")))
1403 (should (equal '("foo" "bar")
1404 (org-babel-script-escape "('foo', 'bar')")))
1405 (should (equal '("foo" "bar")
1406 (org-babel-script-escape "['foo', 'bar']")))
1407 (should (equal '("foo" "bar")
1408 (org-babel-script-escape "{'foo', 'bar'}")))
1409 ;; Single quoted strings
1410 (should (equal "foo"
1411 (org-babel-script-escape "'foo'")))
1412 ;; ... with internal double quote
1413 (should (equal "foo\"bar"
1414 (org-babel-script-escape "'foo\"bar'")))
1415 ;; ... with internal backslash
1416 (should (equal "foo\\bar"
1417 (org-babel-script-escape "'foo\\bar'")))
1418 ;; ... with internal escaped backslash
1419 (should (equal "foo\\bar"
1420 (org-babel-script-escape "'foo\\\\bar'")))
1421 ;; ... with internal backslash-double quote
1422 (should (equal "foo\\\"bar"
1423 (org-babel-script-escape "'foo\\\"bar'")))
1424 ;; ... with internal escaped backslash-double quote
1425 (should (equal "foo\\\"bar"
1426 (org-babel-script-escape "'foo\\\\\"bar'")))
1427 ;; ... with internal escaped single quote
1428 (should (equal "foo'bar"
1429 (org-babel-script-escape "'foo\\'bar'")))
1430 ;; ... with internal escaped backslash-escaped single quote
1431 (should (equal "foo\\'bar"
1432 (org-babel-script-escape "'foo\\\\\\'bar'")))
1433 ;; Double quoted strings
1434 (should (equal "foo"
1435 (org-babel-script-escape "\"foo\"")))
1436 ;; ... with internal single quote
1437 (should (equal "foo'bar"
1438 (org-babel-script-escape "\"foo'bar\"")))
1439 ;; ... with internal backslash
1440 (should (equal "foo\\bar"
1441 (org-babel-script-escape "\"foo\\bar\"")))
1442 ;; ... with internal escaped backslash
1443 (should (equal "foo\\bar"
1444 (org-babel-script-escape "\"foo\\\\bar\"")))
1445 ;; ... with internal backslash-single quote
1446 (should (equal "foo\\'bar"
1447 (org-babel-script-escape "\"foo\\'bar\"")))
1448 ;; ... with internal escaped backslash-single quote
1449 (should (equal "foo\\'bar"
1450 (org-babel-script-escape "\"foo\\\\'bar\"")))
1451 ;; ... with internal escaped double quote
1452 (should (equal "foo\"bar"
1453 (org-babel-script-escape "\"foo\\\"bar\"")))
1454 ;; ... with internal escaped backslash-escaped double quote
1455 (should (equal "foo\\\"bar"
1456 (org-babel-script-escape "\"foo\\\\\\\"bar\""))))
1458 (ert-deftest ob
/process-params-no-duplicates
()
1459 (should (equal (org-babel-process-params '((:colname-names .
1)
1460 (:rowname-names .
1)
1461 (:result-params .
1)
1463 (:var .
"\"foo\"")))
1465 (:colname-names .
1)
1466 (:rowname-names .
1)
1467 (:result-params .
1)
1468 (:result-type . value
)))))
1470 (defun org-test-babel-confirm-evaluate (eval-value)
1471 (org-test-with-temp-text (format "#+begin_src emacs-lisp :eval %s
1473 #+end_src" eval-value
)
1474 (goto-char (point-min))
1475 (let ((info (org-babel-get-src-block-info)))
1476 (org-babel-check-confirm-evaluate info
))))
1478 (ert-deftest ob
/check-eval
()
1479 (let ((org-confirm-babel-evaluate t
))
1481 (dolist (pair '(("no" . nil
)
1485 (should (eq (org-test-babel-confirm-evaluate (car pair
)) (cdr pair
))))
1487 (let ((org-babel-exp-reference-buffer t
))
1488 (dolist (pair '(("no" . nil
)
1492 ("never-export" . nil
)
1494 ("query-export" . query
)))
1495 (message (car pair
))
1496 (should (eq (org-test-babel-confirm-evaluate (car pair
)) (cdr pair
))))))
1497 (let ((org-confirm-babel-evaluate nil
))
1499 (dolist (pair '(("no" . nil
)
1503 (should (eq (org-test-babel-confirm-evaluate (car pair
)) (cdr pair
))))
1505 (let ((org-babel-exp-reference-buffer t
))
1506 (dolist (pair '(("no" . nil
)
1510 ("never-export" . nil
)
1512 ("query-export" . query
)))
1513 (message (car pair
))
1514 (should (eq (org-test-babel-confirm-evaluate (car pair
)) (cdr pair
)))))))
1516 (defun org-test-ob/update-block-body
()
1517 "Test `org-babel-update-block-body' specifications."
1519 (equal "#+begin_src elisp\n 2\n#+end_src"
1520 (let ((org-edit-src-content-indentation 2))
1521 (org-test-with-temp-text "#+begin_src elisp\n(+ 1 1)\n#+end_src"
1522 (org-babel-update-block-body "2")
1524 ;; Preserve block indentation.
1526 (equal " #+begin_src elisp\n 2\n #+end_src"
1527 (let ((org-edit-src-content-indentation 1))
1528 (org-test-with-temp-text
1529 " #+begin_src elisp\n (+ 1 1)\n #+end_src"
1530 (org-babel-update-block-body "2")
1532 ;; Ignore NEW-BODY global indentation.
1534 (equal "#+begin_src elisp\n 2\n#+end_src"
1535 (let ((org-edit-src-content-indentation 2))
1536 (org-test-with-temp-text "#+begin_src elisp\n(+ 1 1)\n#+end_src"
1537 (org-babel-update-block-body " 2")
1539 ;; When indentation should be preserved ignore the two rules above.
1541 (equal " #+begin_src elisp\n2\n #+end_src"
1542 (let ((org-edit-src-content-indentation 1)
1543 (org-src-preserve-indentation t
))
1544 (org-test-with-temp-text
1545 " #+begin_src elisp\n (+ 1 1)\n #+end_src"
1546 (org-babel-update-block-body "2")
1549 (equal " #+begin_src elisp -i\n2\n #+end_src"
1550 (let ((org-edit-src-content-indentation 1))
1551 (org-test-with-temp-text
1552 " #+begin_src elisp -i\n (+ 1 1)\n #+end_src"
1553 (org-babel-update-block-body "2")
1556 (equal "#+begin_src elisp\n 2\n#+end_src"
1557 (let ((org-edit-src-content-indentation 2)
1558 (org-src-preserve-indentation t
))
1559 (org-test-with-temp-text "#+begin_src elisp\n(+ 1 1)\n#+end_src"
1560 (org-babel-update-block-body " 2")
1563 (equal "#+begin_src elisp -i\n 2\n#+end_src"
1564 (let ((org-edit-src-content-indentation 2)
1565 (org-src-preserve-indentation t
))
1566 (org-test-with-temp-text "#+begin_src elisp -i\n(+ 1 1)\n#+end_src"
1567 (org-babel-update-block-body " 2")
1568 (buffer-string))))))
1572 ;;; test-ob ends here