This is my first attempt at any elisp whatsoever, so there are bound to be kinks in the system. If you discover an issue, feel free to email me at [email protected] or, better yet, fork the repo, perform the fix, and submit a pull request (bonus points for topic branches!).
First, you'll have to install this package's dependencies. go-check-mode
relies on:
- go-mode:
go-mode
should be installed and working properly for all go-related files.go-mode
should come with go itself, but you can also fetch an improved version here - go-check plugin: in order to perform fine-grained testing (i.e. run a single test instead of all tests, for instance),
go-check-mode
depends (not surprisingly) on the gocheck library
Once all dependcies are in place, go ahead and install go-check-mode
on the machine of your choice:
-
Either git clone this repo or simply download the raw
go-check-mode.el
file, whichever strikes your fancy -
Put
go-check-mode.el
somewhere on Emac's load path so it can be found by those who seek it -
Activate the mode itself by adding the following
require
line in your .emacs file`(require 'go-check-mode)`
-
Bask in the glory that is TDD without having to bail out of the marvelous world of Emacs to run your specs
The following variables can be customized to better suite your workflow (M-x customize-group <RET> go-check-mode <RET>
):
- go-check-key-command-prefix:
go-check-mode
usesC-c ,
as its keymap prefix command by default, but this is configurable to anything of your choosing - go-check-runner:
go-check-mode
normally runs tests by calling out togo test
via Emacs' absurdly powerful compilation-mode. You can change thego test
command by settinggo-check-runner
to something else. Of course, note that whatever this command turns out to be, it must support gocheck's CLI flags (mainly-gocheck.f
,-gocheck.v
, and-gocheck.vv
)
Remember, with great power comes great responsibility! Configure at your own peril.
The keybindings made available by go-check-mode
are listed below, assuming you've kept the default keymap prefix:
Key | Name | Behavior |
---|---|---|
C-c , a |
go-check-all | run all tests within the current directory |
C-c , s |
go-check-single | run the test function the cursor is currently in. If the mark is active, run all tests found in region. |
C-c , c |
go-check-current | run all tests in the file |
C-c , e |
go-check-ad-hoc | run all tests that match the regexp provided in the mini-buffer |
C-c , r |
go-check-rerun | re-run the previous test command |
C-c , t |
go-check-toggle | toggle between a test file and its target file |
Note that go-check-mode
will make different keybindings available depending on what buffer is currently being visited (i.e. has focus):
- _Within an test.go file: all commands are available
- Within a regular .go file: only
go-check-rerun
,go-check-all
,go-check-current
, andgo-check-toggle
are available - Within any other file: only
go-check-rerun
is available
One can use Emacs' prefix command arguments to have better control over the compilation process' output. Each command (save for go-check-rerun
) can be run with one of the following prefixes:
- C-1: run tests with the
-gocheck.v
flag - C-2: run tests with the
-gocheck.vv
flag - C-u: edit the compilation command immediately before the command itself is run
So, for instance, doing C-u C-c , s
lets you modify the go-check-single
command to include another test of your choosing.
go-check-mode
assumes a fairly flat file structure when it comes to how tests are organized. Basically, a test file is expected to be in the same directory as its target file and should be named identically to the target file except with a _test.go
suffix instead of simply the .go
extension.
- Much thanks to rspec-mode, from which came inspiration for many of the ideas used here