summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Müller <ulm@gentoo.org>2024-11-06 21:26:33 +0100
committerUlrich Müller <ulm@gentoo.org>2024-11-06 21:26:33 +0100
commit7d3c99b45c65c3756b6eff8cc4fd07bcc1d73386 (patch)
tree5b5764a7083a16e1b0d5c5514a2f3531d76dfc54
parentMake XEmacs less chatty in tests (diff)
downloadebuild-mode-7d3c99b45c65c3756b6eff8cc4fd07bcc1d73386.tar.gz
ebuild-mode-7d3c99b45c65c3756b6eff8cc4fd07bcc1d73386.tar.bz2
ebuild-mode-7d3c99b45c65c3756b6eff8cc4fd07bcc1d73386.zip
Simplify test code for skeleton functions
* test/ebuild-mode-tests.el (ebuild-mode-test-skeleton): * test/glep-mode-tests.el (glep-mode-test-skeleton): * test/gentoo-newsitem-mode-tests.el (gentoo-newsitem-test-skeleton): * test/devbook-mode-tests.el (devbook-mode-test-skeleton): Move variable and function for test input into the cl-letf* form and delete them from global scope. Signed-off-by: Ulrich Müller <ulm@gentoo.org>
-rw-r--r--ChangeLog10
-rw-r--r--test/devbook-mode-tests.el19
-rw-r--r--test/ebuild-mode-tests.el35
-rw-r--r--test/gentoo-newsitem-mode-tests.el31
-rw-r--r--test/glep-mode-tests.el33
5 files changed, 57 insertions, 71 deletions
diff --git a/ChangeLog b/ChangeLog
index 8637efa..2761a37 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2024-11-06 Ulrich Müller <ulm@gentoo.org>
+
+ * test/ebuild-mode-tests.el (ebuild-mode-test-skeleton):
+ * test/glep-mode-tests.el (glep-mode-test-skeleton):
+ * test/gentoo-newsitem-mode-tests.el
+ (gentoo-newsitem-test-skeleton):
+ * test/devbook-mode-tests.el (devbook-mode-test-skeleton):
+ Move variable and function for test input into the cl-letf* form
+ and delete them from global scope.
+
2024-11-03 Ulrich Müller <ulm@gentoo.org>
* test/xemacs-test-wrapper.el (ert-deftest): Silence info-level
diff --git a/test/devbook-mode-tests.el b/test/devbook-mode-tests.el
index 37edc8b..2529bbd 100644
--- a/test/devbook-mode-tests.el
+++ b/test/devbook-mode-tests.el
@@ -26,11 +26,6 @@
(defmacro devbook-mode-test-run-silently (&rest body)
`(let ((inhibit-message t)) ,@body))
-(defvar devbook-mode-test-input nil)
-
-(defun devbook-mode-test-input (&rest _args)
- (concat (pop devbook-mode-test-input)))
-
(ert-deftest devbook-mode-test-locate-schema ()
(cl-letf* ((rncfile "/home/larry/devmanual/devbook.rnc")
((symbol-function 'file-exists-p)
@@ -52,14 +47,12 @@
(ert-deftest devbook-mode-test-skeleton ()
(with-temp-buffer
- (cl-letf (((symbol-function 'read-from-minibuffer)
- #'devbook-mode-test-input)
- ((symbol-function 'read-string)
- #'devbook-mode-test-input)
- (buffer-file-name
- "/home/larry/devmanual/quickstart/text.xml"))
- (setq devbook-mode-test-input
- '("Quickstart guide"))
+ (cl-letf* ((buffer-file-name "/home/larry/devmanual/quickstart/text.xml")
+ (testinput '("Quickstart guide"))
+ (getinput (lambda (&rest _args)
+ (concat (pop testinput))))
+ ((symbol-function 'read-from-minibuffer) getinput)
+ ((symbol-function 'read-string) getinput))
(devbook-insert-skeleton))
(let ((buf1 (concat "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<guide self=\"quickstart/\">\n"
diff --git a/test/ebuild-mode-tests.el b/test/ebuild-mode-tests.el
index 1a7db49..e81d4c8 100644
--- a/test/ebuild-mode-tests.el
+++ b/test/ebuild-mode-tests.el
@@ -47,11 +47,6 @@
((symbol-function 'clear-message) #'ignore))
,@body)))
-(defvar ebuild-mode-test-input nil)
-
-(defun ebuild-mode-test-input (&rest _args)
- (concat (pop ebuild-mode-test-input)))
-
(ert-deftest ebuild-mode-test-arch-lessp ()
(should (ebuild-mode-arch-lessp "amd64" "x86"))
(should-not (ebuild-mode-arch-lessp "amd64-linux" "x86"))
@@ -215,21 +210,21 @@
(ert-deftest ebuild-mode-test-skeleton ()
(with-temp-buffer
- (cl-letf (((symbol-function 'read-from-minibuffer)
- #'ebuild-mode-test-input)
- ((symbol-function 'read-string)
- #'ebuild-mode-test-input))
- (setq ebuild-mode-test-input
- '("8" ; EAPI
- "" ; inherit
- "Skeleton test" ; DESCRIPTION
- "https://www.gentoo.org/" ; HOMEPAGE
- "" ; SRC_URI
- "" ; S
- "GPL-2+" "MIT" "" ; LICENSE
- "~amd64" "" ; KEYWORDS
- "" ; IUSE
- "")) ; RESTRICT
+ (cl-letf* ((testinput
+ '("8" ; EAPI
+ "" ; inherit
+ "Skeleton test" ; DESCRIPTION
+ "https://www.gentoo.org/" ; HOMEPAGE
+ "" ; SRC_URI
+ "" ; S
+ "GPL-2+" "MIT" "" ; LICENSE
+ "~amd64" "" ; KEYWORDS
+ "" ; IUSE
+ "")) ; RESTRICT
+ (getinput (lambda (&rest _args)
+ (concat (pop testinput))))
+ ((symbol-function 'read-from-minibuffer) getinput)
+ ((symbol-function 'read-string) getinput))
(ebuild-mode-test-run-with-fixed-time
(if (featurep 'xemacs)
;; prevent a segfault (seen with XEmacs 21.4.24 and 21.5.35)
diff --git a/test/gentoo-newsitem-mode-tests.el b/test/gentoo-newsitem-mode-tests.el
index 134527c..665e80d 100644
--- a/test/gentoo-newsitem-mode-tests.el
+++ b/test/gentoo-newsitem-mode-tests.el
@@ -28,11 +28,6 @@
(defalias 'cl-letf #'letf)
(defalias 'cl-letf* #'letf*)))
-(defvar gentoo-newsitem-test-input nil)
-
-(defun gentoo-newsitem-test-input (&rest _args)
- (concat (pop gentoo-newsitem-test-input)))
-
(ert-deftest gentoo-newsitem-test-font-lock ()
(with-temp-buffer
(gentoo-newsitem-mode)
@@ -49,19 +44,19 @@
(ert-deftest gentoo-newsitem-test-skeleton ()
(with-temp-buffer
- (cl-letf (((symbol-function 'read-from-minibuffer)
- #'gentoo-newsitem-test-input)
- ((symbol-function 'read-string)
- #'gentoo-newsitem-test-input))
- (setq gentoo-newsitem-test-input
- '("Skeleton test" ; Title
- "Larry the Cow <larry@example.org>" "" ; Author
- "" ; Translator
- "2024-08-10" ; Posted
- "" ; News-Item-Format
- "" ; Display-If-Installed
- "" ; Display-If-Keyword
- "")) ; Display-If-Profile
+ (cl-letf* ((testinput
+ '("Skeleton test" ; Title
+ "Larry the Cow <larry@example.org>" "" ; Author
+ "" ; Translator
+ "2024-08-10" ; Posted
+ "" ; News-Item-Format
+ "" ; Display-If-Installed
+ "" ; Display-If-Keyword
+ "")) ; Display-If-Profile
+ (getinput (lambda (&rest _args)
+ (concat (pop testinput))))
+ ((symbol-function 'read-from-minibuffer) getinput)
+ ((symbol-function 'read-string) getinput))
(if (featurep 'xemacs)
;; prevent a segfault (seen with XEmacs 21.4.24 and 21.5.35)
;; https://foss.heptapod.net/xemacs/xemacs/-/issues/6
diff --git a/test/glep-mode-tests.el b/test/glep-mode-tests.el
index 0706759..ec06eb5 100644
--- a/test/glep-mode-tests.el
+++ b/test/glep-mode-tests.el
@@ -35,11 +35,6 @@
(funcall orig-fun fmt-string (or time fixed-time) zone))))
,@body)))
-(defvar glep-mode-test-input nil)
-
-(defun glep-mode-test-input (&rest _args)
- (concat (pop glep-mode-test-input)))
-
(ert-deftest glep-mode-test-font-lock ()
(with-temp-buffer
(glep-mode)
@@ -90,21 +85,19 @@
(ert-deftest glep-mode-test-skeleton ()
(with-temp-buffer
- (cl-letf (((symbol-function 'read-from-minibuffer)
- #'glep-mode-test-input)
- ((symbol-function 'read-string)
- #'glep-mode-test-input)
- (buffer-file-name
- "/home/larry/devmanual/quickstart/text.xml"))
- (setq glep-mode-test-input
- '("9999" ; GLEP
- "Skeleton test" ; Title
- "Larry the Cow" ; Author
- "Informational" ; Type
- "Draft" ; Status
- "1" ; Version
- "" ; Requires
- "")) ; Replaces
+ (cl-letf* ((testinput
+ '("9999" ; GLEP
+ "Skeleton test" ; Title
+ "Larry the Cow" ; Author
+ "Informational" ; Type
+ "Draft" ; Status
+ "1" ; Version
+ "" ; Requires
+ "")) ; Replaces
+ (getinput (lambda (&rest _args)
+ (concat (pop testinput))))
+ ((symbol-function 'read-from-minibuffer) getinput)
+ ((symbol-function 'read-string) getinput))
(glep-mode-test-run-with-fixed-time
(glep-mode-insert-skeleton)))
(goto-char (point-min))