1 ;;; test-ob-emacs-lisp.el
3 ;; Copyright (c) 2012-2019 Free Software Foundation, Inc.
4 ;; Authors: Eric Schulte, Martyn Jago
6 ;; This file is not part of GNU Emacs.
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
23 ;; Org tests for ob-emacs-lisp.el live here
26 (ert-deftest ob-emacs-lisp
/commented-last-block-line-no-var
()
27 (org-test-with-temp-text-in-file "
28 #+begin_src emacs-lisp
31 (org-babel-next-src-block)
32 (org-babel-execute-maybe)
33 (should (re-search-forward "results:" nil t
))
38 (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
39 (org-test-with-temp-text-in-file "
40 #+begin_src emacs-lisp
44 (org-babel-next-src-block)
45 (org-babel-execute-maybe)
46 (should (re-search-forward "results:" nil t
))
51 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
53 (ert-deftest ob-emacs-lisp
/commented-last-block-line-with-var
()
54 (org-test-with-temp-text-in-file "
55 #+begin_src emacs-lisp :var a=1
58 (org-babel-next-src-block)
59 (org-babel-execute-maybe)
60 (re-search-forward "results" nil t
)
64 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
66 (ert-deftest ob-emacs-lisp
/commented-last-block-line
()
69 (org-test-with-temp-text-in-file "
70 #+begin_src emacs-lisp :var a=2
73 (org-babel-next-src-block)
74 (org-babel-execute-maybe)
75 (re-search-forward "results" nil t
)
76 (buffer-substring-no-properties (line-beginning-position 2)
77 (line-end-position 2))))))
79 (ert-deftest ob-emacs-lisp
/dynamic-lexical-execute
()
80 (cl-flet ((execute (text)
81 (org-test-with-temp-text-in-file text
82 (org-babel-next-src-block)
83 (org-babel-execute-maybe)
84 (re-search-forward "results" nil t
)
85 (re-search-forward ": " nil t
)
86 (buffer-substring-no-properties (point) (point-at-eol)))))
88 (should (string= "dynamic" (execute "
89 #+begin_src emacs-lisp :lexical no :results verbatim
90 (let ((x 'dynamic)) (funcall (let ((x 'lexical)) (lambda () x))))
93 (should (string= "lexical" (execute "
94 #+begin_src emacs-lisp :lexical yes :results verbatim
95 (let ((x 'dynamic)) (funcall (let ((x 'lexical)) (lambda () x))))
98 (should (string= "dynamic" (let ((x 'dynamic
)) (execute "
99 #+begin_src emacs-lisp :lexical no :results verbatim
103 (should (string= "lexical" (let ((x 'dynamic
)) (execute "
104 #+begin_src emacs-lisp :lexical '((x . lexical)) :results verbatim
108 ;; Src block execution uses `eval'. As of 2019-02-26, `eval' does
109 ;; not dynamically bind `lexical-binding' to the value of its
110 ;; LEXICAL parameter. Hence, (eval 'lexical-binding LEXICAL)
111 ;; evaluates to the same value that just `lexical-binding'
112 ;; evaluates to, even if LEXICAL is different. So tests like the
113 ;; following do not work here:
115 ;; (should (string= "t" (execute "
116 ;; #+begin_src emacs-lisp :lexical yes :results verbatim
120 ;; However, the corresponding test in
121 ;; `ob-emacs-lisp/dynamic-lexical-edit' does work.
124 (ert-deftest ob-emacs-lisp
/dynamic-lexical-edit
()
125 (cl-flet ((execute (text)
126 (org-test-with-temp-text-in-file text
127 (org-babel-next-src-block)
129 (goto-char (point-max))
130 (prog1 (eval-last-sexp 0)
131 (org-edit-src-exit)))))
133 (should (eq 'dynamic
(execute "
134 #+begin_src emacs-lisp :lexical no :results verbatim
135 (let ((x 'dynamic)) (funcall (let ((x 'lexical)) (lambda () x))))
138 (should (eq 'lexical
(execute "
139 #+begin_src emacs-lisp :lexical yes :results verbatim
140 (let ((x 'dynamic)) (funcall (let ((x 'lexical)) (lambda () x))))
143 (should (eq 'dynamic
(let ((x 'dynamic
)) (execute "
144 #+begin_src emacs-lisp :lexical no :results verbatim
148 (should (eq 'lexical
(let ((x 'dynamic
)) (execute "
149 #+begin_src emacs-lisp :lexical '((x . lexical)) :results verbatim
153 (should (equal nil
(execute "
154 #+begin_src emacs-lisp :lexical no :results verbatim
158 (should (equal t
(execute "
159 #+begin_src emacs-lisp :lexical yes :results verbatim
163 (should (equal '((x .
0)) (execute "
164 #+begin_src emacs-lisp :lexical '((x . 0)) :results verbatim
168 (provide 'test-ob-emacs-lisp
)
170 ;;; test-ob-emacs-lisp.el ends here