From: Jonas Bernoulli <jonas@bernoul.li>
To: notmuch@notmuchmail.org
Subject: [PATCH v3 2/4] test: Deal with Emacs 27 switching to lexical scope by default
Date: Mon, 27 Jul 2020 17:25:01 +0200 [thread overview]
Message-ID: <20200727152503.15939-3-jonas@bernoul.li> (raw)
In-Reply-To: <20200727152503.15939-1-jonas@bernoul.li>
Starting with Emacs 27 undeclared variables in evaluated interactive
code uses lexical scope. This includes code passed with '--eval' as
we do in the Emacs tests, which also happen to assume dynamic scope.
- This can affect variables defined by libraries that we use. We
let-bind such variables to change the behavior of functions which we
then call with these bindings in effect. If these libraries are not
loaded beforehand, then the bindings are lexical and fail to have
the effect we intended.
At this time only 'smtpmail' has to be loaded explicitly (for the
variables let-bound in emacs_deliver_message and emacs_fcc_message).
'message' doesn't have to be loaded explicitly, because loading
'notmuch' (in 'run_emacs') already takes care of that, indirectly.
- Our own testing-only variables also have to be declared explicitly.
We should have done that anyway, but because of how and where these
variables are used it was very easy to overlook that (i.e. it isn't
something the byte-compiler ever looks at). Not so in Emacs 27
anymore; here this oversight caused four tests to fail.
The numeric values of these variables get incremented by functions
that we add to hooks that are run by many tests, not just the tests
where we actually inspect the value and therefore take care to let-
bind the values to 0 before we begin. The global values therefore
have to be numeric values as well. I have chosen -100 instead of 0
as the default in case someone writes a test that inspects the value
but forgets to let-bind the value. I hope that the unusual negative
value that one is going to see in such a case will help debugging
the issue.
---
test/test-lib.el | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/test/test-lib.el b/test/test-lib.el
index b47b388e..15271b02 100644
--- a/test/test-lib.el
+++ b/test/test-lib.el
@@ -22,6 +22,12 @@
(require 'cl-lib)
+;; Ensure that the dynamic variables that are defined by this library
+;; are defined by the time that we let-bind them. This is needed
+;; because starting with Emacs 27 undeclared variables in evaluated
+;; interactive code (such as our tests) use lexical scope.
+(require 'smtpmail)
+
;; `read-file-name' by default uses `completing-read' function to read
;; user input. It does not respect `standard-input' variable which we
;; use in tests to provide user input. So replace it with a plain
@@ -113,6 +119,12 @@ (defun add-hook-counter (hook)
(add-hook-counter 'notmuch-hello-mode-hook)
(add-hook-counter 'notmuch-hello-refresh-hook)
+(defvar notmuch-hello-mode-hook-counter -100
+ "Tests that care about this counter must let-bind it to 0.")
+
+(defvar notmuch-hello-refresh-hook-counter -100
+ "Tests that care about this counter must let-bind it to 0.")
+
(defadvice notmuch-search-process-filter (around pessimal activate disable)
"Feed notmuch-search-process-filter one character at a time."
(let ((string (ad-get-arg 1)))
--
2.26.0
next prev parent reply other threads:[~2020-07-27 15:25 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-24 18:09 [PATCH 0/3] Adjust test for changes in Emacs 27 Jonas Bernoulli
2020-07-24 18:09 ` [PATCH 1/3] gitignore: Ignore generated sphinx.config Jonas Bernoulli
2020-07-24 18:28 ` David Bremner
2020-07-24 18:34 ` Jonas Bernoulli
2020-07-24 18:09 ` [PATCH 2/3] test: Deal with Emacs 27 switching to lexical scope by default Jonas Bernoulli
2020-07-24 18:09 ` [PATCH 3/3] test: Explicitly state that we want to sign with sender Jonas Bernoulli
2020-08-15 14:25 ` David Bremner
2020-07-26 21:26 ` [PATCH 0/3] Adjust test for changes in Emacs 27 Jonas Bernoulli
2020-07-26 21:26 ` [PATCH 1/3] gitignore: Ignore generated sphinx.config Jonas Bernoulli
2020-07-27 18:23 ` Tomi Ollila
2020-07-27 20:08 ` Jonas Bernoulli
2020-07-26 21:26 ` [PATCH 2/3] test: Deal with Emacs 27 switching to lexical scope by default Jonas Bernoulli
2020-07-27 11:34 ` David Bremner
2020-07-26 21:26 ` [PATCH 3/3] test: Explicitly state that we want to sign with sender Jonas Bernoulli
2020-07-27 15:24 ` [PATCH v3 0/4] Adjust test for changes in Emacs 27 Jonas Bernoulli
2020-07-27 15:25 ` [PATCH v3 1/4] gitignore: Ignore generated sphinx.config Jonas Bernoulli
2020-07-27 15:25 ` Jonas Bernoulli [this message]
2020-07-27 15:25 ` [PATCH v3 3/4] test: Remove misguided emacs testing utilities Jonas Bernoulli
2020-07-27 15:25 ` [PATCH v3 4/4] test: Explicitly state that we want to sign with sender Jonas Bernoulli
2020-07-28 11:45 ` [PATCH v3 0/4] Adjust test for changes in Emacs 27 David Bremner
2020-07-29 18:38 ` Jonas Bernoulli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200727152503.15939-3-jonas@bernoul.li \
--to=jonas@bernoul.li \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.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).