aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorPhilipp Stephani2022-09-13 17:12:57 +0200
committerLars Ingebrigtsen2022-09-13 17:12:57 +0200
commitfffa53ff1afe097fe38f7664df5debe9811201d1 (patch)
treecdc34b558e9b4684b8362706a75a5a2d563f1ec8 /test
parent6d8f5161ead689b7a2e44a7de0a695f0ab4c833b (diff)
downloademacs-fffa53ff1afe097fe38f7664df5debe9811201d1.tar.gz
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')
-rw-r--r--test/lisp/emacs-lisp/cl-macs-tests.el32
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 @@
25(require 'cl-macs) 25(require 'cl-macs)
26(require 'edebug) 26(require 'edebug)
27(require 'ert) 27(require 'ert)
28(require 'ert-x)
29(require 'pcase)
28 30
29 31
30;;;; cl-loop tests -- many adapted from Steele's CLtL2 32;;;; cl-loop tests -- many adapted from Steele's CLtL2
@@ -758,4 +760,34 @@ collection clause."
758 (should (equal (cdr error) 760 (should (equal (cdr error)
759 '("Misplaced t or `otherwise' clause"))))))) 761 '("Misplaced t or `otherwise' clause")))))))
760 762
763(ert-deftest cl-case-warning ()
764 "Test that `cl-case' and `cl-ecase' warn about suspicious
765constructs."
766 (pcase-dolist (`(,case . ,message)
767 `((nil . "Case nil will never match")
768 ('nil . ,(concat "Case 'nil will match `quote'. "
769 "If that's intended, write "
770 "(nil quote) instead. "
771 "Otherwise, don't quote `nil'."))
772 ('t . ,(concat "Case 't will match `quote'. "
773 "If that's intended, write "
774 "(t quote) instead. "
775 "Otherwise, don't quote `t'."))
776 ('foo . ,(concat "Case 'foo will match `quote'. "
777 "If that's intended, write "
778 "(foo quote) instead. "
779 "Otherwise, don't quote `foo'."))
780 (#'foo . ,(concat "Case #'foo will match "
781 "`function'. If that's "
782 "intended, write (foo function) "
783 "instead. Otherwise, don't "
784 "quote `foo'."))))
785 (dolist (macro '(cl-case cl-ecase))
786 (let ((form `(,macro val (,case 1))))
787 (ert-info ((prin1-to-string form) :prefix "Form: ")
788 (ert-with-message-capture messages
789 (macroexpand form)
790 (should (equal messages
791 (concat "Warning: " message "\n")))))))))
792
761;;; cl-macs-tests.el ends here 793;;; cl-macs-tests.el ends here