feat(go): add test-file function and keybinding

This commit is contained in:
Alfonso Fernando Álvarez 2022-08-03 20:31:42 +01:00 committed by Henrik Lissner
parent 55544200be
commit 887e9fd12c
2 changed files with 14 additions and 1 deletions

View file

@ -11,7 +11,7 @@
(compile cmd))) (compile cmd)))
(defun +go--run-tests (args) (defun +go--run-tests (args)
(let ((cmd (concat "go test " args))) (let ((cmd (concat "go test -test.v " args)))
(setq +go-test-last (concat "cd " default-directory ";" cmd)) (setq +go-test-last (concat "cd " default-directory ";" cmd))
(+go--spawn cmd))) (+go--spawn cmd)))
@ -41,6 +41,18 @@
(+go--run-tests (concat "-run" "='^\\Q" (match-string-no-properties 2) "\\E$'"))) (+go--run-tests (concat "-run" "='^\\Q" (match-string-no-properties 2) "\\E$'")))
(error "Must be in a _test.go file"))) (error "Must be in a _test.go file")))
;;;###autoload
(defun +go/test-file ()
(interactive)
(if (string-match "_test\\.go" buffer-file-name)
(save-excursion
(goto-char (point-min))
(let ((func-list))
(while (re-search-forward "^func[ ]+\\(([[:alnum:]]*?[ ]?[*]?[[:alnum:]]+)[ ]+\\)?\\(Test[[:alnum:]_]+\\)(.*)" nil t)
(push (match-string-no-properties 2) func-list))
(+go--run-tests (concat "-run" "='^(" (string-join func-list "|") ")$'"))))
(error "Must be in a _test.go file")))
;;;###autoload ;;;###autoload
(defun +go/bench-all () (defun +go/bench-all ()
(interactive) (interactive)

View file

@ -56,6 +56,7 @@
"a" #'+go/test-all "a" #'+go/test-all
"s" #'+go/test-single "s" #'+go/test-single
"n" #'+go/test-nested "n" #'+go/test-nested
"f" #'+go/test-file
"g" #'go-gen-test-dwim "g" #'go-gen-test-dwim
"G" #'go-gen-test-all "G" #'go-gen-test-all
"e" #'go-gen-test-exported "e" #'go-gen-test-exported