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

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

[elpa] externals/assess a459abe966 11/95: New macro `sisyphus-with-prese


From: ELPA Syncer
Subject: [elpa] externals/assess a459abe966 11/95: New macro `sisyphus-with-preserved-buffer-list'.
Date: Tue, 19 Jul 2022 15:57:29 -0400 (EDT)

branch: externals/assess
commit a459abe9661cbc982294b32da3b374117efd534b
Author: Phillip Lord <phillip.lord@newcastle.ac.uk>
Commit: Phillip Lord <phillip.lord@newcastle.ac.uk>

    New macro `sisyphus-with-preserved-buffer-list'.
---
 sisyphus.el           | 33 +++++++++++++++++++++++++++------
 test/sisyphus-test.el | 20 ++++++++++++++++++++
 2 files changed, 47 insertions(+), 6 deletions(-)

diff --git a/sisyphus.el b/sisyphus.el
index 61af3f1400..2ad29d7e06 100644
--- a/sisyphus.el
+++ b/sisyphus.el
@@ -35,7 +35,7 @@
 
 ;; Really, all the functions in here should be tested. But some of the tests 
are
 ;; really, realy hard to test because they depend on the output of ert test,
-;; wh
+
 
 
 
@@ -48,8 +48,16 @@
 (require 'pp)
 (require 'ert)
 (require 'm-buffer-at)
+(require 'dash)
+;; #+end_src
+
+;; #+begin_src emacs-lisp
+(define-error 'deliberate-error
+  "An error deliberately caused during testing."
+  'error)
 ;; #+end_src
 
+
 ;; ** Advice
 
 
@@ -82,6 +90,9 @@
 
 ;; How do do this cleanly? Apply patch to ert.el?
 
+
+
+
 ;; *** String Comparision
 
 ;; #+begin_src emacs-lisp
@@ -214,11 +225,21 @@ print any messages!"
 ;; ** Create buffers
 
 
-;; Need to think carefully about this, but would like to create buffers. Temp
-;; buffers are generally a good option but what if we have a named buffer, but
-;; the named buffer is already open. What happens if a test creates a buffer? 
Can
-;; we detect the buffer creation and close them again?
-;; "with-protected-buffer-list" perhaps, or "save-buffer-list-excursion".
+
+(defmacro sisyphus-with-preserved-buffer-list (&rest body)
+  "Evaluate BODY, but delete any buffers that have been created."
+  `(let ((before-buffer-list
+          (buffer-list)))
+     (unwind-protect
+         (progn
+           ,@body)
+       (--map
+        (kill-buffer it)
+        (-difference (buffer-list)
+                     before-buffer-list)))))
+
+
+
 
 ;; ** Open files
 
diff --git a/test/sisyphus-test.el b/test/sisyphus-test.el
index 665b9f7352..57c4239832 100644
--- a/test/sisyphus-test.el
+++ b/test/sisyphus-test.el
@@ -152,3 +152,23 @@ This also tests the advice on string=."
        (sisyphus-file-string=
         sisyphus-test-hello.txt
         "goodbye"))))))
+
+
+(ert-deftest preserved-buffer-list ()
+  (should
+   (=
+    (length (buffer-list))
+    (progn
+      (sisyphus-with-preserved-buffer-list
+       (generate-new-buffer "preserved-buffer-list"))
+      (length (buffer-list)))))
+
+  (should
+   (=
+    (length (buffer-list))
+    (condition-case e
+        (sisyphus-with-preserved-buffer-list
+         (generate-new-buffer "preserved-buffer-list")
+         (signal 'deliberate-error nil))
+      (deliberate-error
+       (length (buffer-list)))))))



reply via email to

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