Fix macOS 12 deprecation notices
[emacs.git] / test / lisp / progmodes / elisp-mode-tests.el
blob12e61cf8d18cc76972176d69381ead5b128ecf8f
1 ;;; elisp-mode-tests.el --- Tests for emacs-lisp-mode -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2015-2016 Free Software Foundation, Inc.
5 ;; Author: Dmitry Gutov <dgutov@yandex.ru>
6 ;; Author: Stephen Leake <stephen_leake@member.fsf.org>
8 ;; This file is part of GNU Emacs.
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.
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.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;; Code:
25 (require 'ert)
26 (require 'xref)
28 ;;; Completion
30 (defun elisp--test-completions ()
31 (let ((data (elisp-completion-at-point)))
32 (all-completions (buffer-substring (nth 0 data) (nth 1 data))
33 (nth 2 data)
34 (plist-get (nthcdr 3 data) :predicate))))
36 (ert-deftest elisp-completes-functions ()
37 (with-temp-buffer
38 (emacs-lisp-mode)
39 (insert "(ba")
40 (let ((comps (elisp--test-completions)))
41 (should (member "backup-buffer" comps))
42 (should-not (member "backup-inhibited" comps)))))
44 (ert-deftest elisp-completes-variables ()
45 (with-temp-buffer
46 (emacs-lisp-mode)
47 (insert "(foo ba")
48 (let ((comps (elisp--test-completions)))
49 (should (member "backup-inhibited" comps))
50 (should-not (member "backup-buffer" comps)))))
52 (ert-deftest elisp-completes-anything-quoted ()
53 (dolist (text '("`(foo ba" "(foo 'ba"
54 "`(,foo ba" "`,(foo `ba"
55 "'(foo (ba"))
56 (with-temp-buffer
57 (emacs-lisp-mode)
58 (insert text)
59 (let ((comps (elisp--test-completions)))
60 (should (member "backup-inhibited" comps))
61 (should (member "backup-buffer" comps))
62 (should (member "backup" comps))))))
64 (ert-deftest elisp-completes-variables-unquoted ()
65 (dolist (text '("`(foo ,ba" "`(,(foo ba" "`(,ba"))
66 (with-temp-buffer
67 (emacs-lisp-mode)
68 (insert text)
69 (let ((comps (elisp--test-completions)))
70 (should (member "backup-inhibited" comps))
71 (should-not (member "backup-buffer" comps))))))
73 (ert-deftest elisp-completes-functions-in-special-macros ()
74 (dolist (text '("(declare-function ba" "(cl-callf2 ba"))
75 (with-temp-buffer
76 (emacs-lisp-mode)
77 (insert text)
78 (let ((comps (elisp--test-completions)))
79 (should (member "backup-buffer" comps))
80 (should-not (member "backup-inhibited" comps))))))
82 (ert-deftest elisp-completes-functions-after-hash-quote ()
83 (ert-deftest elisp-completes-functions-after-let-bindings ()
84 (with-temp-buffer
85 (emacs-lisp-mode)
86 (insert "#'ba")
87 (let ((comps (elisp--test-completions)))
88 (should (member "backup-buffer" comps))
89 (should-not (member "backup-inhibited" comps))))))
91 (ert-deftest elisp-completes-local-variables ()
92 (with-temp-buffer
93 (emacs-lisp-mode)
94 (insert "(let ((bar 1) baz) (foo ba")
95 (let ((comps (elisp--test-completions)))
96 (should (member "backup-inhibited" comps))
97 (should (member "bar" comps))
98 (should (member "baz" comps)))))
100 (ert-deftest elisp-completest-variables-in-let-bindings ()
101 (dolist (text '("(let (ba" "(let* ((ba"))
102 (with-temp-buffer
103 (emacs-lisp-mode)
104 (insert text)
105 (let ((comps (elisp--test-completions)))
106 (should (member "backup-inhibited" comps))
107 (should-not (member "backup-buffer" comps))))))
109 (ert-deftest elisp-completes-functions-after-let-bindings ()
110 (with-temp-buffer
111 (emacs-lisp-mode)
112 (insert "(let ((bar 1) (baz 2)) (ba")
113 (let ((comps (elisp--test-completions)))
114 (should (member "backup-buffer" comps))
115 (should-not (member "backup-inhibited" comps)))))
117 ;;; xref
119 (defun xref-elisp-test-descr-to-target (xref)
120 "Return an appropriate `looking-at' match string for XREF."
121 (let* ((loc (xref-item-location xref))
122 (type (or (xref-elisp-location-type loc)
123 'defun)))
125 (cl-case type
126 (defalias
127 ;; summary: "(defalias xref)"
128 ;; target : "(defalias 'xref"
129 (concat "(defalias '" (substring (xref-item-summary xref) 10 -1)))
131 (defun
132 (let ((summary (xref-item-summary xref))
133 (file (xref-elisp-location-file loc)))
134 (cond
135 ((string= "c" (file-name-extension file))
136 ;; summary: "(defun buffer-live-p)"
137 ;; target : "DEFUN (buffer-live-p"
138 (concat
139 (upcase (substring summary 1 6))
140 " (\""
141 (substring summary 7 -1)
142 "\""))
145 (substring summary 0 -1))
148 (defvar
149 (let ((summary (xref-item-summary xref))
150 (file (xref-elisp-location-file loc)))
151 (cond
152 ((string= "c" (file-name-extension file))
153 ;; summary: "(defvar system-name)"
154 ;; target : "DEFVAR_LISP ("system-name", "
155 ;; summary: "(defvar abbrev-mode)"
156 ;; target : DEFVAR_PER_BUFFER ("abbrev-mode"
157 (concat
158 (upcase (substring summary 1 7))
159 (if (bufferp (variable-binding-locus (xref-elisp-location-symbol loc)))
160 "_PER_BUFFER (\""
161 "_LISP (\"")
162 (substring summary 8 -1)
163 "\""))
166 (substring summary 0 -1))
169 (feature
170 ;; summary: "(feature xref)"
171 ;; target : "(provide 'xref)"
172 (concat "(provide '" (substring (xref-item-summary xref) 9 -1)))
174 (otherwise
175 (substring (xref-item-summary xref) 0 -1))
179 (defun xref-elisp-test-run (xrefs expected-xrefs)
180 (should (= (length xrefs) (length expected-xrefs)))
181 (while xrefs
182 (let* ((xref (pop xrefs))
183 (expected (pop expected-xrefs))
184 (expected-xref (or (when (consp expected) (car expected)) expected))
185 (expected-source (when (consp expected) (cdr expected))))
187 ;; Downcase the filenames for case-insensitive file systems.
188 (setf (xref-elisp-location-file (oref xref location))
189 (downcase (xref-elisp-location-file (oref xref location))))
191 (setf (xref-elisp-location-file (oref expected-xref location))
192 (downcase (xref-elisp-location-file (oref expected-xref location))))
194 (should (equal xref expected-xref))
196 (xref--goto-location (xref-item-location xref))
197 (back-to-indentation)
198 (should (looking-at (or expected-source
199 (xref-elisp-test-descr-to-target expected)))))
202 (defmacro xref-elisp-deftest (name computed-xrefs expected-xrefs)
203 "Define an ert test for an xref-elisp feature.
204 COMPUTED-XREFS and EXPECTED-XREFS are lists of xrefs, except if
205 an element of EXPECTED-XREFS is a cons (XREF . TARGET), TARGET is
206 matched to the found location; otherwise, match
207 to (xref-elisp-test-descr-to-target xref)."
208 (declare (indent defun)
209 (debug (symbolp "name")))
210 `(ert-deftest ,(intern (concat "xref-elisp-test-" (symbol-name name))) ()
211 (let ((find-file-suppress-same-file-warnings t))
212 (xref-elisp-test-run ,computed-xrefs ,expected-xrefs)
215 ;; When tests are run from the Makefile, 'default-directory' is $HOME,
216 ;; so we must provide this dir to expand-file-name in the expected
217 ;; results. This also allows running these tests from other
218 ;; directories.
220 ;; We add 'downcase' here to deliberately cause a potential problem on
221 ;; case-insensitive file systems. On such systems, `load-file-name'
222 ;; may not have the same case as the real file system, since the user
223 ;; can set `load-path' to have the wrong case (on my Windows system,
224 ;; `load-path' has the correct case, so this causes the expected test
225 ;; values to have the wrong case). This is handled in
226 ;; `xref-elisp-test-run'.
227 (defconst emacs-test-dir (downcase (file-name-directory (or load-file-name (buffer-file-name)))))
230 ;; alphabetical by test name
232 ;; Autoloads require no special support; they are handled as functions.
234 ;; FIXME: defalias-defun-c cmpl-prefix-entry-head
235 ;; FIXME: defalias-defvar-el allout-mode-map
237 (xref-elisp-deftest find-defs-constructor
238 (elisp--xref-find-definitions 'xref-make-elisp-location)
239 ;; 'xref-make-elisp-location' is just a name for the default
240 ;; constructor created by the cl-defstruct, so the location is the
241 ;; cl-defstruct location.
242 (list
243 (cons
244 (xref-make "(cl-defstruct (xref-elisp-location (:constructor xref-make-elisp-location)))"
245 (xref-make-elisp-location
246 'xref-elisp-location 'define-type
247 (expand-file-name "../../../lisp/progmodes/elisp-mode.el" emacs-test-dir)))
248 ;; It's not worth adding another special case to `xref-elisp-test-descr-to-target' for this
249 "(cl-defstruct (xref-elisp-location")
252 (xref-elisp-deftest find-defs-defalias-defun-el
253 (elisp--xref-find-definitions 'Buffer-menu-sort)
254 (list
255 (xref-make "(defalias Buffer-menu-sort)"
256 (xref-make-elisp-location
257 'Buffer-menu-sort 'defalias
258 (expand-file-name "../../../lisp/buff-menu.elc" emacs-test-dir)))
259 (xref-make "(defun tabulated-list-sort)"
260 (xref-make-elisp-location
261 'tabulated-list-sort nil
262 (expand-file-name "../../../lisp/emacs-lisp/tabulated-list.el" emacs-test-dir)))
265 ;; FIXME: defconst
267 ;; FIXME: eieio defclass
269 ;; Possible ways of defining the default method implementation for a
270 ;; generic function. We declare these here, so we know we cover all
271 ;; cases, and we don't rely on other code not changing.
273 ;; When the generic and default method are declared in the same place,
274 ;; elisp--xref-find-definitions only returns one.
276 (cl-defstruct (xref-elisp-root-type)
277 slot-1)
279 (cl-defgeneric xref-elisp-generic-no-methods (arg1 arg2)
280 "doc string generic no-methods"
281 ;; No default implementation, no methods, but fboundp is true for
282 ;; this symbol; it calls cl-no-applicable-method
285 ;; WORKAROUND: ‘this’ is unused, and the byte compiler complains, so
286 ;; it should be spelled ‘_this’. But for some unknown reason, that
287 ;; causes the batch mode test to fail; the symbol shows up as
288 ;; ‘this’. It passes in interactive tests, so I haven't been able to
289 ;; track down the problem.
290 (cl-defmethod xref-elisp-generic-no-default ((this xref-elisp-root-type) arg2)
291 "doc string generic no-default xref-elisp-root-type"
292 "non-default for no-default")
294 ;; defgeneric after defmethod in file to ensure the fallback search
295 ;; method of just looking for the function name will fail.
296 (cl-defgeneric xref-elisp-generic-no-default (arg1 arg2)
297 "doc string generic no-default generic"
298 ;; No default implementation; this function calls the cl-generic
299 ;; dispatching code.
302 (cl-defgeneric xref-elisp-generic-co-located-default (arg1 arg2)
303 "doc string generic co-located-default"
304 "co-located default")
306 (cl-defmethod xref-elisp-generic-co-located-default ((this xref-elisp-root-type) arg2)
307 "doc string generic co-located-default xref-elisp-root-type"
308 "non-default for co-located-default")
310 (cl-defgeneric xref-elisp-generic-separate-default (arg1 arg2)
311 "doc string generic separate-default"
312 ;; default implementation provided separately
315 (cl-defmethod xref-elisp-generic-separate-default (arg1 arg2)
316 "doc string generic separate-default default"
317 "separate default")
319 (cl-defmethod xref-elisp-generic-separate-default ((this xref-elisp-root-type) arg2)
320 "doc string generic separate-default xref-elisp-root-type"
321 "non-default for separate-default")
323 (cl-defmethod xref-elisp-generic-implicit-generic (arg1 arg2)
324 "doc string generic implicit-generic default"
325 "default for implicit generic")
327 (cl-defmethod xref-elisp-generic-implicit-generic ((this xref-elisp-root-type) arg2)
328 "doc string generic implicit-generic xref-elisp-root-type"
329 "non-default for implicit generic")
332 (xref-elisp-deftest find-defs-defgeneric-no-methods
333 (elisp--xref-find-definitions 'xref-elisp-generic-no-methods)
334 (list
335 (xref-make "(cl-defgeneric xref-elisp-generic-no-methods)"
336 (xref-make-elisp-location
337 'xref-elisp-generic-no-methods 'cl-defgeneric
338 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
341 (xref-elisp-deftest find-defs-defgeneric-no-default
342 (elisp--xref-find-definitions 'xref-elisp-generic-no-default)
343 (list
344 (xref-make "(cl-defgeneric xref-elisp-generic-no-default)"
345 (xref-make-elisp-location
346 'xref-elisp-generic-no-default 'cl-defgeneric
347 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
348 (xref-make "(cl-defmethod xref-elisp-generic-no-default ((this xref-elisp-root-type) arg2))"
349 (xref-make-elisp-location
350 (cl--generic-load-hist-format
351 'xref-elisp-generic-no-default nil '(xref-elisp-root-type t))
352 'cl-defmethod
353 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
356 (xref-elisp-deftest find-defs-defgeneric-co-located-default
357 (elisp--xref-find-definitions 'xref-elisp-generic-co-located-default)
358 (list
359 (xref-make "(cl-defgeneric xref-elisp-generic-co-located-default)"
360 (xref-make-elisp-location
361 'xref-elisp-generic-co-located-default 'cl-defgeneric
362 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
363 (xref-make "(cl-defmethod xref-elisp-generic-co-located-default ((this xref-elisp-root-type) arg2))"
364 (xref-make-elisp-location
365 (cl--generic-load-hist-format
366 'xref-elisp-generic-co-located-default nil
367 '(xref-elisp-root-type t))
368 'cl-defmethod
369 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
372 (xref-elisp-deftest find-defs-defgeneric-separate-default
373 (elisp--xref-find-definitions 'xref-elisp-generic-separate-default)
374 (list
375 (xref-make "(cl-defgeneric xref-elisp-generic-separate-default)"
376 (xref-make-elisp-location
377 'xref-elisp-generic-separate-default 'cl-defgeneric
378 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
379 (xref-make "(cl-defmethod xref-elisp-generic-separate-default (arg1 arg2))"
380 (xref-make-elisp-location
381 (cl--generic-load-hist-format
382 'xref-elisp-generic-separate-default nil '(t t))
383 'cl-defmethod
384 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
385 (xref-make "(cl-defmethod xref-elisp-generic-separate-default ((this xref-elisp-root-type) arg2))"
386 (xref-make-elisp-location
387 (cl--generic-load-hist-format
388 'xref-elisp-generic-separate-default nil
389 '(xref-elisp-root-type t))
390 'cl-defmethod
391 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
394 (xref-elisp-deftest find-defs-defgeneric-implicit-generic
395 (elisp--xref-find-definitions 'xref-elisp-generic-implicit-generic)
396 (list
397 (xref-make "(cl-defmethod xref-elisp-generic-implicit-generic (arg1 arg2))"
398 (xref-make-elisp-location
399 (cl--generic-load-hist-format
400 'xref-elisp-generic-implicit-generic nil '(t t))
401 'cl-defmethod
402 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
403 (xref-make "(cl-defmethod xref-elisp-generic-implicit-generic ((this xref-elisp-root-type) arg2))"
404 (xref-make-elisp-location
405 (cl--generic-load-hist-format
406 'xref-elisp-generic-implicit-generic nil
407 '(xref-elisp-root-type t))
408 'cl-defmethod
409 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
412 ;; Test that we handle more than one method
414 ;; When run from the Makefile, etags is not loaded at compile time,
415 ;; but it is by the time this test is run. interactively; don't fail
416 ;; for that.
417 (require 'etags)
418 (xref-elisp-deftest find-defs-defgeneric-el
419 (elisp--xref-find-definitions 'xref-location-marker)
420 (list
421 (xref-make "(cl-defgeneric xref-location-marker)"
422 (xref-make-elisp-location
423 'xref-location-marker 'cl-defgeneric
424 (expand-file-name "../../../lisp/progmodes/xref.el" emacs-test-dir)))
425 (xref-make "(cl-defmethod xref-location-marker ((l xref-elisp-location)))"
426 (xref-make-elisp-location
427 (cl--generic-load-hist-format
428 'xref-location-marker nil '(xref-elisp-location))
429 'cl-defmethod
430 (expand-file-name "../../../lisp/progmodes/elisp-mode.el" emacs-test-dir)))
431 (xref-make "(cl-defmethod xref-location-marker ((l xref-file-location)))"
432 (xref-make-elisp-location
433 (cl--generic-load-hist-format
434 'xref-location-marker nil '(xref-file-location))
435 'cl-defmethod
436 (expand-file-name "../../../lisp/progmodes/xref.el" emacs-test-dir)))
437 (xref-make "(cl-defmethod xref-location-marker ((l xref-buffer-location)))"
438 (xref-make-elisp-location
439 (cl--generic-load-hist-format
440 'xref-location-marker nil '(xref-buffer-location))
441 'cl-defmethod
442 (expand-file-name "../../../lisp/progmodes/xref.el" emacs-test-dir)))
443 (xref-make "(cl-defmethod xref-location-marker ((l xref-bogus-location)))"
444 (xref-make-elisp-location
445 (cl--generic-load-hist-format
446 'xref-location-marker nil '(xref-bogus-location))
447 'cl-defmethod
448 (expand-file-name "../../../lisp/progmodes/xref.el" emacs-test-dir)))
449 (xref-make "(cl-defmethod xref-location-marker ((l xref-etags-location)))"
450 (xref-make-elisp-location
451 (cl--generic-load-hist-format
452 'xref-location-marker nil '(xref-etags-location))
453 'cl-defmethod
454 (expand-file-name "../../../lisp/progmodes/etags.el" emacs-test-dir)))
457 (xref-elisp-deftest find-defs-defgeneric-eval
458 (elisp--xref-find-definitions (eval '(cl-defgeneric stephe-leake-cl-defgeneric ())))
459 nil)
461 ;; Define some mode-local overloadable/overridden functions for xref to find
462 (require 'mode-local)
464 (define-overloadable-function xref-elisp-overloadable-no-methods ()
465 "doc string overloadable no-methods")
467 (define-overloadable-function xref-elisp-overloadable-no-default ()
468 "doc string overloadable no-default")
470 ;; FIXME: byte compiler complains about unused lexical arguments
471 ;; generated by this macro.
472 (define-mode-local-override xref-elisp-overloadable-no-default c-mode
473 (start end &optional nonterminal depth returnonerror)
474 "doc string overloadable no-default c-mode."
475 "result overloadable no-default c-mode.")
477 (define-overloadable-function xref-elisp-overloadable-co-located-default ()
478 "doc string overloadable co-located-default"
479 "result overloadable co-located-default.")
481 (define-mode-local-override xref-elisp-overloadable-co-located-default c-mode
482 (start end &optional nonterminal depth returnonerror)
483 "doc string overloadable co-located-default c-mode."
484 "result overloadable co-located-default c-mode.")
486 (define-overloadable-function xref-elisp-overloadable-separate-default ()
487 "doc string overloadable separate-default.")
489 (defun xref-elisp-overloadable-separate-default-default ()
490 "doc string overloadable separate-default default"
491 "result overloadable separate-default.")
493 (define-mode-local-override xref-elisp-overloadable-separate-default c-mode
494 (start end &optional nonterminal depth returnonerror)
495 "doc string overloadable separate-default c-mode."
496 "result overloadable separate-default c-mode.")
498 (xref-elisp-deftest find-defs-define-overload-no-methods
499 (elisp--xref-find-definitions 'xref-elisp-overloadable-no-methods)
500 (list
501 (xref-make "(define-overloadable-function xref-elisp-overloadable-no-methods)"
502 (xref-make-elisp-location
503 'xref-elisp-overloadable-no-methods 'define-overloadable-function
504 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
507 (xref-elisp-deftest find-defs-define-overload-no-default
508 (elisp--xref-find-definitions 'xref-elisp-overloadable-no-default)
509 (list
510 (xref-make "(define-overloadable-function xref-elisp-overloadable-no-default)"
511 (xref-make-elisp-location
512 'xref-elisp-overloadable-no-default 'define-overloadable-function
513 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
514 (xref-make "(define-mode-local-override xref-elisp-overloadable-no-default c-mode)"
515 (xref-make-elisp-location
516 '(xref-elisp-overloadable-no-default-c-mode . c-mode) 'define-mode-local-override
517 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
520 (xref-elisp-deftest find-defs-define-overload-co-located-default
521 (elisp--xref-find-definitions 'xref-elisp-overloadable-co-located-default)
522 (list
523 (xref-make "(define-overloadable-function xref-elisp-overloadable-co-located-default)"
524 (xref-make-elisp-location
525 'xref-elisp-overloadable-co-located-default 'define-overloadable-function
526 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
527 (xref-make "(define-mode-local-override xref-elisp-overloadable-co-located-default c-mode)"
528 (xref-make-elisp-location
529 '(xref-elisp-overloadable-co-located-default-c-mode . c-mode) 'define-mode-local-override
530 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
533 (xref-elisp-deftest find-defs-define-overload-separate-default
534 (elisp--xref-find-definitions 'xref-elisp-overloadable-separate-default)
535 (list
536 (xref-make "(define-overloadable-function xref-elisp-overloadable-separate-default)"
537 (xref-make-elisp-location
538 'xref-elisp-overloadable-separate-default 'define-overloadable-function
539 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
540 (xref-make "(defun xref-elisp-overloadable-separate-default-default)"
541 (xref-make-elisp-location
542 'xref-elisp-overloadable-separate-default-default nil
543 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
544 (xref-make "(define-mode-local-override xref-elisp-overloadable-separate-default c-mode)"
545 (xref-make-elisp-location
546 '(xref-elisp-overloadable-separate-default-c-mode . c-mode) 'define-mode-local-override
547 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
550 (xref-elisp-deftest find-defs-defun-el
551 (elisp--xref-find-definitions 'xref-find-definitions)
552 (list
553 (xref-make "(defun xref-find-definitions)"
554 (xref-make-elisp-location
555 'xref-find-definitions nil
556 (expand-file-name "../../../lisp/progmodes/xref.el" emacs-test-dir)))))
558 (xref-elisp-deftest find-defs-defun-eval
559 (elisp--xref-find-definitions (eval '(defun stephe-leake-defun ())))
560 nil)
562 (xref-elisp-deftest find-defs-defun-c
563 (elisp--xref-find-definitions 'buffer-live-p)
564 (list
565 (xref-make "(defun buffer-live-p)"
566 (xref-make-elisp-location 'buffer-live-p nil "src/buffer.c"))))
568 ;; FIXME: deftype
570 (xref-elisp-deftest find-defs-defun-c-defvar-c
571 (xref-backend-definitions 'elisp "system-name")
572 (list
573 (xref-make "(defvar system-name)"
574 (xref-make-elisp-location 'system-name 'defvar "src/editfns.c"))
575 (xref-make "(defun system-name)"
576 (xref-make-elisp-location 'system-name nil "src/editfns.c")))
579 (xref-elisp-deftest find-defs-defun-el-defvar-c
580 (xref-backend-definitions 'elisp "abbrev-mode")
581 ;; It's a minor mode, but the variable is defined in buffer.c
582 (list
583 (xref-make "(defvar abbrev-mode)"
584 (xref-make-elisp-location 'abbrev-mode 'defvar "src/buffer.c"))
585 (cons
586 (xref-make "(defun abbrev-mode)"
587 (xref-make-elisp-location
588 'abbrev-mode nil
589 (expand-file-name "../../../lisp/abbrev.el" emacs-test-dir)))
590 "(define-minor-mode abbrev-mode"))
593 ;; Source for both variable and defun is "(define-minor-mode
594 ;; compilation-minor-mode". There is no way to tell that directly from
595 ;; the symbol, but we can use (memq sym minor-mode-list) to detect
596 ;; that the symbol is a minor mode. See `elisp--xref-find-definitions'
597 ;; for more comments.
599 ;; IMPROVEME: return defvar instead of defun if source near starting
600 ;; point indicates the user is searching for a variable, not a
601 ;; function.
602 (require 'compile) ;; not loaded by default at test time
603 (xref-elisp-deftest find-defs-defun-defvar-el
604 (elisp--xref-find-definitions 'compilation-minor-mode)
605 (list
606 (cons
607 (xref-make "(defun compilation-minor-mode)"
608 (xref-make-elisp-location
609 'compilation-minor-mode nil
610 (expand-file-name "../../../lisp/progmodes/compile.el" emacs-test-dir)))
611 "(define-minor-mode compilation-minor-mode")
614 (xref-elisp-deftest find-defs-defvar-el
615 (elisp--xref-find-definitions 'xref--marker-ring)
616 (list
617 (xref-make "(defvar xref--marker-ring)"
618 (xref-make-elisp-location
619 'xref--marker-ring 'defvar
620 (expand-file-name "../../../lisp/progmodes/xref.el" emacs-test-dir)))
623 (xref-elisp-deftest find-defs-defvar-c
624 (elisp--xref-find-definitions 'default-directory)
625 (list
626 (cons
627 (xref-make "(defvar default-directory)"
628 (xref-make-elisp-location 'default-directory 'defvar "src/buffer.c"))
629 ;; IMPROVEME: we might be able to compute this target
630 "DEFVAR_PER_BUFFER (\"default-directory\"")))
632 (xref-elisp-deftest find-defs-defvar-eval
633 (elisp--xref-find-definitions (eval '(defvar stephe-leake-defvar nil)))
634 nil)
636 (xref-elisp-deftest find-defs-face-el
637 (elisp--xref-find-definitions 'font-lock-keyword-face)
638 ;; 'font-lock-keyword-face is both a face and a var
639 (list
640 (xref-make "(defvar font-lock-keyword-face)"
641 (xref-make-elisp-location
642 'font-lock-keyword-face 'defvar
643 (expand-file-name "../../../lisp/font-lock.el" emacs-test-dir)))
644 (xref-make "(defface font-lock-keyword-face)"
645 (xref-make-elisp-location
646 'font-lock-keyword-face 'defface
647 (expand-file-name "../../../lisp/font-lock.el" emacs-test-dir)))
650 (xref-elisp-deftest find-defs-face-eval
651 (elisp--xref-find-definitions (eval '(defface stephe-leake-defface nil "")))
652 nil)
654 (xref-elisp-deftest find-defs-feature-el
655 (elisp--xref-find-definitions 'xref)
656 (list
657 (cons
658 (xref-make "(feature xref)"
659 (xref-make-elisp-location
660 'xref 'feature
661 (expand-file-name "../../../lisp/progmodes/xref.el" emacs-test-dir)))
662 ";;; Code:")
665 (xref-elisp-deftest find-defs-feature-eval
666 (elisp--xref-find-definitions (eval '(provide 'stephe-leake-feature)))
667 nil)
669 (ert-deftest elisp--preceding-sexp--char-name ()
670 (with-temp-buffer
671 (emacs-lisp-mode)
672 (insert "?\\N{HEAVY CHECK MARK}")
673 (should (equal (elisp--preceding-sexp) ?\N{HEAVY CHECK MARK}))))
675 (provide 'elisp-mode-tests)
676 ;;; elisp-mode-tests.el ends here