cmd/test2json: benchmark output lines are attributed to the preceding test #49505
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes. (v1.17.3)
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
We have three files:
I executed the following:
go test -json -shuffle off -bench '.+' -count 1 ./pkg/example
What did you expect to see?
A series of events in JSON format whose
Test
property shows the name of the test/benchmark/example being executed. The benchmark should emit events bearing the field"Test": "BenchmarkCountToN"
.What did you see instead?
The events corresponding to the benchmark are marked with the name of the preceding test (here:
"Test": "TestCountToN"
).Uncommenting the
fmt
import andExampleCountToN
inpkg/example/x_test.go
causes the benchmark events to be annotated as"Test": "ExampleCountToN"
:Deleting
TestCountToN
andExampleCountToN
and leaving only the benchmark causes the"Test"
field to disappear from the output entirely:It appears that the
Test
field of theevent
struct is not populated at all for benchmarks, and the printer uses its last set value if one is available.The text was updated successfully, but these errors were encountered: