From: Sean Whitton Date: Fri, 30 May 2025 10:41:06 +0000 (+0100) Subject: Gather variable binding tests in data-tests.el X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=32f9159051a6dffd406746be70d8f5beabef335d;p=emacs.git Gather variable binding tests in data-tests.el * test/lisp/emacs-lisp/lisp-tests.el (c-e-x, c-e-l): Move to data-tests.el. (core-elisp-tests-2-window-configurations): Rename ... (core-elisp-tests-1-window-configurations): ... to this. (core-elisp-tests-3-backquote): Rename ... (core-elisp-tests-2-backquote): ... to this. (core-elisp-tests-1-defvar-in-let) (core-elisp-tests-4-toplevel-values): Move and rename ... * test/src/data-tests.el (binding-test-defvar-in-let) (binding-test-toplevel-values): ... to these. (c-e-x, c-e-l): Moved from data-tests.el. (cherry picked from commit f699b6e4f409c0cc98703a2cea9b243ff8cb570a) --- diff --git a/test/lisp/emacs-lisp/lisp-tests.el b/test/lisp/emacs-lisp/lisp-tests.el index 1ef6bc864a7..d7cdaa3b331 100644 --- a/test/lisp/emacs-lisp/lisp-tests.el +++ b/test/lisp/emacs-lisp/lisp-tests.el @@ -212,21 +212,7 @@ (goto-char (point-min)) (should-error (forward-sexp)))) ;; FIXME: Shouldn't be an error. -;; Test some core Elisp rules. -(defvar c-e-x) -(ert-deftest core-elisp-tests-1-defvar-in-let () - "Test some core Elisp rules." - (with-temp-buffer - ;; Check that when defvar is run within a let-binding, the toplevel default - ;; is properly initialized. - (should (equal (list (let ((c-e-x 1)) (defvar c-e-x 2) c-e-x) c-e-x) - '(1 2))) - (should (equal (list (let ((c-e-x 1)) - (defcustom c-e-x 2 "doc" :group 'blah :type 'integer) c-e-x) - c-e-x) - '(1 2))))) - -(ert-deftest core-elisp-tests-2-window-configurations () +(ert-deftest core-elisp-tests-1-window-configurations () "Test properties of window-configurations." (let ((wc (current-window-configuration))) (with-current-buffer (window-buffer (frame-selected-window)) @@ -235,40 +221,10 @@ (set-window-configuration wc) (should (or (not mark-active) (mark))))) -(ert-deftest core-elisp-tests-3-backquote () +;; For variable binding tests, see src/data-tests.el. +(ert-deftest core-elisp-tests-2-backquote () (should (eq 3 (eval ``,,'(+ 1 2) t)))) -(defvar-local c-e-l 'foo) -(ert-deftest core-elisp-tests-4-toplevel-values () - (setq-default c-e-l 'foo) - (let ((c-e-l 'bar)) - (let ((c-e-l 'baz)) - (setq-default c-e-l 'bar) - (should (eq c-e-l 'bar)) - (should (eq (default-toplevel-value 'c-e-l) 'foo)) - (set-default-toplevel-value 'c-e-l 'baz) - (should (eq c-e-l 'bar)) - (should (eq (default-toplevel-value 'c-e-l) 'baz)))) - (let ((c-e-u 'foo)) - (should (condition-case _ - (default-toplevel-value 'c-e-u) - (void-variable t)))) - (with-temp-buffer - (setq-local c-e-l 'bar) - (should (eq (buffer-local-toplevel-value 'c-e-l) 'bar)) - (let ((c-e-l 'baz)) - (let ((c-e-l 'quux)) - (setq-local c-e-l 'baz) - (should (eq c-e-l 'baz)) - (should (eq (buffer-local-toplevel-value 'c-e-l) 'bar)) - (set-buffer-local-toplevel-value 'c-e-l 'foo) - (should (eq c-e-l 'baz)) - (should (eq (buffer-local-toplevel-value 'c-e-l) 'foo))))) - (with-temp-buffer - (should (condition-case _ - (buffer-local-toplevel-value 'c-e-l) - (void-variable t))))) - ;; Test up-list and backward-up-list. (defun lisp-run-up-list-test (fn data start instructions) (cl-labels ((posof (thing) diff --git a/test/src/data-tests.el b/test/src/data-tests.el index 260bdb281bb..75be9856463 100644 --- a/test/src/data-tests.el +++ b/test/src/data-tests.el @@ -354,6 +354,19 @@ comparing the subr with a much slower Lisp implementation." (setq-default binding-test-some-local 'new-default)) (should (eq binding-test-some-local 'some)))) +(defvar c-e-x) +(ert-deftest binding-test-defvar-in-let () + "Test some core Elisp rules." + (with-temp-buffer + ;; Check that when defvar is run within a let-binding, the toplevel default + ;; is properly initialized. + (should (equal (list (let ((c-e-x 1)) (defvar c-e-x 2) c-e-x) c-e-x) + '(1 2))) + (should (equal (list (let ((c-e-x 1)) + (defcustom c-e-x 2 "doc" :group 'blah :type 'integer) c-e-x) + c-e-x) + '(1 2))))) + (ert-deftest data-tests--let-buffer-local () (let ((blvar (make-symbol "blvar"))) (set-default blvar nil) @@ -396,6 +409,37 @@ comparing the subr with a much slower Lisp implementation." (should (equal (default-value var) def))) ))))) +(defvar-local c-e-l 'foo) +(ert-deftest binding-test-toplevel-values () + (setq-default c-e-l 'foo) + (let ((c-e-l 'bar)) + (let ((c-e-l 'baz)) + (setq-default c-e-l 'bar) + (should (eq c-e-l 'bar)) + (should (eq (default-toplevel-value 'c-e-l) 'foo)) + (set-default-toplevel-value 'c-e-l 'baz) + (should (eq c-e-l 'bar)) + (should (eq (default-toplevel-value 'c-e-l) 'baz)))) + (let ((c-e-u 'foo)) + (should (condition-case _ + (default-toplevel-value 'c-e-u) + (void-variable t)))) + (with-temp-buffer + (setq-local c-e-l 'bar) + (should (eq (buffer-local-toplevel-value 'c-e-l) 'bar)) + (let ((c-e-l 'baz)) + (let ((c-e-l 'quux)) + (setq-local c-e-l 'baz) + (should (eq c-e-l 'baz)) + (should (eq (buffer-local-toplevel-value 'c-e-l) 'bar)) + (set-buffer-local-toplevel-value 'c-e-l 'foo) + (should (eq c-e-l 'baz)) + (should (eq (buffer-local-toplevel-value 'c-e-l) 'foo))))) + (with-temp-buffer + (should (condition-case _ + (buffer-local-toplevel-value 'c-e-l) + (void-variable t))))) + (ert-deftest binding-test-makunbound () "Tests of makunbound, from the manual." (with-current-buffer binding-test-buffer-B