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.
This commit is contained in:
parent
ed02b88bba
commit
0b099e34dc
2 changed files with 9 additions and 1 deletions
|
@ -218,7 +218,11 @@ it has to be wrapped in `(eval (quote ...))'.
|
||||||
`(:expected-result-type ,expected-result))
|
`(:expected-result-type ,expected-result))
|
||||||
,@(when tags-supplied-p
|
,@(when tags-supplied-p
|
||||||
`(:tags ,tags))
|
`(: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))))
|
',name))))
|
||||||
|
|
||||||
(defvar ert--find-test-regexp
|
(defvar ert--find-test-regexp
|
||||||
|
|
|
@ -816,6 +816,10 @@ This macro is used to test if macroexpansion in `should' works."
|
||||||
(should (equal (ert-test-failed-condition result)
|
(should (equal (ert-test-failed-condition result)
|
||||||
'(ert-test-failed "Boo")))))
|
'(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)
|
(provide 'ert-tests)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue