all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
blob 0153f327ba806c325dbef749238c490da76c4648 4377 bytes (raw)
name: test/lisp/progmodes/etags-tests.el 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
 
;;; etags-tests.el --- Test suite for etags.el.

;; Copyright (C) 2016-2017 Free Software Foundation, Inc.

;; Author: Eli Zaretskii <eliz@gnu.org>

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.

;;; Code:

(require 'ert)
(require 'etags)
(eval-when-compile (require 'cl-lib))

(defvar his-masters-voice t)

(defconst etags-tests--test-dir
  (or (getenv "EMACS_TEST_DIRECTORY")
      (expand-file-name "../../.."
                        (or load-file-name buffer-file-name))))

(defun y-or-n-p (_prompt)
  "Replacement for `y-or-n-p' that returns what we tell it to."
  his-masters-voice)

(ert-deftest etags-bug-158 ()
  "Test finding tags with local and global tags tables."
  (let ((buf-with-global-tags (get-buffer-create "*buf-global*"))
        (buf-with-local-tags (get-buffer-create "*buf-local*"))
        xref-buf)
    (set-buffer buf-with-global-tags)
    (setq default-directory (expand-file-name "."))
    (visit-tags-table
     (expand-file-name "manual/etags/ETAGS.good_1" etags-tests--test-dir))
    ;; Check that tags in ETAGS.good_1 are recognized.
    (setq xref-buf (xref-find-definitions "LL_Task_Procedure_Access/t"))
    (should (bufferp xref-buf))
    (kill-buffer xref-buf)
    (setq xref-buf (xref-find-definitions "PrintAdd"))
    (should (bufferp xref-buf))
    (kill-buffer xref-buf)
    ;; Check that tags not in ETAGS.good_1, but in ETAGS.good_3, are
    ;; NOT recognized.
    (should-error (xref-find-definitions "intNumber") :type 'user-error)
    (kill-buffer xref-buf)
    (set-buffer buf-with-local-tags)
    (setq default-directory (expand-file-name "."))
    (let (his-masters-voice)
      (visit-tags-table
       (expand-file-name "manual/etags/ETAGS.good_3" etags-tests--test-dir)
       t))
    ;; Check that tags in ETAGS.good_1 are recognized.
    (setq xref-buf (xref-find-definitions "LL_Task_Procedure_Access/t"))
    (should (bufferp xref-buf))
    (kill-buffer xref-buf)
    (setq xref-buf (xref-find-definitions "PrintAdd"))
    (should (bufferp xref-buf))
    (kill-buffer xref-buf)
    ;; Check that tags in ETAGS.good_3 are recognized.  This is a test
    ;; for bug#158.
    (setq xref-buf (xref-find-definitions "intNumber"))
    (should (or (null xref-buf)
                (bufferp xref-buf)))
    ;; Bug #17326
    (should (string= (file-name-nondirectory
                      (buffer-local-value 'tags-file-name buf-with-local-tags))
                     "ETAGS.good_3"))
    (should (string= (file-name-nondirectory
                      (default-value 'tags-file-name))
                     "ETAGS.good_1"))
    (if (bufferp xref-buf) (kill-buffer xref-buf))))

(ert-deftest etags-bug-23164 ()
  "Test that setting a local value of tags table doesn't signal errors."
  (set-buffer (get-buffer-create "*foobar*"))
  (fundamental-mode)
  (visit-tags-table
   (expand-file-name "manual/etags/ETAGS.good_3" etags-tests--test-dir)
   t)
  (should (equal (should-error (xref-find-definitions "foobar123"))
                 '(user-error "No definitions found for: foobar123"))))

(ert-deftest etags-buffer-local-tags-table-list ()
  "Test that a buffer-local value of `tags-table-list' is used."
  (let ((file (make-temp-file "etag-test-tmpfile")))
    (set-buffer (find-file-noselect file))
    (fundamental-mode)
    (setq-local tags-table-list
                (list (expand-file-name "manual/etags/ETAGS.good_3"
                                        etags-tests--test-dir)))
    (cl-letf ((tag-tables tags-table-list)
              (tags-file-name nil)
              ((symbol-function 'read-file-name)
               (lambda (&rest _)
                 (error "We should not prompt the user"))))
      (should (visit-tags-table-buffer))
      (should (equal tags-file-name (car tag-tables))))))

debug log:

solving 0153f327ba ...
found 0153f327ba in https://git.savannah.gnu.org/cgit/emacs.git

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.