📅  最后修改于: 2023-12-03 15:30:59.824000             🧑  作者: Mango
If you are a Go programmer, you might already know that Go has built-in support for testing using the testing
package. You can write test functions and run them using the go test
command. But have you ever noticed that the output of go test
is not very colorful?
Well, there is a solution to that problem. The go test
command has an option called -color
that can be used to enable color output. By default, color output is disabled. Here's how you can enable it:
$ go test -color
This will produce color output in your terminal when you run the tests.
But what if you are using a shell other than Bash? No worries, you can still enjoy colorful output. You just need to set the GO_TEST_COLOR
environment variable to 1
.
Here's an example for the Fish shell:
$ set -x GO_TEST_COLOR 1
$ go test
And here's an example for the Zsh shell:
$ export GO_TEST_COLOR=1
$ go test
Note that you need to set the environment variable before running the go test
command.
That's it! Now you can enjoy colorful test output in your favorite shell. Happy testing!
Markdown code:
# Go Test Color Output - Shell-Bash
If you are a Go programmer, you might already know that Go has built-in support for testing using the `testing` package. You can write test functions and run them using the `go test` command. But have you ever noticed that the output of `go test` is not very colorful?
Well, there is a solution to that problem. The `go test` command has an option called `-color` that can be used to enable color output. By default, color output is disabled. Here's how you can enable it:
$ go test -color
This will produce color output in your terminal when you run the tests.
But what if you are using a shell other than Bash? No worries, you can still enjoy colorful output. You just need to set the `GO_TEST_COLOR` environment variable to `1`.
Here's an example for the Fish shell:
```fish
$ set -x GO_TEST_COLOR 1
$ go test
And here's an example for the Zsh shell:
$ export GO_TEST_COLOR=1
$ go test
Note that you need to set the environment variable before running the go test
command.
That's it! Now you can enjoy colorful test output in your favorite shell. Happy testing!
Markdown render:
# Go Test Color Output - Shell-Bash
If you are a Go programmer, you might already know that Go has built-in support for testing using the `testing` package. You can write test functions and run them using the `go test` command. But have you ever noticed that the output of `go test` is not very colorful?
Well, there is a solution to that problem. The `go test` command has an option called `-color` that can be used to enable color output. By default, color output is disabled. Here's how you can enable it:
$ go test -color
This will produce color output in your terminal when you run the tests.
But what if you are using a shell other than Bash? No worries, you can still enjoy colorful output. You just need to set the `GO_TEST_COLOR` environment variable to `1`.
Here's an example for the Fish shell:
```fish
$ set -x GO_TEST_COLOR 1
$ go test
And here's an example for the Zsh shell:
$ export GO_TEST_COLOR=1
$ go test
Note that you need to set the environment variable before running the go test
command.
That's it! Now you can enjoy colorful test output in your favorite shell. Happy testing!