summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Kangas <stefan@marxist.se>2020-11-22 07:19:11 +0100
committerStefan Kangas <stefan@marxist.se>2020-11-22 07:19:11 +0100
commit9490f12c4dc4deb16f4e900646319f6de033982c (patch)
treee6d5264ae011226fa458406702c0a39aeb4d8fa4
parentb6339fc19c378d66ce1bc53499552dfaa3c0c8c0 (diff)
downloademacs-9490f12c4dc4deb16f4e900646319f6de033982c.tar.gz
emacs-9490f12c4dc4deb16f4e900646319f6de033982c.tar.bz2
emacs-9490f12c4dc4deb16f4e900646319f6de033982c.zip
Test for byte-compiler warning "variable lacks prefix"
* test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp--with-warning-test): New macro. (bytecomp-warn-wrong-args, bytecomp-warn-wrong-args-subr): Use above new macro. (bytecomp-warn-variable-lacks-prefix): New test.
-rw-r--r--test/lisp/emacs-lisp/bytecomp-tests.el26
1 files changed, 16 insertions, 10 deletions
diff --git a/test/lisp/emacs-lisp/bytecomp-tests.el b/test/lisp/emacs-lisp/bytecomp-tests.el
index e0a3cc2fb82..680aa514a27 100644
--- a/test/lisp/emacs-lisp/bytecomp-tests.el
+++ b/test/lisp/emacs-lisp/bytecomp-tests.el
@@ -516,19 +516,25 @@ Subtests signal errors if something goes wrong."
;; Should not warn that mt--test2 is not known to be defined.
(should-not (re-search-forward "my--test2" nil t))))
+(defmacro bytecomp--with-warning-test (re-warning &rest form)
+ (declare (indent 1))
+ `(with-current-buffer (get-buffer-create "*Compile-Log*")
+ (let ((inhibit-read-only t)) (erase-buffer))
+ (byte-compile ,@form)
+ (ert-info ((buffer-string) :prefix "buffer: ")
+ (should (re-search-forward ,re-warning)))))
+
(ert-deftest bytecomp-warn-wrong-args ()
- (with-current-buffer (get-buffer-create "*Compile-Log*")
- (let ((inhibit-read-only t)) (erase-buffer))
- (byte-compile '(remq 1 2 3))
- (ert-info ((buffer-string) :prefix "buffer: ")
- (should (re-search-forward "remq.*3.*2")))))
+ (bytecomp--with-warning-test "remq.*3.*2"
+ '(remq 1 2 3)))
(ert-deftest bytecomp-warn-wrong-args-subr ()
- (with-current-buffer (get-buffer-create "*Compile-Log*")
- (let ((inhibit-read-only t)) (erase-buffer))
- (byte-compile '(safe-length 1 2 3))
- (ert-info ((buffer-string) :prefix "buffer: ")
- (should (re-search-forward "safe-length.*3.*1")))))
+ (bytecomp--with-warning-test "safe-length.*3.*1"
+ '(safe-length 1 2 3)))
+
+(ert-deftest bytecomp-warn-variable-lacks-prefix ()
+ (bytecomp--with-warning-test "foo.*lacks a prefix"
+ '(defvar foo nil)))
(ert-deftest test-eager-load-macro-expansion ()
(test-byte-comp-compile-and-load nil