Use lexical-binding in fortune.el and add tests

* lisp/play/fortune.el: Use lexical-binding.  Remove redundant
:group args.
(fortune-in-buffer): Quote function symbol as such.
* test/lisp/play/fortune-resources/fortunes:
* test/lisp/play/fortune-tests.el: New files.
* .gitignore: Ignore generated file fortunes.dat.
This commit is contained in:
Stefan Kangas 2020-11-14 15:55:08 +01:00
parent ca023e69e2
commit 08b1028c1e
4 changed files with 108 additions and 57 deletions

1
.gitignore vendored
View file

@ -153,6 +153,7 @@ test/manual/etags/ETAGS
test/manual/etags/CTAGS
test/manual/indent/*.new
test/lisp/gnus/mml-sec-resources/random_seed
test/lisp/play/fortune-resources/fortunes.dat
# ctags, etags.
TAGS

View file

@ -1,4 +1,4 @@
;;; fortune.el --- use fortune to create signatures
;;; fortune.el --- use fortune to create signatures -*- lexical-binding: t -*-
;; Copyright (C) 1999, 2001-2020 Free Software Foundation, Inc.
@ -63,76 +63,75 @@
:link '(emacs-commentary-link "fortune.el")
:version "21.1"
:group 'games)
(defcustom fortune-dir "~/docs/ascii/misc/fortunes/"
"The directory to look in for local fortune cookies files."
:type 'directory)
(defcustom fortune-file
(expand-file-name "usenet" fortune-dir)
"The file in which local fortune cookies will be stored."
:type 'file)
(defcustom fortune-database-extension ".dat"
"The extension of the corresponding fortune database.
Normally you won't have a reason to change it."
:type 'string)
(defcustom fortune-program "fortune"
"Program to select a fortune cookie."
:type 'string)
(defcustom fortune-program-options ()
"List of options to pass to the fortune program."
:type '(choice (repeat (string :tag "Option"))
(string :tag "Obsolete string of options"))
:version "23.1")
(defcustom fortune-strfile "strfile"
"Program to compute a new fortune database."
:type 'string)
(defcustom fortune-strfile-options ""
"Options to pass to the strfile program (a string)."
:type 'string)
(defcustom fortune-quiet-strfile-options "> /dev/null"
"Text added to the command for running `strfile'.
By default it discards the output produced by `strfile'.
Set this to \"\" if you would like to see the output."
:type 'string)
(defcustom fortune-always-compile t
"Non-nil means automatically compile fortune files.
If nil, you must invoke `fortune-compile' manually to do that."
:type 'boolean)
(defgroup fortune-signature nil
"Settings for use of fortune for signatures."
:group 'fortune
:group 'mail)
(defcustom fortune-dir "~/docs/ascii/misc/fortunes/"
"The directory to look in for local fortune cookies files."
:type 'directory
:group 'fortune)
(defcustom fortune-file
(expand-file-name "usenet" fortune-dir)
"The file in which local fortune cookies will be stored."
:type 'file
:group 'fortune)
(defcustom fortune-database-extension ".dat"
"The extension of the corresponding fortune database.
Normally you won't have a reason to change it."
:type 'string
:group 'fortune)
(defcustom fortune-program "fortune"
"Program to select a fortune cookie."
:type 'string
:group 'fortune)
(defcustom fortune-program-options ()
"List of options to pass to the fortune program."
:type '(choice (repeat (string :tag "Option"))
(string :tag "Obsolete string of options"))
:version "23.1"
:group 'fortune)
(defcustom fortune-strfile "strfile"
"Program to compute a new fortune database."
:type 'string
:group 'fortune)
(defcustom fortune-strfile-options ""
"Options to pass to the strfile program (a string)."
:type 'string
:group 'fortune)
(defcustom fortune-quiet-strfile-options "> /dev/null"
"Text added to the command for running `strfile'.
By default it discards the output produced by `strfile'.
Set this to \"\" if you would like to see the output."
:type 'string
:group 'fortune)
(defcustom fortune-always-compile t
"Non-nil means automatically compile fortune files.
If nil, you must invoke `fortune-compile' manually to do that."
:type 'boolean
:group 'fortune)
(defcustom fortune-author-line-prefix " -- "
"Prefix to put before the author name of a fortunate."
:type 'string
:group 'fortune-signature)
:type 'string)
(defcustom fortune-fill-column fill-column
"Fill column for fortune files."
:type 'integer
:group 'fortune-signature)
:type 'integer)
(defcustom fortune-from-mail "private e-mail"
"String to use to characterize that the fortune comes from an e-mail.
No need to add an `in'."
:type 'string
:group 'fortune-signature)
:type 'string)
(defcustom fortune-sigstart ""
"Some text to insert before the fortune cookie, in a mail signature."
:type 'string
:group 'fortune-signature)
:type 'string)
(defcustom fortune-sigend ""
"Some text to insert after the fortune cookie, in a mail signature."
:type 'string
:group 'fortune-signature)
:type 'string)
;; not customizable settings
@ -297,7 +296,7 @@ specifies the file to choose the fortune from."
(erase-buffer)
(if fortune-always-compile
(fortune-compile fort-file))
(apply 'call-process
(apply #'call-process
fortune-program ; program to call
nil fortune-buffer nil ; INFILE BUFFER DISPLAY
(append (if (stringp fortune-program-options)
@ -334,7 +333,6 @@ and choose the directory as the fortune-file."
(setq buffer-read-only t))
;;; Provide ourselves.
(provide 'fortune)
;;; fortune.el ends here

View file

@ -0,0 +1,11 @@
Embarrassed
Manual-Writer
Accused of
Communist
Subversion
%
Embarrassingly
Mundane
Advertising
Cuts
Sales

View file

@ -0,0 +1,41 @@
;;; fortune-tests.el --- Tests for fortune.el -*- lexical-binding: t -*-
;; Copyright (C) 2020 Free Software Foundation, Inc.
;; 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/>.
;;; Commentary:
;;; Code:
(require 'ert)
(require 'ert-x)
(require 'fortune)
(defvar fortune-tests--regexp
(rx (| "Embarrassed" "Embarrassingly")))
(ert-deftest test-fortune ()
(skip-unless (executable-find "fortune"))
(unwind-protect
(let ((fortune-file (ert-resource-file "fortunes")))
(fortune)
(goto-char (point-min))
(should (looking-at fortune-tests--regexp)))
(kill-buffer fortune-buffer-name)))
(provide 'fortune-tests)
;;; fortune-tests.el ends here