Subject: [bug#76686] [PATCH emacs-team 00/45] Test emacs packages by default

From: Morgan Smith <[email-masked]>
Date: Sun, 02 Mar 2025 19:29:12 -0500

Liliana Marie Prikler <[email-masked]> writes:

> Hi folks,
>
> this patch adds code – similar to what we have in other ecosystems – to
> make an educated guess on what test framework is used and use it.  Newly
> packaged Emacs libraries should thus expect to be tested with tests
> needing to be explicitly disabled otherwise; just like in the rest of
> Guix.
>
> Cheers

Looks good to me just reading through them.  Some of the test commands
looks a little complicated though with a lot of boiler plate (like
emacs-list-utils).  Any thoughts on perhaps using a helper function like
the (untested) attached patch?

>From 631833f951e52047a4b8ea3a5598ec0b377a67d4 Mon Sep 17 00:00:00 2001
Message-ID: <631833[email-masked]>
From: Morgan Smith <[email-masked]>
Date: Sun, 2 Mar 2025 19:18:44 -0500
Subject: [PATCH] guix: emacs-utils: Add new function
 'emacs-batch-eval-command'.

* guix/build/emacs-utils.scm(emacs-batch-eval-command): New function.
(emacs-batch-eval): Define in terms of 'emacs-batch-eval-command'.

Change-Id: I27c10bc7a93be02385ad47cadd124379bcaaad52
---
 guix/build/emacs-utils.scm | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/guix/build/emacs-utils.scm b/guix/build/emacs-utils.scm
index aeb364133a..dea062897e 100644
--- a/guix/build/emacs-utils.scm
+++ b/guix/build/emacs-utils.scm
@@ -63,12 +63,22 @@ (define (expr->string expr)
       expr
       (format #f "~s" expr)))
 
+(define* (emacs-batch-eval-command expr #:key (load-directories '())
+                                   (load-files '()) dynamic?)
+  "Return a command to run Emacs in batch mode, and execute the Elisp code
+EXPR.  If LOAD-DIRECTORIES is a list of directories, add them to the load path
+before running EXPR.  If LOAD-FILES is a list of files, load them before
+running EXPR.  DYNAMIC? is true, evaluate using dynamic scoping."
+  `("emacs" "--quick" "--batch"
+    ,@(map (lambda file) (string-append "--directory=" file) load-files)
+    ,@(map (lambda file) (string-append "--load=" file) load-files)
+    (format #f "--eval=(eval '~a ~:[t~;nil~])"
+            (expr->string expr) dynamic?)))
+
 (define* (emacs-batch-eval expr #:key dynamic?)
   "Run Emacs in batch mode, and execute the Elisp code EXPR.  If DYNAMIC? is
 true, evaluate using dynamic scoping."
-  (invoke (%emacs) "--quick" "--batch"
-          (format #f "--eval=(eval '~a ~:[t~;nil~])"
-                  (expr->string expr) dynamic?)))
+  (invoke (%emacs) (cdr (emacs-batch-eval-command expr #:dynamic dynamic))))
 
 (define (emacs-batch-edit-file file expr)
   "Load FILE in Emacs using batch mode, and execute the elisp code EXPR."
-- 
2.48.1