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: Benchmark prints nothing on failure #32066

Open
rogpeppe opened this issue May 15, 2019 · 3 comments
Open

testing: Benchmark prints nothing on failure #32066

rogpeppe opened this issue May 15, 2019 · 3 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@rogpeppe
Copy link
Contributor

Benchmark functions can call Log, Error and Fatal, but if the benchmark is run with the Benchmark function, all messages are discarded.

https://play.golang.org/p/fd5Ed-il70V

Perhaps the messages should be printed to standard error?

@josharian josharian changed the title Benchmark prints nothing on failure testing: Benchmark prints nothing on failure May 15, 2019
@FiloSottile FiloSottile added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 16, 2019
@FiloSottile FiloSottile added this to the Go1.14 milestone May 16, 2019
@fodil-a
Copy link

fodil-a commented May 20, 2019

Hi, I can confirm that the output is discarded, here is the writer used in the context of the benchmark

w: discard{},

Calls from Log, Error, or Fatal will print nothing, because the Write call of the discard writer does nothing.

go/src/testing/benchmark.go

Lines 783 to 785 in fbc6a97

type discard struct{}
func (discard) Write(b []byte) (n int, err error) { return len(b), nil }

@rsc rsc modified the milestones: Go1.14, Backlog Oct 9, 2019
@lahsivjar
Copy link

I stumbled upon this today, any updates on this? It feels like a pretty valid case and I was hoping it could do one of the following:

  1. testing.Benchmark takes io.Writer as an input.
  2. Allow users to create a custom testing.B and call Benchmark on top of it.

@fodil-a
Copy link

fodil-a commented Aug 22, 2023

If anyone from the team agrees the the approach of creating a new func that take a io.Writer and uses it here

w: discard{},

I can do the code, should be pretty easy to add and test 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants