https://github.com/tpaschalis/hop
An interactive test runner for Go
https://github.com/tpaschalis/hop
go golang interactive-test-runner testing testing-tool
Last synced: 8 months ago
JSON representation
An interactive test runner for Go
- Host: GitHub
- URL: https://github.com/tpaschalis/hop
- Owner: tpaschalis
- License: mit
- Created: 2020-07-28T19:21:21.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-08-06T19:39:22.000Z (over 5 years ago)
- Last Synced: 2025-02-09T04:45:53.398Z (about 1 year ago)
- Topics: go, golang, interactive-test-runner, testing, testing-tool
- Language: Go
- Homepage:
- Size: 202 KB
- Stars: 3
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hop
*This is a work-in-progress. Things are likely to change (a lot). Hopefully for the best.*

Hop is an interactive test runner for Go. It was inspired by Jest's [*--watch*](https://jestjs.io/docs/en/cli#--watch) mode and [this](https://twitter.com/felixge/status/1286359708799062016) tweet. It's called Hop, because well, you just hop in and start running your tests! Coffee and music are optional, but recommended!
## Installation and Usage
You can get `hop` by running.
```bash
$ go get -u github.com/tpaschalis/hop
# or
$ git clone https://github.com/tpaschalis/hop.git
$ cd hop
$ go install .
```
It comes with two modes; the default plain old boring B&W, as well as fabulous 🌈🎨🎆🍭colourized output.
Just provide the `--colour` flag!
## Here's Hop in action!
*Monochrome mode*
[](https://asciinema.org/a/UenZ2mIRGR2el929n0TYwRWt4)
## Are you just wrapping some commands?
Yes, I'm candy wrapping the following commands in a for-loop. Plus colours! You could probably do this yourself using some bash + aliases, but where's the fun in that?!
```
go test -v ./...
go test -v ./... -count=1
go test -v ./... -list .
go test -v ./... -list
go test -v ./... -run
go test -v ./... -bench=. -run ^Benchmark
```
## How does it work?
Hop is a simple REPL, which runs the aforementioned `go test` commands. As we mentioned, it features two modes, monochrome (by default) which displays the stdout/stderr, and colourful (enabled by using `--colour`).
Hop uses two custom `io.Writer` types, *monochromeWriter* and *colourizedWriter*. After that, it's just using [`exec.Command`](https://golang.org/pkg/os/exec/#Command), and `io.MultiWriter` to stream the output to our custom writer.
The inspiration, Jest, works a little bit different. It watches for files for changes and reruns tests related to changed files only. I tried using [fsnotify](https://github.com/fsnotify/fsnotify) for the same effect, but ultimately I decided it isn't worth it.
Changes to a specific file might have effects on a different package, so something like fsnotify would not catch all the cases. The good news is that the `go test` tool takes care of all this, by caching tests that wouldn't change, and rerunning any tests that are affected by changes, which is what we'd ultimately want!
## These colors suck!
First off, I'm using *colour*, with an 'ou'. Mainly because 'monochrome' and 'colourized' have the same number of letters.
Secondly, that's very probable! You could change them by tinkering with the `colors.go` file (see the irony?).
I'm probably going to add some easy way to configure them from a text file. I'm a below average designer, so feel free to propose changes!
## Roadmap
- Show pretty-printed coverage
- Run tests with specific tags
- Run previously failed tests