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 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)
This commit is contained in:
w08r 2024-12-19 09:53:02 +00:00 committed by Eli Zaretskii
parent dc41ddb4d6
commit ac3b678607
2 changed files with 22 additions and 4 deletions

View file

@ -548,6 +548,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
+++

View file

@ -53,6 +53,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)
@ -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.