diff --git a/modules/lang/go/autoload.el b/modules/lang/go/autoload.el index 709bd2a2e..4e13dcab4 100644 --- a/modules/lang/go/autoload.el +++ b/modules/lang/go/autoload.el @@ -41,6 +41,21 @@ (+go--run-tests (concat "-run" "='" (match-string-no-properties 2) "'"))) (error "Must be in a _test.go file"))) +;;;###autoload +(defun +go/bench-all () + (interactive) + (+go--run-tests "-test.run=NONE -test.bench=\".*\"")) + +;;;###autoload +(defun +go/bench-single () + (interactive) + (if (string-match "_test\\.go" buffer-file-name) + (save-excursion + (re-search-backward "^func[ ]+\\(([[:alnum:]]*?[ ]?[*]?[[:alnum:]]+)[ ]+\\)?\\(Benchmark[[:alnum:]_]+\\)(.*)") + (+go--run-tests (concat "-test.run=NONE -test.bench" "='" (match-string-no-properties 2) "'"))) + (error "Must be in a _test.go file"))) + + ;;;###autoload (defun +go/play-buffer-or-region (&optional beg end) "TODO" diff --git a/modules/lang/go/config.el b/modules/lang/go/config.el index 05947af45..948675616 100644 --- a/modules/lang/go/config.el +++ b/modules/lang/go/config.el @@ -55,7 +55,10 @@ "n" #'+go/test-nested "g" #'go-gen-test-dwim "G" #'go-gen-test-all - "e" #'go-gen-test-exported))) + "e" #'go-gen-test-exported + (:prefix ("b" . "bench") + "s" #'+go/bench-single + "a" #'+go/bench-all)))) (use-package! gorepl-mode