4

Say I have a function that is called on an idle timer:

(defun tmp:create () (mkdir "test"))
(run-with-idle-time 3 nil #'tmp:create)

How can I test that this function works?

Using something like

(ert-deftest async () ""
  (should-not (file-exists-p "test"))
  (sleep-for 4)
  (should (file-exists-p "test")))

doesn't work.

6

Idle timers won't be touched until the call stack has been cleared, so sitting won't actually help, it is only once all execution has stopped with the timer be run, so in your case, the idle timer won't run until 3 seconds of idle time after your whole test has run.

To combat this, you can call ert-run-idle-timers from ert-x.el in your test.

2
  • That function doesn't seem to exist :( (24.4) – Sean Allred Jan 30 '15 at 1:39
  • 1
    load-library ert-x, sorry didn't specify that. – Jordon Biondo Jan 30 '15 at 1:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.