]> git.eshelyaron.com Git - emacs.git/commitdiff
Make ert explainers work on function aliases
authorLars Ingebrigtsen <larsi@gnus.org>
Thu, 13 Jan 2022 08:48:15 +0000 (09:48 +0100)
committerLars Ingebrigtsen <larsi@gnus.org>
Thu, 13 Jan 2022 08:49:19 +0000 (09:49 +0100)
* lisp/emacs-lisp/ert.el: New function.
(ert--expand-should-1): Use it (bug#53178).

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

index e31ebf5f7bb2bae756fa4703f9aba89e4d8c81e4..9c6b0e15bbe7f889c41e464a204521bde42879a5 100644 (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.
 
index ac130644743a3b303ed0b4c3c45446e32447250c..270cca1c2e7126680c60f5a751ff84e3b4169b6b 100644 (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)