1;;; help-fns-tests.el --- tests for help-fns.el -*- lexical-binding: t -*- 2 3;; Copyright (C) 2014-2021 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 <https://www.gnu.org/licenses/>. 21 22;;; Commentary: 23 24;;; Code: 25 26(require 'ert) 27(require 'help-fns) 28 29(autoload 'help-fns-test--macro "foo" nil nil t) 30 31 32;;; Several tests for describe-function 33 34(defun help-fns-tests--describe-function (func) 35 "Helper function for `describe-function' tests. 36FUNC is the function to describe, a symbol. 37Return first line of the output of (describe-function-1 FUNC)." 38 (let ((string (with-output-to-string 39 (describe-function-1 func)))) 40 (string-match "\\(.+\\)\n" string) 41 (match-string-no-properties 1 string))) 42 43(ert-deftest help-fns-test-bug17410 () 44 "Test for https://debbugs.gnu.org/17410 ." 45 (let ((regexp "autoloaded Lisp macro") 46 (result (help-fns-tests--describe-function 'help-fns-test--macro))) 47 (should (string-match regexp result)))) 48 49(ert-deftest help-fns-test-built-in () 50 (let ((regexp "a built-in function in .C source code") 51 (result (help-fns-tests--describe-function 'mapcar))) 52 (should (string-match regexp result)))) 53 54(ert-deftest help-fns-test-interactive-built-in () 55 (let ((regexp "an interactive built-in function in .C source code") 56 (result (help-fns-tests--describe-function 're-search-forward))) 57 (should (string-match regexp result)))) 58 59(ert-deftest help-fns-test-lisp-macro () 60 (let ((regexp "a Lisp macro in .+subr\\.el") 61 (result (help-fns-tests--describe-function 'when))) 62 (should (string-match regexp result)))) 63 64(ert-deftest help-fns-test-lisp-defun () 65 (let ((regexp (if (featurep 'native-compile) 66 "a native compiled Lisp function in .+subr\\.el" 67 "a compiled Lisp function in .+subr\\.el")) 68 (result (help-fns-tests--describe-function 'last))) 69 (should (string-match regexp result)))) 70 71(ert-deftest help-fns-test-lisp-defsubst () 72 (let ((regexp "a compiled Lisp function in .+subr\\.el") 73 (result (help-fns-tests--describe-function 'posn-window))) 74 (should (string-match regexp result)))) 75 76(ert-deftest help-fns-test-alias-to-defun () 77 (let ((regexp "an alias for .set-file-modes. in .+subr\\.el") 78 (result (help-fns-tests--describe-function 'chmod))) 79 (should (string-match regexp result)))) 80 81(ert-deftest help-fns-test-bug23887 () 82 "Test for https://debbugs.gnu.org/23887 ." 83 (let ((regexp "an alias for .re-search-forward. in .+subr\\.el") 84 (result (help-fns-tests--describe-function 'search-forward-regexp))) 85 (should (string-match regexp result)))) 86 87(ert-deftest help-fns-test-dangling-alias () 88 "Make sure we don't burp on bogus aliases." 89 (let ((f (make-symbol "bogus-alias"))) 90 (define-obsolete-function-alias f 'help-fns-test--undefined-function "past") 91 (describe-symbol f))) 92 93;;; Test describe-function over functions with funny names 94(defun abc\\\[universal-argument\]b\`c\'d\\e\"f (x) 95 "A function with a funny name. 96 97\(fn XYZZY)" 98 x) 99 100(defun defgh\\\[universal-argument\]b\`c\'d\\e\"f (x) 101 "Another function with a funny name." 102 x) 103 104(ert-deftest help-fns-test-funny-names () 105 "Test for help with functions with funny names." 106 (describe-function 'abc\\\[universal-argument\]b\`c\'d\\e\"f) 107 (with-current-buffer "*Help*" 108 (goto-char (point-min)) 109 (should (search-forward 110 "(abc\\\\\\[universal-argument\\]b\\`c\\'d\\\\e\\\"f XYZZY)"))) 111 (describe-function 'defgh\\\[universal-argument\]b\`c\'d\\e\"f) 112 (with-current-buffer "*Help*" 113 (goto-char (point-min)) 114 (should (search-forward 115 "(defgh\\\\\\[universal-argument\\]b\\`c\\'d\\\\e\\\"f X)")))) 116 117 118;;; Test for describe-symbol 119(ert-deftest help-fns-test-describe-symbol () 120 "Test the `describe-symbol' function." 121 ;; 'describe-symbol' would originally signal an error for 122 ;; 'font-lock-comment-face'. 123 (describe-symbol 'font-lock-comment-face) 124 (with-current-buffer "*Help*" 125 (should (> (point-max) 1)) 126 (goto-char (point-min)) 127 (should (looking-at "^font-lock-comment-face is ")))) 128 129(defvar foo-test-map) 130(defvar help-fns-test--describe-keymap-foo) 131 132 133;;; Tests for describe-keymap 134(ert-deftest help-fns-test-find-keymap-name () 135 (should (equal (help-fns-find-keymap-name lisp-mode-map) 'lisp-mode-map)) 136 ;; Follow aliasing. 137 (unwind-protect 138 (progn 139 (defvaralias 'foo-test-map 'lisp-mode-map) 140 (should (equal (help-fns-find-keymap-name foo-test-map) 'lisp-mode-map))) 141 (makunbound 'foo-test-map))) 142 143(ert-deftest help-fns-test-describe-keymap/symbol () 144 (describe-keymap 'minibuffer-local-must-match-map) 145 (with-current-buffer "*Help*" 146 (should (looking-at "^minibuffer-local-must-match-map is")))) 147 148(ert-deftest help-fns-test-describe-keymap/value () 149 (describe-keymap minibuffer-local-must-match-map) 150 (with-current-buffer "*Help*" 151 (should (looking-at "\nKey")))) 152 153(ert-deftest help-fns-test-describe-keymap/not-keymap () 154 (should-error (describe-keymap nil)) 155 (should-error (describe-keymap emacs-version))) 156 157(ert-deftest help-fns-test-describe-keymap/let-bound () 158 (let ((foobar minibuffer-local-must-match-map)) 159 (describe-keymap foobar) 160 (with-current-buffer "*Help*" 161 (should (looking-at "\nKey"))))) 162 163(ert-deftest help-fns-test-describe-keymap/dynamically-bound-no-file () 164 (setq help-fns-test--describe-keymap-foo minibuffer-local-must-match-map) 165 (describe-keymap 'help-fns-test--describe-keymap-foo) 166 (with-current-buffer "*Help*" 167 (should (looking-at "^help-fns-test--describe-keymap-foo is")))) 168 169;;; Tests for find-lisp-object-file-name 170(ert-deftest help-fns-test-bug24697-function-search () 171 (should-not (find-lisp-object-file-name 'tab-width 1))) 172 173(ert-deftest help-fns-test-bug24697-non-internal-variable () 174 (let ((help-fns--test-var (make-symbol "help-fns--test-var"))) 175 ;; simulate an internal variable 176 (put help-fns--test-var 'variable-documentation 1) 177 (should-not (find-lisp-object-file-name help-fns--test-var 'defface)) 178 (should-not (find-lisp-object-file-name help-fns--test-var 1)))) 179 180;;; help-fns-tests.el ends here 181