]> git.eshelyaron.com Git - emacs.git/commitdiff
Use ambient lexical-binding value in ert-deftest body (bug#50738)
authorMattias Engdegård <mattiase@acm.org>
Thu, 23 Sep 2021 12:02:21 +0000 (14:02 +0200)
committerMattias Engdegård <mattiase@acm.org>
Sat, 25 Sep 2021 18:25:01 +0000 (20:25 +0200)
* lisp/emacs-lisp/ert.el (ert-deftest):
Evaluate the body of `ert-deftest` with the `lexical-binding` value of
the source file (or more precisely the value in force when the
definition is evaluated), which is what everyone expected, instead of
always using dynamic binding which is what they got until now.
* test/lisp/emacs-lisp/ert-tests.el
(ert-test-deftest-lexical-binding-t): New test.

lisp/emacs-lisp/ert.el
test/lisp/emacs-lisp/ert-tests.el

index d4d8510064ad75dfcdc7afb06f936aabdb3ea5f3..6d867abd7a2717dcd09408b3966ad87ad9dbec6f 100644 (file)
@@ -218,7 +218,11 @@ it has to be wrapped in `(eval (quote ...))'.
                             `(:expected-result-type ,expected-result))
                         ,@(when tags-supplied-p
                             `(:tags ,tags))
-                        :body (lambda () ,@body)))
+                        :body (lambda ()
+                                ;; Use the value of `lexical-binding' in
+                                ;; the source file when evaluating the body.
+                                (let ((lexical-binding ,lexical-binding))
+                                  ,@body))))
          ',name))))
 
 (defvar ert--find-test-regexp
index 5c9696105e92695572f84fad7ecb885543be2ea3..a18664bba3bac1f5f6edc115e6b7611fca1908de 100644 (file)
@@ -816,6 +816,10 @@ This macro is used to test if macroexpansion in `should' works."
     (should (equal (ert-test-failed-condition result)
                    '(ert-test-failed "Boo")))))
 
+(ert-deftest ert-test-deftest-lexical-binding-t ()
+  "Check that `lexical-binding' in `ert-deftest' has the file value."
+  (should (equal lexical-binding t)))
+
 
 (provide 'ert-tests)