I'd like to mock a function for a unit test that I'm writing. I want the mocked function to count how many times it was called but I'm having issues related to the scope of the count variable.
Here is an example of what I'm trying to do:
;; Assumes lexical-binding is t
(defvar example-settings nil)
(defun function-to-test ()
(funcall (car example-settings)))
(let* ((function-to-mock-call-cnt 0)
(example-settings
'((lambda ()
(setq function-to-mock-call-cnt
(1+ function-to-mock-call-cnt))))))
(function-to-test)
function-to-mock-call-cnt)
However, this fails with the error void-variable.
Can someone help me understand why this doesn't work?
org-agenda-bulk-custom-functions
is to a quoted list. Those lambdas aren't defined as functions there - the(lambda...)
for each is just a list. How do you expect the lexical bindings of those 3 vars to be captured in those lambdas as functions? You might just try using#'
in front of each(lambda...)
. Otherwise, you might need to use a backquote for the ``org-agenda...` var value, and use commas to insert the lambdas, so they're interpreted at that time (or compile time), to pick up those lexical args. Someone else will no doubt have a better explanation/solution.Invalid bulk action: P
- but then, I don't have the patch in my Org mode. After updating my Org mode to latest, I get(void-function org-test-agenda--kill-all-agendas)
when I run the above code, but still no complaints about those variables.