[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
emacs-28 aacafbe: Refactor mh-utils-tests macro 'with-mh-test-env'
From: |
Stephen Gildea |
Subject: |
emacs-28 aacafbe: Refactor mh-utils-tests macro 'with-mh-test-env' |
Date: |
Tue, 5 Oct 2021 23:36:44 -0400 (EDT) |
branch: emacs-28
commit aacafbe267306a2bb5d504ae408008d1ff7e9c8f
Author: Stephen Gildea <stepheng+emacs@gildea.com>
Commit: Stephen Gildea <stepheng+emacs@gildea.com>
Refactor mh-utils-tests macro 'with-mh-test-env'
* test/lisp/mh-e/mh-utils-tests.el (with-mh-test-env): Refactor to
reduce the size of the expanded macro.
(mh-test-utils-setup): New helper function.
(mh-ensure-native-trampolines): Absorbed by mh-test-utils-setup.
---
test/lisp/mh-e/mh-utils-tests.el | 36 +++++++++++++++++++-----------------
1 file changed, 19 insertions(+), 17 deletions(-)
diff --git a/test/lisp/mh-e/mh-utils-tests.el b/test/lisp/mh-e/mh-utils-tests.el
index f1282ab..bf684db 100644
--- a/test/lisp/mh-e/mh-utils-tests.el
+++ b/test/lisp/mh-e/mh-utils-tests.el
@@ -95,26 +95,28 @@ install an MH variant and test it interactively."
(mh-sub-folders-cache (make-hash-table :test #'equal))
;; remember the original value
(original-mh-envvar (getenv "MH")))
- (unless mh-test-variant-logged-already
- (mh-variant-set mh-variant)
- (setq mh-test-variant-logged-already t))
(unwind-protect
(progn
- (if mh-variant-in-use
- (setq temp-home-dir (mh-test-utils-setup-with-variant))
- (mh-test-utils-setup-with-mocks))
+ (setq temp-home-dir (mh-test-utils-setup))
,@body)
(if temp-home-dir (delete-directory temp-home-dir t))
(setenv "MH" original-mh-envvar))))
-(defun mh-ensure-native-trampolines ()
- "Build head of time the trampolines we'll need.
-As `call-process'' and `file-directory-p' will be redefined, the
-native compiler will invoke `call-process' to compile the
-respective trampolines. To avoid interferences with the
-`call-process' mocking we build these AOT."
+(defun mh-test-utils-setup ()
+ "Set dynamically bound variables needed by mock and/or variants.
+Return the name of the root of the created directory tree, if any."
+ (unless mh-test-variant-logged-already
+ (mh-variant-set mh-variant)
+ (setq mh-test-variant-logged-already t))
+ ;; As `call-process'' and `file-directory-p' will be redefined, the
+ ;; native compiler will invoke `call-process' to compile the
+ ;; respective trampolines. To avoid interference with the
+ ;; `call-process' mocking, we build these ahead of time.
(when (native-comp-available-p)
- (mapc #'comp-subr-trampoline-install '(call-process file-directory-p))))
+ (mapc #'comp-subr-trampoline-install '(call-process file-directory-p)))
+ (if mh-variant-in-use
+ (mh-test-utils-setup-with-variant)
+ (mh-test-utils-setup-with-mocks)))
(defun mh-test-utils-setup-with-mocks ()
"Set dynamically bound variables so that MH programs are mocked out.
@@ -125,9 +127,10 @@ The tests use this method if no configured MH variant is
found."
(mh-populate-sub-folders-cache "+rela-folder/bar")
(mh-populate-sub-folders-cache "+rela-folder/foo")
(mh-populate-sub-folders-cache "+rela-folder/food")
- (mh-ensure-native-trampolines)
(fset 'call-process #'mh-test-utils-mock-call-process)
- (fset 'file-directory-p #'mh-test-utils-mock-file-directory-p))
+ (fset 'file-directory-p #'mh-test-utils-mock-file-directory-p)
+ ;; no temp directory created
+ nil)
(defun mh-test-utils-mock-call-process (program
&optional _infile _destination _display
@@ -196,7 +199,7 @@ Return the name of the root of the created directory tree.
Set dynamically bound variables so that MH programs may log.
The tests use this method if a configured MH variant is found."
(let* ((temp-home-dir
- (make-temp-file "emacs-mh-e-unit-test" t))
+ (make-temp-file "emacs-mh-e-unit-test-" t))
(profile (expand-file-name
".mh_profile" temp-home-dir))
(mail-dir (expand-file-name "Mail" temp-home-dir))
@@ -215,7 +218,6 @@ The tests use this method if a configured MH variant is
found."
(make-directory (expand-file-name "foo" abso-folder) t)
(make-directory (expand-file-name "food" abso-folder) t)
(setq mh-test-abs-folder abso-folder)
- (mh-ensure-native-trampolines)
(fset 'call-process #'mh-test-utils-log-call-process)
(fset 'file-directory-p #'mh-test-utils-log-file-directory-p)
temp-home-dir))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- emacs-28 aacafbe: Refactor mh-utils-tests macro 'with-mh-test-env',
Stephen Gildea <=