1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

Silence byte-compiler in some tests

* test/lisp/dired-tests.el:
* test/lisp/emacs-lisp/cl-macs-tests.el:
* test/lisp/emacs-lisp/derived-tests.el:
* test/lisp/emacs-lisp/eieio-tests/eieio-tests.el:
* test/lisp/emacs-lisp/generator-tests.el:
* test/lisp/emacs-lisp/lisp-tests.el:
* test/lisp/emacs-lisp/seq-tests.el (test-seq-let)
(test-seq-setq):
* test/lisp/emacs-lisp/subr-x-tests.el (subr-x-test-if-let*-false)
(subr-x-test-if-let*-and-laziness-is-preserved)
(subr-x-test-when-let*-false)
(subr-x-test-when-let*-and-laziness-is-preserved):
* test/lisp/emacs-lisp/timer-tests.el
(timer-tests-debug-timer-check):
* test/lisp/format-spec-tests.el (format-spec-do-flags-truncate)
(format-spec-do-flags-pad):
* test/lisp/ls-lisp-tests.el (ls-lisp-test-bug27762):
* test/lisp/obsolete/cl-tests.el (labels-function-quoting):
* test/lisp/progmodes/elisp-mode-tests.el:
* test/lisp/replace-tests.el (replace-regexp-bug45973):
* test/lisp/ses-tests.el:
* test/lisp/subr-tests.el:
* test/lisp/tar-mode-tests.el (tar-mode-test-tar-grind-file-mode):
* test/src/data-tests.el (data-tests--set-default-per-buffer):
* test/src/search-tests.el
(test-replace-match-modification-hooks): Silence byte-compiler.
This commit is contained in:
Stefan Kangas 2021-12-04 15:49:42 +01:00
parent aa6681a51a
commit 7c68c84674
19 changed files with 152 additions and 101 deletions

View file

