From: Lars Ingebrigtsen Date: Thu, 13 Jan 2022 08:48:15 +0000 (+0100) Subject: Make ert explainers work on function aliases X-Git-Tag: emacs-29.0.90~3099 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=9c31be6dc31f10efcfb8dc76053e8bf3f62eef2c;p=emacs.git Make ert explainers work on function aliases * lisp/emacs-lisp/ert.el: New function. (ert--expand-should-1): Use it (bug#53178). --- diff --git a/lisp/emacs-lisp/ert.el b/lisp/emacs-lisp/ert.el index e31ebf5f7bb..9c6b0e15bbe 100644 --- a/lisp/emacs-lisp/ert.el +++ b/lisp/emacs-lisp/ert.el @@ -335,15 +335,20 @@ It should only be stopped when ran from inside `ert--run-test-internal'." (unless (eql ,value ',default-value) (list :value ,value)) (unless (eql ,value ',default-value) - (let ((-explainer- - (and (symbolp ',fn-name) - (get ',fn-name 'ert-explainer)))) - (when -explainer- - (list :explanation - (apply -explainer- ,args)))))) + (when-let ((-explainer- + (ert--get-explainer ',fn-name))) + (list :explanation + (apply -explainer- ,args))))) value) ,value)))))))) +(defun ert--get-explainer (fn-name) + (when (symbolp fn-name) + (cl-loop for fn in (cons fn-name (function-alias-p fn-name)) + for explainer = (get fn 'ert-explainer) + when explainer + return explainer))) + (defun ert--expand-should (whole form inner-expander) "Helper function for the `should' macro and its variants. diff --git a/test/lisp/emacs-lisp/ert-tests.el b/test/lisp/emacs-lisp/ert-tests.el index ac130644743..270cca1c2e7 100644 --- a/test/lisp/emacs-lisp/ert-tests.el +++ b/test/lisp/emacs-lisp/ert-tests.el @@ -881,6 +881,9 @@ This macro is used to test if macroexpansion in `should' works." "Check that `lexical-binding' in `ert-deftest' has the file value." (should (equal lexical-binding t))) +(ert-deftest ert-test-get-explainer () + (should (eq (ert--get-explainer 'string-equal) 'ert--explain-string-equal)) + (should (eq (ert--get-explainer 'string=) 'ert--explain-string-equal))) (provide 'ert-tests)