1

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: ")
  s)

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

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?

Lindydancer
  • 6,095
  • 1
  • 13
  • 25

1 Answers1

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.

Stefan
  • 26,154
  • 3
  • 46
  • 84
  • 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`. – Lindydancer Sep 23 '20 at 07: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 Sep 23 '20 at 13:45