diff options
author | Ryan C. Thompson <rct@thompsonclan.org> | 2019-08-28 17:14:44 -0700 |
---|---|---|
committer | Ryan C. Thompson <rct@thompsonclan.org> | 2019-12-30 17:44:38 -0500 |
commit | 25462ddfdf430308c5fa9219d2f16a626e2913cf (patch) | |
tree | de5a92bed48daea388f822b6eed1b36063188463 | |
parent | 26e2dedb3558954ed5429753e39c028c43d5b63a (diff) |
Record calls to spied-on functions that throw errors
This addes another slot to the spy-context struct that is used to
record the signal thrown by the spied function, if any.
Fixes #139.
-rw-r--r-- | buttercup.el | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/buttercup.el b/buttercup.el index ba5c203..fdddc7e 100644 --- a/buttercup.el +++ b/buttercup.el @@ -1025,6 +1025,7 @@ DESCRIPTION has the same meaning as in `xit'. FUNCTION is ignored." (cl-defstruct spy-context args return-value + thrown-signal current-buffer) (defun spy-on (symbol &optional keyword arg) @@ -1106,15 +1107,35 @@ responsibility to ensure ARG is a command." (defun buttercup--make-spy (fun) "Create a new spy function wrapping FUN and tracking calls to itself." (let (this-spy-function) - (setq this-spy-function - (lambda (&rest args) - (let ((return-value (apply fun args))) + (setq + this-spy-function + (lambda (&rest args) + (let ((returned nil) + (return-value nil)) + (condition-case err + (progn + (setq return-value (apply fun args) + returned t) + (buttercup--spy-calls-add + this-spy-function + (make-spy-context :args args + :return-value return-value + :thrown-signal nil + :current-buffer (current-buffer))) + return-value) + (error + ;; If returned is non-nil, then the error we caught + ;; didn't come from FUN, so we shouldn't record it. + (unless returned (buttercup--spy-calls-add this-spy-function (make-spy-context :args args - :return-value return-value - :current-buffer (current-buffer))) - return-value))) + :return-value nil + :thrown-signal err + :current-buffer (current-buffer)))) + ;; Regardless, we only caught this error order to record + ;; it, so we need to re-throw it. + (signal (car err) (cdr err))))))) ;; Add the interactive form from `fun', if any (when (interactive-form fun) (setq this-spy-function |