[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

27.0.50: How can I test a buffer-local window-configuration-change-hook

From: Phil Sainty
Subject: 27.0.50: How can I test a buffer-local window-configuration-change-hook in batch mode?
Date: Thu, 24 Oct 2019 23:50:47 +1300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0

(The following might all apply to the global hook as well?
I've only been testing with the buffer-local value.)

The NEWS entry "Window change functions have been redesigned."
explains that a bunch of things have changed in Emacs 27.

The particular issue I'm having seems to be due to:

"Hooks reacting to window changes run now only when
redisplay detects that a change has actually occurred."

The new behaviour still works in practice for my library[1],
but in my tests it fails (in Emacs 27 only), and I don't know
what I should be doing instead.

In a test for a buffer-local window-configuration-change-hook
I can assert that a buffer is initially not displayed, and then
call `display-buffer' and assert that it *is* now displayed in
a window -- yet the buffer's window-configuration-change-hook
function hasn't been called.  (Which, IIUC, is intentional.)

;; -*- lexical-binding:t -*-
(require 'ert)
(ert-deftest buffer-local-window-configuration-change-hook ()
    (add-hook 'window-configuration-change-hook 'emacs-lisp-mode nil t)
    (should (eq major-mode 'fundamental-mode))
    (should (eq nil (get-buffer-window)))
    (display-buffer (current-buffer))
    (should (window-live-p (get-buffer-window)))
    (should (eq major-mode 'emacs-lisp-mode))))

This fails (only at the final assertion) for both interactive
(M-x ert-run-tests-interactively) and batch mode testing
(emacs -batch -l ./my-test.el -f ert-run-tests-batch-and-exit).

Selector: buffer-local-window-configuration-change-hook
Passed:  0
Failed:  1 (1 unexpected)
Skipped: 0
Total:   1/1

Started at:   2019-10-24 19:30:08+1300
Finished at:  2019-10-24 19:30:08+1300


F buffer-local-window-configuration-change-hook
       (eq major-mode 'emacs-lisp-mode))
      (eq fundamental-mode emacs-lisp-mode)
      :value nil))

Similarly, evaling the following in *scratch*:

  (add-hook 'window-configuration-change-hook 'emacs-lisp-mode nil t)
  (display-buffer (current-buffer))
  (message "%S %S" major-mode (current-buffer)))


26.3: "emacs-lisp-mode #<buffer  *temp*>"
27.0.50: "fundamental-mode #<buffer  *temp*>"

If I then add an explicit call to `redisplay':

  (add-hook 'window-configuration-change-hook 'emacs-lisp-mode nil t)
  (display-buffer (current-buffer))
  (message "%S %S" major-mode (current-buffer)))

I observe a flicker of the temporary buffer, and the output in
27.0.50 is what I want:

"emacs-lisp-mode #<buffer  *temp*>"

Adding an equivalent call to `redisplay' in the ERT test also allows
the test to succeed when called interactively:

Selector: buffer-local-window-configuration-change-hook
Passed:  1
Failed:  0
Skipped: 0
Total:   1/1

But in batch mode, the revised test still fails:

$ emacs -batch -l ./my-test.el -f ert-run-tests-batch-and-exit
Running 1 tests (2019-10-24 20:19:07+1300, selector ‘t’)
Test buffer-local-window-configuration-change-hook backtrace:
  signal(ert-test-failed (((should (eq major-mode 'emacs-lisp-mode)) :
  ert-fail(((should (eq major-mode 'emacs-lisp-mode)) :form (eq fundam
  (if (unwind-protect (setq value-17 (apply fn-15 args-16)) (setq form
  (let (form-description-19) (if (unwind-protect (setq value-17 (apply
  (let ((value-17 'ert-form-evaluation-aborted-18)) (let (form-descrip
  (let* ((fn-15 #'eq) (args-16 (condition-case err (let ((signal-hook-
  (progn (add-hook 'window-configuration-change-hook 'emacs-lisp-mode
  (unwind-protect (progn (add-hook 'window-configuration-change-hook '
  (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn
  (let ((temp-buffer (generate-new-buffer " *temp*"))) (save-current-b
  (closure (t) nil (let ((temp-buffer (generate-new-buffer " *temp*"))
  ert--run-test-internal(#s(ert--test-execution-info :test #s(ert-test
  ert-run-test(#s(ert-test :name buffer-local-window-configuration-cha
  ert-run-or-rerun-test(#s(ert--stats :selector t :tests [#s(ert-test
  ert-run-tests(t #f(compiled-function (event-type &rest event-args) #
  command-line-1(("-l" "./my-test.el" "-f" "ert-run-tests-batch-and-ex
Test buffer-local-window-configuration-change-hook condition:
       (eq major-mode 'emacs-lisp-mode))
      (eq fundamental-mode emacs-lisp-mode)
      :value nil))
   FAILED  1/1  buffer-local-window-configuration-change-hook (0.000329 sec)

Ran 1 tests, 0 results as expected, 1 unexpected (2019-10-24
20:19:07+1300, 0.174241 sec)

1 unexpected results:
   FAILED  buffer-local-window-configuration-change-hook

How does one write tests for this new behaviour?

(And very tangentially, should I be adding :tags '(:causes-redisplay)
to this test?  I encountered that while trying to figure this out, but
a basic grep suggests nothing other than ERT's own tests use it.)


[1] Context is:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]