From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id +GCQJffxHl8sEQAA0tVLHw (envelope-from ) for ; Mon, 27 Jul 2020 15:25:43 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id kMF4IffxHl/5MgAAbx9fmQ (envelope-from ) for ; Mon, 27 Jul 2020 15:25:43 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [144.217.243.247]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (2048 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 5380F9401AE for ; Mon, 27 Jul 2020 15:25:43 +0000 (UTC) Received: from [144.217.243.247] (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id E4C4E27E07; Mon, 27 Jul 2020 11:25:17 -0400 (EDT) Received: from mail.hostpark.net (mail.hostpark.net [212.243.197.30]) by mail.notmuchmail.org (Postfix) with ESMTPS id A57B527C46 for ; Mon, 27 Jul 2020 11:25:07 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.hostpark.net (Postfix) with ESMTP id 8A924165C5 for ; Mon, 27 Jul 2020 17:25:04 +0200 (CEST) X-Virus-Scanned: by Hostpark/NetZone Mailprotection at hostpark.net Received: from mail.hostpark.net ([127.0.0.1]) by localhost (mail0.hostpark.net [127.0.0.1]) (amavisd-new, port 10124) with ESMTP id sAAxsdSI8UaH for ; Mon, 27 Jul 2020 17:25:04 +0200 (CEST) Received: from customer (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.hostpark.net (Postfix) with ESMTPSA id 59424165CB for ; Mon, 27 Jul 2020 17:25:04 +0200 (CEST) From: Jonas Bernoulli 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 Message-Id: <20200727152503.15939-3-jonas@bernoul.li> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200727152503.15939-1-jonas@bernoul.li> References: <20200724180924.21944-1-jonas@bernoul.li> <20200727152503.15939-1-jonas@bernoul.li> MIME-Version: 1.0 Message-ID-Hash: CWPCL4NA3SJQN4QNEA33P6LFAWIE3ZFA X-Message-ID-Hash: CWPCL4NA3SJQN4QNEA33P6LFAWIE3ZFA X-MailFrom: jonas@bernoul.li X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Spam-Score: 0.03 X-TUID: dbet6HO61qnb 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