unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
blob 1c6dcb63a5c82b104cd35dbaf55b9705ddd5f42a 7611 bytes (raw)
name: test/lisp/man-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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
 
;;; man-tests.el --- Test suite for man.  -*- lexical-binding:t -*-

;; Copyright (C) 2013-2023 Free Software Foundation, Inc.

;; Author: Wolfgang Jenkner <wjenkner@inode.at>
;; Keywords: help, internal, unix

;; 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 <https://www.gnu.org/licenses/>.

;;; Code:

(require 'ert)
(require 'man)
(require 'seq)

(defconst man-tests-parse-man-k-tests
  '(;; GNU/Linux: man-db-2.6.1
    ("\
sin (3)              - sine function
sinf (3)             - sine function
sinl (3)             - sine function"
     . (#("sin(3)" 0 6 (help-echo "sine function")) #("sinf(3)" 0 7 (help-echo "sine function")) #("sinl(3)" 0 7 (help-echo "sine function"))))
    ;; GNU/Linux: man-1.6g
    ("\
sin                  (3)  - sine function
sinf [sin]           (3)  - sine function
sinl [sin]           (3)  - sine function"
     . (#("sin(3)" 0 6 (help-echo "sine function")) #("sinf(3)" 0 7 (help-echo "sine function")) #("sinl(3)" 0 7 (help-echo "sine function"))))
    ;; FreeBSD 9
    ("\
sin(3), sinf(3), sinl(3) - sine functions"
     . (#("sin(3)" 0 6 (help-echo "sine functions")) #("sinf(3)" 0 7 (help-echo "sine functions")) #("sinl(3)" 0 7 (help-echo "sine functions"))))
    ;; SunOS, Solaris
    ;; https://docs.oracle.com/cd/E19455-01/805-6331/usradm-7/index.html
    ;; SunOS 4
    ("\
tset, reset (1)    - establish or restore terminal characteristics"
     . (#("tset(1)" 0 7 (help-echo "establish or restore terminal characteristics")) #("reset(1)" 0 8 (help-echo "establish or restore terminal characteristics"))))
    ;; SunOS 5.7, Solaris
    ("\
reset  tset (1b)   - establish or restore terminal characteristics
tset   tset (1b)   - establish or restore terminal characteristics"
     . (#("reset(1b)" 0 8 (help-echo "establish or restore terminal characteristics")) #("tset(1b)" 0 7 (help-echo "establish or restore terminal characteristics"))))
    ;; Minix 3
    ;; http://www.minix3.org/manpages/html5/whatis.html
    ("\
cawf, nroff (1) - C version of the nroff-like, Amazingly Workable (text) Formatter
whatis (5) - database of online manual pages"
     . (#("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"))))
    ;; HP-UX
    ;; https://docstore.mik.ua/manuals/hp-ux/en/B2355-60130/man.1.html
    ;; Assuming that the line break in the zgrep description was
    ;; introduced by the man page formatting.
    ("\
grep, egrep, fgrep (1) - search a file for a pattern
zgrep(1) - search possibly compressed files for a regular expression"
     . (#("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"))))
    ;; AIX
    ;; http://pic.dhe.ibm.com/infocenter/aix/v7r1/topic/com.ibm.aix.cmds/doc/aixcmds6/whatis.htm
    ("\
ls(1)  -Displays the contents of a directory."
    . (#("ls(1)" 0 5 (help-echo "Displays the contents of a directory."))))
    ;; https://www.ibm.com/developerworks/mydeveloperworks/blogs/cgaix/entry/catman_0703_102_usr_lbin_mkwhatis_the_error_number_is_1?lang=en
    ("\
loopmount(1)    - Associate an image file to a loopback device."
     . (#("loopmount(1)" 0 12 (help-echo "Associate an image file to a loopback device."))))
    )
  "List of tests for `Man-parse-man-k'.
Each element is a cons cell whose car is a string containing
man -k output.  That should result in the table which is stored
in the cdr of the element.")

(defun man-tests-name-equal-p (name description string)
  (and (equal name string)
       (not (next-single-property-change 0 'help-echo string))
       (equal (get-text-property 0 'help-echo string) description)))

(defun man-tests-parse-man-k-test-case (test)
  (let ((temp-buffer (get-buffer-create " *test-man*"))
	(man-k-output (car test)))
    (unwind-protect
	(save-window-excursion
	  (with-current-buffer temp-buffer
	    (erase-buffer)
	    (insert man-k-output)
	    (let ((result (Man-parse-man-k))
		  (checklist (cdr test)))
	      (while (and checklist result
			  (man-tests-name-equal-p
			   (car checklist)
			   (get-text-property 0 'help-echo
					      (car checklist))
			   (pop result)))
		(pop checklist))
	      (and (null checklist) (null result)))))
      (and (buffer-name temp-buffer)
	   (kill-buffer temp-buffer)))))

(ert-deftest man-tests ()
  "Test man."
  (dolist (test man-tests-parse-man-k-tests)
    (should (man-tests-parse-man-k-test-case test))))

(defun man-tests-filter-strings (_buffer strings)
  "Run `Man-bgproc-filter' on each of STRINGS.
The formatted result will be inserted into BUFFER."
  (let ((proc (start-process "dummy man-tests proc" (current-buffer) "cat")))
    (set-process-query-on-exit-flag proc nil)
    (dolist (str strings)
      (Man-bgproc-filter proc str))))

(ert-deftest man-bgproc-filter-buttonize-includes ()
  ;; Test with abridged version of printf man page (Bug#36927).
  (let ((str "\
PRINTF(3)              Linux Programmer's Manual             PRINTF(3)

NAME
       printf, fprintf, dprintf, sprintf, snprintf, vprintf, vfprintf,

SYNOPSIS
       #include <stdio.h>

       int printf(const char *format, ...);

       #include <stdarg.h>

       int vsprintf(char *str, const char *format, va_list ap);

DESCRIPTION
       The functions in the printf() family produce  output  according\n"))
    (with-temp-buffer
      (dolist (chunks
               (list
                ;; Test a few different kinds of chunking.
                (list str)
                (seq-mapcat (lambda (line)
                              (list line "\n"))
                            (split-string str "\n"))
                (mapcar #'string str)))
        (erase-buffer)
        (man-tests-filter-strings (current-buffer) chunks)
        (goto-char (point-min))
        (ert-info ((format "%S" chunks) :prefix "Input: ")
          (search-forward "#include <stdio.h>")
          (let ((button (button-at (match-beginning 0))))
            (should (and button (eq 'Man-xref-header-file (button-type button)))))
          (search-forward "#include <stdarg.h>")
          (let ((button (button-at (match-beginning 0))))
            (should (and button (eq 'Man-xref-header-file (button-type button))))))))))

(ert-deftest man-tests-Man-translate-references ()
  (should (equal (Man-translate-references "basename")
                 "basename"))
  (should (equal (Man-translate-references "basename(3)")
                 "3 basename"))
  (should (equal (Man-translate-references "basename(3v)")
                 "3v basename"))
  (should (equal (Man-translate-references ";id")
                 "\\;id"))
  (should (equal (Man-translate-references "-k basename")
                 "-k basename")))

(provide 'man-tests)

;;; man-tests.el ends here

debug log:

solving 1c6dcb63a5c ...
found 1c6dcb63a5c in https://yhetil.org/emacs-bugs/tencent_B89C8F336F35EB3562777DF226E178C19708@qq.com/ ||
	https://yhetil.org/emacs-bugs/tencent_3C358C354C777BF23EE1D3C1839C3F331C08@qq.com/
found e3657d7df8a in https://git.savannah.gnu.org/cgit/emacs.git
preparing index
index prepared:
100644 e3657d7df8a0de794f9bab758549691b4c490066	test/lisp/man-tests.el

applying [1/1] https://yhetil.org/emacs-bugs/tencent_B89C8F336F35EB3562777DF226E178C19708@qq.com/
diff --git a/test/lisp/man-tests.el b/test/lisp/man-tests.el
index e3657d7df8a..1c6dcb63a5c 100644

Checking patch test/lisp/man-tests.el...
Applied patch test/lisp/man-tests.el cleanly.

skipping https://yhetil.org/emacs-bugs/tencent_3C358C354C777BF23EE1D3C1839C3F331C08@qq.com/ for 1c6dcb63a5c
index at:
100644 1c6dcb63a5c82b104cd35dbaf55b9705ddd5f42a	test/lisp/man-tests.el

(*) 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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).