unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Changing buffer in filter function has no effect in ERT
@ 2015-04-22  8:53 Robin Neatherway
  0 siblings, 0 replies; only message in thread
From: Robin Neatherway @ 2015-04-22  8:53 UTC (permalink / raw)
  To: help-gnu-emacs

I have a test for fsharp-mode to exercise the jump to definition
functionality. Communicating with the background process involves
sending a command and then letting the filter function handle the
response, which may involve switching to a different buffer. This
works fine "for real", but no in the test. Strangely, the buffer
switch seems to have worked in the filter function, but has no effect
on what the main test function considers to be the current buffer.

I have created a minimal repro, which is included below. It simply
runs ls, and has a filter function that uses find-file to switch
buffer. The output from message indicates that the buffer switch has
succeeded, but the test function which polls the current buffer at 1s
intervals always outputs the same result for the current buffer.

The test can be run with emacs -Q --batch -l repro.el -l ert -f
ert-run-tests-batch-and-exit if the below text is saved to repro.el.

(require 'ert)

(defun start-proc ()
  (let ((proc (let (process-connection-type)
                (start-process "background" "*background*" "/bin/ls"))))
    (when (process-live-p proc)
      (progn
        (set-process-coding-system proc 'utf-8-auto)
        (set-process-filter proc 'bg-filter-output)
        (set-process-query-on-exit-flag proc nil)))))

(defun bg-filter-output (proc str)
  (message "In filter")
  (find-file "2.txt")
  (message "Buffer name now: %s" (file-name-nondirectory buffer-file-name)))

(defun wait-for-condition (fun)
  (with-timeout (3)
    (while (not (funcall fun))
      (sleep-for 1))))

(ert-deftest change-file-bg ()
  "Check it changes file even in filter output"
  (find-file "1.txt")
  (start-proc)
  (wait-for-condition
   (lambda () (progn
           (message "buffer: %s" (file-name-nondirectory buffer-file-name))
           (not (equal "1.txt" (file-name-nondirectory buffer-file-name))))))
  (should (equal (file-name-nondirectory buffer-file-name) "2.txt")))



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-04-22  8:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-22  8:53 Changing buffer in filter function has no effect in ERT Robin Neatherway

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).