Go: code coverage of the current diff
Every time I write tests in my
Go projects, I use code coverage to be completely sure I don’t
skip important parts that I intended to test. For viewing the reports,
depending on the situation, I use either the built-in coverage reports in
Neovim (powered by vim-go
plugin), or for
more complex cases – gocovsh
.
In small projects, both ways work great. On larger codebases there might be some issues navigating the reports: it might take some time to find the files I actually modify across packages. This struggle was the reason behing this pull request.
One of my favourite gocovsh
features is an ability to parse git diff
output
and overlay Go code coverage reports on top of it. Following the Unix
philosophy, gocovsh
accepts the familiar output of git diff
as its input
instead (both with --name-only
flag and without it):
# when on some feature branch
$ git diff master | gocovsh
In this mode, gocovsh
will not only show only the Go files affected by your
current work, but also will filter the lines you haven’t touched from the
output.
Enjoy the distraction-free coverage reports straght in the command line, and
don’t forget to give gocovsh
a star
⭐️