I like it when terminal/console test runs actually show their output in either red or green text. It seems like a lot of the testing libraries available for Go have this. However, I'd like to just use the default testing package that comes with Go. Is there a way to colorize it's output with red and green?
Join Stack Overflow to learn, share knowledge, and build your career.
|
You can create a wrapper shell script for this and color it using color escape sequence. Here's a simple example on Linux (I'm not sure how this would look on windows, but I guess there is a way.. :) )
|
|||||||||
|
|
You can use grc, a generic colourizer, to colourize anything. On Debian/Ubuntu, install with Create a config directory in your home directory:
Then create your personal grc config in
Then create a Go test colourization config in
Now you can run Go tests with:
Sample output: To avoid typing
Now you get colourization simply by running:
|
|||||||||||||||||||||
|
|
There's also a tool called richgo that does exactly this, in a user-friendly way. |
|||
|
|
|
You would still need a library to add color escape code like:
From there, you specify what you want to color (StdOut or StdErr, like in this example) |
|||||||||||||
|
|
BoltDB has some test methods that look like this:
Here are the rest. I added the green dots here. |
|||
|
|

