test-ob-exp.el 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. ;;; test-ob-exp.el
  2. ;; Copyright (c) 2010-2015 Eric Schulte
  3. ;; Authors: Eric Schulte
  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. ;;; Comments:
  16. ;; Template test file for Org tests
  17. ;;; Code:
  18. (defmacro org-test-with-expanded-babel-code (&rest body)
  19. "Execute BODY while in a buffer with all Babel code evaluated.
  20. Current buffer is a copy of the original buffer."
  21. `(let ((string (org-with-wide-buffer (buffer-string)))
  22. (narrowing (list (point-min) (point-max)))
  23. (org-export-use-babel t))
  24. (with-temp-buffer
  25. (org-mode)
  26. (insert string)
  27. (apply #'narrow-to-region narrowing)
  28. (org-babel-exp-process-buffer)
  29. (goto-char (point-min))
  30. (progn ,@body))))
  31. (ert-deftest test-ob-exp/org-babel-exp-src-blocks/w-no-headers ()
  32. "Testing export without any headlines in the Org mode file."
  33. (require 'ox-ascii)
  34. (let ((text-file (concat (file-name-sans-extension org-test-no-heading-file)
  35. ".txt")))
  36. (when (file-exists-p text-file) (delete-file text-file))
  37. (org-test-in-example-file org-test-no-heading-file
  38. ;; Export the file to HTML.
  39. (org-export-to-file 'ascii text-file))
  40. ;; should create a ".txt" file
  41. (should (file-exists-p text-file))
  42. ;; should not create a file with "::" appended to its name
  43. (should-not (file-exists-p (concat org-test-no-heading-file "::")))
  44. (when (file-exists-p text-file) (delete-file text-file))))
  45. (ert-deftest test-ob-exp/org-babel-exp-src-blocks/w-no-file ()
  46. "Testing export from buffers which are not visiting any file."
  47. (require 'ox-ascii)
  48. (let ((name (generate-new-buffer-name "*Org ASCII Export*")))
  49. (org-test-in-example-file nil
  50. (org-export-to-buffer 'ascii name nil nil nil t))
  51. ;; Should create a new buffer.
  52. (should (buffer-live-p (get-buffer name)))
  53. ;; Should contain the content of the buffer.
  54. (with-current-buffer (get-buffer name)
  55. (should (string-match (regexp-quote org-test-file-ob-anchor)
  56. (buffer-string))))
  57. (when (get-buffer name) (kill-buffer name))))
  58. (ert-deftest test-ob-exp/org-babel-exp-src-blocks/w-no-headers2 ()
  59. "Testing export without any headlines in the Org file."
  60. (let ((html-file (concat (file-name-sans-extension
  61. org-test-link-in-heading-file)
  62. ".html")))
  63. (when (file-exists-p html-file) (delete-file html-file))
  64. (org-test-in-example-file org-test-link-in-heading-file
  65. ;; export the file to html
  66. (org-export-to-file 'html html-file))
  67. ;; should create a .html file
  68. (should (file-exists-p html-file))
  69. ;; should not create a file with "::" appended to its name
  70. (should-not (file-exists-p (concat org-test-link-in-heading-file "::")))
  71. (when (file-exists-p html-file) (delete-file html-file))))
  72. (ert-deftest ob-exp/noweb-on-export ()
  73. "Noweb header arguments export correctly.
  74. - yes expand on both export and tangle
  75. - no expand on neither export or tangle
  76. - tangle expand on only tangle not export"
  77. (should
  78. (equal
  79. '("(message \"expanded1\")" "(message \"expanded2\")" ";; noweb-1-yes-start
  80. (message \"expanded1\")" ";; noweb-no-start
  81. <<noweb-example1>>" ";; noweb-2-yes-start
  82. (message \"expanded2\")"
  83. ";; noweb-tangle-start
  84. <<noweb-example1>>
  85. <<noweb-example2>>")
  86. (org-test-at-id "eb1f6498-5bd9-45e0-9c56-50717053e7b7"
  87. (org-narrow-to-subtree)
  88. (org-element-map
  89. (org-test-with-expanded-babel-code (org-element-parse-buffer))
  90. 'src-block
  91. (lambda (src) (org-trim (org-element-property :value src))))))))
  92. (ert-deftest ob-exp/noweb-on-export-with-exports-results ()
  93. "Noweb header arguments export correctly using :exports results.
  94. - yes expand on both export and tangle
  95. - no expand on neither export or tangle
  96. - tangle expand on only tangle not export"
  97. (should
  98. (equal
  99. '(";; noweb-no-start
  100. <<noweb-example1>>" "<<noweb-example1>>
  101. <<noweb-example2>>")
  102. (org-test-at-id "8701beb4-13d9-468c-997a-8e63e8b66f8d"
  103. (org-narrow-to-subtree)
  104. (org-element-map
  105. (org-test-with-expanded-babel-code (org-element-parse-buffer))
  106. 'src-block
  107. (lambda (src) (org-trim (org-element-property :value src))))))))
  108. (ert-deftest ob-exp/exports-both ()
  109. "Test the \":exports both\" header argument.
  110. The code block evaluation should create both a code block and
  111. a table."
  112. (org-test-at-id "92518f2a-a46a-4205-a3ab-bcce1008a4bb"
  113. (org-narrow-to-subtree)
  114. (let ((tree (org-test-with-expanded-babel-code (org-element-parse-buffer))))
  115. (should (and (org-element-map tree 'src-block 'identity)
  116. (org-element-map tree 'table 'identity))))))
  117. (ert-deftest ob-exp/mixed-blocks-with-exports-both ()
  118. (should
  119. (equal
  120. '(property-drawer plain-list src-block fixed-width src-block plain-list)
  121. (org-test-at-id "5daa4d03-e3ea-46b7-b093-62c1b7632df3"
  122. (org-narrow-to-subtree)
  123. (mapcar 'org-element-type
  124. (org-element-map
  125. (org-test-with-expanded-babel-code
  126. (org-element-parse-buffer 'greater-element))
  127. 'section 'org-element-contents nil t))))))
  128. (ert-deftest ob-exp/export-with-name ()
  129. (should
  130. (string-match
  131. "=qux="
  132. (let ((org-babel-exp-code-template
  133. "=%name=\n#+BEGIN_SRC %lang%flags\nbody\n#+END_SRC"))
  134. (org-test-at-id "b02ddd8a-eeb8-42ab-8664-8a759e6f43d9"
  135. (org-narrow-to-subtree)
  136. (org-test-with-expanded-babel-code
  137. (buffer-string)))))))
  138. (ert-deftest ob-exp/export-with-header-argument ()
  139. (let ((org-babel-exp-code-template
  140. "
  141. | header | value |
  142. |---------+----------|
  143. | foo | %foo |
  144. | results | %results |
  145. #+BEGIN_SRC %lang%flags\nbody\n#+END_SRC"))
  146. (org-test-at-id "b02ddd8a-eeb8-42ab-8664-8a759e6f43d9"
  147. (org-narrow-to-subtree)
  148. (org-test-with-expanded-babel-code
  149. (should (string-match "baz" (buffer-string)))
  150. (should (string-match "replace" (buffer-string)))))))
  151. (ert-deftest ob-exp/noweb-no-export-and-exports-both ()
  152. (should
  153. (string-match
  154. "<<noweb-no-export-and-exports-both-1>>"
  155. (org-test-at-id "8a820f6c-7980-43db-8a24-0710d33729c9"
  156. (org-narrow-to-subtree)
  157. (org-test-with-expanded-babel-code
  158. (org-element-map (org-element-parse-buffer) 'src-block
  159. (lambda (src-block) (org-element-property :value src-block))
  160. nil t))))))
  161. (ert-deftest ob-exp/evaluate-all-executables-in-order ()
  162. (should
  163. (equal '(5 4 3 2 1)
  164. (let ((org-export-use-babel t) *evaluation-collector*)
  165. (org-test-at-id "96cc7073-97ec-4556-87cf-1f9bffafd317"
  166. (org-narrow-to-subtree)
  167. (buffer-string)
  168. (org-test-with-expanded-babel-code *evaluation-collector*))))))
  169. (ert-deftest ob-exp/exports-inline ()
  170. (should
  171. (string-match
  172. (regexp-quote "Here is one in the middle {{{results(=1=)}}} of a line.
  173. Here is one at the end of a line. {{{results(=2=)}}}
  174. {{{results(=3=)}}} Here is one at the beginning of a line.")
  175. (org-test-at-id "54cb8dc3-298c-4883-a933-029b3c9d4b18"
  176. (org-narrow-to-subtree)
  177. (let ((org-babel-inline-result-wrap "=%s="))
  178. (org-test-with-expanded-babel-code (buffer-string)))))))
  179. (ert-deftest ob-exp/exports-inline-code ()
  180. (let ((org-babel-inline-result-wrap "=%s=")
  181. (org-export-use-babel t))
  182. (should
  183. (string-match "\\`src_emacs-lisp\\(?:\\[]\\)?{(\\+ 1 1)}$"
  184. (org-test-with-temp-text
  185. "src_emacs-lisp[:exports code]{(+ 1 1)}"
  186. (org-babel-exp-process-buffer)
  187. (buffer-string))))
  188. (should
  189. (string-match "\\`src_emacs-lisp\\(?:\\[]\\)?{(\\+ 1 1)}$"
  190. (org-test-with-temp-text
  191. "src_emacs-lisp[ :exports code ]{(+ 1 1)}"
  192. (org-babel-exp-process-buffer)
  193. (buffer-string))))
  194. (should
  195. (string-match "\\`src_emacs-lisp\\(?:\\[]\\)?{(\\+ 1 1)} {{{results(=2=)}}}$"
  196. (org-test-with-temp-text
  197. "src_emacs-lisp[:exports both]{(+ 1 1)}"
  198. (org-babel-exp-process-buffer)
  199. (buffer-string))))
  200. (should
  201. (string-match "\\`{{{results(=2=)}}}$"
  202. (org-test-with-temp-text
  203. "src_emacs-lisp[:exports results :results scalar]{(+ 1 1)}"
  204. (org-babel-exp-process-buffer)
  205. (buffer-string))))
  206. (should
  207. (let ((text "foosrc_emacs-lisp[:exports code]{(+ 1 1)}"))
  208. (string-match (regexp-quote text)
  209. (org-test-with-temp-text
  210. text
  211. (org-babel-exp-process-buffer)
  212. (buffer-string)))))
  213. (should
  214. (let ((text "src_emacs lisp{(+ 1 1)}"))
  215. (string-match (regexp-quote text)
  216. (org-test-with-temp-text
  217. text
  218. (org-babel-exp-process-buffer)
  219. (buffer-string)))))
  220. (should
  221. (string-match
  222. (replace-regexp-in-string
  223. "\\\\\\[]{" "\\(?:\\[]\\)?{" ;accept both src_sh[]{...} or src_sh{...}
  224. (regexp-quote "Here is one in the middle src_sh[]{echo 1} of a line.
  225. Here is one at the end of a line. src_sh[]{echo 2}
  226. src_sh[]{echo 3} Here is one at the beginning of a line.
  227. Here is one that is also evaluated: src_sh[]{echo 4} {{{results(=4=)}}}")
  228. nil t)
  229. (org-test-at-id "cd54fc88-1b6b-45b6-8511-4d8fa7fc8076"
  230. (org-narrow-to-subtree)
  231. (org-test-with-expanded-babel-code (buffer-string)))))))
  232. (ert-deftest ob-exp/exports-inline-code-double-eval ()
  233. "Based on default header arguments for inline code blocks (:exports
  234. results), the resulting code block `src_emacs-lisp{2}' should also be
  235. evaluated."
  236. (let ((org-babel-inline-result-wrap "=%s=")
  237. (org-export-use-babel t))
  238. (should
  239. (string-match "\\`{{{results(src_emacs-lisp\\[\\]{2})}}}$"
  240. (org-test-with-temp-text
  241. "src_emacs-lisp[:exports results :results code]{(+ 1 1)}"
  242. (org-babel-exp-process-buffer)
  243. (buffer-string))))))
  244. (ert-deftest ob-exp/exports-inline-code-eval-code-once ()
  245. "Ibid above, except that the resulting inline code block should not
  246. be evaluated."
  247. (let ((org-export-use-babel t))
  248. (should
  249. (string-match "{{{results(src_emacs-lisp\\(?:\\[[: a-zA-Z]+]\\)?{2})}}}$"
  250. (org-test-with-temp-text
  251. (concat "src_emacs-lisp[:exports results :results code "
  252. ":results_switches \":exports code\"]{(+ 1 1)}")
  253. (org-babel-exp-process-buffer)
  254. (buffer-string))))))
  255. (ert-deftest ob-exp/exports-inline-code-double-eval-exports-both ()
  256. (let ((org-export-use-babel t))
  257. (should
  258. (string-match (concat "\\`src_emacs-lisp\\(?:\\[]\\)?{(\\+ 1 1)} "
  259. "{{{results(src_emacs-lisp\\[ :exports code\\]{2})}}}$")
  260. (org-test-with-temp-text
  261. (concat "src_emacs-lisp[:exports both :results code "
  262. ":results_switches \":exports code\"]{(+ 1 1)}")
  263. (org-babel-exp-process-buffer)
  264. (buffer-string))))))
  265. (ert-deftest ob-exp/export-call-line-information ()
  266. (org-test-at-id "bec63a04-491e-4caa-97f5-108f3020365c"
  267. (org-narrow-to-subtree)
  268. (let ((org-babel-exp-call-line-template "\n: call: %line special-token"))
  269. (org-test-with-expanded-babel-code
  270. (should (string-match "double" (buffer-string)))
  271. (should (string-match "16" (buffer-string)))
  272. (should (string-match "special-token" (buffer-string)))))))
  273. (ert-deftest ob-exp/noweb-strip-export-ensure-strips ()
  274. (org-test-at-id "8e7bd234-99b2-4b14-8cd6-53945e409775"
  275. (org-narrow-to-subtree)
  276. (org-babel-next-src-block 2)
  277. (should (= 110 (org-babel-execute-src-block)))
  278. (let ((result (org-test-with-expanded-babel-code (buffer-string))))
  279. (should-not (string-match (regexp-quote "<<strip-export-1>>") result))
  280. (should-not (string-match (regexp-quote "i=\"10\"") result)))))
  281. (ert-deftest ob-exp/use-case-of-reading-entry-properties ()
  282. (org-test-at-id "cc5fbc20-bca5-437a-a7b8-2b4d7a03f820"
  283. (org-narrow-to-subtree)
  284. (let* ((case-fold-search nil)
  285. (result (org-test-with-expanded-babel-code (buffer-string)))
  286. (sect "a:1, b:0, c:3, d:0, e:0")
  287. (sub0 "a:1, b:2, c:4, d:0, e:0")
  288. (sub1 "a:1, b:2, c:5, d:0, e:6")
  289. (func sub0))
  290. ;; entry "section"
  291. (should (string-match (concat "_shell-sect-call\n: shell " sect "\n")
  292. result))
  293. (should (string-match (concat "_elisp-sect-call\n: elisp " sect "\n")
  294. result))
  295. (should (string-match (concat "\n- sect inline shell " sect "\n")
  296. result))
  297. (should (string-match (concat "\n- sect inline elisp " sect "\n")
  298. result))
  299. ;; entry "subsection", call without arguments
  300. (should (string-match (concat "_shell-sub0-call\n: shell " sub0 "\n")
  301. result))
  302. (should (string-match (concat "_elisp-sub0-call\n: elisp " sub0 "\n")
  303. result))
  304. (should (string-match (concat "\n- sub0 inline shell " sub0 "\n")
  305. result))
  306. (should (string-match (concat "\n- sub0 inline elisp " sub0 "\n")
  307. result))
  308. ;; entry "subsection", call with arguments
  309. (should (string-match (concat "_shell-sub1-call\n: shell " sub1 "\n")
  310. result))
  311. (should (string-match (concat "_elisp-sub1-call\n: elisp " sub1 "\n")
  312. result))
  313. (should (string-match (concat "\n- sub1 inline shell " sub1 "\n")
  314. result))
  315. (should (string-match (concat "\n- sub1 inline elisp " sub1 "\n")
  316. result))
  317. ;; entry "function definition"
  318. (should (string-match (concat "_location_shell\n: shell " func "\n")
  319. result))
  320. (should (string-match (concat "_location_elisp\n: elisp " func "\n")
  321. result)))))
  322. (ert-deftest ob-exp/export-from-a-temp-buffer ()
  323. (let ((org-export-use-babel t))
  324. (org-test-with-temp-text
  325. "
  326. #+Title: exporting from a temporary buffer
  327. #+name: foo
  328. #+BEGIN_SRC emacs-lisp
  329. :foo
  330. #+END_SRC
  331. #+name: bar
  332. #+BEGIN_SRC emacs-lisp
  333. :bar
  334. #+END_SRC
  335. #+BEGIN_SRC emacs-lisp :var foo=foo :noweb yes :exports results
  336. (list foo <<bar>>)
  337. #+END_SRC
  338. "
  339. (let* ((ascii (org-export-as 'ascii)))
  340. (should (string-match
  341. (regexp-quote " :foo :bar \n")
  342. ascii))))))
  343. (ert-deftest ob-export/export-with-results-before-block ()
  344. "Test export when results are inserted before source block."
  345. (let ((org-export-use-babel t))
  346. (should
  347. (equal
  348. "#+RESULTS: src1
  349. : 2
  350. #+NAME: src1
  351. #+BEGIN_SRC emacs-lisp
  352. \(+ 1 1)
  353. #+END_SRC"
  354. (org-test-with-temp-text
  355. "#+RESULTS: src1
  356. #+NAME: src1
  357. #+BEGIN_SRC emacs-lisp :exports both
  358. \(+ 1 1)
  359. #+END_SRC"
  360. (org-babel-exp-process-buffer)
  361. (org-trim (org-no-properties (buffer-string))))))))
  362. (ert-deftest ob-export/export-src-block-with-switches ()
  363. "Test exporting a source block with switches."
  364. (should
  365. (string-match
  366. "\\`#\\+BEGIN_SRC emacs-lisp -n -r$"
  367. (org-test-with-temp-text
  368. "#+BEGIN_SRC emacs-lisp -n -r\n\(+ 1 1)\n#+END_SRC"
  369. (org-babel-exp-process-buffer)
  370. (buffer-string)))))
  371. (ert-deftest ob-export/export-src-block-with-flags ()
  372. "Test exporting a source block with a flag."
  373. (should
  374. (string-match
  375. "\\`#\\+BEGIN_SRC emacs-lisp -some-flag$"
  376. (org-test-with-temp-text
  377. "#+BEGIN_SRC emacs-lisp :flags -some-flag\n\(+ 1 1)\n#+END_SRC"
  378. (org-babel-exp-process-buffer)
  379. (buffer-string)))))
  380. (ert-deftest ob-export/export-and-indentation ()
  381. "Test indentation of evaluated source blocks during export."
  382. ;; No indentation.
  383. (should
  384. (string-match
  385. "^t"
  386. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n t\n#+END_SRC"
  387. (let ((indent-tabs-mode t)
  388. (tab-width 1)
  389. (org-src-preserve-indentation nil))
  390. (org-babel-exp-process-buffer)
  391. (buffer-string)))))
  392. ;; Preserve indentation with "-i" flag.
  393. (should
  394. (string-match
  395. "^ t"
  396. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -i\n t\n#+END_SRC"
  397. (let ((indent-tabs-mode t)
  398. (tab-width 1))
  399. (org-babel-exp-process-buffer)
  400. (buffer-string)))))
  401. ;; Preserve indentation with a non-nil
  402. ;; `org-src-preserve-indentation'.
  403. (should
  404. (string-match
  405. "^ t"
  406. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n t\n#+END_SRC"
  407. (let ((indent-tabs-mode t)
  408. (tab-width 1)
  409. (org-src-preserve-indentation t))
  410. (org-babel-exp-process-buffer)
  411. (buffer-string))))))
  412. (ert-deftest ob-export/export-under-commented-headline ()
  413. "Test evaluation of code blocks under COMMENT headings."
  414. (let ((org-export-use-babel t)
  415. (org-babel-inline-result-wrap "=%s="))
  416. ;; Do not eval block in a commented headline.
  417. (should
  418. (string-match
  419. ": 2"
  420. (org-test-with-temp-text "* Headline
  421. #+BEGIN_SRC emacs-lisp :exports results
  422. \(+ 1 1)
  423. #+END_SRC"
  424. (org-babel-exp-process-buffer)
  425. (buffer-string))))
  426. (should-not
  427. (string-match
  428. ": 2"
  429. (org-test-with-temp-text "* COMMENT Headline
  430. #+BEGIN_SRC emacs-lisp :exports results
  431. \(+ 1 1)
  432. #+END_SRC"
  433. (org-babel-exp-process-buffer)
  434. (buffer-string))))
  435. ;; Do not eval inline blocks either.
  436. (should
  437. (string-match
  438. "=2="
  439. (org-test-with-temp-text "* Headline
  440. src_emacs-lisp{(+ 1 1)}"
  441. (org-babel-exp-process-buffer)
  442. (buffer-string))))
  443. (should-not
  444. (string-match
  445. "=2="
  446. (org-test-with-temp-text "* COMMENT Headline
  447. src_emacs-lisp{(+ 1 1)}"
  448. (org-babel-exp-process-buffer)
  449. (buffer-string))))
  450. ;; Also check parent headlines.
  451. (should-not
  452. (string-match
  453. ": 2"
  454. (org-test-with-temp-text "
  455. * COMMENT Headline
  456. ** Children
  457. #+BEGIN_SRC emacs-lisp :exports results
  458. \(+ 1 1)
  459. #+END_SRC"
  460. (org-babel-exp-process-buffer)
  461. (buffer-string))))))
  462. (ert-deftest ob-export/reference-in-post-header ()
  463. "Test references in :post header during export."
  464. (should
  465. (org-test-with-temp-text "
  466. #+NAME: foo
  467. #+BEGIN_SRC emacs-lisp :exports none :var bar=\"baz\"
  468. (concat \"bar\" bar)
  469. #+END_SRC
  470. #+NAME: nofun
  471. #+BEGIN_SRC emacs-lisp :exports results :post foo(\"nofun\")
  472. #+END_SRC"
  473. (org-babel-exp-process-buffer) t)))
  474. (ert-deftest ob-export/babel-evaluate ()
  475. "Test `org-export-use-babel' effect."
  476. ;; When nil, no Babel code is executed.
  477. (should-not
  478. (string-match-p
  479. "2"
  480. (org-test-with-temp-text
  481. "#+BEGIN_SRC emacs-lisp :exports results\n(+ 1 1)\n#+END_SRC"
  482. (let ((org-export-use-babel nil)) (org-babel-exp-process-buffer))
  483. (buffer-string))))
  484. (should-not
  485. (string-match-p
  486. "2"
  487. (org-test-with-temp-text
  488. "src_emacs-lisp{(+ 1 1)}"
  489. (let ((org-export-use-babel nil)) (org-babel-exp-process-buffer))
  490. (buffer-string))))
  491. ;; When non-nil, all Babel code types are executed.
  492. (should
  493. (string-match-p
  494. "2"
  495. (org-test-with-temp-text
  496. "#+BEGIN_SRC emacs-lisp :exports results\n(+ 1 1)\n#+END_SRC"
  497. (let ((org-export-use-babel t)) (org-babel-exp-process-buffer))
  498. (buffer-string))))
  499. (should
  500. (string-match-p
  501. "2"
  502. (org-test-with-temp-text
  503. "src_emacs-lisp{(+ 1 1)}"
  504. (let ((org-export-use-babel t)) (org-babel-exp-process-buffer))
  505. (buffer-string)))))
  506. (ert-deftest ob-export/body-with-coderef ()
  507. "Test exporting a code block with coderefs."
  508. (should
  509. (equal "#+BEGIN_SRC emacs-lisp\n0 (ref:foo)\n#+END_SRC"
  510. (org-test-with-temp-text
  511. "#+BEGIN_SRC emacs-lisp :exports code\n0 (ref:foo)\n#+END_SRC"
  512. (let ((org-export-use-babel t)
  513. (org-coderef-label-format "(ref:foo)"))
  514. (org-babel-exp-process-buffer))
  515. (buffer-string))))
  516. (should
  517. (equal
  518. "#+BEGIN_SRC emacs-lisp -l \"r:%s\"\n1 r:foo\n#+END_SRC"
  519. (org-test-with-temp-text
  520. "#+BEGIN_SRC emacs-lisp -l \"r:%s\" -lisp :exports code\n1 r:foo\n#+END_SRC"
  521. (let ((org-export-use-babel t))
  522. (org-babel-exp-process-buffer))
  523. (buffer-string)))))
  524. (ert-deftest ob-exp/src-block-with-affiliated-keyword ()
  525. "Test exporting a code block with affiliated keywords."
  526. ;; Pathological case: affiliated keyword matches inline src block
  527. ;; syntax.
  528. (should
  529. (equal "#+name: call_foo\n#+BEGIN_SRC emacs-lisp\n42\n#+END_SRC"
  530. (org-test-with-temp-text
  531. "#+name: call_foo\n#+BEGIN_SRC emacs-lisp\n42\n#+END_SRC"
  532. (let ((org-export-use-babel t))
  533. (org-babel-exp-process-buffer))
  534. (buffer-string)))))
  535. (provide 'test-ob-exp)
  536. ;;; test-ob-exp.el ends here