]> git.eshelyaron.com Git - emacs.git/commitdiff
Enable extra flags in 'go-ts-mode' test commands
authorw08r <will.08rien@gmail.com>
Thu, 19 Dec 2024 09:53:02 +0000 (09:53 +0000)
committerEshel Yaron <me@eshelyaron.com>
Wed, 8 Jan 2025 08:33:16 +0000 (09:33 +0100)
* lisp/progmodes/go-ts-mode.el (go-ts-mode-test-flags):
(go-ts-mode--get-test-flags): New custom variable and function
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: Announce the new user option.  (Bug#74786)

(cherry picked from commit ac3b67860761f0b80e6fd4071d1ec868a9f6b083)

etc/NEWS
lisp/progmodes/go-ts-mode.el

index 21542b61b579eb88de3131369bb11056821044c9..8fc73569a1f74eb151666c2cc9f22fa2b2971bb2 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -449,6 +449,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
 
 +++
index 630d6a68f59d279cc13cbd0d993f07e9061e92e2..ef5e3dd350d76aefbfc20a4dfa95900c538defe1 100644 (file)
   :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)
@@ -393,13 +399,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."
@@ -458,9 +471,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.