man-tests.el 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. ;;; man-tests.el --- Test suite for man.
  2. ;; Copyright (C) 2013-2017 Free Software Foundation, Inc.
  3. ;; Author: Wolfgang Jenkner <wjenkner@inode.at>
  4. ;; Keywords: help, internal, unix
  5. ;; This file is part of GNU Emacs.
  6. ;; GNU Emacs is free software: you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation, either version 3 of the License, or
  9. ;; (at your option) any later version.
  10. ;; GNU Emacs is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Code:
  17. (require 'ert)
  18. (require 'man)
  19. (defconst man-tests-parse-man-k-tests
  20. '(;; GNU/Linux: man-db-2.6.1
  21. ("\
  22. sin (3) - sine function
  23. sinf (3) - sine function
  24. sinl (3) - sine function"
  25. . (#("sin(3)" 0 6 (help-echo "sine function")) #("sinf(3)" 0 7 (help-echo "sine function")) #("sinl(3)" 0 7 (help-echo "sine function"))))
  26. ;; GNU/Linux: man-1.6g
  27. ("\
  28. sin (3) - sine function
  29. sinf [sin] (3) - sine function
  30. sinl [sin] (3) - sine function"
  31. . (#("sin(3)" 0 6 (help-echo "sine function")) #("sinf(3)" 0 7 (help-echo "sine function")) #("sinl(3)" 0 7 (help-echo "sine function"))))
  32. ;; FreeBSD 9
  33. ("\
  34. sin(3), sinf(3), sinl(3) - sine functions"
  35. . (#("sin(3)" 0 6 (help-echo "sine functions")) #("sinf(3)" 0 7 (help-echo "sine functions")) #("sinl(3)" 0 7 (help-echo "sine functions"))))
  36. ;; SunOS, Solaris
  37. ;; http://docs.oracle.com/cd/E19455-01/805-6331/usradm-7/index.html
  38. ;; SunOS 4
  39. ("\
  40. tset, reset (1) - establish or restore terminal characteristics"
  41. . (#("tset(1)" 0 7 (help-echo "establish or restore terminal characteristics")) #("reset(1)" 0 8 (help-echo "establish or restore terminal characteristics"))))
  42. ;; SunOS 5.7, Solaris
  43. ("\
  44. reset tset (1b) - establish or restore terminal characteristics
  45. tset tset (1b) - establish or restore terminal characteristics"
  46. . (#("reset(1b)" 0 8 (help-echo "establish or restore terminal characteristics")) #("tset(1b)" 0 7 (help-echo "establish or restore terminal characteristics"))))
  47. ;; Minix 3
  48. ;; http://www.minix3.org/manpages/html5/whatis.html
  49. ("\
  50. cawf, nroff (1) - C version of the nroff-like, Amazingly Workable (text) Formatter
  51. whatis (5) - database of online manual pages"
  52. . (#("cawf(1)" 0 7 (help-echo "C version of the nroff-like, Amazingly Workable (text) Formatter")) #("nroff(1)" 0 8 (help-echo "C version of the nroff-like, Amazingly Workable (text) Formatter")) #("whatis(5)" 0 9 (help-echo "database of online manual pages"))))
  53. ;; HP-UX
  54. ;; http://docstore.mik.ua/manuals/hp-ux/en/B2355-60130/man.1.html
  55. ;; Assuming that the line break in the zgrep description was
  56. ;; introduced by the man page formatting.
  57. ("\
  58. grep, egrep, fgrep (1) - search a file for a pattern
  59. zgrep(1) - search possibly compressed files for a regular expression"
  60. . (#("grep(1)" 0 7 (help-echo "search a file for a pattern")) #("egrep(1)" 0 8 (help-echo "search a file for a pattern")) #("fgrep(1)" 0 8 (help-echo "search a file for a pattern")) #("zgrep(1)" 0 8 (help-echo "search possibly compressed files for a regular expression"))))
  61. ;; AIX
  62. ;; http://pic.dhe.ibm.com/infocenter/aix/v7r1/topic/com.ibm.aix.cmds/doc/aixcmds6/whatis.htm
  63. ("\
  64. ls(1) -Displays the contents of a directory."
  65. . (#("ls(1)" 0 5 (help-echo "Displays the contents of a directory."))))
  66. ;; https://www.ibm.com/developerworks/mydeveloperworks/blogs/cgaix/entry/catman_0703_102_usr_lbin_mkwhatis_the_error_number_is_1?lang=en
  67. ("\
  68. loopmount(1) - Associate an image file to a loopback device."
  69. . (#("loopmount(1)" 0 12 (help-echo "Associate an image file to a loopback device."))))
  70. )
  71. "List of tests for `Man-parse-man-k'.
  72. Each element is a cons cell whose car is a string containing
  73. man -k output. That should result in the table which is stored
  74. in the cdr of the element.")
  75. (defun man-tests-name-equal-p (name description string)
  76. (and (equal name string)
  77. (not (next-single-property-change 0 'help-echo string))
  78. (equal (get-text-property 0 'help-echo string) description)))
  79. (defun man-tests-parse-man-k-test-case (test)
  80. (let ((temp-buffer (get-buffer-create " *test-man*"))
  81. (man-k-output (car test)))
  82. (unwind-protect
  83. (save-window-excursion
  84. (with-current-buffer temp-buffer
  85. (erase-buffer)
  86. (insert man-k-output)
  87. (let ((result (Man-parse-man-k))
  88. (checklist (cdr test)))
  89. (while (and checklist result
  90. (man-tests-name-equal-p
  91. (car checklist)
  92. (get-text-property 0 'help-echo
  93. (car checklist))
  94. (pop result)))
  95. (pop checklist))
  96. (and (null checklist) (null result)))))
  97. (and (buffer-name temp-buffer)
  98. (kill-buffer temp-buffer)))))
  99. (ert-deftest man-tests ()
  100. "Test man."
  101. (dolist (test man-tests-parse-man-k-tests)
  102. (should (man-tests-parse-man-k-test-case test))))
  103. (provide 'man-tests)
  104. ;;; man-tests.el ends here