From e62ce43cd30fce53d2d90f9d15f5d7dd4b7f240e Mon Sep 17 00:00:00 2001 From: Ola Nilsson Date: Tue, 3 Sep 2019 22:43:30 +0200 Subject: [PATCH] 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"