From 887e9fd12cf748f0ae9db1b43981ee00a655cdb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alfonso=20Fernando=20=C3=81lvarez?= Date: Wed, 3 Aug 2022 20:31:42 +0100 Subject: [PATCH] feat(go): add test-file function and keybinding --- modules/lang/go/autoload.el | 14 +++++++++++++- modules/lang/go/config.el | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) 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