Skip to content

inkel/gotest-mode.el

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 

Repository files navigation

gotest-mode.el

Run Go tests and benchmarks from Emacs using a Transient menu.

Features

  • Run go test or go test -bench via a menu-driven interface
  • Filter tests by name with -run regexp
  • Toggle flags like -v (verbose), -count, -timeout
  • Benchmark-specific options: -bench regexp, -benchmem, -benchtime
  • Output appears in a compilation-mode buffer with error navigation
  • Automatically runs from the Go module root (go.mod directory)
  • Press C-u C-c t inside any func TestXXX or func BenchmarkXXX to run it directly
  • Clickable overlays on test/benchmark func lines: mouse-1 runs that function

Installation

use-package (straight.el)

(use-package gotest-mode
  :straight (:host github :repo "inkel/gotest-mode.el")
  :hook (go-mode . gotest-mode))

use-package (elpaca)

(use-package gotest-mode
  :elpaca (:host github :repo "inkel/gotest-mode.el")
  :hook (go-mode . gotest-mode))

Manual

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))

Usage

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.

Running a single test or benchmark

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

Configuration

Overriding the default key binding

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))

Customization

VariableDefaultDescription
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 . "."))))

Requirements

  • Emacs 28.1+
  • transient 0.6.0+
  • Go toolchain on PATH (or set gotest-go-executable)

License

GPL-3.0-or-later

About

Simple transient mode to execute Go tests and benchmarks

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors