Commit a3a3d3dd authored by Stefan Kangas's avatar Stefan Kangas
Browse files

Make 'eval' use lexical scoping in most tests

* test/lisp/electric-tests.el (electric-pair-define-test-form)
* test/lisp/emacs-lisp/backtrace-tests.el
* test/lisp/emacs-lisp/cl-macs-tests.el
* test/lisp/emacs-lisp/let-alist-tests.el
* test/lisp/emacs-lisp/lisp-tests.el
(elisp-tests-with-temp-buffer, core-elisp-tests-3-backquote):
* test/lisp/emacs-lisp/testcover-resources/testcases.el
* test/lisp/ffap-tests.el (ffap-ido-mode):
* test/lisp/files-tests.el (file-test--do-local-variables-test):
* test/lisp/net/tramp-tests.el (tramp--test-utf8):
* test/lisp/progmodes/elisp-mode-tests.el
(find-defs-defgeneric-eval, find-defs-defun-eval)
(find-defs-defvar-eval, find-defs-face-eval)
(find-defs-feature-eval): Give 'eval' non-nil LEXICAL argument.
* test/lisp/subr-tests.el
* test/src/eval-tests.el (eval-tests--if-dot-string)
(eval-tests-19790-backquote-comma-dot-substitution): Test 'eval'
using LEXICAL as both nil and non-nil.
(eval-tests--let-with-circular-defs): Give explicit nil to 'eval'.
parent 244baa55
......@@ -97,8 +97,8 @@
;; FIXME: avoid `eval'
(mapcar #'car (eval bindings))
(mapcar #'cdr (eval bindings))
(mapcar #'car (eval bindings t))
(mapcar #'cdr (eval bindings t))
(dlet ((python-indent-guess-indent-offset-verbose nil))
(funcall mode)
(insert fixture)
......@@ -187,7 +187,7 @@ The buffer's contents should %s:
(fixture-fn '#'electric-pair-mode))
for mode in (eval modes) ;FIXME: avoid `eval'
for mode in (eval modes t) ;FIXME: avoid `eval'
for (prefix suffix extra-desc) in
......@@ -49,7 +49,7 @@
(setq backtrace-frames (seq-subseq backtrace-frames 0 (1+ this-index))))
(eval backtrace-tests--uncompiled-functions))
(eval backtrace-tests--uncompiled-functions t))
(defun backtrace-tests--backtrace-lines ()
(if debugger-stack-frame-as-list
......@@ -529,7 +529,7 @@ collection clause."
;; Use `eval' so the error is signaled when running the test rather than
;; when macroexpanding it.
(eval '(let ((l (list 1))) (cl-symbol-macrolet ((x 1)) (setq (car l) 0)))))
(eval '(let ((l (list 1))) (cl-symbol-macrolet ((x 1)) (setq (car l) 0))) t))
;; Make sure `gv-synthetic-place' isn't macro-expanded before `setf' gets to
;; see its `gv-expander'.
(should (equal (let ((l '(0)))
......@@ -82,7 +82,7 @@
(ert-deftest let-alist-list-to-sexp ()
"Check that multiple dots are handled correctly."
(should (= 1 (eval (let-alist--list-to-sexp '(a b c d) ''((d (c (b (a . 1)))))))))
(should (= 1 (eval (let-alist--list-to-sexp '(a b c d) ''((d (c (b (a . 1)))))) t)))
(should (equal (let-alist--access-sexp ' 'var)
'(cdr (assq 'baz (cdr (assq 'bar (cdr (assq 'foo var))))))))
(should (equal (let-alist--access-sexp ' 'var) '
......@@ -235,7 +235,7 @@
(should (or (not mark-active) (mark)))))
(ert-deftest core-elisp-tests-3-backquote ()
(should (eq 3 (eval ``,,'(+ 1 2)))))
(should (eq 3 (eval ``,,'(+ 1 2) t))))
;; Test up-list and backward-up-list.
(defun lisp-run-up-list-test (fn data start instructions)
......@@ -324,7 +324,7 @@ start."
(declare (indent 1) (debug (def-form body)))
(let* ((var-pos nil)
(text (with-temp-buffer
(insert (eval contents))
(insert (eval contents t))
(goto-char (point-min))
(while (re-search-forward elisp-test-point-position-regex nil t)
(push (list (intern (match-string-no-properties 1))
......@@ -424,7 +424,7 @@
(defmacro testcover-testcase-nth-case (arg vec)
(declare (indent 1)
(debug (form (vector &rest form))))
`(eval (aref ,vec%%% ,arg%%%))%%%)
`(eval (aref ,vec%%% ,arg%%%) t)%%%)
(defun testcover-testcase-use-nth-case (choice val)
(testcover-testcase-nth-case choice
......@@ -132,7 +132,7 @@ left alone when opening a URL in an external browser."
;; Macros in BODY are expanded when the test is defined, not when it
;; is run. If a macro (possibly with side effects) is to be tested,
;; it has to be wrapped in `(eval (quote ...))'.
(eval (quote (ido-everywhere)))
(eval (quote (ido-everywhere)) t)
(let ((read-file-name-function (lambda (&rest args)
(nth 4 args)
......@@ -136,7 +136,7 @@ form.")
;; Prevent any dir-locals file interfering with the tests.
(enable-dir-local-variables nil))
(eval (nth 2 test-settings)))))
(eval (nth 2 test-settings) t))))
(ert-deftest files-tests-local-variables ()
"Test the file-local variables implementation."
......@@ -6609,7 +6609,7 @@ Use the \"ls\" command."
;; Use all available language specific snippets.
(lambda (x)
(stringp (setq x (eval (get-language-info (car x) 'sample-text))))
(stringp (setq x (eval (get-language-info (car x) 'sample-text) t)))
;; Filter out strings which use unencodable characters.
(not (and (or (tramp--test-gvfs-p) (tramp--test-smb-p))
......@@ -610,7 +610,7 @@ to (xref-elisp-test-descr-to-target xref)."
(xref-elisp-deftest find-defs-defgeneric-eval
(elisp--xref-find-definitions (eval '(cl-defgeneric stephe-leake-cl-defgeneric ())))
(elisp--xref-find-definitions (eval '(cl-defgeneric stephe-leake-cl-defgeneric ()) t))
;; Define some mode-local overloadable/overridden functions for xref to find
......@@ -712,7 +712,7 @@ to (xref-elisp-test-descr-to-target xref)."
(expand-file-name "../../../lisp/progmodes/xref.el" emacs-test-dir)))))
(xref-elisp-deftest find-defs-defun-eval
(elisp--xref-find-definitions (eval '(defun stephe-leake-defun ())))
(elisp--xref-find-definitions (eval '(defun stephe-leake-defun ()) t))
(xref-elisp-deftest find-defs-defun-c
......@@ -797,7 +797,7 @@ to (xref-elisp-test-descr-to-target xref)."
"DEFVAR_PER_BUFFER (\"default-directory\"")))
(xref-elisp-deftest find-defs-defvar-eval
(elisp--xref-find-definitions (eval '(defvar stephe-leake-defvar nil)))
(elisp--xref-find-definitions (eval '(defvar stephe-leake-defvar nil) t))
(xref-elisp-deftest find-defs-face-el
......@@ -815,7 +815,7 @@ to (xref-elisp-test-descr-to-target xref)."
(xref-elisp-deftest find-defs-face-eval
(elisp--xref-find-definitions (eval '(defface stephe-leake-defface nil "")))
(elisp--xref-find-definitions (eval '(defface stephe-leake-defface nil "") t))
(xref-elisp-deftest find-defs-feature-el
......@@ -830,7 +830,7 @@ to (xref-elisp-test-descr-to-target xref)."
(xref-elisp-deftest find-defs-feature-eval
(elisp--xref-find-definitions (eval '(provide 'stephe-leake-feature)))
(elisp--xref-find-definitions (eval '(provide 'stephe-leake-feature) t))
(ert-deftest elisp--preceding-sexp--char-name ()
......@@ -611,12 +611,13 @@ indirectly `mapbacktrace'."
(ert-deftest subr-tests--dolist--wrong-number-of-args ()
"Test that `dolist' doesn't accept wrong types or length of SPEC,
cf. Bug#25477."
(should-error (eval '(dolist (a)))
:type 'wrong-number-of-arguments)
(should-error (eval '(dolist (a () 'result 'invalid)) t)
:type 'wrong-number-of-arguments)
(should-error (eval '(dolist "foo") t)
:type 'wrong-type-argument))
(dolist (lb '(nil t))
(should-error (eval '(dolist (a)) lb)
:type 'wrong-number-of-arguments)
(should-error (eval '(dolist (a () 'result 'invalid)) lb)
:type 'wrong-number-of-arguments)
(should-error (eval '(dolist "foo") lb)
:type 'wrong-type-argument)))
(ert-deftest subr-tests-bug22027 ()
"Test for ."
......@@ -86,23 +86,27 @@ Bug#24912."
(ert-deftest eval-tests--if-dot-string ()
"Check that Emacs rejects (if . \"string\")."
(should-error (eval '(if . "abc")) :type 'wrong-type-argument)
(should-error (eval '(if . "abc") nil) :type 'wrong-type-argument)
(should-error (eval '(if . "abc") t) :type 'wrong-type-argument)
(let ((if-tail (list '(setcdr if-tail "abc") t)))
(should-error (eval (cons 'if if-tail))))
(should-error (eval (cons 'if if-tail) nil) :type 'void-variable)
(should-error (eval (cons 'if if-tail) t) :type 'void-variable))
(let ((if-tail (list '(progn (setcdr if-tail "abc") nil) t)))
(should-error (eval (cons 'if if-tail)))))
(should-error (eval (cons 'if if-tail) nil) :type 'void-variable)
(should-error (eval (cons 'if if-tail) t) :type 'void-variable)))
(ert-deftest eval-tests--let-with-circular-defs ()
"Check that Emacs reports an error for (let VARS ...) when VARS is circular."
(let ((vars (list 'v)))
(setcdr vars vars)
(dolist (let-sym '(let let*))
(should-error (eval (list let-sym vars))))))
(should-error (eval (list let-sym vars) nil)))))
(ert-deftest eval-tests--mutating-cond ()
"Check that Emacs doesn't crash on a cond clause that mutates during eval."
(let ((clauses (list '((progn (setcdr clauses "ouch") nil)))))
(should-error (eval (cons 'cond clauses)))))
(should-error (eval (cons 'cond clauses) nil))
(should-error (eval (cons 'cond clauses) t))))
(defun eval-tests--exceed-specbind-limit ()
(defvar eval-tests--var1)
......@@ -184,7 +188,8 @@ are found on the stack and therefore not garbage collected."
Don't handle destructive splicing in backquote expressions (like
in Common Lisp). Instead, make sure substitution in backquote
expressions works for identifiers starting with period."
(should (equal (let ((.x 'identity)) (eval `(,.x 'ok))) 'ok)))
(should (equal (let ((.x 'identity)) (eval `(,.x 'ok) nil)) 'ok))
(should (equal (let ((.x 'identity)) (eval `(,.x 'ok) t)) 'ok)))
(ert-deftest eval-tests/backtrace-in-batch-mode ()
(let ((emacs (expand-file-name invocation-name invocation-directory)))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment