Run Go tests and benchmarks from Emacs using a Transient menu.
- Run
go testorgo test -benchvia a menu-driven interface - Filter tests by name with
-runregexp - Toggle flags like
-v(verbose),-count,-timeout - Benchmark-specific options:
-benchregexp,-benchmem,-benchtime - Output appears in a
compilation-modebuffer with error navigation - Automatically runs from the Go module root (
go.moddirectory) - Press
C-u C-c tinside anyfunc TestXXXorfunc BenchmarkXXXto run it directly - Clickable overlays on test/benchmark
funclines: mouse-1 runs that function
(use-package gotest-mode
:straight (:host github :repo "inkel/gotest-mode.el")
:hook (go-mode . gotest-mode))(use-package gotest-mode
:elpaca (:host github :repo "inkel/gotest-mode.el")
:hook (go-mode . gotest-mode))Clone the repository and add it to your load path:
(add-to-list 'load-path "/path/to/gotest-mode.el")
(require 'gotest-mode)
(add-hook 'go-mode-hook #'gotest-mode)If you use use-package, add :ensure nil to prevent it from trying to
fetch the package from ELPA/MELPA:
(add-to-list 'load-path "/path/to/gotest-mode.el")
(use-package gotest-mode
:ensure nil
:hook (go-mode . gotest-mode))With gotest-mode active in a Go buffer, press C-c t to open the menu:
Run Go tests and benchmarks -v Verbose -r Test name regexp -c Run count (1) -d Timeout t Run tests b Run benchmarks
Press t to run tests immediately, or set options first then press t.
Press b to open the benchmark sub-menu with additional options.
With point anywhere inside a func TestFoo or func BenchmarkFoo body,
press C-u C-c t to run only that function (no menu appears):
go test -run=^TestFoo$ ./... go test -bench=^BenchmarkFoo$ -run=^$ ./...
You can also click with mouse-1 on any func Test... or func Benchmark...
line — gotest-mode adds a clickable overlay that runs the function directly.
Press b to open the benchmark sub-menu with additional options:
Run Go benchmarks -B Benchmark regexp (.) -m Memory allocations -T Benchmark time -v Verbose -r Test name regexp -c Run count (1) -d Timeout b Run benchmarks
The default binding is C-c t. To use a different key, rebind it in
your use-package declaration:
(use-package gotest-mode
:straight (:host github :repo "inkel/gotest-mode.el")
:hook (go-mode . gotest-mode)
:bind (:map gotest-mode-map
("C-c C-t" . gotest-dispatch)))Or to set a global binding instead of using the minor mode:
(use-package gotest-mode
:straight (:host github :repo "inkel/gotest-mode.el")
:bind ("C-c C-t" . gotest-dispatch))| Variable | Default | Description |
|---|---|---|
gotest-go-executable | "go" | Path to the Go binary |
gotest-default-package | "./..." | Package pattern passed to go test |
gotest-compilation-buffer-name | "*Go Test*" | Name of the output buffer |
To run only the current package instead of the whole module:
(setq gotest-default-package ".")Or set it per-project via .dir-locals.el:
((go-mode . ((gotest-default-package . "."))))- Emacs 28.1+
- transient 0.6.0+
- Go toolchain on
PATH(or setgotest-go-executable)
GPL-3.0-or-later