Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing: colorize output on failing tests #46921

Open
wymli opened this issue Jun 25, 2021 · 6 comments
Open

testing: colorize output on failing tests #46921

wymli opened this issue Jun 25, 2021 · 6 comments

Comments

@wymli
Copy link

@wymli wymli commented Jun 25, 2021

What version of Go are you using (go version)?

$ go version
go version go1.16.2 windows/amd64

Proposal

Can we have color print when unit test case fail?

What did you expect to see?

Maybe we can have color print when unit test pass or fail, we can make a switch in pkg testing like t.RedErrorf(...)or cmd go test like go test ./... --color

What did you see instead?

When we have many test cases, and normally we will add -v to debug, it's hard to find the failed case.
Because we have many test flags,likego test $(go list ./... | grep -v "/neverTest") -coverprofile=cover.out -covermode=conut -gcflags=all=-l -v, the go test cmd will be placed in a unit_test.sh typically.
We won't change the script, keeping -v, which will bring many debug messages, resulting in the fact that it's hard for us to find which case failed.

By the way, do we have some better ways to only test some dirs, or exclude some dirs?

@seankhliao
Copy link
Contributor

@seankhliao seankhliao commented Jun 25, 2021

I believe this is best handled outside the go tool, eg with https://github.com/rakyll/gotest

@seankhliao seankhliao changed the title testing: can we have color print when unit test case fail? testing: colorize output on failing tests Jun 25, 2021
@wymli
Copy link
Author

@wymli wymli commented Jun 25, 2021

I believe this is best handled outside the go tool, eg with https://github.com/rakyll/gotest

rakyll/gotest is excellent, but it is hard to persuade the tech lead to introduce non-official cmd tools into company's ci/cd pipeline.

@davecheney
Copy link
Contributor

@davecheney davecheney commented Jun 25, 2021

why would you colorise ci? in my experience most ci systems do not use ansi color

@wymli
Copy link
Author

@wymli wymli commented Jun 25, 2021

why would you colorise ci? in my experience most ci systems do not use ansi color

Before ci, i will run it locally to verify the program behavior, using the same script.
You don’t want the two environments to use different commands, right?

@wymli
Copy link
Author

@wymli wymli commented Jun 25, 2021

but if ci doesn’t support ansi colours, then you’re going to get a vomit of line noise in return.

for human vision:
in my campany, ci log supports ansi colors.
And it will be a kind of disaster to search the detail of why it failed from all black string in your ci log.

for auto parsing:
the ci pipeline will parse file cover.out, which is generated using -coverprofile=cover.out, without detail colorful log.

and yeah, maybe i could have two sricpts, one for ci using go test, and one for dev machine using rakyll/gotest.

@dmitshur dmitshur added this to the Backlog milestone Jun 28, 2021
@invidian
Copy link

@invidian invidian commented Aug 22, 2021

Also, right now there is no way to distinguish the output from t.Log, t.Errorf and t.Fatalf. Would be nice to have Error and Fatal printing in red, while Log would remain as default. Alternatively, some tags on log level could be printed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants