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

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

[nongnu] elpa/buttercup e62ce43 207/340: test: Do not leak functions fro


From: ELPA Syncer
Subject: [nongnu] elpa/buttercup e62ce43 207/340: test: Do not leak functions from "The Spy " test suite
Date: Thu, 16 Dec 2021 14:59:35 -0500 (EST)

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

    test: Do not leak functions from "The Spy " test suite
    
    The (symbol-function test-function) cannot be lexically bound, but
    equivalent behaviour can be acheived using before-all and after-all.
---
 tests/test-buttercup.el | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/tests/test-buttercup.el b/tests/test-buttercup.el
index 06dcce4..e99a964 100644
--- a/tests/test-buttercup.el
+++ b/tests/test-buttercup.el
@@ -613,16 +613,27 @@
 ;;; Spies
 
 (describe "The Spy "
-  (let (test-function)
+  (let (saved-test-function saved-test-command)
     ;; We use `before-all' here because some tests need to access the
     ;; same function as previous tests in order to work, so overriding
     ;; the function before each test would invalidate those tests.
     (before-all
+      (setq saved-test-function (and (fboundp 'test-function)
+                                     (symbol-function 'test-function))
+            saved-test-command (and (fboundp 'test-command)
+                                    (symbol-function 'test-command)))
       (fset 'test-function (lambda (a b)
                              (+ a b)))
       (fset 'test-command (lambda ()
                             (interactive)
                             t)))
+    (after-all
+      (if saved-test-function
+          (fset 'test-function saved-test-function)
+        (fmakunbound 'test-function))
+      (if saved-test-command
+          (fset 'test-command saved-test-command)
+        (fmakunbound 'test-command)))
 
     (describe "`spy-on' function"
       (it "replaces a symbol's function slot"



reply via email to

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