You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you want to run a specific test file (ie, go test foo_test.go instead of go test), you lose the ability to capture stderr as it is then sent to stdout.
Example: http://play.golang.org/p/Q51fPoXxI3
I found this behavior surprising and think that go test foo_test.go should honor stderr. I had a couple of thoughts on how to approach this. One would be to alter https://github.com/golang/go/blob/master/src/cmd/go/test.go#L410 and have an additional OR clause for len(pkgArgs)==1, but I'm sure the current design was chosen for a reason. Maybe we could check if all args are .go files? Another thought was to assign cmd.Stderr to a separate buffer for printing later. Though, I'm not sure the best way to then print it later. Another thought was to not assign cmd.Stderr to the buffer, and let stderr come through even when we may not be streaming output, but that seems less than ideal and could be unexpected for the end user.
I would have prepared a couple of PRs to show either option working, but I can't seem to get a local build of Go to run against *_test.go files (it thinks it is importing something requiring C source files and complains about needing cgo).
Not sure there is anything else I can do until I figure out how to run go test with a local build of Go. Is this something y'all agree should be fixed? Thanks and cheers!
The text was updated successfully, but these errors were encountered:
ianlancetaylor
changed the title
Go test changes stderr to stdout when you run specific tests
cmd/go: go test changes stderr to stdout when you run specific tests
Jan 15, 2016
What you are seeing is that the output is buffered and printed as a block except in the special case of "go test" with no arguments.
The reason to do this is to separate the output from multiple tests. The reason not to include len(args) == 1 is that if you use a wildcard that resolves to 1 thing, that behavior needs to be the same as resolving to 2 things. At this point I think all these decisions are not likely to change.
If you care deeply about stdout vs stderr you can use 'go test -c && ./foo.test'.
If you want to run a specific test file (ie,
go test foo_test.go
instead ofgo test
), you lose the ability to capture stderr as it is then sent to stdout.Example: http://play.golang.org/p/Q51fPoXxI3
This is because
testStreamOutput
is set to false here when you pass in a single test file but don't provide the verbose flag: https://github.com/golang/go/blob/master/src/cmd/go/test.go#L1079I found this behavior surprising and think that
go test foo_test.go
should honor stderr. I had a couple of thoughts on how to approach this. One would be to alter https://github.com/golang/go/blob/master/src/cmd/go/test.go#L410 and have an additionalOR
clause forlen(pkgArgs)==1
, but I'm sure the current design was chosen for a reason. Maybe we could check if all args are.go
files? Another thought was to assigncmd.Stderr
to a separate buffer for printing later. Though, I'm not sure the best way to then print it later. Another thought was to not assigncmd.Stderr
to the buffer, and let stderr come through even when we may not be streaming output, but that seems less than ideal and could be unexpected for the end user.I would have prepared a couple of PRs to show either option working, but I can't seem to get a local build of Go to run against
*_test.go
files (it thinks it is importing something requiring C source files and complains about needing cgo).Not sure there is anything else I can do until I figure out how to run
go test
with a local build of Go. Is this something y'all agree should be fixed? Thanks and cheers!The text was updated successfully, but these errors were encountered: