Home > Article > Backend Development > How can I colorize Go test output using the default testing package?
Colorizing Output in Go Tests with Default Testing Package
While many Go testing libraries offer colored output, colorizing the output of the default testing package can be achieved using a generic colourizer called grc.
Installation:
On Debian/Ubuntu:
apt-get install grc
On macOS with Homebrew:
brew install grc
Configuration:
Create a configuration directory:
mkdir ~/.grc
Configure your grc settings in ~/.grc/grc.conf:
# Go ^([/\w\.]+\/)?go test\b conf.gotest
Create a Go test colourization config in ~/.grc/conf.gotest:
# Example configuration regexp==== RUN .* colour=bright_blue - regexp=--- PASS: .* (\(\d+\.\d+s\)) colour=green, yellow - regexp=^PASS$ colour=bold white on_green - regexp=^(ok|FAIL)\s+.* colour=default, magenta - regexp=--- FAIL: .* (\(\d+\.\d+s\)) colour=red, yellow - regexp=^FAIL$ colour=bold white on_red - regexp=[^\s]+\.go(:\d+)? colour=cyan
Usage:
To colourize Go test runs, use the following command:
grc go test -v ./..
Optional Alias:
For convenience, you can add an alias to your shell:
alias go=grc go
Now, you can simply run go test -v ./.. to get colorized output.
The above is the detailed content of How can I colorize Go test output using the default testing package?. For more information, please follow other related articles on the PHP Chinese website!