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.

Sean Allred
  • 6,861
  • 16
  • 85

1 Answers1

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.

Jordon Biondo
  • 12,332
  • 2
  • 41
  • 62