diff options
author | Philipp Stephani <phst@google.com> | 2022-09-13 17:12:57 +0200 |
---|---|---|
committer | Lars Ingebrigtsen <larsi@gnus.org> | 2022-09-13 17:12:57 +0200 |
commit | fffa53ff1afe097fe38f7664df5debe9811201d1 (patch) | |
tree | cdc34b558e9b4684b8362706a75a5a2d563f1ec8 /test/lisp/emacs-lisp/cl-macs-tests.el | |
parent | 6d8f5161ead689b7a2e44a7de0a695f0ab4c833b (diff) | |
download | emacs-fffa53ff1afe097fe38f7664df5debe9811201d1.tar.gz emacs-fffa53ff1afe097fe38f7664df5debe9811201d1.tar.bz2 emacs-fffa53ff1afe097fe38f7664df5debe9811201d1.zip |
Have 'cl-case' warn about suspicious cases
* lisp/emacs-lisp/cl-macs.el (cl-case): Warn if the user passes a nil
key list (which would never match). Warn about quoted symbols that
should probably be unquoted.
* test/lisp/emacs-lisp/cl-macs-tests.el (cl-case-warning): New unit
test (bug#51368).
Diffstat (limited to 'test/lisp/emacs-lisp/cl-macs-tests.el')
-rw-r--r-- | test/lisp/emacs-lisp/cl-macs-tests.el | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/test/lisp/emacs-lisp/cl-macs-tests.el b/test/lisp/emacs-lisp/cl-macs-tests.el index 77817abd85c..427b8f46893 100644 --- a/test/lisp/emacs-lisp/cl-macs-tests.el +++ b/test/lisp/emacs-lisp/cl-macs-tests.el @@ -25,6 +25,8 @@ (require 'cl-macs) (require 'edebug) (require 'ert) +(require 'ert-x) +(require 'pcase) ;;;; cl-loop tests -- many adapted from Steele's CLtL2 @@ -758,4 +760,34 @@ collection clause." (should (equal (cdr error) '("Misplaced t or `otherwise' clause"))))))) +(ert-deftest cl-case-warning () + "Test that `cl-case' and `cl-ecase' warn about suspicious +constructs." + (pcase-dolist (`(,case . ,message) + `((nil . "Case nil will never match") + ('nil . ,(concat "Case 'nil will match `quote'. " + "If that's intended, write " + "(nil quote) instead. " + "Otherwise, don't quote `nil'.")) + ('t . ,(concat "Case 't will match `quote'. " + "If that's intended, write " + "(t quote) instead. " + "Otherwise, don't quote `t'.")) + ('foo . ,(concat "Case 'foo will match `quote'. " + "If that's intended, write " + "(foo quote) instead. " + "Otherwise, don't quote `foo'.")) + (#'foo . ,(concat "Case #'foo will match " + "`function'. If that's " + "intended, write (foo function) " + "instead. Otherwise, don't " + "quote `foo'.")))) + (dolist (macro '(cl-case cl-ecase)) + (let ((form `(,macro val (,case 1)))) + (ert-info ((prin1-to-string form) :prefix "Form: ") + (ert-with-message-capture messages + (macroexpand form) + (should (equal messages + (concat "Warning: " message "\n"))))))))) + ;;; cl-macs-tests.el ends here |