Make 'eval' use lexical scoping in most tests

* test/lisp/electric-tests.el (electric-pair-define-test-form)
(define-electric-pair-test):
* test/lisp/emacs-lisp/backtrace-tests.el
(backtrace-tests--uncompiled-functions):
* test/lisp/emacs-lisp/cl-macs-tests.el
(cl-macs-test--symbol-macrolet):
* test/lisp/emacs-lisp/let-alist-tests.el
(let-alist-list-to-sexp):
* 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
(testcover-testcase-nth-case):
* 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
(subr-tests--dolist--wrong-number-of-args):
* test/src/eval-tests.el (eval-tests--if-dot-string)
(eval-tests--mutating-cond)
(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'.
This commit is contained in:
Stefan Kangas 2021-11-20 12:54:48 +01:00
parent 244baa550b
commit a3a3d3dd07
12 changed files with 35 additions and 29 deletions

View file

@ -97,8 +97,8 @@
(with-temp-buffer
(cl-progv
;; 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))
`(progn
,@(cl-loop
for mode in (eval modes) ;FIXME: avoid `eval'
for mode in (eval modes t) ;FIXME: avoid `eval'
append
(cl-loop
for (prefix suffix extra-desc) in

View file

@ -49,7 +49,7 @@
(setq backtrace-frames (seq-subseq backtrace-frames 0 (1+ this-index))))
(backtrace-print))))
(eval backtrace-tests--uncompiled-functions))
(eval backtrace-tests--uncompiled-functions t))
(defun backtrace-tests--backtrace-lines ()
(if debugger-stack-frame-as-list

View file

@ -529,7 +529,7 @@ collection clause."
(should-error
;; 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)))

View file

@ -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 '.foo.bar.baz 'var)
'(cdr (assq 'baz (cdr (assq 'bar (cdr (assq 'foo var))))))))
(should (equal (let-alist--access-sexp '..foo.bar.baz 'var) '.foo.bar.baz)))

View file

@ -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))

View file

@ -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

View file

@ -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)
(expand-file-name
(nth 4 args)

View file

@ -136,7 +136,7 @@ form.")
;; Prevent any dir-locals file interfering with the tests.
(enable-dir-local-variables nil))
(hack-local-variables)
(eval (nth 2 test-settings)))))
(eval (nth 2 test-settings) t))))
(ert-deftest files-tests-local-variables ()
"Test the file-local variables implementation."

View file

@ -6609,7 +6609,7 @@ Use the \"ls\" command."
;; Use all available language specific snippets.
(lambda (x)
(and
(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))
(unencodable-char-position

View file

@ -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))
nil)
;; 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))
nil)
(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))
nil)
(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))
nil)
(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))
nil)
(ert-deftest elisp--preceding-sexp--char-name ()

View file

@ -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 https://debbugs.gnu.org/22027 ."

View file

@ -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)))