fatih / color

Color package for Go (golang)
https://pkg.go.dev/github.com/fatih/color
MIT License
7.36k stars 619 forks source link

color does not work with ./... #21

Closed drewwells closed 9 years ago

drewwells commented 9 years ago

I ran into this while upgrading some tests to check for colorized output. Tests worked fine in the package, but go test ./... fails. You can reproduce this easily in this repo.

tests pass go test

tests fail go test ./...

fatih commented 9 years ago

Hi @drewwells. The problem lies with this line:

var NoColor = !isatty.IsTerminal(os.Stdout.Fd())

Somehow this get's set to false when go test ./... is called. If you call just go test it's still true. Another interesting thing is that go test -v ./... also works.

So I'm not quite sure why the stdout changes between go test ./... and go test -v ./.... I don't have the time for debugging, but you can easily fix it by adding the -v flag :)

drewwells commented 9 years ago

oh nice, -v is a good workaround. I think that is intended behavior, I have noticed stdout doesn't get populated when recursively executing tests. If each test manually assigned a fd to os.Stdout, would that pass the isTerminal check?

fatih commented 9 years ago

@drewwells I've just set it explicit to false. Tests should always be the same, so depending on the environment is something which should imho be changed. Now even go test ./... works as intended.

drewwells commented 9 years ago

Ah okay, since NoColor is exported I should be able to add those to my tests too. Thanks!