From 7d3c99b45c65c3756b6eff8cc4fd07bcc1d73386 Mon Sep 17 00:00:00 2001 From: Ulrich Müller Date: Wed, 6 Nov 2024 21:26:33 +0100 Subject: Simplify test code for skeleton functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- ChangeLog | 10 ++++++++++ test/devbook-mode-tests.el | 19 ++++++------------- test/ebuild-mode-tests.el | 35 +++++++++++++++-------------------- test/gentoo-newsitem-mode-tests.el | 31 +++++++++++++------------------ test/glep-mode-tests.el | 33 +++++++++++++-------------------- 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 + + * 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 * 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 "\n" "\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 " "" ; 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 " "" ; 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)) -- cgit v1.2.3-65-gdbad