[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 0b099e3 2/7: Use ambient lexical-binding value in ert-deftest bod
From: |
Mattias Engdegård |
Subject: |
master 0b099e3 2/7: Use ambient lexical-binding value in ert-deftest body (bug#50738) |
Date: |
Sat, 25 Sep 2021 14:30:49 -0400 (EDT) |
branch: master
commit 0b099e34dc726c3ed0e7b63028f42c2a2720ba7c
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>
Use ambient lexical-binding value in ert-deftest body (bug#50738)
* 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 | 6 +++++-
test/lisp/emacs-lisp/ert-tests.el | 4 ++++
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/lisp/emacs-lisp/ert.el b/lisp/emacs-lisp/ert.el
index d4d8510..6d867ab 100644
--- a/lisp/emacs-lisp/ert.el
+++ b/lisp/emacs-lisp/ert.el
@@ -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
diff --git a/test/lisp/emacs-lisp/ert-tests.el
b/test/lisp/emacs-lisp/ert-tests.el
index 5c96961..a18664b 100644
--- a/test/lisp/emacs-lisp/ert-tests.el
+++ b/test/lisp/emacs-lisp/ert-tests.el
@@ -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)
- master updated (80fddff -> e6656df), Mattias Engdegård, 2021/09/25
- master 32de11d 3/7: ; Remove various duplicated words, Mattias Engdegård, 2021/09/25
- master e93bdfb 5/7: ; * doc/emacs/help.texi (Misc Help): @key{f1} -> @key{F1}, Mattias Engdegård, 2021/09/25
- master ed02b88 1/7: Renege on anonymous &rest (bug#50268, bug#50720), Mattias Engdegård, 2021/09/25
- master e6656df 7/7: ; * lisp/wid-edit.el (natnum): rectify tag string, Mattias Engdegård, 2021/09/25
- master 8d0ee5e 4/7: Constant-propagate variables bound outside loops, Mattias Engdegård, 2021/09/25
- master 45c32d7 6/7: Fix byte-compiler crash for legal dynamic-binding code, Mattias Engdegård, 2021/09/25
- master 0b099e3 2/7: Use ambient lexical-binding value in ert-deftest body (bug#50738),
Mattias Engdegård <=