aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/lisp/emacs-lisp/bytecomp-tests.el90
1 files changed, 90 insertions, 0 deletions
diff --git a/test/lisp/emacs-lisp/bytecomp-tests.el b/test/lisp/emacs-lisp/bytecomp-tests.el
index 83162d250fc..6fe7f5b571d 100644
--- a/test/lisp/emacs-lisp/bytecomp-tests.el
+++ b/test/lisp/emacs-lisp/bytecomp-tests.el
@@ -686,6 +686,96 @@ literals (Bug#20852)."
686 (should-not (member '(byte-constant 333) lap)) 686 (should-not (member '(byte-constant 333) lap))
687 (should (member '(byte-constant 444) lap))))) 687 (should (member '(byte-constant 444) lap)))))
688 688
689(defun test-suppression (form suppress match)
690 (let ((lexical-binding t)
691 (byte-compile-log-buffer (generate-new-buffer " *Compile-Log*")))
692 ;; Check that we get a warning without suppression.
693 (with-current-buffer byte-compile-log-buffer
694 (let ((inhibit-read-only t))
695 (erase-buffer)))
696 (test-byte-comp-compile-and-load t form)
697 (with-current-buffer byte-compile-log-buffer
698 (unless match
699 (error "%s" (buffer-string)))
700 (goto-char (point-min))
701 (should (re-search-forward match nil t)))
702 ;; And that it's gone now.
703 (with-current-buffer byte-compile-log-buffer
704 (let ((inhibit-read-only t))
705 (erase-buffer)))
706 (test-byte-comp-compile-and-load t
707 `(with-suppressed-warnings ,suppress
708 ,form))
709 (with-current-buffer byte-compile-log-buffer
710 (goto-char (point-min))
711 (should-not (re-search-forward match nil t)))
712 ;; Also check that byte compiled forms are identical.
713 (should (equal (byte-compile form)
714 (byte-compile
715 `(with-suppressed-warnings ,suppress ,form))))))
716
717(ert-deftest bytecomp-test--with-suppressed-warnings ()
718 (test-suppression
719 '(defvar prefixless)
720 '((lexical prefixless))
721 "global/dynamic var .prefixless. lacks")
722
723 (test-suppression
724 '(defun foo()
725 (let ((nil t))
726 (message-mail)))
727 '((constants nil))
728 "Warning: attempt to let-bind constant .nil.")
729
730 (test-suppression
731 '(progn
732 (defun obsolete ()
733 (declare (obsolete foo "22.1")))
734 (defun zot ()
735 (obsolete)))
736 '((obsolete obsolete))
737 "Warning: .obsolete. is an obsolete function")
738
739 (test-suppression
740 '(progn
741 (defun wrong-params (foo &optional unused)
742 (ignore unused)
743 foo)
744 (defun zot ()
745 (wrong-params 1 2 3)))
746 '((callargs wrong-params))
747 "Warning: wrong-params called with")
748
749 (test-byte-comp-compile-and-load nil
750 (defvar obsolete-variable nil)
751 (make-obsolete-variable 'obsolete-variable nil "24.1"))
752 (test-suppression
753 '(defun zot ()
754 obsolete-variable)
755 '((obsolete obsolete-variable))
756 "obsolete")
757
758 (test-suppression
759 '(defun zot ()
760 (mapcar #'list '(1 2 3))
761 nil)
762 '((mapcar mapcar))
763 "Warning: .mapcar. called for effect")
764
765 (test-suppression
766 '(defun zot ()
767 free-variable)
768 '((free-vars free-variable))
769 "Warning: reference to free variable")
770
771 (test-suppression
772 '(defun zot ()
773 (save-excursion
774 (set-buffer (get-buffer-create "foo"))
775 nil))
776 '((suspicious set-buffer))
777 "Warning: Use .with-current-buffer. rather than"))
778
689;; Local Variables: 779;; Local Variables:
690;; no-byte-compile: t 780;; no-byte-compile: t
691;; End: 781;; End: