Home > Backend Development > Golang > How can I colorize the default Go test output?

How can I colorize the default Go test output?

Susan Sarandon
Release: 2024-11-16 11:32:03
Original
713 people have browsed it

How can I colorize the default Go test output?

Colorizing Default Go Test Output

The native testing package in Go lacks built-in colorized output. However, you can leverage an external tool like grc (generic colourizer) to colorize test results.

Using grc for Colorization

Install grc using your preferred package manager (e.g., apt-get install grc for Debian/Ubuntu). After installation, create a configuration file (~/.grc/grc.conf) with the following entry:

^([/\w\.]+\/)?go test\b
conf.gotest
Copy after login

Next, create a grc configuration file for customizing Go test output colors (~/.grc/conf.gotest):

# Go test grc colorizer configuration
regexp==== RUN .*
colour=bright_blue
-
regexp=--- PASS: .* (\(\d+\.\d+s\))
colour=green, yellow
-
...
Copy after login

Running Colorized Tests

Now, you can run your Go tests with colorization using the following command:

grc go test -v ./..
Copy after login

Aliases for Convenience

To simplify the process, add an alias to your shell's configuration file:

alias go=grc go
Copy after login

This allows you to run colorized tests simply by using the "go test" command.

The above is the detailed content of How can I colorize the default Go test output?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template