aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Kangas2020-11-14 15:55:08 +0100
committerStefan Kangas2020-11-14 15:55:08 +0100
commit08b1028c1ecea9e560eb08154bfb3fc557f1275d (patch)
treefbdf2c5a905107cb10d4360586ed1da97463e3ac
parentca023e69e2d9ea79814a6c5f92c6e31c8f1efa70 (diff)
downloademacs-08b1028c1ecea9e560eb08154bfb3fc557f1275d.tar.gz
emacs-08b1028c1ecea9e560eb08154bfb3fc557f1275d.zip
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.
-rw-r--r--.gitignore1
-rw-r--r--lisp/play/fortune.el68
-rw-r--r--test/lisp/play/fortune-resources/fortunes11
-rw-r--r--test/lisp/play/fortune-tests.el41
4 files changed, 86 insertions, 35 deletions
diff --git a/.gitignore b/.gitignore
index 29565d0417b..c969dcadf96 100644
--- a/.gitignore
+++ b/.gitignore
@@ -153,6 +153,7 @@ test/manual/etags/ETAGS
153test/manual/etags/CTAGS 153test/manual/etags/CTAGS
154test/manual/indent/*.new 154test/manual/indent/*.new
155test/lisp/gnus/mml-sec-resources/random_seed 155test/lisp/gnus/mml-sec-resources/random_seed
156test/lisp/play/fortune-resources/fortunes.dat
156 157
157# ctags, etags. 158# ctags, etags.
158TAGS 159TAGS
diff --git a/lisp/play/fortune.el b/lisp/play/fortune.el
index f8859d954f8..c180fd06c34 100644
--- a/lisp/play/fortune.el
+++ b/lisp/play/fortune.el
@@ -1,4 +1,4 @@
1;;; fortune.el --- use fortune to create signatures 1;;; fortune.el --- use fortune to create signatures -*- lexical-binding: t -*-
2 2
3;; Copyright (C) 1999, 2001-2020 Free Software Foundation, Inc. 3;; Copyright (C) 1999, 2001-2020 Free Software Foundation, Inc.
4 4
@@ -63,76 +63,75 @@
63 :link '(emacs-commentary-link "fortune.el") 63 :link '(emacs-commentary-link "fortune.el")
64 :version "21.1" 64 :version "21.1"
65 :group 'games) 65 :group 'games)
66(defgroup fortune-signature nil
67 "Settings for use of fortune for signatures."
68 :group 'fortune
69 :group 'mail)
70 66
71(defcustom fortune-dir "~/docs/ascii/misc/fortunes/" 67(defcustom fortune-dir "~/docs/ascii/misc/fortunes/"
72 "The directory to look in for local fortune cookies files." 68 "The directory to look in for local fortune cookies files."
73 :type 'directory 69 :type 'directory)
74 :group 'fortune) 70
75(defcustom fortune-file 71(defcustom fortune-file
76 (expand-file-name "usenet" fortune-dir) 72 (expand-file-name "usenet" fortune-dir)
77 "The file in which local fortune cookies will be stored." 73 "The file in which local fortune cookies will be stored."
78 :type 'file 74 :type 'file)
79 :group 'fortune) 75
80(defcustom fortune-database-extension ".dat" 76(defcustom fortune-database-extension ".dat"
81 "The extension of the corresponding fortune database. 77 "The extension of the corresponding fortune database.
82Normally you won't have a reason to change it." 78Normally you won't have a reason to change it."
83 :type 'string 79 :type 'string)
84 :group 'fortune) 80
85(defcustom fortune-program "fortune" 81(defcustom fortune-program "fortune"
86 "Program to select a fortune cookie." 82 "Program to select a fortune cookie."
87 :type 'string 83 :type 'string)
88 :group 'fortune) 84
89(defcustom fortune-program-options () 85(defcustom fortune-program-options ()
90 "List of options to pass to the fortune program." 86 "List of options to pass to the fortune program."
91 :type '(choice (repeat (string :tag "Option")) 87 :type '(choice (repeat (string :tag "Option"))
92 (string :tag "Obsolete string of options")) 88 (string :tag "Obsolete string of options"))
93 :version "23.1" 89 :version "23.1")
94 :group 'fortune) 90
95(defcustom fortune-strfile "strfile" 91(defcustom fortune-strfile "strfile"
96 "Program to compute a new fortune database." 92 "Program to compute a new fortune database."
97 :type 'string 93 :type 'string)
98 :group 'fortune) 94
99(defcustom fortune-strfile-options "" 95(defcustom fortune-strfile-options ""
100 "Options to pass to the strfile program (a string)." 96 "Options to pass to the strfile program (a string)."
101 :type 'string 97 :type 'string)
102 :group 'fortune) 98
103(defcustom fortune-quiet-strfile-options "> /dev/null" 99(defcustom fortune-quiet-strfile-options "> /dev/null"
104 "Text added to the command for running `strfile'. 100 "Text added to the command for running `strfile'.
105By default it discards the output produced by `strfile'. 101By default it discards the output produced by `strfile'.
106Set this to \"\" if you would like to see the output." 102Set this to \"\" if you would like to see the output."
107 :type 'string 103 :type 'string)
108 :group 'fortune)
109 104
110(defcustom fortune-always-compile t 105(defcustom fortune-always-compile t
111 "Non-nil means automatically compile fortune files. 106 "Non-nil means automatically compile fortune files.
112If nil, you must invoke `fortune-compile' manually to do that." 107If nil, you must invoke `fortune-compile' manually to do that."
113 :type 'boolean 108 :type 'boolean)
114 :group 'fortune) 109
110(defgroup fortune-signature nil
111 "Settings for use of fortune for signatures."
112 :group 'fortune
113 :group 'mail)
114
115(defcustom fortune-author-line-prefix " -- " 115(defcustom fortune-author-line-prefix " -- "
116 "Prefix to put before the author name of a fortunate." 116 "Prefix to put before the author name of a fortunate."
117 :type 'string 117 :type 'string)
118 :group 'fortune-signature) 118
119(defcustom fortune-fill-column fill-column 119(defcustom fortune-fill-column fill-column
120 "Fill column for fortune files." 120 "Fill column for fortune files."
121 :type 'integer 121 :type 'integer)
122 :group 'fortune-signature) 122
123(defcustom fortune-from-mail "private e-mail" 123(defcustom fortune-from-mail "private e-mail"
124 "String to use to characterize that the fortune comes from an e-mail. 124 "String to use to characterize that the fortune comes from an e-mail.
125No need to add an `in'." 125No need to add an `in'."
126 :type 'string 126 :type 'string)
127 :group 'fortune-signature) 127
128(defcustom fortune-sigstart "" 128(defcustom fortune-sigstart ""
129 "Some text to insert before the fortune cookie, in a mail signature." 129 "Some text to insert before the fortune cookie, in a mail signature."
130 :type 'string 130 :type 'string)
131 :group 'fortune-signature) 131
132(defcustom fortune-sigend "" 132(defcustom fortune-sigend ""
133 "Some text to insert after the fortune cookie, in a mail signature." 133 "Some text to insert after the fortune cookie, in a mail signature."
134 :type 'string 134 :type 'string)
135 :group 'fortune-signature)
136 135
137 136
138;; not customizable settings 137;; not customizable settings
@@ -297,7 +296,7 @@ specifies the file to choose the fortune from."
297 (erase-buffer) 296 (erase-buffer)
298 (if fortune-always-compile 297 (if fortune-always-compile
299 (fortune-compile fort-file)) 298 (fortune-compile fort-file))
300 (apply 'call-process 299 (apply #'call-process
301 fortune-program ; program to call 300 fortune-program ; program to call
302 nil fortune-buffer nil ; INFILE BUFFER DISPLAY 301 nil fortune-buffer nil ; INFILE BUFFER DISPLAY
303 (append (if (stringp fortune-program-options) 302 (append (if (stringp fortune-program-options)
@@ -334,7 +333,6 @@ and choose the directory as the fortune-file."
334 (setq buffer-read-only t)) 333 (setq buffer-read-only t))
335 334
336 335
337;;; Provide ourselves.
338(provide 'fortune) 336(provide 'fortune)
339 337
340;;; fortune.el ends here 338;;; fortune.el ends here
diff --git a/test/lisp/play/fortune-resources/fortunes b/test/lisp/play/fortune-resources/fortunes
new file mode 100644
index 00000000000..f1ddc512d00
--- /dev/null
+++ b/test/lisp/play/fortune-resources/fortunes
@@ -0,0 +1,11 @@
1Embarrassed
2Manual-Writer
3Accused of
4Communist
5Subversion
6%
7Embarrassingly
8Mundane
9Advertising
10Cuts
11Sales
diff --git a/test/lisp/play/fortune-tests.el b/test/lisp/play/fortune-tests.el
new file mode 100644
index 00000000000..97263405e8a
--- /dev/null
+++ b/test/lisp/play/fortune-tests.el
@@ -0,0 +1,41 @@
1;;; fortune-tests.el --- Tests for fortune.el -*- lexical-binding: t -*-
2
3;; Copyright (C) 2020 Free Software Foundation, Inc.
4
5;; This file is part of GNU Emacs.
6
7;; GNU Emacs is free software: you can redistribute it and/or modify
8;; it under the terms of the GNU General Public License as published by
9;; the Free Software Foundation, either version 3 of the License, or
10;; (at your option) any later version.
11
12;; GNU Emacs is distributed in the hope that it will be useful,
13;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;; GNU General Public License for more details.
16
17;; You should have received a copy of the GNU General Public License
18;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
19
20;;; Commentary:
21
22;;; Code:
23
24(require 'ert)
25(require 'ert-x)
26(require 'fortune)
27
28(defvar fortune-tests--regexp
29 (rx (| "Embarrassed" "Embarrassingly")))
30
31(ert-deftest test-fortune ()
32 (skip-unless (executable-find "fortune"))
33 (unwind-protect
34 (let ((fortune-file (ert-resource-file "fortunes")))
35 (fortune)
36 (goto-char (point-min))
37 (should (looking-at fortune-tests--regexp)))
38 (kill-buffer fortune-buffer-name)))
39
40(provide 'fortune-tests)
41;;; fortune-tests.el ends here