Subject: Re: bug#74786: [PATCH] Add custom args to test compile step

From: "O'Brien, Will" <[email-masked]>
Date: Thu, 02 Jan 2025 11:21:54 +0000

On Wed, Jan 01 2025 at 23:50, Randy Taylor <[email-masked]> wrote:

> Thanks, the patch looks good to me.
> There is a typo:
> +  "Return the flags for test invoation."
>                               ^invocation
>

Fixed.

[...]

>> I think that we can remove the `-run` flag from this function.
>> What do others think? Also, should this be a separate bug/patch
>> (if indeed it is a bug) or I can incorporate this change into the
>> current change set.
>> 
>
> I believe you are correct, we can get rid of the -run flag.
> Please incorporate these changes as part of this patch.

Done.

> (Side note, maybe we should actually pass the package to
> go test instead of relying on default directory but
> don't worry about that for this patch).

Will raise a new issue.

best
--
will

>From 71817f2e23148e65add2a32a53d22abc63f5af42 Mon Sep 17 00:00:00 2001
From: w08r <[email-masked]>
Date: Thu, 19 Dec 2024 09:53:02 +0000
Subject: [PATCH] Enable extra flags in go-ts-mode test commands

* lisp/progmodes/go-ts-mode.el (go-ts-mode-test-flags):
(go-ts-mode--get-test-flags): New custom variable for
controlling test behaviour.
(go-ts-mode--compile-test): Updated to use new test flags
variable for passing extra information to the go test command
line.
(go-ts-mode-test-this-package): Updated to use new test flags
variable for passing extra information to the go test command
line.  Removed incorrect use of -run flag
---
 etc/NEWS                     |  4 ++++
 lisp/progmodes/go-ts-mode.el | 22 ++++++++++++++++++----
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 3efce149dbf..59248f79672 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -463,6 +463,10 @@ package of the current buffer.  It is bound to 'C-c C-t p' in 'go-ts-mode'.
 The 'go-ts-mode-build-tags' user option is available to set a list of
 build tags for the test commands.
 
+The 'go-ts-mode-test-flags' user option is available to set a list of
+additional flags to pass to the go test command line.
+
+
 ** C-ts mode
 
 +++
diff --git a/lisp/progmodes/go-ts-mode.el b/lisp/progmodes/go-ts-mode.el
index 86e74ad58a8..4c9006b3536 100644
--- a/lisp/progmodes/go-ts-mode.el
+++ b/lisp/progmodes/go-ts-mode.el
@@ -52,6 +52,12 @@
   :type '(repeat string)
   :group 'go)
 
+(defcustom go-ts-mode-test-flags nil
+  "List of extra flags for the Go test commands."
+  :version "31.1"
+  :type '(repeat string)
+  :group 'go)
+
 (defvar go-ts-mode--syntax-table
   (let ((table (make-syntax-table)))
     (modify-syntax-entry ?+   "."      table)
@@ -392,13 +398,20 @@ specifying build tags."
       (format "-tags %s" (string-join go-ts-mode-build-tags ","))
     ""))
 
+(defun go-ts-mode--get-test-flags ()
+  "Return the flags for test invocation."
+  (if go-ts-mode-test-flags
+      (mapconcat #'shell-quote-argument go-ts-mode-test-flags " ")
+    ""))
+
 (defun go-ts-mode--compile-test (regexp)
   "Compile the tests matching REGEXP.
 This function respects the `go-ts-mode-build-tags' variable for
 specifying build tags."
-  (compile (format "go test -v %s -run '%s'"
+  (compile (format "go test -v %s -run '%s' %s"
                    (go-ts-mode--get-build-tags-flag)
-                   regexp)))
+                   regexp
+                   (go-ts-mode--get-test-flags))))
 
 (defun go-ts-mode--find-defun-at (start)
   "Return the first defun node from START."
@@ -457,9 +470,10 @@ be run."
 (defun go-ts-mode-test-this-package ()
   "Run all the unit tests under the current package."
   (interactive)
-  (compile (format "go test -v %s -run %s"
+  (compile (format "go test -v %s %s %s"
                    (go-ts-mode--get-build-tags-flag)
-                   default-directory)))
+                   default-directory
+                   (go-ts-mode--get-test-flags))))
 
 ;; go.mod support.
 
-- 
2.32.0