test-ob.el 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186
  1. ;;; test-ob.el --- tests for ob.el
  2. ;; Copyright (c) 2010-2014 Eric Schulte
  3. ;; Authors: Eric Schulte, Martyn Jago
  4. ;; This file is not part of GNU Emacs.
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Code:
  16. (ert-deftest test-org-babel/multi-line-header-regexp ()
  17. (should(equal "^[ \t]*#\\+headers?:[ \t]*\\([^\n]*\\)$"
  18. org-babel-multi-line-header-regexp))
  19. ;;TODO can be optimised - and what about blah4 blah5 blah6?
  20. (should (string-match
  21. org-babel-multi-line-header-regexp
  22. " \t #+headers: blah1 blah2 blah3 \t\n\t\n blah4 blah5 blah6 \n"))
  23. (should
  24. (equal
  25. "blah1 blah2 blah3 \t"
  26. (match-string
  27. 1
  28. " \t #+headers: blah1 blah2 blah3 \t\n\t\n blah4 blah5 blah6 \n")))
  29. ;;TODO Check - should this fail?
  30. (should
  31. (not (org-test-string-exact-match
  32. org-babel-multi-line-header-regexp
  33. " \t #+headers : blah1 blah2 blah3 \t\n\t\n blah4 blah5 blah6 \n"))))
  34. (ert-deftest test-org-babel/src-block-regexp ()
  35. (let ((test-block
  36. (concat
  37. "#+begin_src language -n-r-a-b -c :argument-1 yes :argument-2 no\n"
  38. "echo this is a test\n"
  39. "echo Currently in ' $PWD\n"
  40. "#+end_src"))
  41. (language "language")
  42. (flags "-n-r-a-b -c ")
  43. (arguments ":argument-1 yes :argument-2 no")
  44. (body "echo this is a test\necho Currently in ' $PWD\n"))
  45. (should (string-match org-babel-src-block-regexp test-block))
  46. (should (string-match org-babel-src-block-regexp (upcase test-block)))
  47. (should (equal language (match-string 2 test-block)))
  48. ;;TODO Consider refactoring
  49. (should (equal flags (match-string 3 test-block)))
  50. (should (equal arguments (match-string 4 test-block)))
  51. (should (equal body (match-string 5 test-block)))
  52. ;;no switches
  53. (should (org-test-string-exact-match
  54. org-babel-src-block-regexp
  55. (replace-regexp-in-string flags "" test-block)))
  56. ;;no header arguments
  57. (should (org-test-string-exact-match
  58. org-babel-src-block-regexp
  59. (replace-regexp-in-string arguments "" test-block)))
  60. ;; should be valid with no body
  61. (should (org-test-string-exact-match
  62. org-babel-src-block-regexp
  63. (replace-regexp-in-string body "" test-block)))))
  64. (ert-deftest test-org-babel/get-header ()
  65. (should (not (org-babel-get-header
  66. org-babel-default-header-args :doesnt-exist)))
  67. (should(equal '((:session . "none"))
  68. (org-babel-get-header
  69. org-babel-default-header-args :session)))
  70. (should(equal '((:session . "none"))
  71. (org-babel-get-header
  72. org-babel-default-header-args :session nil)))
  73. (should (not (org-babel-get-header
  74. org-babel-default-header-args :SESSION)))
  75. (should (equal '((:tangle . "no"))
  76. (org-babel-get-header
  77. org-babel-default-header-args :tangle)))
  78. ;; with OTHERS option
  79. (should (equal org-babel-default-header-args
  80. (org-babel-get-header
  81. org-babel-default-header-args :doesnt-exist 'others)))
  82. (should (equal org-babel-default-header-args
  83. (org-babel-get-header
  84. org-babel-default-header-args nil 'others)))
  85. (should (null
  86. (assoc :noweb
  87. (org-babel-get-header
  88. org-babel-default-header-args :noweb 'others)))))
  89. (ert-deftest test-org-babel/default-inline-header-args ()
  90. (should(equal
  91. '((:session . "none") (:results . "replace") (:exports . "results"))
  92. org-babel-default-inline-header-args)))
  93. (ert-deftest ob-test/org-babel-combine-header-arg-lists ()
  94. (let ((results (org-babel-combine-header-arg-lists
  95. '((foo . :any)
  96. (bar)
  97. (baz . ((foo bar) (baz)))
  98. (qux . ((foo bar baz qux)))
  99. (quux . ((foo bar))))
  100. '((bar)
  101. (baz . ((baz)))
  102. (quux . :any)))))
  103. (dolist (pair '((foo . :any)
  104. (bar)
  105. (baz . ((baz)))
  106. (quux . :any)
  107. (qux . ((foo bar baz qux)))))
  108. (should (equal (cdr pair)
  109. (cdr (assoc (car pair) results)))))))
  110. ;;; ob-get-src-block-info
  111. (ert-deftest test-org-babel/get-src-block-info-language ()
  112. (org-test-at-marker nil org-test-file-ob-anchor
  113. (let ((info (org-babel-get-src-block-info)))
  114. (should (string= "emacs-lisp" (nth 0 info))))))
  115. (ert-deftest test-org-babel/get-src-block-info-body ()
  116. (org-test-at-marker nil org-test-file-ob-anchor
  117. (let ((info (org-babel-get-src-block-info)))
  118. (should (string-match (regexp-quote org-test-file-ob-anchor)
  119. (nth 1 info))))))
  120. (ert-deftest test-org-babel/get-src-block-info-tangle ()
  121. (org-test-at-marker nil org-test-file-ob-anchor
  122. (let ((info (org-babel-get-src-block-info)))
  123. (should (string= "no" (cdr (assoc :tangle (nth 2 info))))))))
  124. (ert-deftest test-org-babel/elisp-in-header-arguments ()
  125. "Test execution of elisp forms in header arguments."
  126. (org-test-with-temp-text-in-file "
  127. * elisp forms in header arguments
  128. :PROPERTIES:
  129. :var: prop = (* 7 6)
  130. :END:
  131. #+begin_src emacs-lisp
  132. prop
  133. #+end_src"
  134. (goto-char (point-min))
  135. (org-babel-next-src-block)
  136. (let ((info (org-babel-get-src-block-info)))
  137. (should (= 42 (org-babel-execute-src-block))))))
  138. (ert-deftest test-org-babel/simple-named-code-block ()
  139. "Test that simple named code blocks can be evaluated."
  140. (org-test-with-temp-text-in-file "
  141. #+name: i-have-a-name
  142. #+begin_src emacs-lisp
  143. 42
  144. #+end_src"
  145. (org-babel-next-src-block 1)
  146. (should (= 42 (org-babel-execute-src-block)))))
  147. (ert-deftest test-org-babel/simple-variable-resolution ()
  148. "Test that simple variable resolution is working."
  149. (org-test-with-temp-text-in-file "
  150. #+name: four
  151. #+begin_src emacs-lisp
  152. (list 1 2 3 4)
  153. #+end_src
  154. #+begin_src emacs-lisp :var four=four
  155. (length four)
  156. #+end_src"
  157. (org-babel-next-src-block 2)
  158. (should (= 4 (org-babel-execute-src-block)))
  159. (forward-line 5)
  160. (should (string= ": 4" (buffer-substring
  161. (point-at-bol)
  162. (point-at-eol))))))
  163. (ert-deftest test-org-babel/multi-line-header-arguments ()
  164. "Test that multi-line header arguments and can be read."
  165. (org-test-with-temp-text-in-file "
  166. #+headers: :var letters='(a b c d e f g)
  167. #+begin_src emacs-lisp :var numbers='(1 2 3 4 5 6 7)
  168. (require 'cl)
  169. (defalias 'my-map (if (org-version-check \"24.2.50\" \"cl\" :predicate)
  170. 'cl-map
  171. 'map))
  172. (my-map 'list #'list numbers letters)
  173. #+end_src"
  174. (org-babel-next-src-block)
  175. (let ((results (org-babel-execute-src-block)))
  176. (should(equal 'a (cadr (assoc 1 results))))
  177. (should(equal 'd (cadr (assoc 4 results)))))))
  178. (ert-deftest test-org-babel/parse-header-args ()
  179. (org-test-with-temp-text-in-file "
  180. #+begin_src example-lang :session :results output :var num=9
  181. the body
  182. #+end_src"
  183. (org-babel-next-src-block)
  184. (let* ((info (org-babel-get-src-block-info))
  185. (params (nth 2 info)))
  186. (message "%S" params)
  187. (should (equal "example-lang" (nth 0 info)))
  188. (should (string= "the body" (org-babel-trim (nth 1 info))))
  189. (should-not (member '(:session\ \ \ \ ) params))
  190. (should (equal '(:session) (assoc :session params)))
  191. (should (equal '(:result-type . output) (assoc :result-type params)))
  192. (should (equal '(num . 9) (cdr (assoc :var params)))))))
  193. (ert-deftest test-org-babel/parse-header-args2 ()
  194. (org-test-with-temp-text-in-file "
  195. * resolving sub-trees as references
  196. #+begin_src emacs-lisp :var text=d4faa7b3-072b-4dcf-813c-dd7141c633f3
  197. (length text)
  198. #+end_src
  199. #+begin_src org :noweb yes
  200. <<simple-subtree>>
  201. <<d4faa7b3-072b-4dcf-813c-dd7141c633f3>>
  202. #+end_src
  203. ** simple subtree with custom ID
  204. :PROPERTIES:
  205. :CUSTOM_ID: simple-subtree
  206. :END:
  207. this is simple"
  208. (should (string-match (regexp-quote "this is simple")
  209. (org-babel-ref-resolve "simple-subtree")))
  210. (org-babel-next-src-block)
  211. (should (= 14 (org-babel-execute-src-block)))))
  212. (ert-deftest test-org-babel/inline-src-blocks ()
  213. (org-test-at-id "54cb8dc3-298c-4883-a933-029b3c9d4b18"
  214. (macrolet ((at-next (&rest body)
  215. `(progn
  216. (move-end-of-line 1)
  217. (re-search-forward org-babel-inline-src-block-regexp nil t)
  218. (goto-char (match-beginning 1))
  219. (save-match-data ,@body))))
  220. (at-next (should (equal 1 (org-babel-execute-src-block))))
  221. (at-next (should (equal 2 (org-babel-execute-src-block))))
  222. (at-next (should (equal 3 (org-babel-execute-src-block)))))))
  223. (ert-deftest test-org-babel/org-babel-get-inline-src-block-matches ()
  224. (org-test-at-id "0D0983D4-DE33-400A-8A05-A225A567BC74"
  225. (let ((test-point (point)))
  226. (should (fboundp 'org-babel-get-inline-src-block-matches))
  227. (should (re-search-forward "src_" nil t)) ;; 1
  228. (should (org-babel-get-inline-src-block-matches))
  229. (should (re-search-forward "}" nil (point-at-bol))) ;; 1
  230. (should-not (org-babel-get-inline-src-block-matches))
  231. (should (re-search-forward "in" nil t)) ;; 2
  232. (should-not (org-babel-get-inline-src-block-matches))
  233. (should (re-search-forward "echo" nil t)) ;; 2
  234. (should (org-babel-get-inline-src-block-matches))
  235. (should (re-search-forward "blocks" nil t)) ;; 3
  236. (backward-char 8) ;; 3
  237. (should (org-babel-get-inline-src-block-matches))
  238. (forward-char 1) ;;3
  239. (should-not (org-babel-get-inline-src-block-matches))
  240. (should (re-search-forward ":results" nil t)) ;; 4
  241. (should (org-babel-get-inline-src-block-matches))
  242. (end-of-line)
  243. (should-not (org-babel-get-inline-src-block-matches)))))
  244. (ert-deftest test-org-babel/inline-src_blk-default-results-replace-line-1 ()
  245. (let ((test-line "src_sh{echo 1}"))
  246. ;; src_ at bol line 1...
  247. (org-test-with-temp-text
  248. test-line
  249. (goto-char (point-min)) (org-ctrl-c-ctrl-c)
  250. (should (string=
  251. (concat test-line " =1=")
  252. (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
  253. (forward-char) (org-ctrl-c-ctrl-c)
  254. (should (string=
  255. (concat test-line " =1= =1=")
  256. (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
  257. (re-search-forward "1}")
  258. (should-error (org-ctrl-c-ctrl-c))
  259. (backward-char) ;; last char of block body
  260. (org-ctrl-c-ctrl-c)
  261. (should (string=
  262. (concat test-line " =1= =1= =1=")
  263. (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
  264. ;; src_ follows space line 1...
  265. (let ((test-line " src_emacs-lisp{ 1 }"))
  266. (org-test-with-temp-text
  267. test-line
  268. (should-error (org-ctrl-c-ctrl-c))
  269. (forward-char) (org-ctrl-c-ctrl-c)
  270. (should (string=
  271. (concat test-line " =1=")
  272. (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
  273. (re-search-forward "{ 1 ") (org-ctrl-c-ctrl-c)
  274. (should (string=
  275. (concat test-line " =1= =1=")
  276. (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
  277. (forward-char)
  278. (should-error (org-ctrl-c-ctrl-c))))))
  279. (ert-deftest test-org-babel/inline-src_blk-default-results-replace-line-2 ()
  280. ;; src_ at bol line 2...
  281. (let ((test-line " src_emacs-lisp{ \"x\" }"))
  282. (org-test-with-temp-text
  283. (concat "\n" test-line)
  284. (should-error (org-ctrl-c-ctrl-c))
  285. (goto-char (point-min))
  286. (should-error (org-ctrl-c-ctrl-c))
  287. (forward-line)
  288. (should-error (org-ctrl-c-ctrl-c))
  289. (forward-char) (org-ctrl-c-ctrl-c)
  290. (should (string=
  291. (concat test-line " =x=")
  292. (buffer-substring-no-properties
  293. (point-at-bol) (point-at-eol))))))
  294. (let ((test-line "Some text prior to block src_emacs-lisp{ \"y\" }"))
  295. (org-test-with-temp-text
  296. test-line
  297. (goto-char (point-max))
  298. (insert (concat "\n" test-line " end"))
  299. (re-search-backward "src") (org-ctrl-c-ctrl-c)
  300. (should (string=
  301. (concat test-line " =y= end")
  302. (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
  303. (re-search-forward "\" ") (org-ctrl-c-ctrl-c)
  304. (should (string=
  305. (concat test-line " =y= =y= end")
  306. (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
  307. (forward-char)
  308. (should-error (org-ctrl-c-ctrl-c)))))
  309. (ert-deftest test-org-babel/inline-src_blk-manual-results-replace ()
  310. (let ((test-line " src_emacs-lisp[:results replace]{ \"x\" }"))
  311. (org-test-with-temp-text
  312. (concat "\n" test-line)
  313. (should-error (org-ctrl-c-ctrl-c))
  314. (goto-char (point-max))
  315. (should-error (org-ctrl-c-ctrl-c))
  316. (beginning-of-line)
  317. (should-error (org-ctrl-c-ctrl-c))
  318. (forward-char) (org-ctrl-c-ctrl-c)
  319. (should (string=
  320. (concat test-line " =x=")
  321. (buffer-substring-no-properties
  322. (point-at-bol) (point-at-eol))))))
  323. (let ((test-line (concat " Some text prior to block "
  324. "src_emacs-lisp[:results replace]{ \"y\" }")))
  325. (org-test-with-temp-text test-line
  326. (goto-char (point-max))
  327. (insert (concat "\n" test-line " end"))
  328. (re-search-backward "src") (org-ctrl-c-ctrl-c)
  329. (should (string=
  330. (concat test-line " =y= end")
  331. (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
  332. (re-search-forward "\" ") (org-ctrl-c-ctrl-c)
  333. (should (string=
  334. (concat test-line " =y= =y= end")
  335. (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
  336. (forward-char)
  337. (should-error (org-ctrl-c-ctrl-c)))))
  338. (ert-deftest test-org-babel/inline-src_blk-results-silent ()
  339. (let ((test-line "src_emacs-lisp[ :results silent ]{ \"x\" }"))
  340. (org-test-with-temp-text test-line
  341. (org-ctrl-c-ctrl-c)
  342. (should (string= test-line
  343. (buffer-substring-no-properties
  344. (point-at-bol) (point-at-eol))))
  345. (end-of-buffer)
  346. (should-error (org-ctrl-c-ctrl-c))))
  347. (let ((test-line (concat " Some text prior to block src_emacs-lisp"
  348. "[ :results silent ]{ \"y\" }")))
  349. (org-test-with-temp-text
  350. test-line
  351. (goto-char (point-max))
  352. (insert (concat "\n" test-line " end"))
  353. (re-search-backward "src_") (org-ctrl-c-ctrl-c)
  354. (should (string= (concat test-line " end")
  355. (buffer-substring-no-properties
  356. (point-at-bol) (point-at-eol))))
  357. (re-search-forward "\" ") (org-ctrl-c-ctrl-c)
  358. (should (string= (concat test-line " end")
  359. (buffer-substring-no-properties
  360. (point-at-bol) (point-at-eol))))
  361. (forward-char)
  362. (should-error (org-ctrl-c-ctrl-c)))))
  363. (ert-deftest test-org-babel/inline-src_blk-results-raw ()
  364. (let ((test-line "src_emacs-lisp[ :results raw ]{ \"x\" }"))
  365. (org-test-with-temp-text test-line
  366. (org-ctrl-c-ctrl-c)
  367. (should (string= (concat test-line " x")
  368. (buffer-string)))))
  369. (let ((test-line (concat " Some text prior to block "
  370. "src_emacs-lisp[ :results raw ]{ \"the\" }")))
  371. (org-test-with-temp-text (concat test-line " end")
  372. (re-search-forward "src_") (org-ctrl-c-ctrl-c)
  373. (should (string= (concat test-line " the end")
  374. (buffer-substring-no-properties
  375. (point-at-bol) (point-at-eol))))
  376. (re-search-forward "\" ") (org-ctrl-c-ctrl-c)
  377. (should (string= (concat test-line " the the end")
  378. (buffer-substring-no-properties
  379. (point-at-bol) (point-at-eol))))
  380. (forward-char)
  381. (should-error (org-ctrl-c-ctrl-c)))))
  382. (ert-deftest test-org-babel/inline-src_blk-results-file ()
  383. (let ((test-line "src_emacs-lisp[ :results file ]{ \"~/test-file\" }"))
  384. (org-test-with-temp-text
  385. test-line
  386. (org-ctrl-c-ctrl-c)
  387. (should (string= (concat test-line " [[file:~/test-file]]")
  388. (buffer-substring-no-properties
  389. (point-min) (point-max)))))))
  390. (ert-deftest test-org-babel/inline-src_blk-results-scalar ()
  391. (let ((test-line "src_emacs-lisp[ :results scalar ]{ \"x\" }"))
  392. (org-test-with-temp-text
  393. test-line
  394. (org-ctrl-c-ctrl-c)
  395. (should (string= (concat test-line " =\"x\"=")
  396. (buffer-substring-no-properties
  397. (point-min) (point-max)))))))
  398. (ert-deftest test-org-babel/inline-src_blk-results-verbatim ()
  399. (let ((test-line "src_emacs-lisp[ :results verbatim ]{ \"x\" }"))
  400. (org-test-with-temp-text
  401. test-line
  402. (org-ctrl-c-ctrl-c)
  403. (should (string= (concat test-line " =\"x\"=")
  404. (buffer-substring-no-properties
  405. (point-min) (point-max)))))))
  406. (ert-deftest test-org-babel/combining-scalar-and-raw-result-types ()
  407. (org-test-with-temp-text-in-file "
  408. #+begin_src sh :results scalar
  409. echo \"[[file:./cv.cls]]\"
  410. #+end_src
  411. #+name:
  412. : [[file:./cv.cls]]
  413. #+begin_src sh :results raw scalar
  414. echo \"[[file:./cv.cls]]\"
  415. #+end_src
  416. "
  417. (flet ((next-result ()
  418. (org-babel-next-src-block)
  419. (org-babel-execute-src-block)
  420. (goto-char (org-babel-where-is-src-block-result))
  421. (forward-line 1)))
  422. (goto-char (point-min))
  423. (next-result)
  424. (should (org-babel-in-example-or-verbatim))
  425. (next-result)
  426. (should (not (org-babel-in-example-or-verbatim))))))
  427. (ert-deftest test-org-babel/no-defaut-value-for-var ()
  428. "Test that the absence of a default value for a variable DOES THROW
  429. a proper error."
  430. (org-test-at-id "f2df5ba6-75fa-4e6b-8441-65ed84963627"
  431. (org-babel-next-src-block)
  432. (let ((err
  433. (should-error (org-babel-execute-src-block) :type 'error)))
  434. (should
  435. (equal
  436. '(error
  437. "Variable \"x\" must be assigned a default value")
  438. err)))))
  439. (ert-deftest test-org-babel/just-one-results-block ()
  440. "Test that evaluating two times the same code block does not result in a
  441. duplicate results block."
  442. (org-test-with-temp-text "#+begin_src sh\necho Hello\n#+end_src\n"
  443. (org-babel-execute-src-block)
  444. (org-babel-execute-src-block) ; second code block execution
  445. (should (search-forward "Hello")) ; the string inside the source code block
  446. (should (search-forward "Hello")) ; the same string in the results block
  447. (should-error (search-forward "Hello"))))
  448. (ert-deftest test-org-babel/nested-code-block ()
  449. "Test nested code blocks inside code blocks don't cause problems."
  450. (org-test-with-temp-text "#+begin_src org :results silent
  451. ,#+begin_src emacs-lisp
  452. , 'foo
  453. ,#+end_src
  454. #+end_src"
  455. (should (string= (org-babel-execute-src-block)
  456. "#+begin_src emacs-lisp\n 'foo\n#+end_src"))))
  457. (ert-deftest test-org-babel/partial-nested-code-block ()
  458. "Test nested code blocks inside code blocks don't cause problems."
  459. (org-test-with-temp-text "#+begin_src org :results silent
  460. ,#+begin_src emacs-lisp
  461. #+end_src"
  462. (should (string= "#+begin_src emacs-lisp" (org-babel-execute-src-block)))))
  463. (ert-deftest test-ob/does-not-replace-a-block-with-the-results ()
  464. (org-test-with-temp-text "#+NAME: foo
  465. #+BEGIN_SRC emacs-lisp
  466. 'foo
  467. #+END_SRC\n"
  468. (org-babel-next-src-block 1)
  469. (should (eq 'foo (org-babel-execute-src-block)))
  470. (goto-char (point-min))
  471. (org-babel-next-src-block 1)
  472. (should (looking-at org-babel-src-block-regexp))))
  473. (ert-deftest test-ob/catches-all-references ()
  474. (org-test-with-temp-text "
  475. #+NAME: literal-example
  476. #+BEGIN_EXAMPLE
  477. A literal example
  478. on two lines
  479. #+END_EXAMPLE
  480. #+NAME: read-literal-example
  481. #+BEGIN_SRC emacs-lisp :var x=literal-example
  482. (concatenate 'string x \" for me.\")
  483. #+END_SRC"
  484. (org-babel-next-src-block 1)
  485. (should (string= (org-babel-execute-src-block)
  486. "A literal example\non two lines for me."))))
  487. (ert-deftest test-ob/resolve-code-blocks-before-data-blocks ()
  488. (org-test-with-temp-text "
  489. #+name: foo
  490. : bar
  491. #+name: foo
  492. #+begin_src emacs-lisp
  493. \"baz\"
  494. #+end_src
  495. #+begin_src emacs-lisp :var foo=foo
  496. foo
  497. #+end_src"
  498. (org-babel-next-src-block 2)
  499. (should (string= (org-babel-execute-src-block) "baz"))))
  500. (ert-deftest test-ob/do-not-resolve-to-partial-names-data ()
  501. (org-test-with-temp-text "
  502. #+tblname: base_plus
  503. | 1 |
  504. | 2 |
  505. #+tblname: base
  506. | 3 |
  507. | 4 |
  508. #+begin_src emacs-lisp :var x=base
  509. x
  510. #+end_src"
  511. (org-babel-next-src-block 1)
  512. (should (equal (org-babel-execute-src-block) '((3) (4))))))
  513. (ert-deftest test-ob/do-not-resolve-to-partial-names-code ()
  514. (org-test-with-temp-text "
  515. #+name: base_plus
  516. #+begin_src emacs-lisp
  517. 'bar
  518. #+end_src
  519. #+name: base
  520. #+begin_src emacs-lisp
  521. 'foo
  522. #+end_src
  523. #+begin_src emacs-lisp :var x=base
  524. x
  525. #+end_src"
  526. (org-babel-next-src-block 3)
  527. (should (equal (org-babel-execute-src-block) "foo"))))
  528. (ert-deftest test-ob/allow-spaces-around-=-in-var-specs ()
  529. (org-test-with-temp-text "#+begin_src emacs-lisp :var a = 1 b = 2 c= 3 d =4
  530. (+ a b c d)
  531. #+end_src
  532. "
  533. (should (= 10 (org-babel-execute-src-block)))))
  534. (ert-deftest test-ob/org-babel-update-intermediate ()
  535. (org-test-with-temp-text "#+name: foo
  536. #+begin_src emacs-lisp
  537. 2
  538. #+end_src
  539. #+results: foo
  540. : 4
  541. #+begin_src emacs-lisp :var it=foo
  542. (+ it 1)
  543. #+end_src"
  544. (let ((org-babel-update-intermediate nil))
  545. (goto-char (point-min))
  546. (org-babel-next-src-block 2)
  547. (should (= 3 (org-babel-execute-src-block)))
  548. (goto-char (point-min))
  549. (forward-line 6)
  550. (should (looking-at ": 4")))
  551. (let ((org-babel-update-intermediate t))
  552. (goto-char (point-min))
  553. (org-babel-next-src-block 2)
  554. (should (= 3 (org-babel-execute-src-block)))
  555. (goto-char (point-min))
  556. (forward-line 6)
  557. (should (looking-at ": 2")))))
  558. (ert-deftest test-ob/eval-header-argument ()
  559. (flet ((check-eval (eval runp)
  560. (org-test-with-temp-text (format "#+begin_src emacs-lisp :eval %s
  561. (setq foo :evald)
  562. #+end_src" eval)
  563. (let ((foo :not-run))
  564. (if runp
  565. (progn (should (org-babel-execute-src-block))
  566. (should (eq foo :evald)))
  567. (progn (should-not (org-babel-execute-src-block))
  568. (should-not (eq foo :evald))))))))
  569. (check-eval "never" nil)
  570. (check-eval "no" nil)
  571. (check-eval "never-export" t)
  572. (check-eval "no-export" t)
  573. (let ((org-current-export-file "something"))
  574. (check-eval "never" nil)
  575. (check-eval "no" nil)
  576. (check-eval "never-export" nil)
  577. (check-eval "no-export" nil))))
  578. (ert-deftest test-ob/noweb-expansion-1 ()
  579. (org-test-with-temp-text "#+begin_src sh :results output :tangle yes
  580. <<foo>>
  581. #+end_src
  582. #+name: foo
  583. #+begin_src sh
  584. bar
  585. #+end_src"
  586. (should (string= (org-babel-expand-noweb-references) "bar"))))
  587. (ert-deftest test-ob/noweb-expansion-2 ()
  588. (org-test-with-temp-text "#+begin_src sh :results output :tangle yes
  589. <<foo>>
  590. #+end_src
  591. #+name: foo
  592. #+begin_src sh :noweb-sep \"\"
  593. bar
  594. #+end_src
  595. #+begin_src sh :noweb-ref foo :noweb-sep \"\"
  596. baz
  597. #+end_src"
  598. (should (string= (org-babel-expand-noweb-references) "barbaz"))))
  599. (ert-deftest test-ob/splitting-variable-lists-in-references ()
  600. (org-test-with-temp-text ""
  601. (should (= 1 (length (org-babel-ref-split-args
  602. "a=\"this, no work\""))))
  603. (should (= 2 (length (org-babel-ref-split-args
  604. "a=\"this, no work\", b=1"))))))
  605. (ert-deftest test-ob/org-babel-balanced-split ()
  606. (should (equal
  607. '(":a 1" "b [2 3]" "c (4 :d (5 6))")
  608. (org-babel-balanced-split ":a 1 :b [2 3] :c (4 :d (5 6))"
  609. '((32 9) . 58)))))
  610. (ert-deftest test-ob/commented-last-block-line-no-var ()
  611. (org-test-with-temp-text-in-file "
  612. #+begin_src emacs-lisp
  613. ;;
  614. #+end_src"
  615. (org-babel-next-src-block)
  616. (org-ctrl-c-ctrl-c)
  617. (should (re-search-forward "\\#\\+results:" nil t))
  618. (forward-line)
  619. (should
  620. (string=
  621. ""
  622. (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
  623. (org-test-with-temp-text-in-file "
  624. #+begin_src emacs-lisp
  625. \"some text\";;
  626. #+end_src"
  627. (org-babel-next-src-block)
  628. (org-ctrl-c-ctrl-c)
  629. (should (re-search-forward "\\#\\+results:" nil t))
  630. (forward-line)
  631. (should
  632. (string=
  633. ": some text"
  634. (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
  635. (ert-deftest test-ob/commented-last-block-line-with-var ()
  636. (org-test-with-temp-text-in-file "
  637. #+begin_src emacs-lisp :var a=1
  638. ;;
  639. #+end_src"
  640. (org-babel-next-src-block)
  641. (org-ctrl-c-ctrl-c)
  642. (re-search-forward "\\#\\+results:" nil t)
  643. (forward-line)
  644. (should (string=
  645. ""
  646. (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
  647. (org-test-with-temp-text-in-file "
  648. #+begin_src emacs-lisp :var a=2
  649. 2;;
  650. #+end_src"
  651. (org-babel-next-src-block)
  652. (org-ctrl-c-ctrl-c)
  653. (re-search-forward "\\#\\+results:" nil t)
  654. (forward-line)
  655. (should (string=
  656. ": 2"
  657. (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
  658. (defun test-ob-verify-result-and-removed-result (result buffer-text)
  659. "Test helper function to test `org-babel-remove-result'.
  660. A temp buffer is populated with BUFFER-TEXT, the first block is executed,
  661. and the result of execution is verified against RESULT.
  662. The block is actually executed /twice/ to ensure result
  663. replacement happens correctly."
  664. (org-test-with-temp-text
  665. buffer-text
  666. (org-babel-next-src-block) (org-ctrl-c-ctrl-c) (org-ctrl-c-ctrl-c)
  667. (should (re-search-forward "\\#\\+results:" nil t))
  668. (forward-line)
  669. (should (string= result
  670. (buffer-substring-no-properties
  671. (point-at-bol)
  672. (- (point-max) 16))))
  673. (org-babel-previous-src-block) (org-babel-remove-result)
  674. (should (string= buffer-text
  675. (buffer-substring-no-properties
  676. (point-min) (point-max))))))
  677. (ert-deftest test-ob/org-babel-remove-result--results-default ()
  678. "Test `org-babel-remove-result' with default :results."
  679. (mapcar (lambda (language)
  680. (test-ob-verify-result-and-removed-result
  681. "\n"
  682. (concat
  683. "* org-babel-remove-result
  684. #+begin_src " language "
  685. #+end_src
  686. * next heading")))
  687. '("sh" "emacs-lisp")))
  688. (ert-deftest test-ob/org-babel-remove-result--results-list ()
  689. "Test `org-babel-remove-result' with :results list."
  690. (test-ob-verify-result-and-removed-result
  691. "- 1
  692. - 2
  693. - 3
  694. - (quote (4 5))"
  695. "* org-babel-remove-result
  696. #+begin_src emacs-lisp :results list
  697. '(1 2 3 '(4 5))
  698. #+end_src
  699. * next heading"))
  700. (ert-deftest test-ob/org-babel-results-indented-wrap ()
  701. "Ensure that wrapped results are inserted correction when indented.
  702. If not inserted correctly then the second evaluation will fail
  703. trying to find the :END: marker."
  704. (org-test-with-temp-text
  705. "- indented
  706. #+begin_src sh :results file wrap
  707. echo test.txt
  708. #+end_src"
  709. (org-babel-next-src-block 1)
  710. (org-babel-execute-src-block)
  711. (org-babel-execute-src-block)))
  712. (ert-deftest test-ob/file-desc-header-argument ()
  713. "Test that the :file-desc header argument is used."
  714. (org-test-with-temp-text "#+begin_src emacs-lisp :results file :file-desc bar
  715. \"foo\"
  716. #+end_src
  717. #+begin_src emacs-lisp :results file :file-desc
  718. \"foo\"
  719. #+end_src"
  720. (org-babel-execute-src-block)
  721. (org-babel-next-src-block 1)
  722. (org-babel-execute-src-block)
  723. (goto-char (point-min))
  724. (should (search-forward "[[file:foo][bar]]" nil t))
  725. (should (search-forward "[[file:foo][foo]]" nil t))))
  726. (ert-deftest test-ob/org-babel-remove-result--results-pp ()
  727. "Test `org-babel-remove-result' with :results pp."
  728. (test-ob-verify-result-and-removed-result
  729. ": \"I /am/ working!\""
  730. "* org-babel-remove-result
  731. #+begin_src emacs-lisp :results pp
  732. \"I /am/ working!\")
  733. #+end_src
  734. * next heading"))
  735. (ert-deftest test-org-babel/inline-src_blk-preceded-punct-preceded-by-point ()
  736. (let ((test-line ".src_emacs-lisp[ :results verbatim ]{ \"x\" }"))
  737. (org-test-with-temp-text
  738. test-line
  739. (forward-char 1)
  740. (org-ctrl-c-ctrl-c)
  741. (should (re-search-forward "=\"x\"=" nil t))
  742. (forward-line))))
  743. (ert-deftest test-ob/commented-last-block-line-with-var ()
  744. (org-test-with-temp-text-in-file "
  745. #+begin_src emacs-lisp :var a=1
  746. ;;
  747. #+end_src"
  748. (org-babel-next-src-block)
  749. (org-ctrl-c-ctrl-c)
  750. (re-search-forward "\\#\\+results:" nil t)
  751. (forward-line)
  752. (should (string=
  753. ""
  754. (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
  755. (org-test-with-temp-text-in-file "
  756. #+begin_src emacs-lisp :var a=2
  757. 2;;
  758. #+end_src"
  759. (org-babel-next-src-block)
  760. (org-ctrl-c-ctrl-c)
  761. (re-search-forward "\\#\\+results:" nil t)
  762. (forward-line)
  763. (should (string=
  764. ": 2"
  765. (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
  766. (defun test-ob-verify-result-and-removed-result (result buffer-text)
  767. "Test helper function to test `org-babel-remove-result'.
  768. A temp buffer is populated with BUFFER-TEXT, the first block is executed,
  769. and the result of execution is verified against RESULT.
  770. The block is actually executed /twice/ to ensure result
  771. replacement happens correctly."
  772. (org-test-with-temp-text
  773. buffer-text
  774. (org-babel-next-src-block) (org-ctrl-c-ctrl-c) (org-ctrl-c-ctrl-c)
  775. (should (re-search-forward "\\#\\+results:" nil t))
  776. (forward-line)
  777. (should (string= result
  778. (buffer-substring-no-properties
  779. (point-at-bol)
  780. (- (point-max) 16))))
  781. (org-babel-previous-src-block) (org-babel-remove-result)
  782. (should (string= buffer-text
  783. (buffer-substring-no-properties
  784. (point-min) (point-max))))))
  785. (ert-deftest test-ob/org-babel-remove-result--results-default ()
  786. "Test `org-babel-remove-result' with default :results."
  787. (mapcar (lambda (language)
  788. (test-ob-verify-result-and-removed-result
  789. "\n"
  790. (concat
  791. "* org-babel-remove-result
  792. #+begin_src " language "
  793. #+end_src
  794. * next heading")))
  795. '("sh" "emacs-lisp")))
  796. (ert-deftest test-ob/org-babel-remove-result--results-list ()
  797. "Test `org-babel-remove-result' with :results list."
  798. (test-ob-verify-result-and-removed-result
  799. "- 1
  800. - 2
  801. - 3
  802. - (quote (4 5))"
  803. "* org-babel-remove-result
  804. #+begin_src emacs-lisp :results list
  805. '(1 2 3 '(4 5))
  806. #+end_src
  807. * next heading"))
  808. (ert-deftest test-ob/org-babel-remove-result--results-wrap ()
  809. "Test `org-babel-remove-result' with :results wrap."
  810. (test-ob-verify-result-and-removed-result
  811. ":RESULTS:
  812. hello there
  813. :END:"
  814. "* org-babel-remove-result
  815. #+begin_src emacs-lisp :results wrap
  816. \"hello there\"
  817. #+end_src
  818. * next heading"))
  819. (ert-deftest test-ob/org-babel-remove-result--results-org ()
  820. "Test `org-babel-remove-result' with :results org."
  821. (test-ob-verify-result-and-removed-result
  822. "#+BEGIN_SRC org
  823. ,* heading
  824. ,** subheading
  825. content
  826. #+END_SRC"
  827. "* org-babel-remove-result
  828. #+begin_src emacs-lisp :results org
  829. \"* heading
  830. ** subheading
  831. content\"
  832. #+end_src
  833. * next heading"))
  834. (ert-deftest test-ob/org-babel-remove-result--results-html ()
  835. "Test `org-babel-remove-result' with :results html."
  836. (test-ob-verify-result-and-removed-result
  837. "#+BEGIN_HTML
  838. <head><body></body></head>
  839. #+END_HTML"
  840. "* org-babel-remove-result
  841. #+begin_src emacs-lisp :results html
  842. \"<head><body></body></head>\"
  843. #+end_src
  844. * next heading"))
  845. (ert-deftest test-ob/org-babel-remove-result--results-latex ()
  846. "Test `org-babel-remove-result' with :results latex."
  847. (test-ob-verify-result-and-removed-result
  848. "#+BEGIN_LaTeX
  849. Line 1
  850. Line 2
  851. Line 3
  852. #+END_LaTeX"
  853. "* org-babel-remove-result
  854. #+begin_src emacs-lisp :results latex
  855. \"Line 1
  856. Line 2
  857. Line 3\"
  858. #+end_src
  859. * next heading"))
  860. (ert-deftest test-ob/org-babel-remove-result--results-code ()
  861. "Test `org-babel-remove-result' with :results code."
  862. (test-ob-verify-result-and-removed-result
  863. "#+BEGIN_SRC emacs-lisp
  864. \"I am working!\"
  865. #+END_SRC"
  866. "* org-babel-remove-result
  867. #+begin_src emacs-lisp :results code
  868. (message \"I am working!\")
  869. #+end_src
  870. * next heading"))
  871. (ert-deftest test-ob/org-babel-remove-result--results-pp ()
  872. "Test `org-babel-remove-result' with :results pp."
  873. (test-ob-verify-result-and-removed-result
  874. ": \"I /am/ working!\""
  875. "* org-babel-remove-result
  876. #+begin_src emacs-lisp :results pp
  877. \"I /am/ working!\")
  878. #+end_src
  879. * next heading"))
  880. (ert-deftest test-ob/results-do-not-replace-code-blocks ()
  881. (org-test-with-temp-text "Block two has a space after the name.
  882. #+name: foo
  883. #+begin_src emacs-lisp
  884. 1
  885. #+end_src emacs-lisp
  886. #+name: foo
  887. #+begin_src emacs-lisp
  888. 2
  889. #+end_src
  890. #+name: foo
  891. #+begin_src emacs-lisp
  892. 3
  893. #+end_src
  894. #+RESULTS: foo
  895. : foo
  896. "
  897. (dolist (num '(1 2 3))
  898. ;; execute the block
  899. (goto-char (point-min))
  900. (org-babel-next-src-block num) (org-babel-execute-src-block)
  901. ;; check the results
  902. (goto-char (point-max))
  903. (move-beginning-of-line 0)
  904. (should (looking-at (format ": %d" num))))))
  905. (ert-deftest test-ob/blocks-with-spaces ()
  906. "Test expansion of blocks followed by blank lines."
  907. (should
  908. (equal "#+BEGIN_SRC emacs-lisp
  909. \(+ 1 2)
  910. #+END_SRC
  911. #+RESULTS:
  912. : 3\n\n\n"
  913. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp
  914. \(+ 1 2)
  915. #+END_SRC\n\n\n"
  916. (org-babel-execute-src-block)
  917. (buffer-string)))))
  918. (ert-deftest test-ob/results-in-narrowed-buffer ()
  919. "Test block execution in a narrowed buffer."
  920. ;; If results don't exist, they should be inserted in visible part
  921. ;; of the buffer.
  922. (should
  923. (equal
  924. "#+BEGIN_SRC emacs-lisp\n(+ 1 2)\n#+END_SRC\n\n#+RESULTS:\n: 3"
  925. (org-test-with-temp-text
  926. "#+BEGIN_SRC emacs-lisp\n(+ 1 2)\n#+END_SRC\n\nParagraph"
  927. (narrow-to-region (point) (save-excursion (forward-line 3) (point)))
  928. (org-babel-execute-src-block)
  929. (org-trim (buffer-string)))))
  930. (should
  931. (equal
  932. "#+NAME: test\n#+BEGIN_SRC emacs-lisp\n(+ 1 2)\n#+END_SRC\n\n#+RESULTS: test\n: 3"
  933. (org-test-with-temp-text
  934. "#+NAME: test\n#+BEGIN_SRC emacs-lisp\n(+ 1 2)\n#+END_SRC\n\nParagraph"
  935. (narrow-to-region (point) (save-excursion (forward-line 4) (point)))
  936. (org-babel-execute-src-block)
  937. (org-trim (buffer-string)))))
  938. ;; Results in visible part of buffer, should be updated here.
  939. (should
  940. (equal
  941. "#+NAME: test
  942. #+BEGIN_SRC emacs-lisp
  943. \(+ 1 2)
  944. #+END_SRC
  945. #+RESULTS: test
  946. : 3"
  947. (org-test-with-temp-text
  948. "#+NAME: test
  949. #+BEGIN_SRC emacs-lisp
  950. \(+ 1 2)
  951. #+END_SRC
  952. #+RESULTS: test
  953. : 4
  954. Paragraph"
  955. (narrow-to-region (point) (save-excursion (forward-line 7) (point)))
  956. (org-babel-execute-src-block)
  957. (org-trim (buffer-string)))))
  958. ;; Results in invisible part of buffer, should be updated there.
  959. (org-test-with-temp-text
  960. "#+NAME: test
  961. #+BEGIN_SRC emacs-lisp
  962. \(+ 1 2)
  963. #+END_SRC
  964. #+RESULTS: test
  965. : 4
  966. Paragraph"
  967. (narrow-to-region (point) (save-excursion (forward-line 4) (point)))
  968. (org-babel-execute-src-block)
  969. (should-not (re-search-forward "^#\\+RESULTS:" nil t))
  970. (widen)
  971. (should (should (re-search-forward "^: 3" nil t)))))
  972. (ert-deftest test-ob/specific-colnames ()
  973. "Test passing specific column names."
  974. (should
  975. (equal "#+name: input-table
  976. | id | var1 |
  977. |----+------|
  978. | 1 | bar |
  979. | 2 | baz |
  980. #+begin_src sh :var data=input-table :exports results :colnames '(Rev Author)
  981. echo \"$data\"
  982. #+end_src
  983. #+RESULTS:
  984. | Rev | Author |
  985. |-----+--------|
  986. | 1 | bar |
  987. | 2 | baz |
  988. "
  989. (org-test-with-temp-text
  990. "#+name: input-table
  991. | id | var1 |
  992. |----+------|
  993. | 1 | bar |
  994. | 2 | baz |
  995. #+begin_src sh :var data=input-table :exports results :colnames '(Rev Author)
  996. echo \"$data\"
  997. #+end_src
  998. "
  999. ;; we should find a code block
  1000. (should (re-search-forward org-babel-src-block-regexp nil t))
  1001. (goto-char (match-beginning 0))
  1002. ;; now that we've located the code block, it may be evaluated
  1003. (org-babel-execute-src-block)
  1004. (buffer-string)))))
  1005. (ert-deftest test-ob/location-of-header-arg-eval ()
  1006. "Test location of header argument evaluation."
  1007. (org-test-with-temp-text "
  1008. #+name: top-block
  1009. #+begin_src emacs-lisp :var pt=(point)
  1010. pt
  1011. #+end_src
  1012. #+name: bottom-block
  1013. #+begin_src emacs-lisp :var pt=top-block()
  1014. pt
  1015. #+end_src
  1016. "
  1017. ;; the value of the second block should be greater than the first
  1018. (should
  1019. (< (progn (re-search-forward org-babel-src-block-regexp nil t)
  1020. (goto-char (match-beginning 0))
  1021. (prog1 (save-match-data (org-babel-execute-src-block))
  1022. (goto-char (match-end 0))))
  1023. (progn (re-search-forward org-babel-src-block-regexp nil t)
  1024. (goto-char (match-beginning 0))
  1025. (org-babel-execute-src-block))))))
  1026. (ert-deftest test-ob/preserve-results-indentation ()
  1027. "Preserve indentation when executing a src block."
  1028. (should
  1029. (equal '(2 2)
  1030. (org-test-with-temp-text
  1031. " #+begin_src emacs-lisp\n (+ 1 1)\n #+end_src"
  1032. (org-babel-execute-src-block)
  1033. (buffer-string)
  1034. (let ((case-fold-search t)) (search-forward "#+results:"))
  1035. ;; Check if both #+RESULTS: keyword and actual results are
  1036. ;; indented by 2 columns.
  1037. (list (org-get-indentation)
  1038. (progn (forward-line) (org-get-indentation)))))))
  1039. (provide 'test-ob)
  1040. ;;; test-ob ends here