diff --git a/modules/lang/go/autoload.el b/modules/lang/go/autoload.el index 54b9505ae..eb4015255 100644 --- a/modules/lang/go/autoload.el +++ b/modules/lang/go/autoload.el @@ -11,7 +11,7 @@ (compile cmd))) (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)) (+go--spawn cmd))) @@ -41,6 +41,18 @@ (+go--run-tests (concat "-run" "='^\\Q" (match-string-no-properties 2) "\\E$'"))) (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 (defun +go/bench-all () (interactive) diff --git a/modules/lang/go/config.el b/modules/lang/go/config.el index 619dceb90..49f1f6996 100644 --- a/modules/lang/go/config.el +++ b/modules/lang/go/config.el @@ -56,6 +56,7 @@ "a" #'+go/test-all "s" #'+go/test-single "n" #'+go/test-nested + "f" #'+go/test-file "g" #'go-gen-test-dwim "G" #'go-gen-test-all "e" #'go-gen-test-exported