emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/buttercup 7a9999f296 2/4: tests: Extend buttercup--test-wi


From: ELPA Syncer
Subject: [nongnu] elpa/buttercup 7a9999f296 2/4: tests: Extend buttercup--test-with-tempdir to handle file content
Date: Sun, 10 Apr 2022 11:57:59 -0400 (EDT)

branch: elpa/buttercup
commit 7a9999f296c3bfbaddd1b5d0e3cbaef34437df70
Author: Ola Nilsson <ola.nilsson@gmail.com>
Commit: Ola Nilsson <ola.nilsson@gmail.com>

    tests: Extend buttercup--test-with-tempdir to handle file content
---
 tests/test-buttercup.el | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/tests/test-buttercup.el b/tests/test-buttercup.el
index a009b5438a..e35127e42c 100644
--- a/tests/test-buttercup.el
+++ b/tests/test-buttercup.el
@@ -76,25 +76,28 @@ variables:
   "Create FILES and execute BODY in a temporary directory.
 FILES shall be a list of file names. An empty file with that name
 will be created in the temporary directory. Any path prefix for a
-file will be created in the temporary directory."
+file will be created in the temporary directory. Elements in FILE
+can also be a list of up to two elements where the first is the
+filename as above and the second is the file contents.
+Return the value of the last form in BODY."
   (declare (debug t) (indent defun))
   (let ((tmproot (cl-gensym))
-        (subdir (cl-gensym))
-        (olddir (cl-gensym))
-        (file (cl-gensym)))
+        (olddir (cl-gensym)))
     `(let ((,tmproot (make-temp-file "buttercup-test-temp-" t))
-           ,subdir
            (,olddir default-directory))
-       (dolist (,file ,files)
-         (setq ,subdir (concat ,tmproot "/" (file-name-directory ,file)))
-         (when (and ,subdir (not (file-exists-p ,subdir)))
-           (make-directory ,subdir t))
-         (write-region "" nil (concat ,tmproot "/" ,file)))
+       (cl-labels ((make-file (file &optional content)
+                     (setq file (expand-file-name file ,tmproot))
+                     (make-directory (file-name-directory file) t)
+                     (write-region (or content "") nil file)))
+         (dolist (file ,files)
+           (if (listp file)
+               (apply #'make-file file)
+             (make-file file))))
        ;; It is tempting to use unwind-protect or condition-case here,
        ;; but that will mask actual test failures by interfering with
        ;; the debugger installed by buttercup
        (cd ,tmproot)
-       ,@body
+       (progn ,@body)
        (cd ,olddir)
        (delete-directory ,tmproot t))))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]