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

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

[nongnu] elpa/buttercup d5572a6 034/340: Refactoring of the cleanup code


From: ELPA Syncer
Subject: [nongnu] elpa/buttercup d5572a6 034/340: Refactoring of the cleanup code.
Date: Thu, 16 Dec 2021 14:58:59 -0500 (EST)

branch: elpa/buttercup
commit d5572a6acdcb70b16fb36c804fa984bb33382c7b
Author: Jorgen Schaefer <contact@jorgenschaefer.de>
Commit: Jorgen Schaefer <contact@jorgenschaefer.de>

    Refactoring of the cleanup code.
---
 buttercup.el | 39 ++++++++++++++++++++-------------------
 1 file changed, 20 insertions(+), 19 deletions(-)

diff --git a/buttercup.el b/buttercup.el
index 2f66314..3679ccd 100644
--- a/buttercup.el
+++ b/buttercup.el
@@ -444,12 +444,18 @@ KEYWORD can have one of the following values:
               return-value)))
     this-spy-function))
 
+(defvar buttercup--cleanup-functions nil)
+
+(defmacro buttercup--with-cleanup (&rest body)
+  `(let ((buttercup--cleanup-functions nil))
+     (unwind-protect (progn ,@body)
+       (dolist (fun buttercup--cleanup-functions)
+         (ignore-errors
+           (funcall fun))))))
+
 (defun buttercup--add-cleanup (function)
-  (if buttercup--current-suite
-      (buttercup-after-each function)
-    (setq buttercup--cleanup-forms
-          (append buttercup--cleanup-forms
-                  (list function)))))
+  (setq buttercup--cleanup-functions
+        (cons function buttercup--cleanup-functions)))
 
 (defun spy-calls-all (spy)
   "Return the contexts of calls to SPY."
@@ -581,21 +587,16 @@ Do not change the global value.")
       (funcall f))
     (message "")))
 
-(defvar buttercup--cleanup-forms nil
-  "")
-
 (defun buttercup-run-spec (spec level)
-  (let ((buttercup--cleanup-forms nil))
-    (message "%s%s"
-             (make-string (* 2 level) ?\s)
-             (buttercup-spec-description spec))
-    (dolist (f buttercup--before-each)
-      (funcall f))
-    (funcall (buttercup-spec-function spec))
-    (dolist (f buttercup--cleanup-forms)
-      (funcall f))
-    (dolist (f buttercup--after-each)
-      (funcall f))))
+  (message "%s%s"
+           (make-string (* 2 level) ?\s)
+           (buttercup-spec-description spec))
+  (buttercup--with-cleanup
+   (dolist (f buttercup--before-each)
+     (funcall f))
+   (funcall (buttercup-spec-function spec))
+   (dolist (f buttercup--after-each)
+     (funcall f))))
 
 (defun buttercup-run-at-point ()
   (let ((buttercup-suites nil)



reply via email to

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