info-xref-tests.el 4.7 KB

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