@ -543,10 +543,12 @@ path's data to use."
((equal "." path) default-directory)
(path)))
(return-size
(car (files-tests--look-up-free-data path))))
;; It is always defined but this silences the byte-compiler:
(when (fboundp 'files-tests--look-up-free-data)
(car (files-tests--look-up-free-data path)))))
(list return-size return-size return-size))))
(defun files-tests--insert-directory-output (dir &optional verbose)
(defun files-tests--insert-directory-output (dir &optional _verbose)
"Run `insert-directory' and return its output."
(with-current-buffer-window "files-tests--insert-directory" nil nil
(let ((dired-free-space 'separate))
@ -555,35 +557,46 @@ path's data to use."
(ert-deftest files-tests-insert-directory-shows-files ()
"Verify `insert-directory' reports the files in the directory."
;; It is always defined but this silences the byte-compiler:
(when (fboundp 'files-tests--insert-directory-output)
(let* ((test-dir (car test-files))
(files (cdr test-files))
(output (files-tests--insert-directory-output test-dir)))
(dolist (file files)
(should (string-match-p file output)))))
(should (string-match-p file output))))))
(defun files-tests--insert-directory-shows-given-free (dir &optional
info-func)
"Run `insert-directory' and verify it reports the correct available space.
Stub `file-system-info' to ensure the available space is consistent,
either with the given stub function or a default one using test data."
;; It is always defined but this silences the byte-compiler:
(when (and (fboundp 'files-tests--make-file-system-info-stub)
(fboundp 'files-tests--look-up-free-data)
(fboundp 'files-tests--insert-directory-output))
(cl-letf (((symbol-function 'file-system-info)
(or info-func
(files-tests--make-file-system-info-stub))))
(should (string-match-p (cadr
(files-tests--look-up-free-data dir))
(files-tests--insert-directory-output dir t)))))
(files-tests--insert-directory-output dir t))))))
(ert-deftest files-tests-insert-directory-shows-free ()
"Test that verbose `insert-directory' shows the correct available space."
;; It is always defined but this silences the byte-compiler:
(when (and (fboundp 'files-tests--insert-directory-shows-given-free)
(fboundp 'files-tests--make-file-system-info-stub))
(files-tests--insert-directory-shows-given-free
test-dir
(files-tests--make-file-system-info-stub test-dir)))
(files-tests--make-file-system-info-stub test-dir))))
(ert-deftest files-tests-bug-50630 ()
"Verify verbose `insert-directory' shows free space of the target directory.
The current directory at call time should not affect the result (Bug#50630)."
;; It is always defined but this silences the byte-compiler:
(when (fboundp 'files-tests--insert-directory-shows-given-free)
(let ((default-directory test-dir-other))
(files-tests--insert-directory-shows-given-free test-dir))))
(files-tests--insert-directory-shows-given-free test-dir)))))
(provide 'dired-tests)
;;; dired-tests.el ends here

View file

@ -668,6 +668,10 @@ collection clause."
#'len))
(`(function (lambda (,_ ,_) . ,_)) t))))
(with-suppressed-warnings ((lexical test) (lexical test1) (lexical test2))
(defvar test)
(defvar test1)
(defvar test2))
(ert-deftest cl-macs--progv ()
(should (= (cl-progv '(test test) '(1 2) test) 2))
(should (equal (cl-progv '(test1 test2) '(1 2) (list test1 test2))

View file

@ -24,13 +24,13 @@
(define-derived-mode derived-tests--parent-mode prog-mode "P"
:after-hook
(let ((f (let ((x "S")) (lambda () x))))
(insert (format "AFP=%s " (let ((x "D")) (funcall f)))))
(insert (format "AFP=%s " (let ((x "D")) x (funcall f)))))
(insert "PB "))
(define-derived-mode derived-tests--child-mode derived-tests--parent-mode "C"
:after-hook
(let ((f (let ((x "S")) (lambda () x))))
(insert (format "AFC=%s " (let ((x "D")) (funcall f)))))
(insert (format "AFC=%s " (let ((x "D")) x (funcall f)))))
(insert "CB "))
(ert-deftest derived-tests-after-hook-lexical ()

View file

@ -172,7 +172,7 @@
;; Check that generic-p works
(should (generic-p 'generic1))
(defmethod generic1 ((c class-a))
(defmethod generic1 ((_c class-a))
"Method on generic1."
'monkey)
@ -240,12 +240,12 @@ Argument C is the class bound to this static method."
(should (make-instance 'class-a :water 'cho))
(should (make-instance 'class-b)))
(defmethod class-cn ((a class-a))
(defmethod class-cn ((_a class-a))
"Try calling `call-next-method' when there isn't one.
Argument A is object of type symbol `class-a'."
(call-next-method))
(defmethod no-next-method ((a class-a) &rest args)
(defmethod no-next-method ((_a class-a) &rest _args)
"Override signal throwing for variable `class-a'.
Argument A is the object of class variable `class-a'."
'moose)
@ -254,7 +254,7 @@ Argument A is the object of class variable `class-a'."
;; Play with call-next-method
(should (eq (class-cn eitest-ab) 'moose)))
(defmethod no-applicable-method ((b class-b) method &rest args)
(defmethod no-applicable-method ((_b class-b) _method &rest _args)
"No need.
Argument B is for booger.
METHOD is the method that was attempting to be called."
@ -264,38 +264,38 @@ METHOD is the method that was attempting to be called."
;; Non-existing methods.
(should (eq (class-cn eitest-b) 'moose)))
(defmethod class-fun ((a class-a))
(defmethod class-fun ((_a class-a))
"Fun with class A."
'moose)
(defmethod class-fun ((b class-b))
(defmethod class-fun ((_b class-b))
"Fun with class B."
(error "Class B fun should not be called")
)
(defmethod class-fun-foo ((b class-b))
(defmethod class-fun-foo ((_b class-b))
"Foo Fun with class B."
'moose)
(defmethod class-fun2 ((a class-a))
(defmethod class-fun2 ((_a class-a))
"More fun with class A."
'moose)
(defmethod class-fun2 ((b class-b))
(defmethod class-fun2 ((_b class-b))
"More fun with class B."
(error "Class B fun2 should not be called")
)
(defmethod class-fun2 ((ab class-ab))
(defmethod class-fun2 ((_ab class-ab))
"More fun with class AB."
(call-next-method))
;; How about if B is the only slot?
(defmethod class-fun3 ((b class-b))
(defmethod class-fun3 ((_b class-b))
"Even More fun with class B."
'moose)
(defmethod class-fun3 ((ab class-ab))
(defmethod class-fun3 ((_ab class-ab))
"Even More fun with class AB."
(call-next-method))
@ -314,17 +314,17 @@ METHOD is the method that was attempting to be called."
(defvar class-fun-value-seq '())
(defmethod class-fun-value :BEFORE ((a class-a))
(defmethod class-fun-value :BEFORE ((_a class-a))
"Return `before', and push `before' in `class-fun-value-seq'."
(push 'before class-fun-value-seq)
'before)
(defmethod class-fun-value :PRIMARY ((a class-a))
(defmethod class-fun-value :PRIMARY ((_a class-a))
"Return `primary', and push `primary' in `class-fun-value-seq'."
(push 'primary class-fun-value-seq)
'primary)
(defmethod class-fun-value :AFTER ((a class-a))
(defmethod class-fun-value :AFTER ((_a class-a))
"Return `after', and push `after' in `class-fun-value-seq'."
(push 'after class-fun-value-seq)
'after)
@ -343,14 +343,14 @@ METHOD is the method that was attempting to be called."
;;
(ert-deftest eieio-test-13-init-methods ()
(defmethod initialize-instance ((a class-a) &rest slots)
(defmethod initialize-instance ((a class-a) &rest _slots)
"Initialize the slots of class-a."
(call-next-method)
(if (/= (oref a test-tag) 1)
(error "shared-initialize test failed."))
(oset a test-tag 2))
(defmethod shared-initialize ((a class-a) &rest slots)
(defmethod shared-initialize ((a class-a) &rest _slots)
"Shared initialize method for class-a."
(call-next-method)
(oset a test-tag 1))
@ -369,7 +369,7 @@ METHOD is the method that was attempting to be called."
(ert-deftest eieio-test-15-slot-missing ()
(defmethod slot-missing ((ab class-ab) &rest foo)
(defmethod slot-missing ((_ab class-ab) &rest _foo)
"If a slot in AB is unbound, return something cool. FOO."
'moose)
@ -425,7 +425,7 @@ METHOD is the method that was attempting to be called."
(ert-deftest eieio-test-18-slot-unbound ()
(defmethod slot-unbound ((a class-a) &rest foo)
(defmethod slot-unbound ((_a class-a) &rest _foo)
"If a slot in A is unbound, ignore FOO."
'moose)
@ -448,7 +448,7 @@ METHOD is the method that was attempting to be called."
(should (eq (oref (class-a) water) 'penguin))
;; Revert the above
(defmethod slot-unbound ((a class-a) &rest foo)
(defmethod slot-unbound ((_a class-a) &rest _foo)
"If a slot in A is unbound, ignore FOO."
;; Disable the old slot-unbound so we can run this test
;; more than once

View file

@ -74,7 +74,7 @@ identical output."
(cps-testcase cps-prog1-b (prog1 1))
(cps-testcase cps-prog1-c (prog2 1 2 3))
(cps-testcase cps-quote (progn 'hello))
(cps-testcase cps-function (progn #'hello))
(cps-testcase cps-function (progn #'message))
(cps-testcase cps-and-fail (and 1 nil 2))
(cps-testcase cps-and-succeed (and 1 2 3))
@ -307,6 +307,7 @@ identical output."
(1+ it)))))))
-2)))
(defun generator-tests-edebug ()) ; silence byte-compiler
(ert-deftest generator-tests-edebug ()
"Check that Bug#40434 is fixed."
(with-temp-buffer

View file

@ -213,6 +213,7 @@
(should-error (forward-sexp)))) ;; FIXME: Shouldn't be an error.
;; Test some core Elisp rules.
(defvar c-e-x)
(ert-deftest core-elisp-tests-1-defvar-in-let ()
"Test some core Elisp rules."
(with-temp-buffer

View file

@ -172,17 +172,23 @@ Evaluate BODY for each created sequence.
(should-not (seq-find #'null '(1 2 3)))
(should (seq-find #'null '(1 2 3) 'sentinel)))
;; Hack to work around the ERT limitation that we can't reliably use
;; `with-suppressed-warnings' inside an `ert-deftest'. (Bug#36568)
(defun seq--contains (&rest args)
(with-suppressed-warnings ((obsolete seq-contains))
(apply #'seq-contains args)))
(ert-deftest test-seq-contains ()
(with-test-sequences (seq '(3 4 5 6))
(should (seq-contains seq 3))
(should-not (seq-contains seq 7)))
(should (seq--contains seq 3))
(should-not (seq--contains seq 7)))
(with-test-sequences (seq '())
(should-not (seq-contains seq 3))
(should-not (seq-contains seq nil))))
(should-not (seq--contains seq 3))
(should-not (seq--contains seq nil))))
(ert-deftest test-seq-contains-should-return-the-elt ()
(with-test-sequences (seq '(3 4 5 6))
(should (= 5 (seq-contains seq 5)))))
(should (= 5 (seq--contains seq 5)))))
(ert-deftest test-seq-contains-p ()
(with-test-sequences (seq '(3 4 5 6))
@ -404,7 +410,7 @@ Evaluate BODY for each created sequence.
(let ((seq '(1 (2 (3 (4))))))
(seq-let (_ (_ (_ (a)))) seq
(should (= a 4))))
(let (seq)
(let ((seq nil))
(seq-let (a b c) seq
(should (null a))
(should (null b))
@ -428,7 +434,7 @@ Evaluate BODY for each created sequence.
(seq '(1 (2 (3 (4))))))
(seq-setq (_ (_ (_ (a)))) seq)
(should (= a 4)))
(let (seq a b c)
(let ((seq nil) a b c)
(seq-setq (a b c) seq)
(should (null a))
(should (null b))

View file

@ -169,13 +169,13 @@
"no")
"no"))
(should (equal
(let (z)
(let ((z nil))
(if-let* (z (a 1) (b 2) (c 3))
"yes"
"no"))
"no"))
(should (equal
(let (d)
(let ((d nil))
(if-let* ((a 1) (b 2) (c 3) d)
"yes"
"no"))
@ -191,7 +191,7 @@
(ert-deftest subr-x-test-if-let*-and-laziness-is-preserved ()
"Test `if-let' respects `and' laziness."
(let (a-called b-called c-called)
(let ((a-called nil) (b-called nil) c-called)
(should (equal
(if-let* ((a nil)
(b (setq b-called t))
@ -199,7 +199,7 @@
"yes"
(list a-called b-called c-called))
(list nil nil nil))))
(let (a-called b-called c-called)
(let ((a-called nil) (b-called nil) c-called)
(should (equal
(if-let* ((a (setq a-called t))
(b nil)
@ -207,7 +207,7 @@
"yes"
(list a-called b-called c-called))
(list t nil nil))))
(let (a-called b-called c-called)
(let ((a-called nil) (b-called nil) c-called)
(should (equal
(if-let* ((a (setq a-called t))
(b (setq b-called t))
@ -329,12 +329,12 @@
"no")
nil))
(should (equal
(let (z)
(let ((z nil))
(when-let* (z (a 1) (b 2) (c 3))
"no"))
nil))
(should (equal
(let (d)
(let ((d nil))
(when-let* ((a 1) (b 2) (c 3) d)
"no"))
nil)))
@ -348,7 +348,7 @@
(ert-deftest subr-x-test-when-let*-and-laziness-is-preserved ()
"Test `when-let' respects `and' laziness."
(let (a-called b-called c-called)
(let ((a-called nil) (b-called nil) (c-called nil))
(should (equal
(progn
(when-let* ((a nil)
@ -357,7 +357,7 @@
"yes")
(list a-called b-called c-called))
(list nil nil nil))))
(let (a-called b-called c-called)
(let ((a-called nil) (b-called nil) (c-called nil))
(should (equal
(progn
(when-let* ((a (setq a-called t))
@ -366,7 +366,7 @@
"yes")
(list a-called b-called c-called))
(list t nil nil))))
(let (a-called b-called c-called)
(let ((a-called nil) (b-called nil) (c-called nil))
(should (equal
(progn
(when-let* ((a (setq a-called t))

View file

@ -37,7 +37,8 @@
(ert-deftest timer-tests-debug-timer-check ()
;; This function exists only if --enable-checking.
(skip-unless (fboundp 'debug-timer-check))
(should (debug-timer-check)))
(when (fboundp 'debug-timer-check) ; silence byte-compiler
(should (debug-timer-check))))
(ert-deftest timer-test-multiple-of-time ()
(should (time-equal-p

View file

@ -56,7 +56,7 @@
(ert-deftest format-spec-do-flags-truncate ()
"Test `format-spec--do-flags' truncation."
(let (flags)
(let ((flags nil))
(should (equal (format-spec--do-flags "" flags nil 0) ""))
(should (equal (format-spec--do-flags "" flags nil 1) ""))
(should (equal (format-spec--do-flags "a" flags nil 0) ""))
@ -75,7 +75,7 @@
(ert-deftest format-spec-do-flags-pad ()
"Test `format-spec--do-flags' padding."
(let (flags)
(let ((flags nil))
(should (equal (format-spec--do-flags "" flags 0 nil) ""))
(should (equal (format-spec--do-flags "" flags 1 nil) " "))
(should (equal (format-spec--do-flags "a" flags 0 nil) "a"))

View file

@ -54,7 +54,8 @@
(kill-buffer buf)
(setq buf (dired (nconc (list dir) files)))
(should (looking-at "src"))
(next-line) ; File names must be aligned.
(with-suppressed-warnings ((interactive-only next-line))
(next-line)) ; File names must be aligned.
(should (looking-at "src")))
(when (buffer-live-p buf) (kill-buffer buf)))))

View file

@ -27,10 +27,15 @@
;; Hack to work around the ERT limitation that we can't reliably use
;; `with-suppressed-warnings' inside an `ert-deftest'. (Bug#36568)
(defun cl-tests-labels-test ()
(with-suppressed-warnings ((obsolete labels))
(funcall (labels ((foo () t))
#'foo))))
(ert-deftest labels-function-quoting ()
"Test that #'foo does the right thing in `labels'." ; Bug#31792.
(should (eq (funcall (labels ((foo () t))
#'foo))
t)))
(should (eq (cl-tests-labels-test) t)))
;;; cl-tests.el ends here

View file

@ -438,7 +438,8 @@ to (xref-elisp-test-descr-to-target xref)."
;; track down the problem.
(cl-defmethod xref-elisp-generic-no-default ((this xref-elisp-root-type) arg2)
"Doc string generic no-default xref-elisp-root-type."
"non-default for no-default")
"non-default for no-default"
(list this arg2)) ; silence byte-compiler
;; defgeneric after defmethod in file to ensure the fallback search
;; method of just looking for the function name will fail.
@ -463,19 +464,23 @@ to (xref-elisp-test-descr-to-target xref)."
(cl-defmethod xref-elisp-generic-separate-default (arg1 arg2)
"Doc string generic separate-default default."
"separate default")
"separate default"
(list arg1 arg2)) ; silence byte-compiler
(cl-defmethod xref-elisp-generic-separate-default ((this xref-elisp-root-type) arg2)
"Doc string generic separate-default xref-elisp-root-type."
"non-default for separate-default")
"non-default for separate-default"
(list this arg2)) ; silence byte-compiler
(cl-defmethod xref-elisp-generic-implicit-generic (arg1 arg2)
"Doc string generic implicit-generic default."
"default for implicit generic")
"default for implicit generic"
(list arg1 arg2)) ; silence byte-compiler
(cl-defmethod xref-elisp-generic-implicit-generic ((this xref-elisp-root-type) arg2)
"Doc string generic implicit-generic xref-elisp-root-type."
"non-default for implicit generic")
"non-default for implicit generic"
(list this arg2)) ; silence byte-compiler
(xref-elisp-deftest find-defs-defgeneric-no-methods
@ -845,7 +850,8 @@ to (xref-elisp-test-descr-to-target xref)."
(if (stringp form)
(insert form)
(pp form (current-buffer)))
(font-lock-debug-fontify)
(with-suppressed-warnings ((interactive-only font-lock-debug-fontify))
(font-lock-debug-fontify))
(goto-char (point-min))
(and (re-search-forward search nil t)
(get-text-property (match-beginning 1) 'face))))

View file

@ -599,11 +599,12 @@ bound to HIGHLIGHT-LOCUS."
(with-temp-buffer
(insert before)
(goto-char (point-min))
(with-suppressed-warnings ((interactive-only replace-regexp))
(replace-regexp
"\\(\\(L\\)\\|\\(R\\)\\)"
'(replace-eval-replacement
replace-quote
(if (match-string 2) "R" "L")))
(if (match-string 2) "R" "L"))))
(should (equal (buffer-string) after)))))
(ert-deftest test-count-matches ()

View file

@ -24,6 +24,10 @@
(require 'ert)
(require 'ses)
;; Silence byte-compiler.
(with-suppressed-warnings ((lexical A2) (lexical A3))
(defvar A2)
(defvar A3))
;; PLAIN FORMULA TESTS
;; ======================================================================

View file

@ -926,6 +926,7 @@ See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=19350."
(should-not (apropos-internal "^next-line$" #'keymapp)))
(defvar test-global-boundp)
(ert-deftest test-buffer-local-boundp ()
(let ((buf (generate-new-buffer "boundp")))
(with-current-buffer buf

View file

@ -24,6 +24,12 @@
(defvar tar-mode-tests-data-directory
(expand-file-name "test/data/decompress" source-directory))
;; Hack to work around the ERT limitation that we can't reliably use
;; `with-suppressed-warnings' inside an `ert-deftest'. (Bug#36568)
(defun tar-mode-tests--tar-grind-file-mode (&rest args)
(with-suppressed-warnings ((obsolete tar-grind-file-mode))
(apply #'tar-grind-file-mode args)))
(ert-deftest tar-mode-test-tar-grind-file-mode ()
(let ((alist (list (cons 448 "rwx------")
(cons 420 "rw-r--r--")
@ -32,7 +38,7 @@
(cons 1024 "-----S---")
(cons 2048 "--S------"))))
(dolist (x alist)
(should (equal (cdr x) (tar-grind-file-mode (car x)))))))
(should (equal (cdr x) (tar-mode-tests--tar-grind-file-mode (car x)))))))
(ert-deftest tar-mode-test-tar-extract-gz ()
(skip-unless (executable-find "gzip"))

View file

@ -433,6 +433,7 @@ comparing the subr with a much slower Lisp implementation."
;; More specifically, test the problem seen in bug#41029 where setting
;; the default value of a variable takes time proportional to the
;; number of buffers.
(when (fboundp 'current-cpu-time) ; silence byte-compiler
(let* ((fun #'error)
(test (lambda ()
(with-temp-buffer
@ -452,7 +453,7 @@ comparing the subr with a much slower Lisp implementation."
(time2 (funcall test)))
(mapc #'kill-buffer bufs)
;; Don't divide one time by the other since they may be 0.
(should (< time2 (* time1 5)))))
(should (< time2 (* time1 5))))))
;; More tests to write -
;; kill-local-variable

View file

@ -28,7 +28,7 @@
(setq ov-set (make-overlay 3 5))
(overlay-put
ov-set 'modification-hooks
(list (lambda (o after &rest _args)
(list (lambda (_o after &rest _args)
(when after
(let ((inhibit-modification-hooks t))
(save-excursion