emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[nongnu] elpa/with-simulated-input 4eedb0eee8 126/134: Use an alternate


From: ELPA Syncer
Subject: [nongnu] elpa/with-simulated-input 4eedb0eee8 126/134: Use an alternate method to disable eager macro-expansion for testing
Date: Mon, 10 Jan 2022 23:00:13 -0500 (EST)

branch: elpa/with-simulated-input
commit 4eedb0eee8ba9ffbb0c0f988ad789e79b4d7a23e
Author: Ryan C. Thompson <rct@thompsonclan.org>
Commit: Ryan C. Thompson <rct@thompsonclan.org>

    Use an alternate method to disable eager macro-expansion for testing
---
 Eldev                              | 23 +++++++++++++++++++++++
 tests/test-with-simulated-input.el | 25 ++++---------------------
 2 files changed, 27 insertions(+), 21 deletions(-)

diff --git a/Eldev b/Eldev
index ed4367454c..b7c9a1f1cd 100644
--- a/Eldev
+++ b/Eldev
@@ -9,3 +9,26 @@
 
 ;; Tell checkdoc not to demand two spaces after a period.
 (setq sentence-end-double-space nil)
+
+;; Disable eager macro expansion during test loading, so that macros
+;; get expanded *during* test execution, not before.
+(defvar internal-macroexpand-for-load-original-symbol-function
+  (symbol-function 'internal-macroexpand-for-load))
+
+(add-hook
+ 'eldev-before-loading-dependencies-hook
+ (lambda (type additional-sets)
+   ;; Execute before loading test deps. This hook is the closest I can
+   ;; find to "right before loading the test files".
+   (when (and type
+              (memq 'test (if (listp additional-sets)
+                              additional-sets
+                            (list additional-sets))))
+     (fmakunbound 'internal-macroexpand-for-load))))
+
+;; In order to minimize the possibility of disruption, put the
+;; function back after loading the tests.
+(add-hook 'eldev-test-buttercup-hook
+          (lambda (&rest _)
+            (fset 'internal-macroexpand-for-load
+                   internal-macroexpand-for-load-original-symbol-function)))
diff --git a/tests/test-with-simulated-input.el 
b/tests/test-with-simulated-input.el
index 8675c9a686..f896424ac6 100644
--- a/tests/test-with-simulated-input.el
+++ b/tests/test-with-simulated-input.el
@@ -46,24 +46,6 @@ from byte-compiled code."
        (wsi-get-unbound-key)
        :not :to-equal previous-key))))
 
-(defmacro progn-at-runtime (&rest body)
-  "Like `progn', but evaluate BODY entirely at runtime.
-
-This is useful if BODY involves macros and you want to defer the
-expansion of those macros until BODY is evaluated.
-
-Note: I don't recommend this function for general use, because it
-doesn't seem to properly put BODY in the correct lexical scope,
-but it's good enough for use in this test suite. Lexical scopes
-established *inside* BODY work just fine, so just make sure to
-put this outside any relevant `let' forms."
-  (declare (debug body))
-  `(eval
-    '(progn
-       ,@(cl-loop for expr in body
-                  collect `(funcall (lambda () ,expr)))
-       lexical-binding)))
-
 (defvar warnings-displayed-count 0
   "Count of warnings that have been displayed.")
 (defsubst reset-warnings-count (&optional n)
@@ -80,9 +62,10 @@ put this outside any relevant `let' forms."
 BODY is wrapped in `progn-at-runtime', so warnings produced
 during macro expansion will be caught as well."
   (declare (debug body))
-  `(let ((warnings-displayed-count 0))
-     (prog1 (progn-at-runtime ,@body)
-       (expect warnings-displayed-count :to-be-greater-than 0))))
+  `(progn
+     (spy-on #'display-warning :and-call-through)
+     (prog1 (progn ,@body)
+       (expect #'display-warning :to-have-been-called))))
 
 (describe "`with-simulated-input'"
 



reply via email to

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