]> code.delx.au - gnu-emacs/blob - test/lisp/help-fns-tests.el
* test/lisp/help-fns-tests.el: Add several tests for 'describe-function'.
[gnu-emacs] / test / lisp / help-fns-tests.el
1 ;;; help-fns.el --- tests for help-fns.el
2
3 ;; Copyright (C) 2014-2016 Free Software Foundation, Inc.
4
5 ;; Maintainer: emacs-devel@gnu.org
6
7 ;; This file is part of GNU Emacs.
8
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
13
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
21
22 ;;; Commentary:
23
24 ;;; Code:
25
26 (require 'ert)
27
28 (autoload 'help-fns-test--macro "help-fns" nil nil t)
29
30 \f
31 ;;; Several tests for describe-function
32
33 (defun help-fns-tests--describe-function (func)
34 "Helper function for `describe-function' tests.
35 FUNC is the function to describe, a symbol.
36 Return first line of the output of (describe-function-1 FUNC)."
37 (let ((string (with-output-to-string
38 (describe-function-1 func))))
39 (string-match "\\(.+\\)\n" string)
40 (match-string-no-properties 1 string)))
41
42 (ert-deftest help-fns-test-bug17410 ()
43 "Test for http://debbugs.gnu.org/17410 ."
44 (let ((regexp "autoloaded Lisp macro")
45 (result (help-fns-tests--describe-function 'help-fns-test--macro)))
46 (should (string-match regexp result))))
47
48 (ert-deftest help-fns-test-built-in ()
49 (let ((regexp "a built-in function in .C source code")
50 (result (help-fns-tests--describe-function 'mapcar)))
51 (should (string-match regexp result))))
52
53 (ert-deftest help-fns-test-interactive-built-in ()
54 (let ((regexp "an interactive built-in function in .C source code")
55 (result (help-fns-tests--describe-function 're-search-forward)))
56 (should (string-match regexp result))))
57
58 (ert-deftest help-fns-test-lisp-macro ()
59 (let ((regexp "a Lisp macro in .subr\.el")
60 (result (help-fns-tests--describe-function 'when)))
61 (should (string-match regexp result))))
62
63 (ert-deftest help-fns-test-lisp-defun ()
64 (let ((regexp "a compiled Lisp function in .subr\.el")
65 (result (help-fns-tests--describe-function 'last)))
66 (should (string-match regexp result))))
67
68 (ert-deftest help-fns-test-lisp-defsubst ()
69 (let ((regexp "a compiled Lisp function in .subr\.el")
70 (result (help-fns-tests--describe-function 'posn-window)))
71 (should (string-match regexp result))))
72
73 (ert-deftest help-fns-test-alias-to-defun ()
74 (let ((regexp "an alias for .set-file-modes. in .subr\.el")
75 (result (help-fns-tests--describe-function 'chmod)))
76 (should (string-match regexp result))))
77
78 (ert-deftest help-fns-test-bug23887 ()
79 "Test for http://debbugs.gnu.org/23887 ."
80 (let ((regexp "an alias for .re-search-forward. in .subr\.el")
81 (result (help-fns-tests--describe-function 'search-forward-regexp)))
82 (should (string-match regexp result))))
83
84 \f
85 ;;; Test describe-function over functions with funny names
86 (defun abc\\\[universal-argument\]b\`c\'d\\e\"f (x)
87 "A function with a funny name.
88
89 \(fn XYZZY)"
90 x)
91
92 (defun defgh\\\[universal-argument\]b\`c\'d\\e\"f (x)
93 "Another function with a funny name."
94 x)
95
96 (ert-deftest help-fns-test-funny-names ()
97 "Test for help with functions with funny names."
98 (describe-function 'abc\\\[universal-argument\]b\`c\'d\\e\"f)
99 (with-current-buffer "*Help*"
100 (goto-char (point-min))
101 (should (search-forward
102 "(abc\\\\\\[universal-argument\\]b\\`c\\'d\\\\e\\\"f XYZZY)")))
103 (describe-function 'defgh\\\[universal-argument\]b\`c\'d\\e\"f)
104 (with-current-buffer "*Help*"
105 (goto-char (point-min))
106 (should (search-forward
107 "(defgh\\\\\\[universal-argument\\]b\\`c\\'d\\\\e\\\"f X)"))))
108
109 \f
110 ;;; Test for describe-symbol
111 (ert-deftest help-fns-test-describe-symbol ()
112 "Test the `describe-symbol' function."
113 ;; 'describe-symbol' would originally signal an error for
114 ;; 'font-lock-comment-face'.
115 (describe-symbol 'font-lock-comment-face)
116 (with-current-buffer "*Help*"
117 (should (> (point-max) 1))
118 (goto-char (point-min))
119 (should (looking-at "^font-lock-comment-face is "))))
120
121 ;;; help-fns.el ends here