Subject: Re: bug#25158: [PATCH] A better way for test code to access messages
From: Eli Zaretskii <[email-masked]>
To: Gemini Lasswell <[email-masked]>
Cc: [email-masked], [email-masked]
Date: Sat, 04 Feb 2017 13:39:53 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

> Cc: Eli Zaretskii <[email-masked]>, Michael Albinus <[email-masked]>
> From: Gemini Lasswell <[email-masked]>
> Date: Sat, 10 Dec 2016 09:29:05 -0800
> 
> Here is a quote from Bug#24939's discussion, regarding the technique
> used by autorevert-tests.el, filenotify-tests.el and the proposed
> kmacro-tests.el to collect messages issued during part of a test by
> temporarily narrowing *Messages*:
> 
> Eli Zaretskii <[email-masked]> writes:
> 
> > I don't like this implementation.  First, playing restriction games
> > with *Messages* is inherently unsafe, because that buffer is treated
> > specially by the code which puts messages there.  Second, this assumes
> > *Messages* will have each message verbatim, which is false, because
> > repeated messages aren't inserted.  And finally, some code can disable
> > message logging or use some mechanism for displaying echo-area
> > messages that bypasses *Messages*, in which case this macro will not
> > catch the message.
> >
> > So I'd suggest instead to override or advice 'message', so you could
> > get your hands on the messages more reliably.  It is possible we
> > should have a more thorough infrastructure for collecting echo-area
> > messages, which probably means parts of it should be implemented in C,
> > but that's a separate project.
> >
> 
> The attached patch adds a new macro called ert-with-message-capture to
> ert-x.el which temporarily adds advice to 'message' to collect messages.
> I've also modified autorevert-tests.el and filenotify-tests.el to use
> the new macro. If or when the more thorough infrastructure is
> implemented, that could replace the use of advice in this macro but the
> tests which use it should not have to change.
> 
> Michael, in modifying autorevert-tests.el, at the start of
> auto-revert-test02-auto-revert-deleted-file, *Messages* was narrowed,
> and then narrowed again before the call to auto-revert--wait-for-revert,
> so it looked safe to delete the first narrowing instead of replacing it
> with ert-with-message-capture. Let me know if I've missed something
> there.

Making these changes didn't introduce any regressions in the relevant
tests, so I pushed them.

Gemini, please consider documenting the new macro in the ERT manual
and in NEWS.

Thanks.