Merge from gnulib
[emacs.git] / test / automated / info-xref.el
blob98d24e1f093eaf869a625cb612b2b0004220c3ca
1 ;;; info-xref.el --- tests for info-xref.el
3 ;; Copyright (C) 2013-2015 Free Software Foundation, Inc.
5 ;; This file is part of GNU Emacs.
7 ;; GNU Emacs is free software: you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (at your option) any later version.
12 ;; GNU Emacs is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
20 ;;; Commentary:
22 ;;; Code:
24 (require 'ert)
25 (require 'info-xref)
27 (defun info-xref-test-internal (body result)
28 "Body of a basic info-xref ert test.
29 BODY is a string from an info buffer.
30 RESULT is a list (NBAD NGOOD NUNAVAIL)."
31 (get-buffer-create info-xref-output-buffer)
32 (setq info-xref-xfile-alist nil)
33 (require 'info)
34 (let ((Info-directory-list '("."))
35 Info-additional-directory-list)
36 (info-xref-with-output
37 (with-temp-buffer
38 (insert body)
39 (info-xref-check-buffer))))
40 (should (equal result (list info-xref-bad info-xref-good info-xref-unavail)))
41 ;; If there was an error, we can leave this around.
42 (kill-buffer info-xref-output-buffer))
44 (ert-deftest info-xref-test-node-crossref ()
45 "Test parsing of @xref{node,crossref,,manual} with Texinfo 4/5."
46 (info-xref-test-internal "
47 *Note crossref: (manual-foo)node. Texinfo 4/5 format with crossref.
48 " '(0 0 1)))
50 (ert-deftest info-xref-test-node-4 ()
51 "Test parsing of @xref{node,,,manual} with Texinfo 4."
52 (info-xref-test-internal "
53 *Note node: (manual-foo)node. Texinfo 4 format with no crossref.
54 " '(0 0 1)))
56 (ert-deftest info-xref-test-node-5 ()
57 "Test parsing of @xref{node,,,manual} with Texinfo 5."
58 (info-xref-test-internal "
59 *Note (manual-foo)node::. Texinfo 5 format with no crossref.
60 " '(0 0 1)))
62 ;; TODO Easier to have static data files in the repo?
63 (defun info-xref-test-write-file (file body)
64 "Write BODY to texi FILE."
65 (with-temp-buffer
66 (insert "\
67 \input texinfo
68 @setfilename "
69 (format "%s.info\n" (file-name-sans-extension file))
71 @settitle test
73 @ifnottex
74 @node Top
75 @top test
76 @end ifnottex
78 @menu
79 * Chapter One::
80 @end menu
82 @node Chapter One
83 @chapter Chapter One
85 text.
88 body
90 @bye
93 (write-region nil nil file nil 'silent))
94 (should (equal 0 (call-process "makeinfo" file))))
96 (ert-deftest info-xref-test-makeinfo ()
97 "Test that info-xref can parse basic makeinfo output."
98 (skip-unless (executable-find "makeinfo"))
99 (let ((tempfile (make-temp-file "info-xref-test" nil ".texi"))
100 (tempfile2 (make-temp-file "info-xref-test2" nil ".texi"))
101 (errflag t))
102 (unwind-protect
103 (progn
104 ;; tempfile contains xrefs to various things, including tempfile2.
105 (info-xref-test-write-file
106 tempfile
107 (concat "\
108 @xref{nodename,,,missing,Missing Manual}.
110 @xref{nodename,crossref,title,missing,Missing Manual}.
112 @xref{Chapter One}.
114 @xref{Chapter One,Something}.
117 (format "@xref{Chapter One,,,%s,Present Manual}.\n"
118 (file-name-sans-extension (file-name-nondirectory
119 tempfile2)))))
120 ;; Something for tempfile to xref to.
121 (info-xref-test-write-file tempfile2 "")
122 (require 'info)
123 (save-window-excursion
124 (let ((Info-directory-list
125 (list
126 (or (file-name-directory tempfile) ".")))
127 Info-additional-directory-list)
128 (info-xref-check (format "%s.info" (file-name-sans-extension
129 tempfile))))
130 (should (equal (list info-xref-bad info-xref-good
131 info-xref-unavail)
132 '(0 1 2)))
133 (setq errflag nil)
134 ;; If there was an error, we can leave this around.
135 (kill-buffer info-xref-output-buffer)))
136 ;; Useful diagnostic in case of problems.
137 (if errflag
138 (with-temp-buffer
139 (call-process "makeinfo" nil t nil "--version")
140 (message "%s" (buffer-string))))
141 (mapc 'delete-file (list tempfile tempfile2
142 (format "%s.info" (file-name-sans-extension
143 tempfile))
144 (format "%s.info" (file-name-sans-extension
145 tempfile2)))))))
147 ;;; info-xref.el ends here