Rework quoting in tutorial
[emacs.git] / test / automated / elisp-mode-tests.el
blob7886b557141007ecc6ca2c7c87e9c744a88aae5c
1 ;;; elisp-mode-tests.el --- Tests for emacs-lisp-mode -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2015 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)))
185 (should (equal xref
186 (or (when (consp expected) (car expected)) expected)))
188 (xref--goto-location (xref-item-location xref))
189 (back-to-indentation)
190 (should (looking-at (or (when (consp expected) (cdr expected))
191 (xref-elisp-test-descr-to-target expected)))))
194 (defmacro xref-elisp-deftest (name computed-xrefs expected-xrefs)
195 "Define an ert test for an xref-elisp feature.
196 COMPUTED-XREFS and EXPECTED-XREFS are lists of xrefs, except if
197 an element of EXPECTED-XREFS is a cons (XREF . TARGET), TARGET is
198 matched to the found location; otherwise, match
199 to (xref-elisp-test-descr-to-target xref)."
200 (declare (indent defun)
201 (debug (symbolp "name")))
202 `(ert-deftest ,(intern (concat "xref-elisp-test-" (symbol-name name))) ()
203 (xref-elisp-test-run ,computed-xrefs ,expected-xrefs)
206 ;; When tests are run from the Makefile, 'default-directory' is $HOME,
207 ;; so we must provide this dir to expand-file-name in the expected
208 ;; results. This also allows running these tests from other
209 ;; directories.
210 (defconst emacs-test-dir (file-name-directory (or load-file-name (buffer-file-name))))
212 ;; alphabetical by test name
214 ;; Autoloads require no special support; they are handled as functions.
216 ;; FIXME: defalias-defun-c cmpl-prefix-entry-head
217 ;; FIXME: defalias-defvar-el allout-mode-map
219 (xref-elisp-deftest find-defs-constructor
220 (elisp--xref-find-definitions 'xref-make-elisp-location)
221 ;; 'xref-make-elisp-location' is just a name for the default
222 ;; constructor created by the cl-defstruct, so the location is the
223 ;; cl-defstruct location.
224 (list
225 (cons
226 (xref-make "(cl-defstruct (xref-elisp-location (:constructor xref-make-elisp-location)))"
227 (xref-make-elisp-location
228 'xref-elisp-location 'define-type
229 (expand-file-name "../../lisp/progmodes/elisp-mode.el" emacs-test-dir)))
230 ;; It's not worth adding another special case to `xref-elisp-test-descr-to-target' for this
231 "(cl-defstruct (xref-elisp-location")
234 (xref-elisp-deftest find-defs-defalias-defun-el
235 (elisp--xref-find-definitions 'Buffer-menu-sort)
236 (list
237 (xref-make "(defalias Buffer-menu-sort)"
238 (xref-make-elisp-location
239 'Buffer-menu-sort 'defalias
240 (expand-file-name "../../lisp/buff-menu.elc" emacs-test-dir)))
241 (xref-make "(defun tabulated-list-sort)"
242 (xref-make-elisp-location
243 'tabulated-list-sort nil
244 (expand-file-name "../../lisp/emacs-lisp/tabulated-list.el" emacs-test-dir)))
247 ;; FIXME: defconst
249 ;; FIXME: eieio defclass
251 ;; Possible ways of defining the default method implementation for a
252 ;; generic function. We declare these here, so we know we cover all
253 ;; cases, and we don't rely on other code not changing.
255 ;; When the generic and default method are declared in the same place,
256 ;; elisp--xref-find-definitions only returns one.
258 (cl-defstruct (xref-elisp-root-type)
259 slot-1)
261 (cl-defgeneric xref-elisp-generic-no-methods ()
262 "doc string generic no-methods"
263 ;; No default implementation, no methods, but fboundp is true for
264 ;; this symbol; it calls cl-no-applicable-method
267 ;; WORKAROUND: ‘this’ is unused, and the byte compiler complains, so
268 ;; it should be spelled ‘_this’. But for some unknown reason, that
269 ;; causes the batch mode test to fail; the symbol shows up as
270 ;; ‘this’. It passes in interactive tests, so I haven't been able to
271 ;; track down the problem.
272 (cl-defmethod xref-elisp-generic-no-default ((this xref-elisp-root-type))
273 "doc string generic no-default xref-elisp-root-type"
274 "non-default for no-default")
276 ;; defgeneric after defmethod in file to ensure the fallback search
277 ;; method of just looking for the function name will fail.
278 (cl-defgeneric xref-elisp-generic-no-default ()
279 "doc string generic no-default generic"
280 ;; No default implementation; this function calls the cl-generic
281 ;; dispatching code.
284 (cl-defgeneric xref-elisp-generic-co-located-default ()
285 "doc string generic co-located-default"
286 "co-located default")
288 (cl-defmethod xref-elisp-generic-co-located-default ((this xref-elisp-root-type))
289 "doc string generic co-located-default xref-elisp-root-type"
290 "non-default for co-located-default")
292 (cl-defgeneric xref-elisp-generic-separate-default ()
293 "doc string generic separate-default"
294 ;; default implementation provided separately
297 (cl-defmethod xref-elisp-generic-separate-default ()
298 "doc string generic separate-default default"
299 "separate default")
301 (cl-defmethod xref-elisp-generic-separate-default ((this xref-elisp-root-type))
302 "doc string generic separate-default xref-elisp-root-type"
303 "non-default for separate-default")
305 (cl-defmethod xref-elisp-generic-implicit-generic ()
306 "doc string generic implicit-generic default"
307 "default for implicit generic")
309 (cl-defmethod xref-elisp-generic-implicit-generic ((this xref-elisp-root-type))
310 "doc string generic implicit-generic xref-elisp-root-type"
311 "non-default for implicit generic")
314 (xref-elisp-deftest find-defs-defgeneric-no-methods
315 (elisp--xref-find-definitions 'xref-elisp-generic-no-methods)
316 (list
317 (xref-make "(cl-defgeneric xref-elisp-generic-no-methods)"
318 (xref-make-elisp-location
319 'xref-elisp-generic-no-methods 'cl-defgeneric
320 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
323 (xref-elisp-deftest find-defs-defgeneric-no-default
324 (elisp--xref-find-definitions 'xref-elisp-generic-no-default)
325 (list
326 (xref-make "(cl-defgeneric xref-elisp-generic-no-default)"
327 (xref-make-elisp-location
328 'xref-elisp-generic-no-default 'cl-defgeneric
329 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
330 (xref-make "(cl-defmethod xref-elisp-generic-no-default ((this xref-elisp-root-type)))"
331 (xref-make-elisp-location
332 '(xref-elisp-generic-no-default xref-elisp-root-type) 'cl-defmethod
333 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
336 (xref-elisp-deftest find-defs-defgeneric-co-located-default
337 (elisp--xref-find-definitions 'xref-elisp-generic-co-located-default)
338 (list
339 (xref-make "(cl-defgeneric xref-elisp-generic-co-located-default)"
340 (xref-make-elisp-location
341 'xref-elisp-generic-co-located-default 'cl-defgeneric
342 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
343 (xref-make "(cl-defmethod xref-elisp-generic-co-located-default ((this xref-elisp-root-type)))"
344 (xref-make-elisp-location
345 '(xref-elisp-generic-co-located-default xref-elisp-root-type) 'cl-defmethod
346 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
349 (xref-elisp-deftest find-defs-defgeneric-separate-default
350 (elisp--xref-find-definitions 'xref-elisp-generic-separate-default)
351 (list
352 (xref-make "(cl-defgeneric xref-elisp-generic-separate-default)"
353 (xref-make-elisp-location
354 'xref-elisp-generic-separate-default 'cl-defgeneric
355 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
356 (xref-make "(cl-defmethod xref-elisp-generic-separate-default ())"
357 (xref-make-elisp-location
358 '(xref-elisp-generic-separate-default) 'cl-defmethod
359 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
360 (xref-make "(cl-defmethod xref-elisp-generic-separate-default ((this xref-elisp-root-type)))"
361 (xref-make-elisp-location
362 '(xref-elisp-generic-separate-default xref-elisp-root-type) 'cl-defmethod
363 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
366 (xref-elisp-deftest find-defs-defgeneric-implicit-generic
367 (elisp--xref-find-definitions 'xref-elisp-generic-implicit-generic)
368 (list
369 (xref-make "(cl-defmethod xref-elisp-generic-implicit-generic ())"
370 (xref-make-elisp-location
371 '(xref-elisp-generic-implicit-generic) 'cl-defmethod
372 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
373 (xref-make "(cl-defmethod xref-elisp-generic-implicit-generic ((this xref-elisp-root-type)))"
374 (xref-make-elisp-location
375 '(xref-elisp-generic-implicit-generic xref-elisp-root-type) 'cl-defmethod
376 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
379 ;; Test that we handle more than one method
381 ;; When run from the Makefile, etags is not loaded at compile time,
382 ;; but it is by the time this test is run. interactively; don't fail
383 ;; for that.
384 (require 'etags)
385 (xref-elisp-deftest find-defs-defgeneric-el
386 (elisp--xref-find-definitions 'xref-location-marker)
387 (list
388 (xref-make "(cl-defgeneric xref-location-marker)"
389 (xref-make-elisp-location
390 'xref-location-marker 'cl-defgeneric
391 (expand-file-name "../../lisp/progmodes/xref.el" emacs-test-dir)))
392 (xref-make "(cl-defmethod xref-location-marker ((l xref-elisp-location)))"
393 (xref-make-elisp-location
394 '(xref-location-marker xref-elisp-location) 'cl-defmethod
395 (expand-file-name "../../lisp/progmodes/elisp-mode.el" emacs-test-dir)))
396 (xref-make "(cl-defmethod xref-location-marker ((l xref-file-location)))"
397 (xref-make-elisp-location
398 '(xref-location-marker xref-file-location) 'cl-defmethod
399 (expand-file-name "../../lisp/progmodes/xref.el" emacs-test-dir)))
400 (xref-make "(cl-defmethod xref-location-marker ((l xref-buffer-location)))"
401 (xref-make-elisp-location
402 '(xref-location-marker xref-buffer-location) 'cl-defmethod
403 (expand-file-name "../../lisp/progmodes/xref.el" emacs-test-dir)))
404 (xref-make "(cl-defmethod xref-location-marker ((l xref-bogus-location)))"
405 (xref-make-elisp-location
406 '(xref-location-marker xref-bogus-location) 'cl-defmethod
407 (expand-file-name "../../lisp/progmodes/xref.el" emacs-test-dir)))
408 (xref-make "(cl-defmethod xref-location-marker ((l xref-etags-location)))"
409 (xref-make-elisp-location
410 '(xref-location-marker xref-etags-location) 'cl-defmethod
411 (expand-file-name "../../lisp/progmodes/etags.el" emacs-test-dir)))
414 (xref-elisp-deftest find-defs-defgeneric-eval
415 (elisp--xref-find-definitions (eval '(cl-defgeneric stephe-leake-cl-defgeneric ())))
416 nil)
418 ;; Define some mode-local overloadable/overridden functions for xref to find
419 (require 'mode-local)
421 (define-overloadable-function xref-elisp-overloadable-no-methods ()
422 "doc string overloadable no-methods")
424 (define-overloadable-function xref-elisp-overloadable-no-default ()
425 "doc string overloadable no-default")
427 ;; FIXME: byte compiler complains about unused lexical arguments
428 ;; generated by this macro.
429 (define-mode-local-override xref-elisp-overloadable-no-default c-mode
430 (start end &optional nonterminal depth returnonerror)
431 "doc string overloadable no-default c-mode."
432 "result overloadable no-default c-mode.")
434 (define-overloadable-function xref-elisp-overloadable-co-located-default ()
435 "doc string overloadable co-located-default"
436 "result overloadable co-located-default.")
438 (define-mode-local-override xref-elisp-overloadable-co-located-default c-mode
439 (start end &optional nonterminal depth returnonerror)
440 "doc string overloadable co-located-default c-mode."
441 "result overloadable co-located-default c-mode.")
443 (define-overloadable-function xref-elisp-overloadable-separate-default ()
444 "doc string overloadable separate-default.")
446 (defun xref-elisp-overloadable-separate-default-default ()
447 "doc string overloadable separate-default default"
448 "result overloadable separate-default.")
450 (define-mode-local-override xref-elisp-overloadable-separate-default c-mode
451 (start end &optional nonterminal depth returnonerror)
452 "doc string overloadable separate-default c-mode."
453 "result overloadable separate-default c-mode.")
455 (xref-elisp-deftest find-defs-define-overload-no-methods
456 (elisp--xref-find-definitions 'xref-elisp-overloadable-no-methods)
457 (list
458 (xref-make "(define-overloadable-function xref-elisp-overloadable-no-methods)"
459 (xref-make-elisp-location
460 'xref-elisp-overloadable-no-methods 'define-overloadable-function
461 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
464 (xref-elisp-deftest find-defs-define-overload-no-default
465 (elisp--xref-find-definitions 'xref-elisp-overloadable-no-default)
466 (list
467 (xref-make "(define-overloadable-function xref-elisp-overloadable-no-default)"
468 (xref-make-elisp-location
469 'xref-elisp-overloadable-no-default 'define-overloadable-function
470 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
471 (xref-make "(define-mode-local-override xref-elisp-overloadable-no-default c-mode)"
472 (xref-make-elisp-location
473 '(xref-elisp-overloadable-no-default-c-mode . c-mode) 'define-mode-local-override
474 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
477 (xref-elisp-deftest find-defs-define-overload-co-located-default
478 (elisp--xref-find-definitions 'xref-elisp-overloadable-co-located-default)
479 (list
480 (xref-make "(define-overloadable-function xref-elisp-overloadable-co-located-default)"
481 (xref-make-elisp-location
482 'xref-elisp-overloadable-co-located-default 'define-overloadable-function
483 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
484 (xref-make "(define-mode-local-override xref-elisp-overloadable-co-located-default c-mode)"
485 (xref-make-elisp-location
486 '(xref-elisp-overloadable-co-located-default-c-mode . c-mode) 'define-mode-local-override
487 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
490 (xref-elisp-deftest find-defs-define-overload-separate-default
491 (elisp--xref-find-definitions 'xref-elisp-overloadable-separate-default)
492 (list
493 (xref-make "(define-overloadable-function xref-elisp-overloadable-separate-default)"
494 (xref-make-elisp-location
495 'xref-elisp-overloadable-separate-default 'define-overloadable-function
496 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
497 (xref-make "(defun xref-elisp-overloadable-separate-default-default)"
498 (xref-make-elisp-location
499 'xref-elisp-overloadable-separate-default-default nil
500 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
501 (xref-make "(define-mode-local-override xref-elisp-overloadable-separate-default c-mode)"
502 (xref-make-elisp-location
503 '(xref-elisp-overloadable-separate-default-c-mode . c-mode) 'define-mode-local-override
504 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
507 (xref-elisp-deftest find-defs-defun-el
508 (elisp--xref-find-definitions 'xref-find-definitions)
509 (list
510 (xref-make "(defun xref-find-definitions)"
511 (xref-make-elisp-location
512 'xref-find-definitions nil
513 (expand-file-name "../../lisp/progmodes/xref.el" emacs-test-dir)))))
515 (xref-elisp-deftest find-defs-defun-eval
516 (elisp--xref-find-definitions (eval '(defun stephe-leake-defun ())))
517 nil)
519 (xref-elisp-deftest find-defs-defun-c
520 (elisp--xref-find-definitions 'buffer-live-p)
521 (list
522 (xref-make "(defun buffer-live-p)"
523 (xref-make-elisp-location 'buffer-live-p nil "src/buffer.c"))))
525 ;; FIXME: deftype
527 (xref-elisp-deftest find-defs-defun-c-defvar-c
528 (elisp-xref-find 'definitions "system-name")
529 (list
530 (xref-make "(defvar system-name)"
531 (xref-make-elisp-location 'system-name 'defvar "src/editfns.c"))
532 (xref-make "(defun system-name)"
533 (xref-make-elisp-location 'system-name nil "src/editfns.c")))
536 (xref-elisp-deftest find-defs-defun-el-defvar-c
537 (elisp-xref-find 'definitions "abbrev-mode")
538 ;; It's a minor mode, but the variable is defined in buffer.c
539 (list
540 (xref-make "(defvar abbrev-mode)"
541 (xref-make-elisp-location 'abbrev-mode 'defvar "src/buffer.c"))
542 (cons
543 (xref-make "(defun abbrev-mode)"
544 (xref-make-elisp-location
545 'abbrev-mode nil
546 (expand-file-name "../../lisp/abbrev.el" emacs-test-dir)))
547 "(define-minor-mode abbrev-mode"))
550 ;; Source for both variable and defun is "(define-minor-mode
551 ;; compilation-minor-mode". There is no way to tell that directly from
552 ;; the symbol, but we can use (memq sym minor-mode-list) to detect
553 ;; that the symbol is a minor mode. See `elisp--xref-find-definitions'
554 ;; for more comments.
556 ;; IMPROVEME: return defvar instead of defun if source near starting
557 ;; point indicates the user is searching for a variable, not a
558 ;; function.
559 (require 'compile) ;; not loaded by default at test time
560 (xref-elisp-deftest find-defs-defun-defvar-el
561 (elisp--xref-find-definitions 'compilation-minor-mode)
562 (list
563 (cons
564 (xref-make "(defun compilation-minor-mode)"
565 (xref-make-elisp-location
566 'compilation-minor-mode nil
567 (expand-file-name "../../lisp/progmodes/compile.el" emacs-test-dir)))
568 "(define-minor-mode compilation-minor-mode")
571 (xref-elisp-deftest find-defs-defvar-el
572 (elisp--xref-find-definitions 'xref--marker-ring)
573 (list
574 (xref-make "(defvar xref--marker-ring)"
575 (xref-make-elisp-location
576 'xref--marker-ring 'defvar
577 (expand-file-name "../../lisp/progmodes/xref.el" emacs-test-dir)))
580 (xref-elisp-deftest find-defs-defvar-c
581 (elisp--xref-find-definitions 'default-directory)
582 (list
583 (cons
584 (xref-make "(defvar default-directory)"
585 (xref-make-elisp-location 'default-directory 'defvar "src/buffer.c"))
586 ;; IMPROVEME: we might be able to compute this target
587 "DEFVAR_PER_BUFFER (\"default-directory\"")))
589 (xref-elisp-deftest find-defs-defvar-eval
590 (elisp--xref-find-definitions (eval '(defvar stephe-leake-defvar nil)))
591 nil)
593 (xref-elisp-deftest find-defs-face-el
594 (elisp--xref-find-definitions 'font-lock-keyword-face)
595 ;; 'font-lock-keyword-face is both a face and a var
596 (list
597 (xref-make "(defvar font-lock-keyword-face)"
598 (xref-make-elisp-location
599 'font-lock-keyword-face 'defvar
600 (expand-file-name "../../lisp/font-lock.el" emacs-test-dir)))
601 (xref-make "(defface font-lock-keyword-face)"
602 (xref-make-elisp-location
603 'font-lock-keyword-face 'defface
604 (expand-file-name "../../lisp/font-lock.el" emacs-test-dir)))
607 (xref-elisp-deftest find-defs-face-eval
608 (elisp--xref-find-definitions (eval '(defface stephe-leake-defface nil "")))
609 nil)
611 (xref-elisp-deftest find-defs-feature-el
612 (elisp--xref-find-definitions 'xref)
613 (list
614 (cons
615 (xref-make "(feature xref)"
616 (xref-make-elisp-location
617 'xref 'feature
618 (expand-file-name "../../lisp/progmodes/xref.el" emacs-test-dir)))
619 ";;; Code:")
622 (xref-elisp-deftest find-defs-feature-eval
623 (elisp--xref-find-definitions (eval '(provide 'stephe-leake-feature)))
624 nil)
626 (provide 'elisp-mode-tests)
627 ;;; elisp-mode-tests.el ends here