test-ob.el 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684
  1. ;;; test-ob.el --- tests for ob.el
  2. ;; Copyright (c) 2010-2015 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-ob/indented-cached-org-bracket-link ()
  17. "When the result of a source block is a cached indented link it
  18. should still return the link."
  19. (should
  20. (let ((default-directory temporary-file-directory))
  21. (org-test-with-temp-text
  22. "
  23. * Test
  24. #+<point>BEGIN_SRC emacs-lisp :file test.txt :cache yes
  25. (message \"test\")
  26. #+END_SRC"
  27. ;; Execute twice as the first time creates the cache.
  28. (org-babel-execute-src-block)
  29. (string= (concat default-directory "test.txt")
  30. (org-babel-execute-src-block))))))
  31. (ert-deftest test-ob/multi-line-header-regexp ()
  32. (should(equal "^[ \t]*#\\+headers?:[ \t]*\\([^\n]*\\)$"
  33. org-babel-multi-line-header-regexp))
  34. ;;TODO can be optimised - and what about blah4 blah5 blah6?
  35. (should (string-match
  36. org-babel-multi-line-header-regexp
  37. " \t #+headers: blah1 blah2 blah3 \t\n\t\n blah4 blah5 blah6 \n"))
  38. (should
  39. (equal
  40. "blah1 blah2 blah3 \t"
  41. (match-string
  42. 1
  43. " \t #+headers: blah1 blah2 blah3 \t\n\t\n blah4 blah5 blah6 \n")))
  44. ;;TODO Check - should this fail?
  45. (should
  46. (not (org-test-string-exact-match
  47. org-babel-multi-line-header-regexp
  48. " \t #+headers : blah1 blah2 blah3 \t\n\t\n blah4 blah5 blah6 \n"))))
  49. (ert-deftest test-ob/src-block-regexp ()
  50. (let ((test-block
  51. (concat
  52. "#+begin_src language -n-r-a-b -c :argument-1 yes :argument-2 no\n"
  53. "echo this is a test\n"
  54. "echo Currently in ' $PWD\n"
  55. "#+end_src"))
  56. (language "language")
  57. (flags "-n-r-a-b -c ")
  58. (arguments ":argument-1 yes :argument-2 no")
  59. (body "echo this is a test\necho Currently in ' $PWD\n"))
  60. (should (string-match org-babel-src-block-regexp test-block))
  61. (should (string-match org-babel-src-block-regexp (upcase test-block)))
  62. (should (equal language (match-string 2 test-block)))
  63. ;;TODO Consider refactoring
  64. (should (equal flags (match-string 3 test-block)))
  65. (should (equal arguments (match-string 4 test-block)))
  66. (should (equal body (match-string 5 test-block)))
  67. ;;no switches
  68. (should (org-test-string-exact-match
  69. org-babel-src-block-regexp
  70. (replace-regexp-in-string flags "" test-block)))
  71. ;;no header arguments
  72. (should (org-test-string-exact-match
  73. org-babel-src-block-regexp
  74. (replace-regexp-in-string arguments "" test-block)))
  75. ;; should be valid with no body
  76. (should (org-test-string-exact-match
  77. org-babel-src-block-regexp
  78. (replace-regexp-in-string body "" test-block)))))
  79. (ert-deftest test-ob/default-inline-header-args ()
  80. (should(equal
  81. '((:session . "none")
  82. (:results . "replace")
  83. (:exports . "results")
  84. (:hlines . "yes"))
  85. org-babel-default-inline-header-args)))
  86. (ert-deftest ob-test/org-babel-combine-header-arg-lists ()
  87. (let ((results (org-babel-combine-header-arg-lists
  88. '((foo . :any)
  89. (bar)
  90. (baz . ((foo bar) (baz)))
  91. (qux . ((foo bar baz qux)))
  92. (quux . ((foo bar))))
  93. '((bar)
  94. (baz . ((baz)))
  95. (quux . :any)))))
  96. (dolist (pair '((foo . :any)
  97. (bar)
  98. (baz . ((baz)))
  99. (quux . :any)
  100. (qux . ((foo bar baz qux)))))
  101. (should (equal (cdr pair)
  102. (cdr (assoc (car pair) results)))))))
  103. ;;; ob-get-src-block-info
  104. (ert-deftest test-ob/get-src-block-info-language ()
  105. (org-test-at-marker nil org-test-file-ob-anchor
  106. (let ((info (org-babel-get-src-block-info)))
  107. (should (string= "emacs-lisp" (nth 0 info))))))
  108. (ert-deftest test-ob/get-src-block-info-body ()
  109. (org-test-at-marker nil org-test-file-ob-anchor
  110. (let ((info (org-babel-get-src-block-info)))
  111. (should (string-match (regexp-quote org-test-file-ob-anchor)
  112. (nth 1 info))))))
  113. (ert-deftest test-ob/get-src-block-info-tangle ()
  114. (org-test-at-marker nil org-test-file-ob-anchor
  115. (let ((info (org-babel-get-src-block-info)))
  116. (should (string= "no" (cdr (assoc :tangle (nth 2 info))))))))
  117. (ert-deftest test-ob/elisp-in-header-arguments ()
  118. "Test execution of elisp forms in header arguments."
  119. (org-test-with-temp-text-in-file "
  120. * elisp forms in header arguments
  121. :PROPERTIES:
  122. :var: prop = (* 7 6)
  123. :END:
  124. #+begin_src emacs-lisp
  125. prop
  126. #+end_src"
  127. (goto-char (point-min))
  128. (org-babel-next-src-block)
  129. (let ((info (org-babel-get-src-block-info)))
  130. (should (= 42 (org-babel-execute-src-block))))))
  131. (ert-deftest test-ob/simple-named-code-block ()
  132. "Test that simple named code blocks can be evaluated."
  133. (org-test-with-temp-text-in-file "
  134. #+name: i-have-a-name
  135. #+begin_src emacs-lisp
  136. 42
  137. #+end_src"
  138. (org-babel-next-src-block 1)
  139. (should (= 42 (org-babel-execute-src-block)))))
  140. (ert-deftest test-ob/simple-variable-resolution ()
  141. "Test that simple variable resolution is working."
  142. (org-test-with-temp-text-in-file "
  143. #+name: four
  144. #+begin_src emacs-lisp
  145. (list 1 2 3 4)
  146. #+end_src
  147. #+begin_src emacs-lisp :var four=four
  148. (length four)
  149. #+end_src"
  150. (org-babel-next-src-block 2)
  151. (should (= 4 (org-babel-execute-src-block)))
  152. (forward-line 5)
  153. (should (string= ": 4" (buffer-substring
  154. (point-at-bol)
  155. (point-at-eol))))))
  156. (ert-deftest test-ob/multi-line-header-arguments ()
  157. "Test that multi-line header arguments and can be read."
  158. (org-test-with-temp-text-in-file "
  159. #+headers: :var letters='(a b c d e f g)
  160. #+begin_src emacs-lisp :var numbers='(1 2 3 4 5 6 7)
  161. (require 'cl)
  162. (defalias 'my-map (if (org-version-check \"24.2.50\" \"cl\" :predicate)
  163. 'cl-map
  164. 'map))
  165. (my-map 'list #'list numbers letters)
  166. #+end_src"
  167. (org-babel-next-src-block)
  168. (let ((results (org-babel-execute-src-block)))
  169. (should(equal 'a (cadr (assoc 1 results))))
  170. (should(equal 'd (cadr (assoc 4 results)))))))
  171. (ert-deftest test-ob/parse-header-args ()
  172. (org-test-with-temp-text-in-file "
  173. #+begin_src example-lang :session :results output :var num=9
  174. the body
  175. #+end_src"
  176. (org-babel-next-src-block)
  177. (let* ((info (org-babel-get-src-block-info))
  178. (params (nth 2 info)))
  179. (message "%S" params)
  180. (should (equal "example-lang" (nth 0 info)))
  181. (should (string= "the body" (org-babel-trim (nth 1 info))))
  182. (should-not (member '(:session\ \ \ \ ) params))
  183. (should (equal '(:session) (assoc :session params)))
  184. (should (equal '(:result-type . output) (assoc :result-type params)))
  185. (should (equal '(num . 9) (cdr (assoc :var params)))))))
  186. (ert-deftest test-ob/parse-header-args2 ()
  187. (org-test-with-temp-text-in-file "
  188. * resolving sub-trees as references
  189. #+begin_src emacs-lisp :var text=d4faa7b3-072b-4dcf-813c-dd7141c633f3
  190. (length text)
  191. #+end_src
  192. #+begin_src org :noweb yes
  193. <<simple-subtree>>
  194. <<d4faa7b3-072b-4dcf-813c-dd7141c633f3>>
  195. #+end_src
  196. ** simple subtree with custom ID
  197. :PROPERTIES:
  198. :CUSTOM_ID: simple-subtree
  199. :END:
  200. this is simple"
  201. (should (string-match (regexp-quote "this is simple")
  202. (org-babel-ref-resolve "simple-subtree")))
  203. (org-babel-next-src-block)
  204. (should (= 14 (org-babel-execute-src-block)))))
  205. (ert-deftest test-ob/inline-src-blocks ()
  206. (should
  207. (= 1
  208. (org-test-with-temp-text
  209. "In the middle <point>src_emacs-lisp{(+ 0 1)} of a line"
  210. (org-babel-execute-src-block))))
  211. (should
  212. (= 2
  213. (org-test-with-temp-text
  214. "One at the end of a line: <point>src_emacs-lisp{(+ 1 1)}"
  215. (org-babel-execute-src-block))))
  216. (should
  217. (= 3
  218. (org-test-with-temp-text
  219. "src_emacs-lisp{(+ 2 1)} at the beginning of a line."
  220. (org-babel-execute-src-block))))
  221. (should
  222. (= 4
  223. (org-test-with-temp-text
  224. "In the middle <point>src_emacs-lisp[:results silent\
  225. :exports code]{(+ 3 1)} of a line"
  226. (org-babel-execute-src-block))))
  227. (should
  228. (= 5
  229. (org-test-with-temp-text
  230. "One at the end of a line: <point>src_emacs-lisp[:results silent\
  231. :exports code]{(+ 4 1)}"
  232. (org-babel-execute-src-block))))
  233. (should
  234. (= 6
  235. (org-test-with-temp-text
  236. "src_emacs-lisp[:results silent :exports code]{(+ 5 1)}\
  237. at the beginning of a line."
  238. (org-babel-execute-src-block))))
  239. (should
  240. (= 7
  241. (org-test-with-temp-text
  242. "One also evaluated: <point>src_emacs-lisp[:exports both\
  243. :results silent]{(+ 6 1)}"
  244. (org-babel-execute-src-block)))))
  245. (ert-deftest test-ob/inline-src_blk-default-results-replace-line-1 ()
  246. (let ((test-line "src_sh{echo 1}")
  247. (org-babel-inline-result-wrap "=%s="))
  248. ;; src_ at bol line 1...
  249. (org-test-with-temp-text
  250. test-line
  251. (goto-char (point-min)) (org-babel-execute-maybe)
  252. (should (string=
  253. (concat test-line " {{{results(=1=)}}}")
  254. (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
  255. (forward-char) (org-babel-execute-maybe)
  256. (should (string=
  257. (concat test-line " {{{results(=1=)}}}")
  258. (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
  259. (re-search-forward "{{{")
  260. ;;(should-error (org-ctrl-c-ctrl-c))
  261. (backward-char 4) ;; last char of block body
  262. (org-babel-execute-maybe)
  263. (should (string=
  264. (concat test-line " {{{results(=1=)}}}")
  265. (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
  266. ;; src_ follows space line 1...
  267. (let ((test-line " src_emacs-lisp{ 1 }"))
  268. (org-test-with-temp-text
  269. test-line
  270. (should-error (org-ctrl-c-ctrl-c))
  271. (forward-char) (org-babel-execute-maybe)
  272. (should (string=
  273. (concat test-line " {{{results(=1=)}}}")
  274. (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
  275. (re-search-forward "{ 1 ") (org-babel-execute-maybe)
  276. (should (string=
  277. (concat test-line " {{{results(=1=)}}}")
  278. (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
  279. (forward-char 6)
  280. (should-error (org-ctrl-c-ctrl-c))
  281. ))))
  282. (ert-deftest test-ob/inline-src_blk-default-results-replace-line-2 ()
  283. ;; src_ at bol line 2...
  284. (let ((test-line " src_emacs-lisp{ \"x\" }")
  285. (org-babel-inline-result-wrap "=%s="))
  286. (org-test-with-temp-text
  287. (concat "\n" test-line)
  288. (should-error (org-ctrl-c-ctrl-c))
  289. (goto-char (point-min))
  290. (should-error (org-ctrl-c-ctrl-c))
  291. (forward-line)
  292. (should-error (org-ctrl-c-ctrl-c))
  293. (forward-char) (org-babel-execute-maybe)
  294. (should (string=
  295. (concat test-line " {{{results(=x=)}}}")
  296. (buffer-substring-no-properties
  297. (point-at-bol) (point-at-eol))))))
  298. (let ((test-line "Some text prior to block src_emacs-lisp{ \"y\" }")
  299. (org-babel-inline-result-wrap "=%s="))
  300. (org-test-with-temp-text
  301. test-line
  302. (goto-char (point-max))
  303. (insert (concat "\n" test-line " end"))
  304. (re-search-backward "src") (org-babel-execute-maybe)
  305. (should (string=
  306. (concat test-line " {{{results(=y=)}}} end")
  307. (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
  308. (re-search-forward "\" ") (org-babel-execute-maybe)
  309. (should (string=
  310. (concat test-line " {{{results(=y=)}}} end")
  311. (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
  312. (forward-char 3)
  313. (should-error (org-ctrl-c-ctrl-c)))))
  314. (ert-deftest test-ob/inline-src_blk-manual-results-replace ()
  315. (let ((test-line " src_emacs-lisp[:results replace]{ \"x\" }")
  316. (org-babel-inline-result-wrap "=%s="))
  317. (org-test-with-temp-text
  318. (concat "\n" test-line)
  319. (should-error (org-ctrl-c-ctrl-c))
  320. (goto-char (point-max))
  321. (org-babel-execute-maybe)
  322. (beginning-of-line)
  323. (should-error (org-ctrl-c-ctrl-c))
  324. (forward-char) (org-babel-execute-maybe)
  325. (should (string=
  326. (concat test-line " {{{results(=x=)}}}")
  327. (buffer-substring-no-properties
  328. (point-at-bol) (point-at-eol))))))
  329. (let ((test-line (concat " Some text prior to block "
  330. "src_emacs-lisp[:results replace]{ \"y\" }"))
  331. (org-babel-inline-result-wrap "=%s="))
  332. (org-test-with-temp-text test-line
  333. (goto-char (point-max))
  334. (insert (concat "\n" test-line " end"))
  335. (re-search-backward "src") (org-babel-execute-maybe)
  336. (should (string=
  337. (concat test-line " {{{results(=y=)}}} end")
  338. (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
  339. (re-search-forward "\" ") (org-babel-execute-maybe)
  340. (should (string=
  341. (concat test-line " {{{results(=y=)}}} end")
  342. (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
  343. (forward-char 3)
  344. (should-error (org-ctrl-c-ctrl-c)))))
  345. (ert-deftest test-ob/inline-src_blk-results-silent ()
  346. (let ((test-line "src_emacs-lisp[ :results silent ]{ \"x\" }"))
  347. (org-test-with-temp-text test-line
  348. (org-babel-execute-maybe)
  349. (should (string= test-line
  350. (buffer-substring-no-properties
  351. (point-at-bol) (point-at-eol))))))
  352. (let ((test-line (concat " Some text prior to block src_emacs-lisp"
  353. "[ :results silent ]{ \"y\" }")))
  354. (org-test-with-temp-text
  355. test-line
  356. (goto-char (point-max))
  357. (insert (concat "\n" test-line " end"))
  358. (re-search-backward "src_") (org-babel-execute-maybe)
  359. (should (string= (concat test-line " end")
  360. (buffer-substring-no-properties
  361. (point-at-bol) (point-at-eol))))
  362. (re-search-forward "\" ") (org-babel-execute-maybe)
  363. (should (string= (concat test-line " end")
  364. (buffer-substring-no-properties
  365. (point-at-bol) (point-at-eol))))
  366. (forward-char 2)
  367. (should-error (org-ctrl-c-ctrl-c)))))
  368. (ert-deftest test-ob/inline-src_blk-results-raw ()
  369. (let ((test-line "src_emacs-lisp[ :results raw ]{ \"x\" }"))
  370. (org-test-with-temp-text test-line
  371. (org-babel-execute-maybe)
  372. (should (string= (concat test-line " x")
  373. (buffer-string)))))
  374. (let ((test-line (concat " Some text prior to block "
  375. "src_emacs-lisp[ :results raw ]{ \"the\" }")))
  376. (org-test-with-temp-text (concat test-line " end")
  377. (re-search-forward "src_") (org-babel-execute-maybe)
  378. (should (string= (concat test-line " the end")
  379. (buffer-substring-no-properties
  380. (point-at-bol) (point-at-eol))))
  381. (re-search-forward "\" ") (org-babel-execute-maybe)
  382. (should (string= (concat test-line " the the end")
  383. (buffer-substring-no-properties
  384. (point-at-bol) (point-at-eol))))
  385. (forward-char 2)
  386. (should-error (org-ctrl-c-ctrl-c)))))
  387. (ert-deftest test-ob/inline-src_blk-results-file ()
  388. (let ((test-line "src_emacs-lisp[ :results file ]{ \"~/test-file\" }"))
  389. (org-test-with-temp-text
  390. test-line
  391. (org-babel-execute-maybe)
  392. (should (string= (concat test-line " {{{results([[file:~/test-file]])}}}")
  393. (buffer-substring-no-properties
  394. (point-min) (point-max)))))))
  395. (ert-deftest test-ob/inline-src_blk-results-scalar ()
  396. (let ((test-line "src_emacs-lisp[ :results scalar ]{ \"x\" }")
  397. (org-babel-inline-result-wrap "=%s="))
  398. (org-test-with-temp-text
  399. test-line
  400. (org-babel-execute-maybe)
  401. (should (string= (concat test-line " {{{results(=\"x\"=)}}}")
  402. (buffer-substring-no-properties
  403. (point-min) (point-max)))))))
  404. (ert-deftest test-ob/inline-src_blk-results-verbatim ()
  405. (let ((test-line "src_emacs-lisp[ :results verbatim ]{ \"x\" }")
  406. (org-babel-inline-result-wrap "=%s="))
  407. (org-test-with-temp-text
  408. test-line
  409. (org-babel-execute-maybe)
  410. (should (string= (concat test-line " {{{results(=\"x\"=)}}}")
  411. (buffer-substring-no-properties
  412. (point-min) (point-max)))))))
  413. (ert-deftest test-ob/combining-scalar-and-raw-result-types ()
  414. (org-test-with-temp-text-in-file "
  415. #+begin_src sh :results scalar
  416. echo \"[[file:./cv.cls]]\"
  417. #+end_src
  418. #+name:
  419. : [[file:./cv.cls]]
  420. #+begin_src sh :results raw scalar
  421. echo \"[[file:./cv.cls]]\"
  422. #+end_src
  423. "
  424. (flet ((next-result ()
  425. (org-babel-next-src-block)
  426. (org-babel-execute-src-block)
  427. (goto-char (org-babel-where-is-src-block-result))
  428. (forward-line 1)))
  429. (goto-char (point-min))
  430. (next-result)
  431. (should (eq (org-element-type (org-element-at-point)) 'fixed-width))
  432. (next-result)
  433. (should-not
  434. (eq (org-element-type (org-element-at-point)) 'fixed-width)))))
  435. (ert-deftest test-ob/no-defaut-value-for-var ()
  436. "Test that the absence of a default value for a variable DOES THROW
  437. a proper error."
  438. (org-test-at-id "f2df5ba6-75fa-4e6b-8441-65ed84963627"
  439. (org-babel-next-src-block)
  440. (let ((err
  441. (should-error (org-babel-execute-src-block) :type 'error)))
  442. (should
  443. (equal
  444. '(error
  445. "Variable \"x\" must be assigned a default value")
  446. err)))))
  447. (ert-deftest test-ob/just-one-results-block ()
  448. "Test that evaluating two times the same code block does not result in a
  449. duplicate results block."
  450. (org-test-with-temp-text "#+begin_src sh\necho Hello\n#+end_src\n"
  451. (org-babel-execute-src-block)
  452. (org-babel-execute-src-block) ; second code block execution
  453. (should (search-forward "Hello")) ; the string inside the source code block
  454. (should (search-forward "Hello")) ; the same string in the results block
  455. (should-error (search-forward "Hello"))))
  456. (ert-deftest test-ob/nested-code-block ()
  457. "Test nested code blocks inside code blocks don't cause problems."
  458. (should
  459. (string= "#+begin_src emacs-lisp\n 'foo\n#+end_src"
  460. (org-test-with-temp-text "#+begin_src org :results silent
  461. ,#+begin_src emacs-lisp
  462. 'foo
  463. ,#+end_src
  464. #+end_src"
  465. (let ((org-edit-src-content-indentation 2)
  466. (org-src-preserve-indentation nil))
  467. (org-babel-execute-src-block))))))
  468. (ert-deftest test-ob/partial-nested-code-block ()
  469. "Test nested code blocks inside code blocks don't cause problems."
  470. (org-test-with-temp-text "#+begin_src org :results silent
  471. ,#+begin_src emacs-lisp
  472. #+end_src"
  473. (should (string= "#+begin_src emacs-lisp" (org-babel-execute-src-block)))))
  474. (ert-deftest test-ob/does-not-replace-a-block-with-the-results ()
  475. (org-test-with-temp-text "#+NAME: foo
  476. #+BEGIN_SRC emacs-lisp
  477. 'foo
  478. #+END_SRC\n"
  479. (org-babel-next-src-block 1)
  480. (should (eq 'foo (org-babel-execute-src-block)))
  481. (goto-char (point-min))
  482. (org-babel-next-src-block 1)
  483. (should (looking-at org-babel-src-block-regexp))))
  484. (ert-deftest test-ob/catches-all-references ()
  485. (org-test-with-temp-text "
  486. #+NAME: literal-example
  487. #+BEGIN_EXAMPLE
  488. A literal example
  489. on two lines
  490. #+END_EXAMPLE
  491. #+NAME: read-literal-example
  492. #+BEGIN_SRC emacs-lisp :var x=literal-example
  493. (concatenate 'string x \" for me.\")
  494. #+END_SRC"
  495. (org-babel-next-src-block 1)
  496. (should (string= (org-babel-execute-src-block)
  497. "A literal example\non two lines\n for me."))))
  498. (ert-deftest test-ob/ignore-reference-in-commented-headings ()
  499. (should
  500. (= 2
  501. (org-test-with-temp-text
  502. "
  503. * COMMENT H1
  504. #+NAME: n
  505. : 1
  506. * H2
  507. #+NAME: n
  508. : 2
  509. * Code
  510. <point>#+BEGIN_SRC emacs-lisp :var x=n
  511. x
  512. #+END_SRC"
  513. (org-babel-execute-src-block)))))
  514. (ert-deftest test-ob/do-not-resolve-to-partial-names-data ()
  515. (org-test-with-temp-text "
  516. #+name: base_plus
  517. | 1 |
  518. | 2 |
  519. #+name: base
  520. | 3 |
  521. | 4 |
  522. #+begin_src emacs-lisp :var x=base
  523. x
  524. #+end_src"
  525. (org-babel-next-src-block 1)
  526. (should (equal (org-babel-execute-src-block) '((3) (4))))))
  527. (ert-deftest test-ob/do-not-resolve-to-partial-names-code ()
  528. (org-test-with-temp-text "
  529. #+name: base_plus
  530. #+begin_src emacs-lisp
  531. 'bar
  532. #+end_src
  533. #+name: base
  534. #+begin_src emacs-lisp
  535. 'foo
  536. #+end_src
  537. #+begin_src emacs-lisp :var x=base
  538. x
  539. #+end_src"
  540. (org-babel-next-src-block 3)
  541. (should (equal (org-babel-execute-src-block) "foo"))))
  542. (ert-deftest test-ob/allow-spaces-around-=-in-var-specs ()
  543. (org-test-with-temp-text "#+begin_src emacs-lisp :var a = 1 b = 2 c= 3 d =4
  544. (+ a b c d)
  545. #+end_src
  546. "
  547. (should (= 10 (org-babel-execute-src-block)))))
  548. (ert-deftest test-ob/org-babel-update-intermediate ()
  549. (org-test-with-temp-text "#+name: foo
  550. #+begin_src emacs-lisp
  551. 2
  552. #+end_src
  553. #+results: foo
  554. : 4
  555. #+begin_src emacs-lisp :var it=foo
  556. (+ it 1)
  557. #+end_src"
  558. (let ((org-babel-update-intermediate nil))
  559. (goto-char (point-min))
  560. (org-babel-next-src-block 2)
  561. (should (= 3 (org-babel-execute-src-block)))
  562. (goto-char (point-min))
  563. (forward-line 6)
  564. (should (looking-at ": 4")))
  565. (let ((org-babel-update-intermediate t))
  566. (goto-char (point-min))
  567. (org-babel-next-src-block 2)
  568. (should (= 3 (org-babel-execute-src-block)))
  569. (goto-char (point-min))
  570. (forward-line 6)
  571. (should (looking-at ": 2")))))
  572. (ert-deftest test-ob/eval-header-argument ()
  573. (flet ((check-eval (eval runp)
  574. (org-test-with-temp-text (format "#+begin_src emacs-lisp :eval %s
  575. (setq foo :evald)
  576. #+end_src" eval)
  577. (let ((foo :not-run))
  578. (if runp
  579. (progn (should (org-babel-execute-src-block))
  580. (should (eq foo :evald)))
  581. (progn (should-not (org-babel-execute-src-block))
  582. (should-not (eq foo :evald))))))))
  583. (check-eval "never" nil)
  584. (check-eval "no" nil)
  585. (check-eval "never-export" t)
  586. (check-eval "no-export" t)
  587. (let ((org-babel-exp-reference-buffer (current-buffer)))
  588. (check-eval "never" nil)
  589. (check-eval "no" nil)
  590. (check-eval "never-export" nil)
  591. (check-eval "no-export" nil))))
  592. (ert-deftest test-ob/noweb-expansion-1 ()
  593. (org-test-with-temp-text "#+begin_src sh :results output :tangle yes
  594. <<foo>>
  595. #+end_src
  596. #+name: foo
  597. #+begin_src sh
  598. bar
  599. #+end_src"
  600. (should (string= (org-babel-expand-noweb-references) "bar"))))
  601. (ert-deftest test-ob/noweb-expansion-2 ()
  602. (org-test-with-temp-text "#+begin_src sh :results output :tangle yes
  603. <<foo>>
  604. #+end_src
  605. #+name: foo
  606. #+begin_src sh :noweb-sep \"\"
  607. bar
  608. #+end_src
  609. #+begin_src sh :noweb-ref foo :noweb-sep \"\"
  610. baz
  611. #+end_src"
  612. (should (string= (org-babel-expand-noweb-references) "barbaz"))))
  613. (ert-deftest test-ob/splitting-variable-lists-in-references ()
  614. (org-test-with-temp-text ""
  615. (should (= 1 (length (org-babel-ref-split-args
  616. "a=\"this, no work\""))))
  617. (should (= 2 (length (org-babel-ref-split-args
  618. "a=\"this, no work\", b=1"))))))
  619. (ert-deftest test-ob/org-babel-balanced-split ()
  620. (should (equal
  621. '(":a 1" "b [2 3]" "c (4 :d (5 6))")
  622. (org-babel-balanced-split ":a 1 :b [2 3] :c (4 :d (5 6))"
  623. '((32 9) . 58)))))
  624. (ert-deftest test-ob/commented-last-block-line-no-var ()
  625. (org-test-with-temp-text-in-file "
  626. #+begin_src emacs-lisp
  627. ;;
  628. #+end_src"
  629. (org-babel-next-src-block)
  630. (org-babel-execute-maybe)
  631. (should (re-search-forward "\\#\\+results:" nil t))
  632. (forward-line)
  633. (should
  634. (string=
  635. ""
  636. (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
  637. (org-test-with-temp-text-in-file "
  638. #+begin_src emacs-lisp
  639. \"some text\";;
  640. #+end_src"
  641. (org-babel-next-src-block)
  642. (org-babel-execute-maybe)
  643. (should (re-search-forward "\\#\\+results:" nil t))
  644. (forward-line)
  645. (should
  646. (string=
  647. ": some text"
  648. (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
  649. (ert-deftest test-ob/commented-last-block-line-with-var ()
  650. (org-test-with-temp-text-in-file "
  651. #+begin_src emacs-lisp :var a=1
  652. ;;
  653. #+end_src"
  654. (org-babel-next-src-block)
  655. (org-babel-execute-maybe)
  656. (re-search-forward "\\#\\+results:" nil t)
  657. (forward-line)
  658. (should (string=
  659. ""
  660. (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
  661. (org-test-with-temp-text-in-file "
  662. #+begin_src emacs-lisp :var a=2
  663. 2;;
  664. #+end_src"
  665. (org-babel-next-src-block)
  666. (org-babel-execute-maybe)
  667. (re-search-forward "\\#\\+results:" nil t)
  668. (forward-line)
  669. (should (string=
  670. ": 2"
  671. (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
  672. (ert-deftest test-ob/org-babel-insert-result--improper-lists ()
  673. "Test `org-babel-insert-result' with improper lists."
  674. ;; Do not error when output is an improper list.
  675. (should
  676. (org-test-with-temp-text
  677. "
  678. <point>#+BEGIN_SRC emacs-lisp
  679. '((1 . nil) (2 . 3))
  680. #+END_SRC
  681. "
  682. (org-babel-execute-maybe) t)))
  683. (ert-deftest test-ob/remove-inline-result ()
  684. "Test `org-babel-remove-inline-result' honors whitespace."
  685. (let*
  686. ((inline-sb "src_emacs-lisp{(+ 1 2)}")
  687. (inline-res " {{{results(=3=)}}}")
  688. (inline-sb-dot (concat inline-sb "."))
  689. (inline-sb-res-dot (concat inline-sb inline-res ".")))
  690. (org-test-with-temp-text
  691. ;; Insert inline_src_block followed by dot.
  692. inline-sb-dot
  693. ;; Insert result before dot.
  694. (org-babel-execute-maybe)
  695. (should (string= inline-sb-res-dot
  696. (buffer-substring-no-properties
  697. (point-at-bol) (point-at-eol))))
  698. ;; Delete whitespace and result.
  699. (org-babel-remove-inline-result)
  700. (should (string= inline-sb-dot
  701. (buffer-substring-no-properties
  702. (point-at-bol) (point-at-eol))))
  703. ;; Add whitespace and result before dot.
  704. (search-forward inline-sb)
  705. (insert " " inline-res)
  706. (goto-char (point-at-bol))
  707. ;; Remove whitespace and result.
  708. (org-babel-remove-inline-result)
  709. (should (string= inline-sb-dot
  710. (buffer-substring-no-properties
  711. (point-at-bol) (point-at-eol))))
  712. ;; Add whitespace before dot.
  713. (search-forward inline-sb)
  714. (insert " ")
  715. (goto-char (point-at-bol))
  716. ;; Add result before whitespace.
  717. (org-babel-execute-maybe)
  718. ;; Remove result - leave trailing whitespace and dot.
  719. (org-babel-remove-inline-result)
  720. (should (string= (concat inline-sb " .")
  721. (buffer-substring-no-properties
  722. (point-at-bol) (point-at-eol)))))))
  723. (defun test-ob-verify-result-and-removed-result (result buffer-text)
  724. "Test helper function to test `org-babel-remove-result'.
  725. A temp buffer is populated with BUFFER-TEXT, the first block is executed,
  726. and the result of execution is verified against RESULT.
  727. The block is actually executed /twice/ to ensure result
  728. replacement happens correctly."
  729. (org-test-with-temp-text
  730. buffer-text
  731. (org-babel-next-src-block) (org-babel-execute-maybe) (org-babel-execute-maybe)
  732. (should (re-search-forward "\\#\\+results:" nil t))
  733. (forward-line)
  734. (should (string= result
  735. (buffer-substring-no-properties
  736. (point-at-bol)
  737. (- (point-max) 16))))
  738. (org-babel-previous-src-block) (org-babel-remove-result)
  739. (should (string= buffer-text
  740. (buffer-substring-no-properties
  741. (point-min) (point-max))))))
  742. (ert-deftest test-ob/org-babel-remove-result--results-default ()
  743. "Test `org-babel-remove-result' with default :results."
  744. (mapcar (lambda (language)
  745. (test-ob-verify-result-and-removed-result
  746. "\n"
  747. (concat
  748. "* org-babel-remove-result
  749. #+begin_src " language "
  750. #+end_src
  751. * next heading")))
  752. '("sh" "emacs-lisp")))
  753. (ert-deftest test-ob/org-babel-remove-result--results-list ()
  754. "Test `org-babel-remove-result' with :results list."
  755. (test-ob-verify-result-and-removed-result
  756. "- 1
  757. - 2
  758. - 3
  759. - (quote (4 5))"
  760. "* org-babel-remove-result
  761. #+begin_src emacs-lisp :results list
  762. '(1 2 3 '(4 5))
  763. #+end_src
  764. * next heading"))
  765. (ert-deftest test-ob/org-babel-results-indented-wrap ()
  766. "Ensure that wrapped results are inserted correction when indented.
  767. If not inserted correctly then the second evaluation will fail
  768. trying to find the :END: marker."
  769. (org-test-with-temp-text
  770. "- indented
  771. #+begin_src sh :results file wrap
  772. echo test.txt
  773. #+end_src"
  774. (org-babel-next-src-block 1)
  775. (org-babel-execute-src-block)
  776. (org-babel-execute-src-block)))
  777. (ert-deftest test-ob/file-desc-header-argument ()
  778. "Test that the :file-desc header argument is used."
  779. (org-test-with-temp-text "#+begin_src emacs-lisp :results file :file-desc bar
  780. \"foo\"
  781. #+end_src
  782. #+begin_src emacs-lisp :results file :file-desc
  783. \"foo\"
  784. #+end_src"
  785. (org-babel-execute-src-block)
  786. (org-babel-next-src-block 1)
  787. (org-babel-execute-src-block)
  788. (goto-char (point-min))
  789. (should (search-forward "[[file:foo][bar]]" nil t))
  790. (should (search-forward "[[file:foo][foo]]" nil t))))
  791. (ert-deftest test-ob/org-babel-remove-result--results-pp ()
  792. "Test `org-babel-remove-result' with :results pp."
  793. (test-ob-verify-result-and-removed-result
  794. ": \"I /am/ working!\""
  795. "* org-babel-remove-result
  796. #+begin_src emacs-lisp :results pp
  797. \"I /am/ working!\")
  798. #+end_src
  799. * next heading"))
  800. (ert-deftest test-ob/inline-src_blk-preceded-punct-preceded-by-point ()
  801. (let ((test-line ".src_emacs-lisp[ :results verbatim ]{ \"x\" }")
  802. (org-babel-inline-result-wrap "=%s="))
  803. (org-test-with-temp-text
  804. test-line
  805. (forward-char 1)
  806. (org-babel-execute-maybe)
  807. (should (re-search-forward "=\"x\"=" nil t))
  808. (forward-line))))
  809. (ert-deftest test-ob/commented-last-block-line-with-var ()
  810. (org-test-with-temp-text-in-file "
  811. #+begin_src emacs-lisp :var a=1
  812. ;;
  813. #+end_src"
  814. (org-babel-next-src-block)
  815. (org-babel-execute-maybe)
  816. (re-search-forward "\\#\\+results:" nil t)
  817. (forward-line)
  818. (should (string=
  819. ""
  820. (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
  821. (org-test-with-temp-text-in-file "
  822. #+begin_src emacs-lisp :var a=2
  823. 2;;
  824. #+end_src"
  825. (org-babel-next-src-block)
  826. (org-babel-execute-maybe)
  827. (re-search-forward "\\#\\+results:" nil t)
  828. (forward-line)
  829. (should (string=
  830. ": 2"
  831. (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
  832. (defun test-ob-verify-result-and-removed-result (result buffer-text)
  833. "Test helper function to test `org-babel-remove-result'.
  834. A temp buffer is populated with BUFFER-TEXT, the first block is executed,
  835. and the result of execution is verified against RESULT.
  836. The block is actually executed /twice/ to ensure result
  837. replacement happens correctly."
  838. (org-test-with-temp-text
  839. buffer-text
  840. (org-babel-next-src-block) (org-babel-execute-maybe) (org-babel-execute-maybe)
  841. (should (re-search-forward "\\#\\+results:" nil t))
  842. (forward-line)
  843. (should (string= result
  844. (buffer-substring-no-properties
  845. (point-at-bol)
  846. (- (point-max) 16))))
  847. (org-babel-previous-src-block) (org-babel-remove-result)
  848. (should (string= buffer-text
  849. (buffer-substring-no-properties
  850. (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
  855. "\n"
  856. (concat
  857. "* org-babel-remove-result
  858. #+begin_src " language "
  859. #+end_src
  860. * next heading")))
  861. '("sh" "emacs-lisp")))
  862. (ert-deftest test-ob/org-babel-remove-result--results-list ()
  863. "Test `org-babel-remove-result' with :results list."
  864. (test-ob-verify-result-and-removed-result
  865. "- 1
  866. - 2
  867. - 3
  868. - (quote (4 5))"
  869. "* org-babel-remove-result
  870. #+begin_src emacs-lisp :results list
  871. '(1 2 3 '(4 5))
  872. #+end_src
  873. * next heading"))
  874. (ert-deftest test-ob/org-babel-remove-result--results-wrap ()
  875. "Test `org-babel-remove-result' with :results wrap."
  876. (test-ob-verify-result-and-removed-result
  877. ":RESULTS:
  878. hello there
  879. :END:"
  880. "* org-babel-remove-result
  881. #+begin_src emacs-lisp :results wrap
  882. \"hello there\"
  883. #+end_src
  884. * next heading"))
  885. (ert-deftest test-ob/org-babel-remove-result--results-org ()
  886. "Test `org-babel-remove-result' with :results org."
  887. (test-ob-verify-result-and-removed-result
  888. "#+BEGIN_SRC org
  889. ,* heading
  890. ,** subheading
  891. content
  892. #+END_SRC"
  893. "* org-babel-remove-result
  894. #+begin_src emacs-lisp :results org
  895. \"* heading
  896. ,** subheading
  897. content\"
  898. #+end_src
  899. * next heading"))
  900. (ert-deftest test-ob/org-babel-remove-result--results-html ()
  901. "Test `org-babel-remove-result' with :results html."
  902. (test-ob-verify-result-and-removed-result
  903. "#+BEGIN_EXPORT html
  904. <head><body></body></head>
  905. #+END_EXPORT"
  906. "* org-babel-remove-result
  907. #+begin_src emacs-lisp :results html
  908. \"<head><body></body></head>\"
  909. #+end_src
  910. * next heading"))
  911. (ert-deftest test-ob/org-babel-remove-result--results-latex ()
  912. "Test `org-babel-remove-result' with :results latex."
  913. (test-ob-verify-result-and-removed-result
  914. "#+BEGIN_EXPORT latex
  915. Line 1
  916. Line 2
  917. Line 3
  918. #+END_EXPORT"
  919. "* org-babel-remove-result
  920. #+begin_src emacs-lisp :results latex
  921. \"Line 1
  922. Line 2
  923. Line 3\"
  924. #+end_src
  925. * next heading"))
  926. (ert-deftest test-ob/org-babel-remove-result--results-code ()
  927. "Test `org-babel-remove-result' with :results code."
  928. (test-ob-verify-result-and-removed-result
  929. "#+BEGIN_SRC emacs-lisp
  930. \"I am working!\"
  931. #+END_SRC"
  932. "* org-babel-remove-result
  933. #+begin_src emacs-lisp :results code
  934. (message \"I am working!\")
  935. #+end_src
  936. * next heading"))
  937. (ert-deftest test-ob/org-babel-remove-result--results-pp ()
  938. "Test `org-babel-remove-result' with :results pp."
  939. (test-ob-verify-result-and-removed-result
  940. ": \"I /am/ working!\""
  941. "* org-babel-remove-result
  942. #+begin_src emacs-lisp :results pp
  943. \"I /am/ working!\")
  944. #+end_src
  945. * next heading"))
  946. (ert-deftest test-ob/results-do-not-replace-code-blocks ()
  947. (org-test-with-temp-text "Block two has a space after the name.
  948. #+name: foo
  949. #+begin_src emacs-lisp
  950. 1
  951. #+end_src
  952. #+name: foo
  953. #+begin_src emacs-lisp
  954. 2
  955. #+end_src
  956. #+name: foo
  957. #+begin_src emacs-lisp
  958. 3
  959. #+end_src
  960. #+RESULTS: foo
  961. : foo
  962. "
  963. (dolist (num '(1 2 3))
  964. ;; execute the block
  965. (goto-char (point-min))
  966. (org-babel-next-src-block num) (org-babel-execute-src-block)
  967. ;; check the results
  968. (goto-char (point-max))
  969. (move-beginning-of-line 0)
  970. (should (looking-at (format ": %d" num))))))
  971. (ert-deftest test-ob/blocks-with-spaces ()
  972. "Test expansion of blocks followed by blank lines."
  973. (should
  974. (equal "#+BEGIN_SRC emacs-lisp
  975. \(+ 1 2)
  976. #+END_SRC
  977. #+RESULTS:
  978. : 3\n\n\n"
  979. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp
  980. \(+ 1 2)
  981. #+END_SRC\n\n\n"
  982. (let ((org-babel-next-src-block "RESULTS"))
  983. (org-babel-execute-src-block))
  984. (buffer-string)))))
  985. (ert-deftest test-ob/results-in-narrowed-buffer ()
  986. "Test block execution in a narrowed buffer."
  987. ;; If results don't exist, they should be inserted in visible part
  988. ;; of the buffer.
  989. (should
  990. (equal
  991. "#+BEGIN_SRC emacs-lisp\n(+ 1 2)\n#+END_SRC\n\n#+RESULTS:\n: 3"
  992. (org-test-with-temp-text
  993. "#+BEGIN_SRC emacs-lisp\n(+ 1 2)\n#+END_SRC\n\nParagraph"
  994. (narrow-to-region (point) (save-excursion (forward-line 3) (point)))
  995. (let ((org-babel-results-keyword "RESULTS"))
  996. (org-babel-execute-src-block))
  997. (org-trim (buffer-string)))))
  998. (should
  999. (equal
  1000. "#+NAME: test\n#+BEGIN_SRC emacs-lisp\n(+ 1 2)\n#+END_SRC\n\n#+RESULTS: test\n: 3"
  1001. (org-test-with-temp-text
  1002. "#+NAME: test\n#+BEGIN_SRC emacs-lisp\n(+ 1 2)\n#+END_SRC\n\nParagraph"
  1003. (narrow-to-region (point) (save-excursion (forward-line 4) (point)))
  1004. (let ((org-babel-results-keyword "RESULTS"))
  1005. (org-babel-execute-src-block))
  1006. (org-trim (buffer-string)))))
  1007. ;; Results in visible part of buffer, should be updated here.
  1008. (should
  1009. (equal
  1010. "#+NAME: test
  1011. #+BEGIN_SRC emacs-lisp
  1012. \(+ 1 2)
  1013. #+END_SRC
  1014. #+RESULTS: test
  1015. : 3"
  1016. (org-test-with-temp-text
  1017. "#+NAME: test
  1018. #+BEGIN_SRC emacs-lisp
  1019. \(+ 1 2)
  1020. #+END_SRC
  1021. #+RESULTS: test
  1022. : 4
  1023. Paragraph"
  1024. (narrow-to-region (point) (save-excursion (forward-line 7) (point)))
  1025. (let ((org-babel-results-keyword "RESULTS"))
  1026. (org-babel-execute-src-block))
  1027. (org-trim (buffer-string)))))
  1028. ;; Results in invisible part of buffer, should be updated there.
  1029. (org-test-with-temp-text
  1030. "#+NAME: test
  1031. #+BEGIN_SRC emacs-lisp
  1032. \(+ 1 2)
  1033. #+END_SRC
  1034. #+RESULTS: test
  1035. : 4
  1036. Paragraph"
  1037. (narrow-to-region (point) (save-excursion (forward-line 4) (point)))
  1038. (let ((org-babel-results-keyword "RESULTS"))
  1039. (org-babel-execute-src-block))
  1040. (should-not (re-search-forward "^#\\+RESULTS:" nil t))
  1041. (widen)
  1042. (should (should (re-search-forward "^: 3" nil t)))))
  1043. (ert-deftest test-ob/specific-colnames ()
  1044. "Test passing specific column names."
  1045. (should
  1046. (equal "#+name: input-table
  1047. | id | var1 |
  1048. |----+------|
  1049. | 1 | bar |
  1050. | 2 | baz |
  1051. #+begin_src sh :var data=input-table :exports results :colnames '(Rev Author)
  1052. echo \"$data\"
  1053. #+end_src
  1054. #+RESULTS:
  1055. | Rev | Author |
  1056. |-----+--------|
  1057. | 1 | bar |
  1058. | 2 | baz |
  1059. "
  1060. (org-test-with-temp-text
  1061. "#+name: input-table
  1062. | id | var1 |
  1063. |----+------|
  1064. | 1 | bar |
  1065. | 2 | baz |
  1066. #+begin_src sh :var data=input-table :exports results :colnames '(Rev Author)
  1067. echo \"$data\"
  1068. #+end_src
  1069. "
  1070. ;; we should find a code block
  1071. (should (re-search-forward org-babel-src-block-regexp nil t))
  1072. (goto-char (match-beginning 0))
  1073. ;; now that we've located the code block, it may be evaluated
  1074. (let ((org-babel-execute-src-block "RESULTS"))
  1075. (org-babel-execute-src-block))
  1076. (buffer-string)))))
  1077. (ert-deftest test-ob/location-of-header-arg-eval ()
  1078. "Test location of header argument evaluation."
  1079. (org-test-with-temp-text "
  1080. #+name: top-block
  1081. #+begin_src emacs-lisp :var pt=(point)
  1082. pt
  1083. #+end_src
  1084. #+name: bottom-block
  1085. #+begin_src emacs-lisp :var pt=top-block()
  1086. pt
  1087. #+end_src
  1088. "
  1089. ;; the value of the second block should be greater than the first
  1090. (should
  1091. (< (progn (re-search-forward org-babel-src-block-regexp nil t)
  1092. (goto-char (match-beginning 0))
  1093. (prog1 (save-match-data (org-babel-execute-src-block))
  1094. (goto-char (match-end 0))))
  1095. (progn (re-search-forward org-babel-src-block-regexp nil t)
  1096. (goto-char (match-beginning 0))
  1097. (org-babel-execute-src-block))))))
  1098. (ert-deftest test-ob/preserve-results-indentation ()
  1099. "Preserve indentation when executing a src block."
  1100. (should
  1101. (equal
  1102. '(2 2)
  1103. (org-test-with-temp-text " #+begin_src emacs-lisp\n(+ 1 1)\n #+end_src"
  1104. (org-babel-execute-src-block)
  1105. (let ((case-fold-search t)) (search-forward "RESULTS"))
  1106. (list (org-get-indentation)
  1107. (progn (forward-line) (org-get-indentation))))))
  1108. (should
  1109. (equal
  1110. '(2 2)
  1111. (org-test-with-temp-text
  1112. " #+name: block\n #+begin_src emacs-lisp\n(+ 1 1)\n #+end_src"
  1113. (org-babel-execute-src-block)
  1114. (let ((case-fold-search t)) (search-forward "RESULTS"))
  1115. (list (org-get-indentation)
  1116. (progn (forward-line) (org-get-indentation))))))
  1117. ;; Don't get fooled by TAB-based indentation.
  1118. (should
  1119. (equal
  1120. '(6 6)
  1121. (org-test-with-temp-text
  1122. "\t #+begin_src emacs-lisp\n\t (+ 1 1)\n\t #+end_src"
  1123. (setq tab-width 4)
  1124. (org-babel-execute-src-block)
  1125. (let ((case-fold-search t)) (search-forward "RESULTS"))
  1126. (list (org-get-indentation)
  1127. (progn (forward-line) (org-get-indentation)))))))
  1128. (ert-deftest test-ob/safe-header-args ()
  1129. "Detect safe and unsafe header args."
  1130. (let ((safe-args '((:cache . "foo")
  1131. (:results . "output")
  1132. (:eval . "never")
  1133. (:eval . "query")))
  1134. (unsafe-args '((:eval . "yes")
  1135. (:results . "output file")
  1136. (:foo . "bar")))
  1137. (malformed-args '((bar . "foo")
  1138. ("foo" . "bar")
  1139. :foo))
  1140. (safe-p (org-babel-header-args-safe-fn org-babel-safe-header-args)))
  1141. (dolist (arg safe-args)
  1142. (should (org-babel-one-header-arg-safe-p arg org-babel-safe-header-args)))
  1143. (dolist (arg unsafe-args)
  1144. (should (not (org-babel-one-header-arg-safe-p arg org-babel-safe-header-args))))
  1145. (dolist (arg malformed-args)
  1146. (should (not (org-babel-one-header-arg-safe-p arg org-babel-safe-header-args))))
  1147. (should (not (funcall safe-p (append safe-args unsafe-args))))))
  1148. (ert-deftest test-ob/noweb-expansions-in-cache ()
  1149. "Ensure that noweb expansions are expanded before caching."
  1150. (let ((noweb-expansions-in-cache-var 0))
  1151. (org-test-with-temp-text "
  1152. #+name: foo
  1153. #+begin_src emacs-lisp
  1154. \"I said\"
  1155. #+end_src
  1156. #+name: bar
  1157. #+begin_src emacs-lisp :noweb yes :cache yes
  1158. (setq noweb-expansions-in-cache-var
  1159. (+ 1 noweb-expansions-in-cache-var))
  1160. (concat <<foo>> \" check noweb expansions\")
  1161. #+end_src
  1162. "
  1163. ;; run the second block to create the cache
  1164. (goto-char (point-min))
  1165. (re-search-forward (regexp-quote "#+name: bar"))
  1166. (should (string= "I said check noweb expansions"
  1167. (org-babel-execute-src-block)))
  1168. (should (= noweb-expansions-in-cache-var 1))
  1169. ;; change the value of the first block
  1170. (goto-char (point-min))
  1171. (re-search-forward (regexp-quote "said"))
  1172. (goto-char (match-beginning 0))
  1173. (insert "haven't ")
  1174. (re-search-forward (regexp-quote "#+name: bar"))
  1175. (should (string= "I haven't said check noweb expansions"
  1176. (org-babel-execute-src-block)))
  1177. (should (= noweb-expansions-in-cache-var 2)))))
  1178. (ert-deftest test-ob/file-ext-and-output-dir ()
  1179. (org-test-at-id "93573e1d-6486-442e-b6d0-3fedbdc37c9b"
  1180. (org-babel-next-src-block)
  1181. (should (equal "file-ext-basic.txt"
  1182. (cdr (assq :file (nth 2 (org-babel-get-src-block-info t))))))
  1183. (org-babel-next-src-block)
  1184. (should (equal "foo/file-ext-dir-relative.txt"
  1185. (cdr (assq :file (nth 2 (org-babel-get-src-block-info t))))))
  1186. (org-babel-next-src-block)
  1187. (should (equal "foo/file-ext-dir-relative-slash.txt"
  1188. (cdr (assq :file (nth 2 (org-babel-get-src-block-info t))))))
  1189. (org-babel-next-src-block)
  1190. (should (equal "/tmp/file-ext-dir-absolute.txt"
  1191. (cdr (assq :file (nth 2 (org-babel-get-src-block-info t))))))
  1192. (org-babel-next-src-block)
  1193. (should (equal "foo.bar"
  1194. (cdr (assq :file (nth 2 (org-babel-get-src-block-info t))))))
  1195. (org-babel-next-src-block)
  1196. (should (equal "xxx/foo.bar"
  1197. (cdr (assq :file (nth 2 (org-babel-get-src-block-info t))))))
  1198. ))
  1199. (ert-deftest test-ob/script-escape ()
  1200. ;; Delimited lists of numbers
  1201. (should (equal '(1 2 3)
  1202. (org-babel-script-escape "[1 2 3]")))
  1203. (should (equal '(1 2 3)
  1204. (org-babel-script-escape "{1 2 3}")))
  1205. (should (equal '(1 2 3)
  1206. (org-babel-script-escape "(1 2 3)")))
  1207. ;; Delimited lists of double-quoted strings
  1208. (should (equal '("foo" "bar")
  1209. (org-babel-script-escape "(\"foo\" \"bar\")")))
  1210. (should (equal '("foo" "bar")
  1211. (org-babel-script-escape "[\"foo\" \"bar\"]")))
  1212. (should (equal '("foo" "bar")
  1213. (org-babel-script-escape "{\"foo\" \"bar\"}")))
  1214. ;; ... with commas
  1215. (should (equal '("foo" "bar")
  1216. (org-babel-script-escape "(\"foo\", \"bar\")")))
  1217. (should (equal '("foo" "bar")
  1218. (org-babel-script-escape "[\"foo\", \"bar\"]")))
  1219. (should (equal '("foo" "bar")
  1220. (org-babel-script-escape "{\"foo\", \"bar\"}")))
  1221. ;; Delimited lists of single-quoted strings
  1222. (should (equal '("foo" "bar")
  1223. (org-babel-script-escape "('foo' 'bar')")))
  1224. (should (equal '("foo" "bar")
  1225. (org-babel-script-escape "['foo' 'bar']")))
  1226. (should (equal '("foo" "bar")
  1227. (org-babel-script-escape "{'foo' 'bar'}")))
  1228. ;; ... with commas
  1229. (should (equal '("foo" "bar")
  1230. (org-babel-script-escape "('foo', 'bar')")))
  1231. (should (equal '("foo" "bar")
  1232. (org-babel-script-escape "['foo', 'bar']")))
  1233. (should (equal '("foo" "bar")
  1234. (org-babel-script-escape "{'foo', 'bar'}")))
  1235. ;; Single quoted strings
  1236. (should (equal "foo"
  1237. (org-babel-script-escape "'foo'")))
  1238. ;; ... with internal double quote
  1239. (should (equal "foo\"bar"
  1240. (org-babel-script-escape "'foo\"bar'")))
  1241. ;; ... with internal backslash
  1242. (should (equal "foo\\bar"
  1243. (org-babel-script-escape "'foo\\bar'")))
  1244. ;; ... with internal escaped backslash
  1245. (should (equal "foo\\bar"
  1246. (org-babel-script-escape "'foo\\\\bar'")))
  1247. ;; ... with internal backslash-double quote
  1248. (should (equal "foo\\\"bar"
  1249. (org-babel-script-escape "'foo\\\"bar'")))
  1250. ;; ... with internal escaped backslash-double quote
  1251. (should (equal "foo\\\"bar"
  1252. (org-babel-script-escape "'foo\\\\\"bar'")))
  1253. ;; ... with internal escaped single quote
  1254. (should (equal "foo'bar"
  1255. (org-babel-script-escape "'foo\\'bar'")))
  1256. ;; ... with internal escaped backslash-escaped single quote
  1257. (should (equal "foo\\'bar"
  1258. (org-babel-script-escape "'foo\\\\\\'bar'")))
  1259. ;; Double quoted strings
  1260. (should (equal "foo"
  1261. (org-babel-script-escape "\"foo\"")))
  1262. ;; ... with internal single quote
  1263. (should (equal "foo'bar"
  1264. (org-babel-script-escape "\"foo'bar\"")))
  1265. ;; ... with internal backslash
  1266. (should (equal "foo\\bar"
  1267. (org-babel-script-escape "\"foo\\bar\"")))
  1268. ;; ... with internal escaped backslash
  1269. (should (equal "foo\\bar"
  1270. (org-babel-script-escape "\"foo\\\\bar\"")))
  1271. ;; ... with internal backslash-single quote
  1272. (should (equal "foo\\'bar"
  1273. (org-babel-script-escape "\"foo\\'bar\"")))
  1274. ;; ... with internal escaped backslash-single quote
  1275. (should (equal "foo\\'bar"
  1276. (org-babel-script-escape "\"foo\\\\'bar\"")))
  1277. ;; ... with internal escaped double quote
  1278. (should (equal "foo\"bar"
  1279. (org-babel-script-escape "\"foo\\\"bar\"")))
  1280. ;; ... with internal escaped backslash-escaped double quote
  1281. (should (equal "foo\\\"bar"
  1282. (org-babel-script-escape "\"foo\\\\\\\"bar\""))))
  1283. (ert-deftest test-ob/process-params-no-duplicates ()
  1284. (should (equal (org-babel-process-params '((:colname-names . 1)
  1285. (:rowname-names . 1)
  1286. (:result-params . 1)
  1287. (:result-type . 1)
  1288. (:var . "\"foo\"")))
  1289. '((:var)
  1290. (:colname-names . 1)
  1291. (:rowname-names . 1)
  1292. (:result-params . 1)
  1293. (:result-type . value)))))
  1294. (defun org-test-babel-confirm-evaluate (eval-value)
  1295. (org-test-with-temp-text (format "#+begin_src emacs-lisp :eval %s
  1296. nil
  1297. #+end_src" eval-value)
  1298. (goto-char (point-min))
  1299. (let ((info (org-babel-get-src-block-info)))
  1300. (org-babel-check-confirm-evaluate info))))
  1301. (ert-deftest test-ob/check-eval ()
  1302. (let ((org-confirm-babel-evaluate t))
  1303. ;; Non-export tests
  1304. (dolist (pair '(("no" . nil)
  1305. ("never" . nil)
  1306. ("query" . query)
  1307. ("yes" . query)))
  1308. (should (eq (org-test-babel-confirm-evaluate (car pair)) (cdr pair))))
  1309. ;; Export tests
  1310. (let ((org-babel-exp-reference-buffer t))
  1311. (dolist (pair '(("no" . nil)
  1312. ("never" . nil)
  1313. ("query" . query)
  1314. ("yes" . query)
  1315. ("never-export" . nil)
  1316. ("no-export" . nil)
  1317. ("query-export" . query)))
  1318. (message (car pair))
  1319. (should (eq (org-test-babel-confirm-evaluate (car pair)) (cdr pair))))))
  1320. (let ((org-confirm-babel-evaluate nil))
  1321. ;; Non-export tests
  1322. (dolist (pair '(("no" . nil)
  1323. ("never" . nil)
  1324. ("query" . query)
  1325. ("yes" . t)))
  1326. (should (eq (org-test-babel-confirm-evaluate (car pair)) (cdr pair))))
  1327. ;; Export tests
  1328. (let ((org-babel-exp-reference-buffer t))
  1329. (dolist (pair '(("no" . nil)
  1330. ("never" . nil)
  1331. ("query" . query)
  1332. ("yes" . t)
  1333. ("never-export" . nil)
  1334. ("no-export" . nil)
  1335. ("query-export" . query)))
  1336. (message (car pair))
  1337. (should (eq (org-test-babel-confirm-evaluate (car pair)) (cdr pair)))))))
  1338. (defun org-test-ob/update-block-body ()
  1339. "Test `org-babel-update-block-body' specifications."
  1340. (should
  1341. (equal "#+begin_src elisp\n 2\n#+end_src"
  1342. (let ((org-edit-src-content-indentation 2))
  1343. (org-test-with-temp-text "#+begin_src elisp\n(+ 1 1)\n#+end_src"
  1344. (org-babel-update-block-body "2")
  1345. (buffer-string)))))
  1346. ;; Preserve block indentation.
  1347. (should
  1348. (equal " #+begin_src elisp\n 2\n #+end_src"
  1349. (let ((org-edit-src-content-indentation 1))
  1350. (org-test-with-temp-text
  1351. " #+begin_src elisp\n (+ 1 1)\n #+end_src"
  1352. (org-babel-update-block-body "2")
  1353. (buffer-string)))))
  1354. ;; Ignore NEW-BODY global indentation.
  1355. (should
  1356. (equal "#+begin_src elisp\n 2\n#+end_src"
  1357. (let ((org-edit-src-content-indentation 2))
  1358. (org-test-with-temp-text "#+begin_src elisp\n(+ 1 1)\n#+end_src"
  1359. (org-babel-update-block-body " 2")
  1360. (buffer-string)))))
  1361. ;; When indentation should be preserved ignore the two rules above.
  1362. (should
  1363. (equal " #+begin_src elisp\n2\n #+end_src"
  1364. (let ((org-edit-src-content-indentation 1)
  1365. (org-src-preserve-indentation t))
  1366. (org-test-with-temp-text
  1367. " #+begin_src elisp\n (+ 1 1)\n #+end_src"
  1368. (org-babel-update-block-body "2")
  1369. (buffer-string)))))
  1370. (should
  1371. (equal " #+begin_src elisp -i\n2\n #+end_src"
  1372. (let ((org-edit-src-content-indentation 1))
  1373. (org-test-with-temp-text
  1374. " #+begin_src elisp -i\n (+ 1 1)\n #+end_src"
  1375. (org-babel-update-block-body "2")
  1376. (buffer-string)))))
  1377. (should
  1378. (equal "#+begin_src elisp\n 2\n#+end_src"
  1379. (let ((org-edit-src-content-indentation 2)
  1380. (org-src-preserve-indentation t))
  1381. (org-test-with-temp-text "#+begin_src elisp\n(+ 1 1)\n#+end_src"
  1382. (org-babel-update-block-body " 2")
  1383. (buffer-string)))))
  1384. (should
  1385. (equal "#+begin_src elisp -i\n 2\n#+end_src"
  1386. (let ((org-edit-src-content-indentation 2)
  1387. (org-src-preserve-indentation t))
  1388. (org-test-with-temp-text "#+begin_src elisp -i\n(+ 1 1)\n#+end_src"
  1389. (org-babel-update-block-body " 2")
  1390. (buffer-string))))))
  1391. (ert-deftest test-ob/find-named-result ()
  1392. "Test `org-babel-find-named-result' specifications."
  1393. (should
  1394. (= 1
  1395. (org-test-with-temp-text "#+results: foo\n: result"
  1396. (org-babel-find-named-result "foo"))))
  1397. (should-not
  1398. (org-test-with-temp-text "#+results: foo\n: result"
  1399. (org-babel-find-named-result "bar")))
  1400. (should-not
  1401. (org-test-with-temp-text "#+results: foobar\n: result"
  1402. (org-babel-find-named-result "foo")))
  1403. ;; Search is case insensitive.
  1404. (should
  1405. (org-test-with-temp-text "#+RESULTS: FOO\n: result"
  1406. (org-babel-find-named-result "foo")))
  1407. ;; Handle hash in results keyword.
  1408. (should
  1409. (org-test-with-temp-text "#+results[hash]: FOO\n: result"
  1410. (org-babel-find-named-result "foo")))
  1411. ;; Accept orphaned affiliated keywords.
  1412. (should
  1413. (org-test-with-temp-text "#+results: foo"
  1414. (org-babel-find-named-result "foo"))))
  1415. (ert-deftest test-ob/where-is-src-block-result ()
  1416. "Test `org-babel-where-is-src-block-result' specifications."
  1417. ;; Find anonymous results.
  1418. (should
  1419. (equal "#+RESULTS:"
  1420. (org-test-with-temp-text
  1421. "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC\n\n#+RESULTS:\n: 2"
  1422. (goto-char (org-babel-where-is-src-block-result))
  1423. (buffer-substring-no-properties (point) (line-end-position)))))
  1424. ;; Find named results. Those have priority over anonymous ones.
  1425. (should
  1426. (equal "#+RESULTS: example"
  1427. (org-test-with-temp-text
  1428. "
  1429. <point>#+NAME: example
  1430. #+BEGIN_SRC emacs-lisp
  1431. \(+ 1 1)
  1432. #+END_SRC
  1433. #+RESULTS: example
  1434. : 2"
  1435. (goto-char (org-babel-where-is-src-block-result))
  1436. (buffer-substring-no-properties (point) (line-end-position)))))
  1437. (should
  1438. (equal "#+RESULTS: example"
  1439. (org-test-with-temp-text
  1440. "
  1441. <point>#+NAME: example
  1442. #+BEGIN_SRC emacs-lisp
  1443. \(+ 1 1)
  1444. #+END_SRC
  1445. #+RESULTS:
  1446. : fake
  1447. #+RESULTS: example
  1448. : 2"
  1449. (goto-char (org-babel-where-is-src-block-result))
  1450. (buffer-substring-no-properties (point) (line-end-position)))))
  1451. ;; Return nil when no result is found.
  1452. (should-not
  1453. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  1454. (org-babel-where-is-src-block-result)))
  1455. ;; When optional argument INSERT is non-nil, add RESULTS keyword
  1456. ;; whenever no RESULTS can be found.
  1457. (should
  1458. (equal
  1459. "#+RESULTS:"
  1460. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  1461. (let ((org-babel-results-keyword "RESULTS"))
  1462. (goto-char (org-babel-where-is-src-block-result t)))
  1463. (buffer-substring-no-properties (point) (line-end-position)))))
  1464. ;; Insert a named RESULTS keyword if possible.
  1465. (should
  1466. (equal
  1467. "#+RESULTS: e"
  1468. (org-test-with-temp-text
  1469. "#+NAME: e\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  1470. (let ((org-babel-results-keyword "RESULTS"))
  1471. (goto-char (org-babel-where-is-src-block-result t)))
  1472. (buffer-substring-no-properties (point) (line-end-position)))))
  1473. ;; When optional argument HASH is provided, clear RESULTS keyword
  1474. ;; and related contents if they do not match it.
  1475. (should
  1476. (equal
  1477. "#+RESULTS[bbbb]:"
  1478. (org-test-with-temp-text
  1479. "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC\n\n#+RESULTS[aaaa]:\n: 3"
  1480. (let ((org-babel-results-keyword "RESULTS"))
  1481. (goto-char (org-babel-where-is-src-block-result nil nil "bbbb")))
  1482. (org-trim (buffer-substring-no-properties (point) (point-max))))))
  1483. (should
  1484. (equal
  1485. "#+RESULTS[bbbb]:"
  1486. (org-test-with-temp-text
  1487. "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC\n\n#+RESULTS[aaaa]:"
  1488. (let ((org-babel-results-keyword "RESULTS"))
  1489. (goto-char (org-babel-where-is-src-block-result nil nil "bbbb")))
  1490. (org-trim (buffer-substring-no-properties (point) (point-max))))))
  1491. ;; RESULTS keyword may not be the last affiliated keyword.
  1492. (should
  1493. (equal
  1494. "#+RESULTS[bbbb]:"
  1495. (org-test-with-temp-text
  1496. "
  1497. <point>#+BEGIN_SRC emacs-lisp
  1498. \(+ 1 1)
  1499. #+END_SRC
  1500. #+RESULTS[aaaa]:
  1501. #+NAME: e
  1502. : 3"
  1503. (let ((org-babel-results-keyword "RESULTS"))
  1504. (goto-char (org-babel-where-is-src-block-result nil nil "bbbb")))
  1505. (org-trim (buffer-substring-no-properties (point) (point-max))))))
  1506. ;; HASH does nothing if no RESULTS can be found. However, if INSERT
  1507. ;; is also non-nil, RESULTS keyword is inserted along with the
  1508. ;; expected hash.
  1509. (should
  1510. (equal
  1511. "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  1512. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  1513. (org-babel-where-is-src-block-result nil nil "bbbb")
  1514. (buffer-string))))
  1515. (should
  1516. (equal
  1517. "#+RESULTS[bbbb]:"
  1518. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  1519. (let ((org-babel-results-keyword "RESULTS"))
  1520. (goto-char (org-babel-where-is-src-block-result t nil "bbbb")))
  1521. (org-trim (buffer-substring-no-properties (point) (point-max)))))))
  1522. (provide 'test-ob)
  1523. ;;; test-ob ends here