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

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

[nongnu] elpa/buttercup 38cfa6f 270/340: Fix spy-on on Emacs 24.3 for sy


From: ELPA Syncer
Subject: [nongnu] elpa/buttercup 38cfa6f 270/340: Fix spy-on on Emacs 24.3 for symbols that are not fbound
Date: Thu, 16 Dec 2021 14:59:48 -0500 (EST)

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

    Fix spy-on on Emacs 24.3 for symbols that are not fbound
    
    symbol-function signals an error when called with a nil argument on
    Emacs 24.3.  Add fboundp checks where required to make this work.
---
 buttercup.el            | 8 ++++----
 tests/test-buttercup.el | 5 +++++
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/buttercup.el b/buttercup.el
index 07cef4a..4315f49 100644
--- a/buttercup.el
+++ b/buttercup.el
@@ -1102,10 +1102,10 @@ also be a command with the same interactive form, unless
 `:and-call-fake' is used, in which case it is the caller's
 responsibility to ensure ARG is a command."
   ;; We need to load an autoloaded function before spying on it
-  (when (autoloadp (symbol-function symbol))
+  (when (autoloadp (and (fboundp symbol) (symbol-function symbol)))
     (autoload-do-load (symbol-function symbol) symbol))
-  (cl-assert (not (autoloadp (symbol-function symbol))))
-  (let* ((orig (symbol-function symbol))
+  (cl-assert (not (autoloadp (and (fboundp symbol) (symbol-function symbol)))))
+  (let* ((orig (and (fboundp symbol) (symbol-function symbol)))
          (orig-intform (interactive-form orig))
          (replacement
           (pcase
@@ -1150,7 +1150,7 @@ responsibility to ensure ARG is a command."
 
 (defun buttercup--spy-on-and-call-replacement (spy fun)
   "Replace the function in symbol SPY with a spy calling FUN."
-  (let ((orig-function (symbol-function spy)))
+  (let ((orig-function (and (fboundp spy) (symbol-function spy))))
     (when (buttercup--add-cleanup (lambda ()
                                   (fset spy orig-function)))
       (fset spy (buttercup--make-spy fun)))))
diff --git a/tests/test-buttercup.el b/tests/test-buttercup.el
index e3802d3..fe94749 100644
--- a/tests/test-buttercup.el
+++ b/tests/test-buttercup.el
@@ -746,6 +746,11 @@
                         :to-be :loaded-successfully))
             (delete-file function-file nil))))
 
+      (it "can spy on non-existing functions"
+        (spy-on 'local-function)
+        (local-function)
+        (expect 'local-function :to-have-been-called))
+
       (it "only accepts ARG for keywords that use it"
         (expect
          (spy-on 'test-function :and-call-through :arg-not-allowed)



reply via email to

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