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
minux
changed the title
proposal: testing: detect if benchmark function tampers with b.N?
proposal: testing: panic if benchmark function tampers with b.N?
Feb 23, 2016
There are probably other places in the stdlib, as well as in 3rd party packages, where mutating a struct field/package level variable, intended only for reading, will create mess. That's why I think some //go:readonly or similar annotation considered by go vet might be of more general use.
On the surface, a vet check is plausible. On the other hand, if you're new enough to Go to consider setting b.N then you are likely to not even know about vet. I think the best vet checks are those that will catch things that even experienced Go programmers can make.
If the benchmark function changes b.N, the
testing
package will get very confused.As an example, this (contrived) function:
will lead to this:
I've seen this in the wild, for example:
https://groups.google.com/forum/#!topic/golang-nuts/DjKNjpSHi3M
The text was updated successfully, but these errors were encountered: