diff options
| author | Lars Ingebrigtsen | 2022-01-13 09:48:15 +0100 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2022-01-13 09:49:19 +0100 |
| commit | 9c31be6dc31f10efcfb8dc76053e8bf3f62eef2c (patch) | |
| tree | d7d7381ee7a9d74d355e8957e0b7334f6df48f28 | |
| parent | d30fde6b0ccc02eada1f43e0b4cc1873e42f14d2 (diff) | |
| download | emacs-9c31be6dc31f10efcfb8dc76053e8bf3f62eef2c.tar.gz emacs-9c31be6dc31f10efcfb8dc76053e8bf3f62eef2c.zip | |
Make ert explainers work on function aliases
* lisp/emacs-lisp/ert.el: New function.
(ert--expand-should-1): Use it (bug#53178).
| -rw-r--r-- | lisp/emacs-lisp/ert.el | 17 | ||||
| -rw-r--r-- | test/lisp/emacs-lisp/ert-tests.el | 3 |
2 files changed, 14 insertions, 6 deletions
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'." | |||
| 335 | (unless (eql ,value ',default-value) | 335 | (unless (eql ,value ',default-value) |
| 336 | (list :value ,value)) | 336 | (list :value ,value)) |
| 337 | (unless (eql ,value ',default-value) | 337 | (unless (eql ,value ',default-value) |
| 338 | (let ((-explainer- | 338 | (when-let ((-explainer- |
| 339 | (and (symbolp ',fn-name) | 339 | (ert--get-explainer ',fn-name))) |
| 340 | (get ',fn-name 'ert-explainer)))) | 340 | (list :explanation |
| 341 | (when -explainer- | 341 | (apply -explainer- ,args))))) |
| 342 | (list :explanation | ||
| 343 | (apply -explainer- ,args)))))) | ||
| 344 | value) | 342 | value) |
| 345 | ,value)))))))) | 343 | ,value)))))))) |
| 346 | 344 | ||
| 345 | (defun ert--get-explainer (fn-name) | ||
| 346 | (when (symbolp fn-name) | ||
| 347 | (cl-loop for fn in (cons fn-name (function-alias-p fn-name)) | ||
| 348 | for explainer = (get fn 'ert-explainer) | ||
| 349 | when explainer | ||
| 350 | return explainer))) | ||
| 351 | |||
| 347 | (defun ert--expand-should (whole form inner-expander) | 352 | (defun ert--expand-should (whole form inner-expander) |
| 348 | "Helper function for the `should' macro and its variants. | 353 | "Helper function for the `should' macro and its variants. |
| 349 | 354 | ||
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." | |||
| 881 | "Check that `lexical-binding' in `ert-deftest' has the file value." | 881 | "Check that `lexical-binding' in `ert-deftest' has the file value." |
| 882 | (should (equal lexical-binding t))) | 882 | (should (equal lexical-binding t))) |
| 883 | 883 | ||
| 884 | (ert-deftest ert-test-get-explainer () | ||
| 885 | (should (eq (ert--get-explainer 'string-equal) 'ert--explain-string-equal)) | ||
| 886 | (should (eq (ert--get-explainer 'string=) 'ert--explain-string-equal))) | ||
| 884 | 887 | ||
| 885 | (provide 'ert-tests) | 888 | (provide 'ert-tests) |
| 886 | 889 | ||