unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* 27.0.50: How can I test a buffer-local window-configuration-change-hook in batch mode?
@ 2019-10-24 10:50 Phil Sainty
  2019-10-24 14:23 ` Eli Zaretskii
  0 siblings, 1 reply; 45+ messages in thread
From: Phil Sainty @ 2019-10-24 10:50 UTC (permalink / raw)
  To: emacs-devel@gnu.org

(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 ()
  (with-temp-buffer
    (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).
e.g.:

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.
Finished at:  2019-10-24 19:30:08+1300

F

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


Similarly, evaling the following in *scratch*:

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

Produces:

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


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

(with-temp-buffer
  (add-hook 'window-configuration-change-hook 'emacs-lisp-mode nil t)
  (display-buffer (current-buffer))
  (redisplay)
  (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) #
  ert-run-tests-batch(nil)
  ert-run-tests-batch-and-exit()
  command-line-1(("-l" "./my-test.el" "-f" "ert-run-tests-batch-and-ex
  command-line()
  normal-top-level()
Test buffer-local-window-configuration-change-hook condition:
    (ert-test-failed
     ((should
       (eq major-mode 'emacs-lisp-mode))
      :form
      (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.)


-Phil

[1] Context is:
https://git.savannah.nongnu.org/cgit/so-long.git/commit/so-long.el?h=wip&id=9a4fe9f3e108fc9a041bc937efa8953e39863f7d



^ permalink raw reply	[flat|nested] 45+ messages in thread

end of thread, other threads:[~2019-11-10  3:50 UTC | newest]

Thread overview: 45+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-10-24 10:50 27.0.50: How can I test a buffer-local window-configuration-change-hook in batch mode? Phil Sainty
2019-10-24 14:23 ` Eli Zaretskii
2019-10-24 23:53   ` Phil Sainty
2019-10-25  8:37     ` Eli Zaretskii
2019-10-25  9:20       ` martin rudalics
2019-10-25  9:34         ` Eli Zaretskii
2019-10-26  7:49           ` martin rudalics
2019-10-26  9:08             ` Eli Zaretskii
2019-10-25 10:31       ` Phil Sainty
2019-10-25 12:42         ` Eli Zaretskii
2019-10-25 12:53           ` Stefan Monnier
2019-10-25 13:57             ` Eli Zaretskii
2019-10-25 15:27               ` Stefan Monnier
2019-10-25 18:41                 ` Eli Zaretskii
2019-10-26 12:33               ` Lars Ingebrigtsen
2019-10-26 12:53                 ` Eli Zaretskii
2019-10-26 13:13                   ` Lars Ingebrigtsen
2019-10-26 13:33                     ` Eli Zaretskii
2019-10-26 13:50                       ` Lars Ingebrigtsen
2019-10-26 14:34                         ` Eli Zaretskii
2019-10-26 14:45                           ` Lars Ingebrigtsen
2019-10-26 15:07                             ` Eli Zaretskii
2019-10-25 13:16           ` Phil Sainty
2019-10-25 13:44             ` Eli Zaretskii
2019-10-25  8:51     ` martin rudalics
2019-10-25 10:54       ` Phil Sainty
2019-10-26  7:49         ` martin rudalics
2019-10-26  9:07           ` Eli Zaretskii
2019-10-26 10:57             ` Phil Sainty
2019-10-26 11:28               ` Eli Zaretskii
2019-10-26 12:11                 ` Stefan Monnier
2019-10-26 12:32                   ` Eli Zaretskii
2019-10-26 15:59                     ` Stefan Monnier
2019-10-26 16:28                       ` Eli Zaretskii
2019-10-26 17:14                         ` Stefan Monnier
2019-10-26 17:35                           ` Eli Zaretskii
2019-10-26 19:53                             ` Stefan Monnier
2019-10-26 20:18                               ` Eli Zaretskii
2019-10-26 13:09                 ` Phil Sainty
2019-10-26 13:31                   ` Eli Zaretskii
2019-10-26 12:05           ` Stefan Monnier
2019-10-27  7:49             ` martin rudalics
2019-10-27 17:40               ` Stefan Monnier
2019-10-28  9:39                 ` martin rudalics
2019-11-10  3:50                   ` so-long.el updates (was Re: 27.0.50: How can I test a buffer-local window-configuration-change-hook in batch mode?) Phil Sainty

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).