diff options
| author | Lars Ingebrigtsen | 2019-06-12 15:59:19 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2019-06-12 15:59:19 +0200 |
| commit | f2071b6de417ea079ab55298e8ca8f7bb2ad8d14 (patch) | |
| tree | bbdc2892ff80632a5ffbfda98eb2ff7f20f8131e /test | |
| parent | b8350e52ef6201103b12db5ad8b9268452feb8b6 (diff) | |
| download | emacs-f2071b6de417ea079ab55298e8ca8f7bb2ad8d14.tar.gz emacs-f2071b6de417ea079ab55298e8ca8f7bb2ad8d14.zip | |
Add the new macro with-suppressed-warnings
* lisp/emacs-lisp/byte-run.el (with-suppressed-warnings): New macro.
* doc/lispref/compile.texi (Compiler Errors): Document
with-suppressed-warnings and deemphasise with-no-warnings
slightly.
* lisp/emacs-lisp/bytecomp.el (byte-compile--suppressed-warnings):
New internal variable.
(byte-compile-warning-enabled-p): Heed
byte-compile--suppressed-warnings, bound via with-suppressed-warnings.
(byte-compile-initial-macro-environment): Provide a macro
expansion of with-suppressed-warnings.
(byte-compile-file-form-with-suppressed-warnings): New byte hunk
handler for the suppressed symbol machinery.
(byte-compile-suppressed-warnings): Ditto for the byteop.
(byte-compile-file-form-defmumble): Ditto.
(byte-compile-form, byte-compile-normal-call)
(byte-compile-normal-call, byte-compile-variable-ref)
(byte-compile-set-default, byte-compile-variable-set)
(byte-compile-function-form, byte-compile-set-default)
(byte-compile-warn-obsolete, byte-compile--declare-var): Pass the
symbol being warned in to byte-compile-warning-enabled-p.
* test/lisp/emacs-lisp/bytecomp-tests.el (test-suppression): New
function.
(bytecomp-test--with-suppressed-warnings): Tests.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/emacs-lisp/bytecomp-tests.el | 90 |
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: |