-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
cmd/go: when testing, pass Stdout to test child process directly #18153
Comments
We've never explicitly supported colors or animation or anything like that. I recommend you file a bug against https://github.com/fatih/color and then let @fatih file a concrete bug here about what we changed, if anything. It might be a bug in the color package. |
do you set |
@mattn: Setting it explicitly in the test files fixes the issue. // NoColor defines if the output is colorized or not. It's dynamically set to
// false or true based on the stdout's file descriptor referring to a terminal
// or not. This is a global option and affects all colors. For more control
// over each color block use the methods DisableColor() individually.
var NoColor = !isatty.IsTerminal(os.Stdout.Fd()) Seems like the problem lies here: https://github.com/mattn/go-isatty/blob/master/isatty_linux.go |
Did Go start setting TERM=dumb this cycle? There was another bug about "go bug" reporting TERM=dumb. |
|
Closing, I think there is nothing to do.
|
Excuse me, I don't see how IsTerminal returning Would you like me to file a bug report on https://github.com/mattn/go-isatty instead? |
Please ask on golang-nuts. |
It's likely because go test buffers the test output and thus
the direct output file descriptor is no longer a real tty device.
|
I've tested this with both package main
import (
"fmt"
"os"
"testing"
isatty "github.com/mattn/go-isatty"
)
func TestTerm(t *testing.T) {
isTerminal := isatty.IsTerminal(os.Stdout.Fd())
fmt.Printf("isTerminal = %+v\n", isTerminal)
fmt.Printf("TERM=%q\n", os.Getenv("TERM"))
} On
on
I've also printed the I've checked https://beta.golang.org/doc/go1.8 but couldn't find any information about this change. I've tried to search for any changes about this in the codereview mail list and https://github.com/golang/go/blob/master/doc/go1.8.txt but there was no issues that might affect this. Can anyone point me if there is any information I can check why |
Try your test with GOGC=off. When it works, the root cause probably may exist around |
The same function, if executed inside a On
On
So it's only different when executed with @mikioh I've set |
The problem is that cmd/go in Go 1.8 caches the output of tests, so
stdout really is not a terminal anymore:
$ cat a_test.go
package main
import (
"fmt"
"os"
"testing"
)
func TestTerm(t *testing.T) {
fmt.Println(os.Readlink("/proc/self/fd/1"))
}
$ go test a_test.go -v # go master
=== RUN TestTerm
pipe:[16263977] <nil>
--- PASS: TestTerm (0.00s)
PASS
ok command-line-arguments 0.002s
$ go17 test a_test.go -v # go 1.7
=== RUN TestTerm
/dev/pts/17 <nil>
--- PASS: TestTerm (0.00s)
PASS
ok command-line-arguments 0.001s
$
I'm not sure we need to call out such implementation details in
release notes though.
|
The change that changes this is https://golang.org/cl/22341 to fix #15211.
|
@minux I think this should be a part of the release document or somehow documented. There might be projects outside that assumes stdout is a terminal. Thanks for the CL link, at least it makes sense now. |
CL https://golang.org/cl/33857 mentions this issue. |
We're going to revert part of the change so the test process's output is os.Stdout. |
CL https://golang.org/cl/34010 mentions this issue. |
CL https://golang.org/cl/35957 mentions this issue. |
Fixes (skips) the test on Android, where stdout/stderr are not terminals. Updates #18153 Change-Id: Ieca65150362a5c423747ad751e00f76f0b890746 Reviewed-on: https://go-review.googlesource.com/35957 Run-TryBot: Elias Naur <elias.naur@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Change https://golang.org/cl/200106 mentions this issue: |
This reverts CL 184457. Reason for revert: introduced failures in the regression test for #18153. Fixes #34791 Updates #29062 Change-Id: I4040965163f809083c023be055e69b1149d6214e Reviewed-on: https://go-review.googlesource.com/c/go/+/200106 Run-TryBot: Bryan C. Mills <bcmills@google.com> Reviewed-by: Alexander Rakoczy <alex@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
The decision taken here is making it hard to make certain improvements to |
My counter-argument above is now a proposal, in case anyone has thoughts: #34877 |
What did you do?
Run
go test
in a project that uses colored terminal output in the test files (e.g. scarlet).What did you expect to see?
Colored output like in go 1.7. It worked without problems using https://github.com/fatih/color.
What did you see instead?
Colors don't work. Monochrome output.
Does this issue reproduce with the latest release (go1.7.3)?
No it doesn't. Colored output works with 1.7.3 in
go test
.System details
The text was updated successfully, but these errors were encountered: