Make ert explainers work on function aliases

* lisp/emacs-lisp/ert.el: New function.
(ert--expand-should-1): Use it (bug#53178).
This commit is contained in:
Lars Ingebrigtsen 2022-01-13 09:48:15 +01:00
parent d30fde6b0c
commit 9c31be6dc3
2 changed files with 14 additions and 6 deletions

View file

@ -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.

View file

@ -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)