Commit | Line | Data |
---|---|---|
327a6cca WJ |
1 | ;;; man-tests.el --- Test suite for man. |
2 | ||
ba318903 | 3 | ;; Copyright (C) 2013-2014 Free Software Foundation, Inc. |
327a6cca WJ |
4 | |
5 | ;; Author: Wolfgang Jenkner <wjenkner@inode.at> | |
6 | ;; Keywords: help, internal, unix | |
7 | ||
8 | ;; This file is part of GNU Emacs. | |
9 | ||
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. | |
14 | ||
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. | |
19 | ||
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/>. | |
22 | ||
23 | ;;; Code: | |
24 | ||
25 | (require 'ert) | |
26 | (require 'man) | |
27 | ||
28 | (defconst man-tests-parse-man-k-tests | |
29 | '(;; GNU/Linux: man-db-2.6.1 | |
30 | ("\ | |
31 | sin (3) - sine function | |
32 | sinf (3) - sine function | |
33 | sinl (3) - sine function" | |
34 | . (#("sin(3)" 0 6 (help-echo "sine function")) #("sinf(3)" 0 7 (help-echo "sine function")) #("sinl(3)" 0 7 (help-echo "sine function")))) | |
35 | ;; GNU/Linux: man-1.6g | |
36 | ("\ | |
37 | sin (3) - sine function | |
38 | sinf [sin] (3) - sine function | |
39 | sinl [sin] (3) - sine function" | |
40 | . (#("sin(3)" 0 6 (help-echo "sine function")) #("sinf(3)" 0 7 (help-echo "sine function")) #("sinl(3)" 0 7 (help-echo "sine function")))) | |
41 | ;; FreeBSD 9 | |
42 | ("\ | |
43 | sin(3), sinf(3), sinl(3) - sine functions" | |
44 | . (#("sin(3)" 0 6 (help-echo "sine functions")) #("sinf(3)" 0 7 (help-echo "sine functions")) #("sinl(3)" 0 7 (help-echo "sine functions")))) | |
45 | ;; SunOS, Solaris | |
46 | ;; http://docs.oracle.com/cd/E19455-01/805-6331/usradm-7/index.html | |
47 | ;; SunOS 4 | |
48 | ("\ | |
49 | tset, reset (1) - establish or restore terminal characteristics" | |
50 | . (#("tset(1)" 0 7 (help-echo "establish or restore terminal characteristics")) #("reset(1)" 0 8 (help-echo "establish or restore terminal characteristics")))) | |
51 | ;; SunOS 5.7, Solaris | |
52 | ("\ | |
53 | reset tset (1b) - establish or restore terminal characteristics | |
54 | tset tset (1b) - establish or restore terminal characteristics" | |
55 | . (#("reset(1b)" 0 8 (help-echo "establish or restore terminal characteristics")) #("tset(1b)" 0 7 (help-echo "establish or restore terminal characteristics")))) | |
56 | ;; Minix 3 | |
57 | ;; http://www.minix3.org/manpages/html5/whatis.html | |
58 | ("\ | |
59 | cawf, nroff (1) - C version of the nroff-like, Amazingly Workable (text) Formatter | |
60 | whatis (5) - database of online manual pages" | |
61 | . (#("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")))) | |
62 | ;; HP-UX | |
63 | ;; http://docstore.mik.ua/manuals/hp-ux/en/B2355-60130/man.1.html | |
64 | ;; Assuming that the line break in the zgrep description was | |
65 | ;; introduced by the man page formatting. | |
66 | ("\ | |
67 | grep, egrep, fgrep (1) - search a file for a pattern | |
68 | zgrep(1) - search possibly compressed files for a regular expression" | |
69 | . (#("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")))) | |
70 | ;; AIX | |
71 | ;; http://pic.dhe.ibm.com/infocenter/aix/v7r1/topic/com.ibm.aix.cmds/doc/aixcmds6/whatis.htm | |
72 | ("\ | |
73 | ls(1) -Displays the contents of a directory." | |
74 | . (#("ls(1)" 0 5 (help-echo "Displays the contents of a directory.")))) | |
75 | ;; https://www.ibm.com/developerworks/mydeveloperworks/blogs/cgaix/entry/catman_0703_102_usr_lbin_mkwhatis_the_error_number_is_1?lang=en | |
76 | ("\ | |
77 | loopmount(1) - Associate an image file to a loopback device." | |
78 | . (#("loopmount(1)" 0 12 (help-echo "Associate an image file to a loopback device.")))) | |
79 | ) | |
80 | "List of tests for `Man-parse-man-k'. | |
81 | Each element is a cons cell whose car is a string containing | |
82 | man -k output. That should result in the table which is stored | |
83 | in the cdr of the element.") | |
84 | ||
85 | (defun man-tests-name-equal-p (name description string) | |
86 | (and (equal name string) | |
87 | (not (next-single-property-change 0 'help-echo string)) | |
88 | (equal (get-text-property 0 'help-echo string) description))) | |
89 | ||
90 | (defun man-tests-parse-man-k-test-case (test) | |
91 | (let ((temp-buffer (get-buffer-create " *test-man*")) | |
92 | (man-k-output (car test))) | |
93 | (unwind-protect | |
94 | (save-window-excursion | |
95 | (with-current-buffer temp-buffer | |
96 | (erase-buffer) | |
97 | (insert man-k-output) | |
98 | (let ((result (Man-parse-man-k)) | |
99 | (checklist (cdr test))) | |
100 | (while (and checklist result | |
101 | (man-tests-name-equal-p | |
102 | (car checklist) | |
103 | (get-text-property 0 'help-echo | |
104 | (car checklist)) | |
105 | (pop result))) | |
106 | (pop checklist)) | |
107 | (and (null checklist) (null result))))) | |
108 | (and (buffer-name temp-buffer) | |
109 | (kill-buffer temp-buffer))))) | |
110 | ||
111 | (ert-deftest man-tests () | |
112 | "Test man." | |
113 | (dolist (test man-tests-parse-man-k-tests) | |
114 | (should (man-tests-parse-man-k-test-case test)))) | |
115 | ||
116 | (provide 'man-tests) | |
117 | ||
118 | ;;; man-tests.el ends here |