test-ob-exp.el 20 KB

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