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

cmd/go: test -bench implies "chatty" #18010

Closed
tamird opened this issue Nov 22, 2016 · 20 comments
Closed

cmd/go: test -bench implies "chatty" #18010

tamird opened this issue Nov 22, 2016 · 20 comments
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@tamird
Copy link
Contributor

tamird commented Nov 22, 2016

Consider the following invocations:

go test github.com/cockroachdb/cockroach/pkg/util/stop
go test github.com/cockroachdb/cockroach/pkg/util/stop -bench -

the two should ostensibly produce the same result, but the latter does not omit the output of successful tests as the former does. This does not appear to be documented anywhere.

A somewhat related issue was previously filed (#10713) and closed with e9827f6, even though the behaviour appears to be global depending on the value of the -bench flag rather than based on the type of receiver of Log and Logf.

@quentinmit quentinmit added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Nov 22, 2016
@quentinmit quentinmit added this to the Go1.9 milestone Nov 22, 2016
@josharian
Copy link
Contributor

Possibly related to #17603?

@tamird
Copy link
Contributor Author

tamird commented Nov 23, 2016

Doesn't seem related to me.

On Nov 22, 2016 19:34, "Josh Bleecher Snyder" notifications@github.com
wrote:

Possibly related to #17603 #17603?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#18010 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/ABdsPDdpHGMfPTWQSVXwUvqIIYVNCtCHks5rA4omgaJpZM4K4-HJ
.

@minux
Copy link
Member

minux commented Nov 24, 2016 via email

@tamird
Copy link
Contributor Author

tamird commented Nov 24, 2016

What do you mean by "the standard packages"? What does this have to do with the package being tested?

go version go1.7.1 darwin/amd64

@minux
Copy link
Member

minux commented Nov 24, 2016 via email

@mvdan
Copy link
Member

mvdan commented Nov 24, 2016

@minux I think he means stdout/stderr produced by tests, which is hidden by go test.

@mvdan
Copy link
Member

mvdan commented Nov 24, 2016

Also, what is the reason for the inconsistency between -chatty and -v/-test.v in the docs?

@minux
Copy link
Member

minux commented Nov 24, 2016 via email

@tamird
Copy link
Contributor Author

tamird commented Nov 24, 2016

@minux your example is exactly the problem. if you run go test (without -bench -) you will not see "Tstdout" nor "Tstderr".

@mvdan
Copy link
Member

mvdan commented Nov 24, 2016

@tamird but he did just there and it also prints.

@tamird
Copy link
Contributor Author

tamird commented Nov 24, 2016

Oh, it seems the behaviour is not so simple.

$ (cd foo && go test)
Tstdout
Tstderr
PASS
ok  	github.com/cockroachdb/cockroach/foo	0.005s
$ go test ./foo
ok  	github.com/cockroachdb/cockroach/foo	0.006s
$ go test ./foo -bench -
Tstdout
Tstderr
PASS
ok  	github.com/cockroachdb/cockroach/foo	0.006s

...so if you specify a package name, stdout/stderr are swallowed, but if you don't, they are not. this is so inconsistent as to be crazy.

@minux
Copy link
Member

minux commented Nov 24, 2016 via email

@tamird
Copy link
Contributor Author

tamird commented Nov 25, 2016

Working as intended by whom? None of this is documented, and none of it makes sense.

Why does supplying a package name suppress stdout? "go test assume you're developing that package" this is a rationalization, or something, because it's certainly not documented, and doesn't make an iota of sense.

When -bench is given, go test will always show stdout/stderr, even if it
doesn't match any of the benchmarks (this is because the benchmark
statistics is produced by the testing package, not by the go command,
so if the Go command wants to show you the benchmark result, it can't
hide the other output from the test.)

That sounds like an implementation detail, not a sensible reason that for this behaviour. Again, it is not documented.

@minux
Copy link
Member

minux commented Nov 25, 2016 via email

@tamird
Copy link
Contributor Author

tamird commented Nov 25, 2016

why? it doesn't seem to me that any of this is covered by the Go 1 guarantee.

@minux
Copy link
Member

minux commented Nov 25, 2016 via email

@tamird
Copy link
Contributor Author

tamird commented Nov 25, 2016

As the issue description states, I propose that the -bench flag not affect stdout/stderr suppression.

@knz
Copy link

knz commented May 9, 2017

+1 I think the behavior currently in the code was actually not intended by the designer of this code, and I think anyone using the benchmarking code will welcome fixing this issue that has been there since Go 1.

@rsc
Copy link
Contributor

rsc commented May 22, 2017

Like @minux wrote above, this is working as intended (I designed and wrote the code, and this is what I intended). If running benchmarks, we stream the output from the benchmarks to make sure they are seen at all but also that they are seen as they happen.

The only option we've come up with is to make go test -bench run the binary twice, once for tests (quietly) and once for benchmarks (not quietly). That seems a bit odd, and a different special case (init code would run multiple times, and so on).

@rsc
Copy link
Contributor

rsc commented May 22, 2017

There are conflicting goals here, of course, but since this has been this way from Go 1, I'm inclined to keep things as is.

@rsc rsc closed this as completed May 22, 2017
@golang golang locked and limited conversation to collaborators May 22, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

8 participants