|
@@ -28,7 +28,8 @@
|
|
|
"Execute BODY while in a buffer with all Babel code evaluated.
|
|
|
Current buffer is a copy of the original buffer."
|
|
|
`(let ((string (buffer-string))
|
|
|
- (buf (current-buffer)))
|
|
|
+ (buf (current-buffer))
|
|
|
+ (org-export-babel-evaluate t))
|
|
|
(with-temp-buffer
|
|
|
(org-mode)
|
|
|
(insert string)
|
|
@@ -180,11 +181,10 @@ a table."
|
|
|
(ert-deftest ob-exp/evaluate-all-executables-in-order ()
|
|
|
(should
|
|
|
(equal '(5 4 3 2 1)
|
|
|
- (let (*evaluation-collector*)
|
|
|
+ (let ((org-export-babel-evaluate t) *evaluation-collector*)
|
|
|
(org-test-at-id "96cc7073-97ec-4556-87cf-1f9bffafd317"
|
|
|
(org-narrow-to-subtree)
|
|
|
(buffer-string)
|
|
|
- (fboundp 'org-export-execute-babel-code)
|
|
|
(org-test-with-expanded-babel-code *evaluation-collector*))))))
|
|
|
|
|
|
(ert-deftest ob-exp/exports-inline ()
|
|
@@ -195,91 +195,98 @@ Here is one at the end of a line. =2=
|
|
|
=3= Here is one at the beginning of a line.")
|
|
|
(org-test-at-id "54cb8dc3-298c-4883-a933-029b3c9d4b18"
|
|
|
(org-narrow-to-subtree)
|
|
|
- (org-test-with-expanded-babel-code (buffer-string))))))
|
|
|
+ (let ((org-babel-inline-result-wrap "=%s="))
|
|
|
+ (org-test-with-expanded-babel-code (buffer-string)))))))
|
|
|
|
|
|
(ert-deftest ob-exp/exports-inline-code ()
|
|
|
- (should
|
|
|
- (string-match "\\`src_emacs-lisp\\(?:\\[]\\)?{(\\+ 1 1)}$"
|
|
|
- (org-test-with-temp-text
|
|
|
- "src_emacs-lisp[:exports code]{(+ 1 1)}"
|
|
|
- (org-export-execute-babel-code)
|
|
|
- (buffer-string))))
|
|
|
- (should
|
|
|
- (string-match "\\`src_emacs-lisp\\(?:\\[]\\)?{(\\+ 1 1)}$"
|
|
|
- (org-test-with-temp-text
|
|
|
- "src_emacs-lisp[ :exports code ]{(+ 1 1)}"
|
|
|
- (org-export-execute-babel-code)
|
|
|
- (buffer-string))))
|
|
|
- (should
|
|
|
- (string-match "\\`src_emacs-lisp\\(?:\\[]\\)?{(\\+ 1 1)} =2=$"
|
|
|
- (org-test-with-temp-text
|
|
|
- "src_emacs-lisp[:exports both]{(+ 1 1)}"
|
|
|
- (org-export-execute-babel-code)
|
|
|
- (buffer-string))))
|
|
|
- (should
|
|
|
- (string-match "\\`=2=$"
|
|
|
- (org-test-with-temp-text
|
|
|
- "src_emacs-lisp[:exports results :results scalar]{(+ 1 1)}"
|
|
|
- (org-export-execute-babel-code)
|
|
|
- (buffer-string))))
|
|
|
- (should
|
|
|
- (let ((text "foosrc_emacs-lisp[:exports code]{(+ 1 1)}"))
|
|
|
- (string-match (regexp-quote text)
|
|
|
+ (let ((org-babel-inline-result-wrap "=%s=")
|
|
|
+ (org-export-babel-evaluate t))
|
|
|
+ (should
|
|
|
+ (string-match "\\`src_emacs-lisp\\(?:\\[]\\)?{(\\+ 1 1)}$"
|
|
|
(org-test-with-temp-text
|
|
|
- text
|
|
|
- (org-export-execute-babel-code)
|
|
|
- (buffer-string)))))
|
|
|
- (should
|
|
|
- (let ((text "src_emacs lisp{(+ 1 1)}"))
|
|
|
- (string-match (regexp-quote text)
|
|
|
+ "src_emacs-lisp[:exports code]{(+ 1 1)}"
|
|
|
+ (org-export-execute-babel-code)
|
|
|
+ (buffer-string))))
|
|
|
+ (should
|
|
|
+ (string-match "\\`src_emacs-lisp\\(?:\\[]\\)?{(\\+ 1 1)}$"
|
|
|
(org-test-with-temp-text
|
|
|
- text
|
|
|
- (org-export-execute-babel-code)
|
|
|
- (buffer-string)))))
|
|
|
- (should
|
|
|
- (string-match
|
|
|
- (replace-regexp-in-string
|
|
|
- "\\\\\\[]{" "\\(?:\\[]\\)?{" ;accept both src_sh[]{...} or src_sh{...}
|
|
|
- (regexp-quote "Here is one in the middle src_sh[]{echo 1} of a line.
|
|
|
+ "src_emacs-lisp[ :exports code ]{(+ 1 1)}"
|
|
|
+ (org-export-execute-babel-code)
|
|
|
+ (buffer-string))))
|
|
|
+ (should
|
|
|
+ (string-match "\\`src_emacs-lisp\\(?:\\[]\\)?{(\\+ 1 1)} =2=$"
|
|
|
+ (org-test-with-temp-text
|
|
|
+ "src_emacs-lisp[:exports both]{(+ 1 1)}"
|
|
|
+ (org-export-execute-babel-code)
|
|
|
+ (buffer-string))))
|
|
|
+ (should
|
|
|
+ (string-match "\\`=2=$"
|
|
|
+ (org-test-with-temp-text
|
|
|
+ "src_emacs-lisp[:exports results :results scalar]{(+ 1 1)}"
|
|
|
+ (org-export-execute-babel-code)
|
|
|
+ (buffer-string))))
|
|
|
+ (should
|
|
|
+ (let ((text "foosrc_emacs-lisp[:exports code]{(+ 1 1)}"))
|
|
|
+ (string-match (regexp-quote text)
|
|
|
+ (org-test-with-temp-text
|
|
|
+ text
|
|
|
+ (org-export-execute-babel-code)
|
|
|
+ (buffer-string)))))
|
|
|
+ (should
|
|
|
+ (let ((text "src_emacs lisp{(+ 1 1)}"))
|
|
|
+ (string-match (regexp-quote text)
|
|
|
+ (org-test-with-temp-text
|
|
|
+ text
|
|
|
+ (org-export-execute-babel-code)
|
|
|
+ (buffer-string)))))
|
|
|
+ (should
|
|
|
+ (string-match
|
|
|
+ (replace-regexp-in-string
|
|
|
+ "\\\\\\[]{" "\\(?:\\[]\\)?{" ;accept both src_sh[]{...} or src_sh{...}
|
|
|
+ (regexp-quote "Here is one in the middle src_sh[]{echo 1} of a line.
|
|
|
Here is one at the end of a line. src_sh[]{echo 2}
|
|
|
src_sh[]{echo 3} Here is one at the beginning of a line.
|
|
|
Here is one that is also evaluated: src_sh[]{echo 4} =4=")
|
|
|
- nil t)
|
|
|
- (org-test-at-id "cd54fc88-1b6b-45b6-8511-4d8fa7fc8076"
|
|
|
- (org-narrow-to-subtree)
|
|
|
- (org-test-with-expanded-babel-code (buffer-string))))))
|
|
|
+ nil t)
|
|
|
+ (org-test-at-id "cd54fc88-1b6b-45b6-8511-4d8fa7fc8076"
|
|
|
+ (org-narrow-to-subtree)
|
|
|
+ (org-test-with-expanded-babel-code (buffer-string)))))))
|
|
|
|
|
|
(ert-deftest ob-exp/exports-inline-code-double-eval ()
|
|
|
"Based on default header arguments for inline code blocks (:exports
|
|
|
results), the resulting code block `src_emacs-lisp{2}' should also be
|
|
|
evaluated."
|
|
|
- (should
|
|
|
- (string-match "\\`=2=$"
|
|
|
- (org-test-with-temp-text
|
|
|
- "src_emacs-lisp[:exports results :results code]{(+ 1 1)}"
|
|
|
- (org-export-execute-babel-code)
|
|
|
- (buffer-string)))))
|
|
|
+ (let ((org-babel-inline-result-wrap "=%s=")
|
|
|
+ (org-export-babel-evaluate t))
|
|
|
+ (should
|
|
|
+ (string-match "\\`=2=$"
|
|
|
+ (org-test-with-temp-text
|
|
|
+ "src_emacs-lisp[:exports results :results code]{(+ 1 1)}"
|
|
|
+ (org-export-execute-babel-code)
|
|
|
+ (buffer-string))))))
|
|
|
|
|
|
(ert-deftest ob-exp/exports-inline-code-eval-code-once ()
|
|
|
"Ibid above, except that the resulting inline code block should not
|
|
|
be evaluated."
|
|
|
- (should
|
|
|
- (string-match "\\`src_emacs-lisp\\(?:\\[]\\)?{2}$"
|
|
|
- (org-test-with-temp-text
|
|
|
- (concat "src_emacs-lisp[:exports results :results code "
|
|
|
- ":results_switches \":exports code\"]{(+ 1 1)}")
|
|
|
- (org-export-execute-babel-code)
|
|
|
- (buffer-string)))))
|
|
|
+ (let ((org-export-babel-evaluate t))
|
|
|
+ (should
|
|
|
+ (string-match "\\`src_emacs-lisp\\(?:\\[]\\)?{2}$"
|
|
|
+ (org-test-with-temp-text
|
|
|
+ (concat "src_emacs-lisp[:exports results :results code "
|
|
|
+ ":results_switches \":exports code\"]{(+ 1 1)}")
|
|
|
+ (org-export-execute-babel-code)
|
|
|
+ (buffer-string))))))
|
|
|
|
|
|
(ert-deftest ob-exp/exports-inline-code-double-eval-exports-both ()
|
|
|
- (should
|
|
|
- (string-match (concat "\\`src_emacs-lisp\\(?:\\[]\\)?{(\\+ 1 1)} "
|
|
|
- "src_emacs-lisp\\(?:\\[]\\)?{2}$")
|
|
|
- (org-test-with-temp-text
|
|
|
- (concat "src_emacs-lisp[:exports both :results code "
|
|
|
- ":results_switches \":exports code\"]{(+ 1 1)}")
|
|
|
- (org-export-execute-babel-code)
|
|
|
- (buffer-string)))))
|
|
|
+ (let ((org-export-babel-evaluate t))
|
|
|
+ (should
|
|
|
+ (string-match (concat "\\`src_emacs-lisp\\(?:\\[]\\)?{(\\+ 1 1)} "
|
|
|
+ "src_emacs-lisp\\(?:\\[]\\)?{2}$")
|
|
|
+ (org-test-with-temp-text
|
|
|
+ (concat "src_emacs-lisp[:exports both :results code "
|
|
|
+ ":results_switches \":exports code\"]{(+ 1 1)}")
|
|
|
+ (org-export-execute-babel-code)
|
|
|
+ (buffer-string))))))
|
|
|
|
|
|
(ert-deftest ob-exp/export-call-line-information ()
|
|
|
(org-test-at-id "bec63a04-491e-4caa-97f5-108f3020365c"
|
|
@@ -303,33 +310,34 @@ be evaluated."
|
|
|
(org-test-at-id "cc5fbc20-bca5-437a-a7b8-2b4d7a03f820"
|
|
|
(org-narrow-to-subtree)
|
|
|
(let* ((case-fold-search nil)
|
|
|
+ (org-babel-inline-result-wrap "=%s=")
|
|
|
(result (org-test-with-expanded-babel-code (buffer-string)))
|
|
|
(sect "a:1, b:0, c:3, d:0, e:0")
|
|
|
(sub0 "a:1, b:2, c:4, d:0, e:0")
|
|
|
(sub1 "a:1, b:2, c:5, d:0, e:6")
|
|
|
(func sub0))
|
|
|
;; entry "section"
|
|
|
- (should (string-match (concat "_shell sect call\n: shell " sect "\n")
|
|
|
+ (should (string-match (concat "_shell-sect-call\n: shell " sect "\n")
|
|
|
result))
|
|
|
- (should (string-match (concat "_elisp sect call\n: elisp " sect "\n")
|
|
|
+ (should (string-match (concat "_elisp-sect-call\n: elisp " sect "\n")
|
|
|
result))
|
|
|
(should (string-match (concat "\n- sect inline =shell " sect "=\n")
|
|
|
result))
|
|
|
(should (string-match (concat "\n- sect inline =elisp " sect "=\n")
|
|
|
result))
|
|
|
;; entry "subsection", call without arguments
|
|
|
- (should (string-match (concat "_shell sub0 call\n: shell " sub0 "\n")
|
|
|
+ (should (string-match (concat "_shell-sub0-call\n: shell " sub0 "\n")
|
|
|
result))
|
|
|
- (should (string-match (concat "_elisp sub0 call\n: elisp " sub0 "\n")
|
|
|
+ (should (string-match (concat "_elisp-sub0-call\n: elisp " sub0 "\n")
|
|
|
result))
|
|
|
(should (string-match (concat "\n- sub0 inline =shell " sub0 "=\n")
|
|
|
result))
|
|
|
(should (string-match (concat "\n- sub0 inline =elisp " sub0 "=\n")
|
|
|
result))
|
|
|
;; entry "subsection", call with arguments
|
|
|
- (should (string-match (concat "_shell sub1 call\n: shell " sub1 "\n")
|
|
|
+ (should (string-match (concat "_shell-sub1-call\n: shell " sub1 "\n")
|
|
|
result))
|
|
|
- (should (string-match (concat "_elisp sub1 call\n: elisp " sub1 "\n")
|
|
|
+ (should (string-match (concat "_elisp-sub1-call\n: elisp " sub1 "\n")
|
|
|
result))
|
|
|
(should (string-match (concat "\n- sub1 inline =shell " sub1 "=\n")
|
|
|
result))
|
|
@@ -342,8 +350,9 @@ be evaluated."
|
|
|
result)))))
|
|
|
|
|
|
(ert-deftest ob-exp/export-from-a-temp-buffer ()
|
|
|
- (org-test-with-temp-text
|
|
|
- "
|
|
|
+ (let ((org-export-babel-evaluate t))
|
|
|
+ (org-test-with-temp-text
|
|
|
+ "
|
|
|
#+Title: exporting from a temporary buffer
|
|
|
|
|
|
#+name: foo
|
|
@@ -360,31 +369,32 @@ be evaluated."
|
|
|
(list foo <<bar>>)
|
|
|
#+END_SRC
|
|
|
"
|
|
|
- (let* ((ascii (org-export-as 'ascii)))
|
|
|
- (should (string-match
|
|
|
- (regexp-quote " :foo :bar \n")
|
|
|
- ascii)))))
|
|
|
+ (let* ((ascii (org-export-as 'ascii)))
|
|
|
+ (should (string-match
|
|
|
+ (regexp-quote " :foo :bar \n")
|
|
|
+ ascii))))))
|
|
|
|
|
|
(ert-deftest ob-export/export-with-results-before-block ()
|
|
|
"Test export when results are inserted before source block."
|
|
|
- (should
|
|
|
- (equal
|
|
|
- "#+RESULTS: src1
|
|
|
+ (let ((org-export-babel-evaluate t))
|
|
|
+ (should
|
|
|
+ (equal
|
|
|
+ "#+RESULTS: src1
|
|
|
: 2
|
|
|
|
|
|
#+NAME: src1
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
\(+ 1 1)
|
|
|
#+END_SRC"
|
|
|
- (org-test-with-temp-text
|
|
|
- "#+RESULTS: src1
|
|
|
+ (org-test-with-temp-text
|
|
|
+ "#+RESULTS: src1
|
|
|
|
|
|
#+NAME: src1
|
|
|
#+BEGIN_SRC emacs-lisp :exports both
|
|
|
\(+ 1 1)
|
|
|
#+END_SRC"
|
|
|
- (org-export-execute-babel-code)
|
|
|
- (buffer-string)))))
|
|
|
+ (org-export-execute-babel-code)
|
|
|
+ (org-trim (org-no-properties (buffer-string))))))))
|
|
|
|
|
|
(ert-deftest ob-export/export-src-block-with-switches ()
|
|
|
"Test exporting a source block with switches."
|
|
@@ -441,52 +451,54 @@ be evaluated."
|
|
|
|
|
|
(ert-deftest ob-export/export-under-commented-headline ()
|
|
|
"Test evaluation of code blocks under COMMENT headings."
|
|
|
- ;; Do not eval block in a commented headline.
|
|
|
- (should
|
|
|
- (string-match
|
|
|
- ": 2"
|
|
|
- (org-test-with-temp-text "* Headline
|
|
|
+ (let ((org-export-babel-evaluate t)
|
|
|
+ (org-babel-inline-result-wrap "=%s="))
|
|
|
+ ;; Do not eval block in a commented headline.
|
|
|
+ (should
|
|
|
+ (string-match
|
|
|
+ ": 2"
|
|
|
+ (org-test-with-temp-text "* Headline
|
|
|
#+BEGIN_SRC emacs-lisp :exports results
|
|
|
\(+ 1 1)
|
|
|
#+END_SRC"
|
|
|
- (org-export-execute-babel-code)
|
|
|
- (buffer-string))))
|
|
|
- (should-not
|
|
|
- (string-match
|
|
|
- ": 2"
|
|
|
- (org-test-with-temp-text "* COMMENT Headline
|
|
|
+ (org-export-execute-babel-code)
|
|
|
+ (buffer-string))))
|
|
|
+ (should-not
|
|
|
+ (string-match
|
|
|
+ ": 2"
|
|
|
+ (org-test-with-temp-text "* COMMENT Headline
|
|
|
#+BEGIN_SRC emacs-lisp :exports results
|
|
|
\(+ 1 1)
|
|
|
#+END_SRC"
|
|
|
- (org-export-execute-babel-code)
|
|
|
- (buffer-string))))
|
|
|
- ;; Do not eval inline blocks either.
|
|
|
- (should
|
|
|
- (string-match
|
|
|
- "=2="
|
|
|
- (org-test-with-temp-text "* Headline
|
|
|
+ (org-export-execute-babel-code)
|
|
|
+ (buffer-string))))
|
|
|
+ ;; Do not eval inline blocks either.
|
|
|
+ (should
|
|
|
+ (string-match
|
|
|
+ "=2="
|
|
|
+ (org-test-with-temp-text "* Headline
|
|
|
src_emacs-lisp{(+ 1 1)}"
|
|
|
- (org-export-execute-babel-code)
|
|
|
- (buffer-string))))
|
|
|
- (should-not
|
|
|
- (string-match
|
|
|
- "=2="
|
|
|
- (org-test-with-temp-text "* COMMENT Headline
|
|
|
+ (org-export-execute-babel-code)
|
|
|
+ (buffer-string))))
|
|
|
+ (should-not
|
|
|
+ (string-match
|
|
|
+ "=2="
|
|
|
+ (org-test-with-temp-text "* COMMENT Headline
|
|
|
src_emacs-lisp{(+ 1 1)}"
|
|
|
- (org-export-execute-babel-code)
|
|
|
- (buffer-string))))
|
|
|
- ;; Also check parent headlines.
|
|
|
- (should-not
|
|
|
- (string-match
|
|
|
- ": 2"
|
|
|
- (org-test-with-temp-text "
|
|
|
+ (org-export-execute-babel-code)
|
|
|
+ (buffer-string))))
|
|
|
+ ;; Also check parent headlines.
|
|
|
+ (should-not
|
|
|
+ (string-match
|
|
|
+ ": 2"
|
|
|
+ (org-test-with-temp-text "
|
|
|
* COMMENT Headline
|
|
|
** Children
|
|
|
#+BEGIN_SRC emacs-lisp :exports results
|
|
|
\(+ 1 1)
|
|
|
#+END_SRC"
|
|
|
- (org-export-execute-babel-code)
|
|
|
- (buffer-string)))))
|
|
|
+ (org-export-execute-babel-code)
|
|
|
+ (buffer-string))))))
|
|
|
|
|
|
(ert-deftest ob-export/reference-in-post-header ()
|
|
|
"Test references in :post header during export."
|