aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorSimen Heggestøyl2020-05-03 19:49:55 +0200
committerSimen Heggestøyl2020-05-03 19:50:57 +0200
commit7db0093bc2c2ae3470167eb7490b69baa1904052 (patch)
tree176d3cdacbc51cd3f89adbf86a12655cdf2bfb2c /test
parent82c506192b5ae1a454dccfae2f41fa3ee6d5e990 (diff)
downloademacs-7db0093bc2c2ae3470167eb7490b69baa1904052.tar.gz
emacs-7db0093bc2c2ae3470167eb7490b69baa1904052.zip
Use lexical-binding in check-declare.el and add tests
* lisp/emacs-lisp/check-declare.el: Use lexical-binding. (check-declare-warn): Silence byte compiler warning about unused lexical argument. * test/lisp/emacs-lisp/check-declare-tests.el: New file with tests for check-declare.el.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/emacs-lisp/check-declare-tests.el116
1 files changed, 116 insertions, 0 deletions
diff --git a/test/lisp/emacs-lisp/check-declare-tests.el b/test/lisp/emacs-lisp/check-declare-tests.el
new file mode 100644
index 00000000000..bb9542114c4
--- /dev/null
+++ b/test/lisp/emacs-lisp/check-declare-tests.el
@@ -0,0 +1,116 @@
1;;; check-declare-tests.el --- Tests for check-declare.el -*- lexical-binding: t; -*-
2
3;; Copyright (C) 2020 Free Software Foundation, Inc.
4
5;; Author: Simen Heggestøyl <simenheg@gmail.com>
6;; Keywords:
7
8;; This file is part of GNU Emacs.
9
10;; GNU Emacs is free software: you can redistribute it and/or modify
11;; it under the terms of the GNU General Public License as published by
12;; the Free Software Foundation, either version 3 of the License, or
13;; (at your option) any later version.
14
15;; GNU Emacs is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
21;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
22
23;;; Commentary:
24
25;;
26
27;;; Code:
28
29(require 'check-declare)
30(require 'ert)
31(eval-when-compile (require 'subr-x))
32
33(ert-deftest check-declare-tests-locate ()
34 (should (file-exists-p (check-declare-locate "check-declare" "")))
35 (should
36 (string-prefix-p "ext:" (check-declare-locate "ext:foo" ""))))
37
38(ert-deftest check-declare-tests-scan ()
39 (let ((file (make-temp-file "check-declare-tests-")))
40 (unwind-protect
41 (progn
42 (with-temp-file file
43 (insert
44 (string-join
45 '(";; foo comment"
46 "(declare-function ring-insert \"ring\" (ring item))"
47 "(let ((foo 'code)) foo)")
48 "\n")))
49 (let ((res (check-declare-scan file)))
50 (should (= (length res) 1))
51 (pcase-let ((`((,fnfile ,fn ,arglist ,fileonly)) res))
52 (should (string-match-p "ring" fnfile))
53 (should (equal "ring-insert" fn))
54 (should (equal '(ring item) arglist))
55 (should-not fileonly))))
56 (delete-file file))))
57
58(ert-deftest check-declare-tests-verify ()
59 (let ((file (make-temp-file "check-declare-tests-")))
60 (unwind-protect
61 (progn
62 (with-temp-file file
63 (insert
64 (string-join
65 '(";; foo comment"
66 "(defun foo-fun ())"
67 "(defun ring-insert (ring item)"
68 "\"Insert onto ring RING the item ITEM.\""
69 "nil)")
70 "\n")))
71 (should-not
72 (check-declare-verify
73 file '(("foo.el" "ring-insert" (ring item))))))
74 (delete-file file))))
75
76(ert-deftest check-declare-tests-verify-mismatch ()
77 (let ((file (make-temp-file "check-declare-tests-")))
78 (unwind-protect
79 (progn
80 (with-temp-file file
81 (insert
82 (string-join
83 '(";; foo comment"
84 "(defun foo-fun ())"
85 "(defun ring-insert (ring)"
86 "\"Insert onto ring RING the item ITEM.\""
87 "nil)")
88 "\n")))
89 (should
90 (equal
91 (check-declare-verify
92 file '(("foo.el" "ring-insert" (ring item))))
93 '(("foo.el" "ring-insert" "arglist mismatch")))))
94 (delete-file file))))
95
96(ert-deftest check-declare-tests-sort ()
97 (should-not (check-declare-sort '()))
98 (should (equal (check-declare-sort '((a (1 a)) (b (2)) (d (1 d))))
99 '((2 (b)) (1 (a a) (d d))))))
100
101(ert-deftest check-declare-tests-warn ()
102 (with-temp-buffer
103 (let ((check-declare-warning-buffer (buffer-name)))
104 (check-declare-warn
105 "foo-file" "foo-fun" "bar-file" "it wasn't" 999)
106 (let ((res (buffer-string)))
107 ;; Don't care too much about the format of the output, but
108 ;; check that key information is present.
109 (should (string-match-p "foo-file" res))
110 (should (string-match-p "foo-fun" res))
111 (should (string-match-p "bar-file" res))
112 (should (string-match-p "it wasn't" res))
113 (should (string-match-p "999" res))))))
114
115(provide 'check-declare-tests)
116;;; check-declare-tests.el ends here