From 7fe392d946903f6b0974cc9381c671dbe96f1838 Mon Sep 17 00:00:00 2001 From: Remco Verhoef Date: Sun, 9 Feb 2020 10:58:49 +0100 Subject: [PATCH 1/2] add benchmark bindings (,tbs and ,tba) go supports running benchmarks much similar to running tests, the new key bindings will run single or all benchmark --- modules/lang/go/autoload.el | 15 +++++++++++++++ modules/lang/go/config.el | 6 ++++-- 2 files changed, 19 insertions(+), 2 deletions(-) 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..3c9234718 100644 --- a/modules/lang/go/config.el +++ b/modules/lang/go/config.el @@ -55,8 +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 ("tb" . "bench") + "s" #'+go/bench-single + "a" #'+go/bench-all))) (use-package! gorepl-mode :commands gorepl-run-load-current-file) From 7ebc88790590ab97d3f549d02199f8b501cb8610 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 9 Feb 2020 17:00:28 -0500 Subject: [PATCH 2/2] Merge tb prefix into t prefix --- modules/lang/go/config.el | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/lang/go/config.el b/modules/lang/go/config.el index 3c9234718..948675616 100644 --- a/modules/lang/go/config.el +++ b/modules/lang/go/config.el @@ -55,10 +55,11 @@ "n" #'+go/test-nested "g" #'go-gen-test-dwim "G" #'go-gen-test-all - "e" #'go-gen-test-exported) - (:prefix ("tb" . "bench") - "s" #'+go/bench-single - "a" #'+go/bench-all))) + "e" #'go-gen-test-exported + (:prefix ("b" . "bench") + "s" #'+go/bench-single + "a" #'+go/bench-all)))) + (use-package! gorepl-mode :commands gorepl-run-load-current-file)