aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Kangas2021-11-20 12:54:48 +0100
committerStefan Kangas2021-11-20 12:55:37 +0100
commita3a3d3dd074850a11ade229fc65a07aaa3e44320 (patch)
tree67bb2909c87b4e55448806ddaed0a9c5f1cd738b
parent244baa550beb3ca6f6b87cf86e2dae4465a87cbd (diff)
downloademacs-a3a3d3dd074850a11ade229fc65a07aaa3e44320.tar.gz
emacs-a3a3d3dd074850a11ade229fc65a07aaa3e44320.zip
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'.
-rw-r--r--test/lisp/electric-tests.el6
-rw-r--r--test/lisp/emacs-lisp/backtrace-tests.el2
-rw-r--r--test/lisp/emacs-lisp/cl-macs-tests.el2
-rw-r--r--test/lisp/emacs-lisp/let-alist-tests.el2
-rw-r--r--test/lisp/emacs-lisp/lisp-tests.el4
-rw-r--r--test/lisp/emacs-lisp/testcover-resources/testcases.el2
-rw-r--r--test/lisp/ffap-tests.el2
-rw-r--r--test/lisp/files-tests.el2
-rw-r--r--test/lisp/net/tramp-tests.el2
-rw-r--r--test/lisp/progmodes/elisp-mode-tests.el10
-rw-r--r--test/lisp/subr-tests.el13
-rw-r--r--test/src/eval-tests.el17
12 files changed, 35 insertions, 29 deletions
diff --git a/test/lisp/electric-tests.el b/test/lisp/electric-tests.el
index feeae2b82ad..85727bd0916 100644
--- a/test/lisp/electric-tests.el
+++ b/test/lisp/electric-tests.el
@@ -97,8 +97,8 @@
97 (with-temp-buffer 97 (with-temp-buffer
98 (cl-progv 98 (cl-progv
99 ;; FIXME: avoid `eval' 99 ;; FIXME: avoid `eval'
100 (mapcar #'car (eval bindings)) 100 (mapcar #'car (eval bindings t))
101 (mapcar #'cdr (eval bindings)) 101 (mapcar #'cdr (eval bindings t))
102 (dlet ((python-indent-guess-indent-offset-verbose nil)) 102 (dlet ((python-indent-guess-indent-offset-verbose nil))
103 (funcall mode) 103 (funcall mode)
104 (insert fixture) 104 (insert fixture)
@@ -187,7 +187,7 @@ The buffer's contents should %s:
187 (fixture-fn '#'electric-pair-mode)) 187 (fixture-fn '#'electric-pair-mode))
188 `(progn 188 `(progn
189 ,@(cl-loop 189 ,@(cl-loop
190 for mode in (eval modes) ;FIXME: avoid `eval' 190 for mode in (eval modes t) ;FIXME: avoid `eval'
191 append 191 append
192 (cl-loop 192 (cl-loop
193 for (prefix suffix extra-desc) in 193 for (prefix suffix extra-desc) in
diff --git a/test/lisp/emacs-lisp/backtrace-tests.el b/test/lisp/emacs-lisp/backtrace-tests.el
index 5c4e5305ecc..e35a7a729bc 100644
--- a/test/lisp/emacs-lisp/backtrace-tests.el
+++ b/test/lisp/emacs-lisp/backtrace-tests.el
@@ -49,7 +49,7 @@
49 (setq backtrace-frames (seq-subseq backtrace-frames 0 (1+ this-index)))) 49 (setq backtrace-frames (seq-subseq backtrace-frames 0 (1+ this-index))))
50 (backtrace-print)))) 50 (backtrace-print))))
51 51
52 (eval backtrace-tests--uncompiled-functions)) 52 (eval backtrace-tests--uncompiled-functions t))
53 53
54(defun backtrace-tests--backtrace-lines () 54(defun backtrace-tests--backtrace-lines ()
55 (if debugger-stack-frame-as-list 55 (if debugger-stack-frame-as-list
diff --git a/test/lisp/emacs-lisp/cl-macs-tests.el b/test/lisp/emacs-lisp/cl-macs-tests.el
index 033764a7f98..be2c0fa02b4 100644
--- a/test/lisp/emacs-lisp/cl-macs-tests.el
+++ b/test/lisp/emacs-lisp/cl-macs-tests.el
@@ -529,7 +529,7 @@ collection clause."
529 (should-error 529 (should-error
530 ;; Use `eval' so the error is signaled when running the test rather than 530 ;; Use `eval' so the error is signaled when running the test rather than
531 ;; when macroexpanding it. 531 ;; when macroexpanding it.
532 (eval '(let ((l (list 1))) (cl-symbol-macrolet ((x 1)) (setq (car l) 0))))) 532 (eval '(let ((l (list 1))) (cl-symbol-macrolet ((x 1)) (setq (car l) 0))) t))
533 ;; Make sure `gv-synthetic-place' isn't macro-expanded before `setf' gets to 533 ;; Make sure `gv-synthetic-place' isn't macro-expanded before `setf' gets to
534 ;; see its `gv-expander'. 534 ;; see its `gv-expander'.
535 (should (equal (let ((l '(0))) 535 (should (equal (let ((l '(0)))
diff --git a/test/lisp/emacs-lisp/let-alist-tests.el b/test/lisp/emacs-lisp/let-alist-tests.el
index 88e689c80b8..bbceb04b49d 100644
--- a/test/lisp/emacs-lisp/let-alist-tests.el
+++ b/test/lisp/emacs-lisp/let-alist-tests.el
@@ -82,7 +82,7 @@
82 82
83(ert-deftest let-alist-list-to-sexp () 83(ert-deftest let-alist-list-to-sexp ()
84 "Check that multiple dots are handled correctly." 84 "Check that multiple dots are handled correctly."
85 (should (= 1 (eval (let-alist--list-to-sexp '(a b c d) ''((d (c (b (a . 1))))))))) 85 (should (= 1 (eval (let-alist--list-to-sexp '(a b c d) ''((d (c (b (a . 1)))))) t)))
86 (should (equal (let-alist--access-sexp '.foo.bar.baz 'var) 86 (should (equal (let-alist--access-sexp '.foo.bar.baz 'var)
87 '(cdr (assq 'baz (cdr (assq 'bar (cdr (assq 'foo var)))))))) 87 '(cdr (assq 'baz (cdr (assq 'bar (cdr (assq 'foo var))))))))
88 (should (equal (let-alist--access-sexp '..foo.bar.baz 'var) '.foo.bar.baz))) 88 (should (equal (let-alist--access-sexp '..foo.bar.baz 'var) '.foo.bar.baz)))
diff --git a/test/lisp/emacs-lisp/lisp-tests.el b/test/lisp/emacs-lisp/lisp-tests.el
index 78ecf3ff03d..8301d9906a2 100644
--- a/test/lisp/emacs-lisp/lisp-tests.el
+++ b/test/lisp/emacs-lisp/lisp-tests.el
@@ -235,7 +235,7 @@
235 (should (or (not mark-active) (mark))))) 235 (should (or (not mark-active) (mark)))))
236 236
237(ert-deftest core-elisp-tests-3-backquote () 237(ert-deftest core-elisp-tests-3-backquote ()
238 (should (eq 3 (eval ``,,'(+ 1 2))))) 238 (should (eq 3 (eval ``,,'(+ 1 2) t))))
239 239
240;; Test up-list and backward-up-list. 240;; Test up-list and backward-up-list.
241(defun lisp-run-up-list-test (fn data start instructions) 241(defun lisp-run-up-list-test (fn data start instructions)
@@ -324,7 +324,7 @@ start."
324 (declare (indent 1) (debug (def-form body))) 324 (declare (indent 1) (debug (def-form body)))
325 (let* ((var-pos nil) 325 (let* ((var-pos nil)
326 (text (with-temp-buffer 326 (text (with-temp-buffer
327 (insert (eval contents)) 327 (insert (eval contents t))
328 (goto-char (point-min)) 328 (goto-char (point-min))
329 (while (re-search-forward elisp-test-point-position-regex nil t) 329 (while (re-search-forward elisp-test-point-position-regex nil t)
330 (push (list (intern (match-string-no-properties 1)) 330 (push (list (intern (match-string-no-properties 1))
diff --git a/test/lisp/emacs-lisp/testcover-resources/testcases.el b/test/lisp/emacs-lisp/testcover-resources/testcases.el
index 29094526d7e..4d49e5ae70c 100644
--- a/test/lisp/emacs-lisp/testcover-resources/testcases.el
+++ b/test/lisp/emacs-lisp/testcover-resources/testcases.el
@@ -424,7 +424,7 @@
424(defmacro testcover-testcase-nth-case (arg vec) 424(defmacro testcover-testcase-nth-case (arg vec)
425 (declare (indent 1) 425 (declare (indent 1)
426 (debug (form (vector &rest form)))) 426 (debug (form (vector &rest form))))
427 `(eval (aref ,vec%%% ,arg%%%))%%%) 427 `(eval (aref ,vec%%% ,arg%%%) t)%%%)
428 428
429(defun testcover-testcase-use-nth-case (choice val) 429(defun testcover-testcase-use-nth-case (choice val)
430 (testcover-testcase-nth-case choice 430 (testcover-testcase-nth-case choice
diff --git a/test/lisp/ffap-tests.el b/test/lisp/ffap-tests.el
index 84b9cea6c12..df5c264baad 100644
--- a/test/lisp/ffap-tests.el
+++ b/test/lisp/ffap-tests.el
@@ -132,7 +132,7 @@ left alone when opening a URL in an external browser."
132 ;; Macros in BODY are expanded when the test is defined, not when it 132 ;; Macros in BODY are expanded when the test is defined, not when it
133 ;; is run. If a macro (possibly with side effects) is to be tested, 133 ;; is run. If a macro (possibly with side effects) is to be tested,
134 ;; it has to be wrapped in `(eval (quote ...))'. 134 ;; it has to be wrapped in `(eval (quote ...))'.
135 (eval (quote (ido-everywhere))) 135 (eval (quote (ido-everywhere)) t)
136 (let ((read-file-name-function (lambda (&rest args) 136 (let ((read-file-name-function (lambda (&rest args)
137 (expand-file-name 137 (expand-file-name
138 (nth 4 args) 138 (nth 4 args)
diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el
index 2c4557ead61..d3d58aad5f2 100644
--- a/test/lisp/files-tests.el
+++ b/test/lisp/files-tests.el
@@ -136,7 +136,7 @@ form.")
136 ;; Prevent any dir-locals file interfering with the tests. 136 ;; Prevent any dir-locals file interfering with the tests.
137 (enable-dir-local-variables nil)) 137 (enable-dir-local-variables nil))
138 (hack-local-variables) 138 (hack-local-variables)
139 (eval (nth 2 test-settings))))) 139 (eval (nth 2 test-settings) t))))
140 140
141(ert-deftest files-tests-local-variables () 141(ert-deftest files-tests-local-variables ()
142 "Test the file-local variables implementation." 142 "Test the file-local variables implementation."
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
index 52a03843372..47fa18eb806 100644
--- a/test/lisp/net/tramp-tests.el
+++ b/test/lisp/net/tramp-tests.el
@@ -6609,7 +6609,7 @@ Use the \"ls\" command."
6609 ;; Use all available language specific snippets. 6609 ;; Use all available language specific snippets.
6610 (lambda (x) 6610 (lambda (x)
6611 (and 6611 (and
6612 (stringp (setq x (eval (get-language-info (car x) 'sample-text)))) 6612 (stringp (setq x (eval (get-language-info (car x) 'sample-text) t)))
6613 ;; Filter out strings which use unencodable characters. 6613 ;; Filter out strings which use unencodable characters.
6614 (not (and (or (tramp--test-gvfs-p) (tramp--test-smb-p)) 6614 (not (and (or (tramp--test-gvfs-p) (tramp--test-smb-p))
6615 (unencodable-char-position 6615 (unencodable-char-position
diff --git a/test/lisp/progmodes/elisp-mode-tests.el b/test/lisp/progmodes/elisp-mode-tests.el
index b91f7331a8d..63bae79bb40 100644
--- a/test/lisp/progmodes/elisp-mode-tests.el
+++ b/test/lisp/progmodes/elisp-mode-tests.el
@@ -610,7 +610,7 @@ to (xref-elisp-test-descr-to-target xref)."
610 )) 610 ))
611 611
612(xref-elisp-deftest find-defs-defgeneric-eval 612(xref-elisp-deftest find-defs-defgeneric-eval
613 (elisp--xref-find-definitions (eval '(cl-defgeneric stephe-leake-cl-defgeneric ()))) 613 (elisp--xref-find-definitions (eval '(cl-defgeneric stephe-leake-cl-defgeneric ()) t))
614 nil) 614 nil)
615 615
616;; Define some mode-local overloadable/overridden functions for xref to find 616;; Define some mode-local overloadable/overridden functions for xref to find
@@ -712,7 +712,7 @@ to (xref-elisp-test-descr-to-target xref)."
712 (expand-file-name "../../../lisp/progmodes/xref.el" emacs-test-dir))))) 712 (expand-file-name "../../../lisp/progmodes/xref.el" emacs-test-dir)))))
713 713
714(xref-elisp-deftest find-defs-defun-eval 714(xref-elisp-deftest find-defs-defun-eval
715 (elisp--xref-find-definitions (eval '(defun stephe-leake-defun ()))) 715 (elisp--xref-find-definitions (eval '(defun stephe-leake-defun ()) t))
716 nil) 716 nil)
717 717
718(xref-elisp-deftest find-defs-defun-c 718(xref-elisp-deftest find-defs-defun-c
@@ -797,7 +797,7 @@ to (xref-elisp-test-descr-to-target xref)."
797 "DEFVAR_PER_BUFFER (\"default-directory\""))) 797 "DEFVAR_PER_BUFFER (\"default-directory\"")))
798 798
799(xref-elisp-deftest find-defs-defvar-eval 799(xref-elisp-deftest find-defs-defvar-eval
800 (elisp--xref-find-definitions (eval '(defvar stephe-leake-defvar nil))) 800 (elisp--xref-find-definitions (eval '(defvar stephe-leake-defvar nil) t))
801 nil) 801 nil)
802 802
803(xref-elisp-deftest find-defs-face-el 803(xref-elisp-deftest find-defs-face-el
@@ -815,7 +815,7 @@ to (xref-elisp-test-descr-to-target xref)."
815 )) 815 ))
816 816
817(xref-elisp-deftest find-defs-face-eval 817(xref-elisp-deftest find-defs-face-eval
818 (elisp--xref-find-definitions (eval '(defface stephe-leake-defface nil ""))) 818 (elisp--xref-find-definitions (eval '(defface stephe-leake-defface nil "") t))
819 nil) 819 nil)
820 820
821(xref-elisp-deftest find-defs-feature-el 821(xref-elisp-deftest find-defs-feature-el
@@ -830,7 +830,7 @@ to (xref-elisp-test-descr-to-target xref)."
830 )) 830 ))
831 831
832(xref-elisp-deftest find-defs-feature-eval 832(xref-elisp-deftest find-defs-feature-eval
833 (elisp--xref-find-definitions (eval '(provide 'stephe-leake-feature))) 833 (elisp--xref-find-definitions (eval '(provide 'stephe-leake-feature) t))
834 nil) 834 nil)
835 835
836(ert-deftest elisp--preceding-sexp--char-name () 836(ert-deftest elisp--preceding-sexp--char-name ()
diff --git a/test/lisp/subr-tests.el b/test/lisp/subr-tests.el
index ca0ded1ea3d..e02de952f2f 100644
--- a/test/lisp/subr-tests.el
+++ b/test/lisp/subr-tests.el
@@ -611,12 +611,13 @@ indirectly `mapbacktrace'."
611(ert-deftest subr-tests--dolist--wrong-number-of-args () 611(ert-deftest subr-tests--dolist--wrong-number-of-args ()
612 "Test that `dolist' doesn't accept wrong types or length of SPEC, 612 "Test that `dolist' doesn't accept wrong types or length of SPEC,
613cf. Bug#25477." 613cf. Bug#25477."
614 (should-error (eval '(dolist (a))) 614 (dolist (lb '(nil t))
615 :type 'wrong-number-of-arguments) 615 (should-error (eval '(dolist (a)) lb)
616 (should-error (eval '(dolist (a () 'result 'invalid)) t) 616 :type 'wrong-number-of-arguments)
617 :type 'wrong-number-of-arguments) 617 (should-error (eval '(dolist (a () 'result 'invalid)) lb)
618 (should-error (eval '(dolist "foo") t) 618 :type 'wrong-number-of-arguments)
619 :type 'wrong-type-argument)) 619 (should-error (eval '(dolist "foo") lb)
620 :type 'wrong-type-argument)))
620 621
621(ert-deftest subr-tests-bug22027 () 622(ert-deftest subr-tests-bug22027 ()
622 "Test for https://debbugs.gnu.org/22027 ." 623 "Test for https://debbugs.gnu.org/22027 ."
diff --git a/test/src/eval-tests.el b/test/src/eval-tests.el
index 4f05d99136b..727c98aa5fa 100644
--- a/test/src/eval-tests.el
+++ b/test/src/eval-tests.el
@@ -86,23 +86,27 @@ Bug#24912."
86 86
87(ert-deftest eval-tests--if-dot-string () 87(ert-deftest eval-tests--if-dot-string ()
88 "Check that Emacs rejects (if . \"string\")." 88 "Check that Emacs rejects (if . \"string\")."
89 (should-error (eval '(if . "abc")) :type 'wrong-type-argument) 89 (should-error (eval '(if . "abc") nil) :type 'wrong-type-argument)
90 (should-error (eval '(if . "abc") t) :type 'wrong-type-argument)
90 (let ((if-tail (list '(setcdr if-tail "abc") t))) 91 (let ((if-tail (list '(setcdr if-tail "abc") t)))
91 (should-error (eval (cons 'if if-tail)))) 92 (should-error (eval (cons 'if if-tail) nil) :type 'void-variable)
93 (should-error (eval (cons 'if if-tail) t) :type 'void-variable))
92 (let ((if-tail (list '(progn (setcdr if-tail "abc") nil) t))) 94 (let ((if-tail (list '(progn (setcdr if-tail "abc") nil) t)))
93 (should-error (eval (cons 'if if-tail))))) 95 (should-error (eval (cons 'if if-tail) nil) :type 'void-variable)
96 (should-error (eval (cons 'if if-tail) t) :type 'void-variable)))
94 97
95(ert-deftest eval-tests--let-with-circular-defs () 98(ert-deftest eval-tests--let-with-circular-defs ()
96 "Check that Emacs reports an error for (let VARS ...) when VARS is circular." 99 "Check that Emacs reports an error for (let VARS ...) when VARS is circular."
97 (let ((vars (list 'v))) 100 (let ((vars (list 'v)))
98 (setcdr vars vars) 101 (setcdr vars vars)
99 (dolist (let-sym '(let let*)) 102 (dolist (let-sym '(let let*))
100 (should-error (eval (list let-sym vars)))))) 103 (should-error (eval (list let-sym vars) nil)))))
101 104
102(ert-deftest eval-tests--mutating-cond () 105(ert-deftest eval-tests--mutating-cond ()
103 "Check that Emacs doesn't crash on a cond clause that mutates during eval." 106 "Check that Emacs doesn't crash on a cond clause that mutates during eval."
104 (let ((clauses (list '((progn (setcdr clauses "ouch") nil))))) 107 (let ((clauses (list '((progn (setcdr clauses "ouch") nil)))))
105 (should-error (eval (cons 'cond clauses))))) 108 (should-error (eval (cons 'cond clauses) nil))
109 (should-error (eval (cons 'cond clauses) t))))
106 110
107(defun eval-tests--exceed-specbind-limit () 111(defun eval-tests--exceed-specbind-limit ()
108 (defvar eval-tests--var1) 112 (defvar eval-tests--var1)
@@ -184,7 +188,8 @@ are found on the stack and therefore not garbage collected."
184Don't handle destructive splicing in backquote expressions (like 188Don't handle destructive splicing in backquote expressions (like
185in Common Lisp). Instead, make sure substitution in backquote 189in Common Lisp). Instead, make sure substitution in backquote
186expressions works for identifiers starting with period." 190expressions works for identifiers starting with period."
187 (should (equal (let ((.x 'identity)) (eval `(,.x 'ok))) 'ok))) 191 (should (equal (let ((.x 'identity)) (eval `(,.x 'ok) nil)) 'ok))
192 (should (equal (let ((.x 'identity)) (eval `(,.x 'ok) t)) 'ok)))
188 193
189(ert-deftest eval-tests/backtrace-in-batch-mode () 194(ert-deftest eval-tests/backtrace-in-batch-mode ()
190 (let ((emacs (expand-file-name invocation-name invocation-directory))) 195 (let ((emacs (expand-file-name invocation-name invocation-directory)))