I'm writing tests for an interactive function. I've been using the unread-command-events variable in conjunction with call-interactively to verify that it does the right thing.

However, I just discovered that this doesn't work in batch mode.

For example:

(defun my-dummy (s)
  (interactive "sWrite something: ")

(ert-deftest my-dummy-test ()
  (let ((unread-command-events (listify-key-sequence "Hi!\n")))
    (should (equal (call-interactively #'my-dummy)

When running ert in interactive mode, this works. However, in batch mode, Emacs stops and read the keyboard without consuming input from unread-command-events.

In this a bug in batch mode or is this the expected behaviour?

Is there any other way to do this in batch mode?

1 Answer 1


This is expected behavior, but you can circumvent this problem by let-binding executing-kbd-macro to t, which will convince the minibuffer commands to read from unread-command-events rather than from stdin.

  • Can you elaborate why this is the expected behavior. Binding a somewhat unrelated variable executing-kbd-macro sounds like a hack in my eyes. At the very minimum, this should be documented in relevant places, e.g. in the documentation of unread-command-events. Commented Sep 23, 2020 at 7:38
  • @Lindydancer: Agreed, it's a hack. I found out how to do it by reading the C code; I don't think it was designed for what you need, it just happens to do the trick. M-x report-emacs-bug might be in order to request either better doc, or some less hacky solution.
    – Stefan
    Commented Sep 23, 2020 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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