parser/gotest: Return created id from CreateTest method

This commit is contained in:
Joël Stemmer 2022-08-13 17:08:43 +01:00
parent 50c1179050
commit 83ca558534

View File

@ -108,12 +108,13 @@ func (b *reportBuilder) Build() gtr.Report {
// CreateTest adds a test with the given name to the report, and marks it as // CreateTest adds a test with the given name to the report, and marks it as
// active. // active.
func (b *reportBuilder) CreateTest(name string) { func (b *reportBuilder) CreateTest(name string) int {
if parentID, ok := b.findTestParentID(name); ok { if parentID, ok := b.findTestParentID(name); ok {
b.parentIDs[parentID] = struct{}{} b.parentIDs[parentID] = struct{}{}
} }
id := b.newID() id := b.newID()
b.tests[id] = gtr.NewTest(id, name) b.tests[id] = gtr.NewTest(id, name)
return id
} }
// PauseTest marks the active context as no longer active. Any results or // PauseTest marks the active context as no longer active. Any results or
@ -140,8 +141,7 @@ func (b *reportBuilder) EndTest(name, result string, duration time.Duration, lev
// test did not exist, create one // test did not exist, create one
// TODO: Likely reason is that the user ran go test without the -v // TODO: Likely reason is that the user ran go test without the -v
// flag, should we report this somewhere? // flag, should we report this somewhere?
b.CreateTest(name) id = b.CreateTest(name)
id = b.lastID
} }
t := b.tests[id] t := b.tests[id]
@ -164,8 +164,7 @@ func (b *reportBuilder) End() {
func (b *reportBuilder) BenchmarkResult(name string, iterations int64, nsPerOp, mbPerSec float64, bytesPerOp, allocsPerOp int64) { func (b *reportBuilder) BenchmarkResult(name string, iterations int64, nsPerOp, mbPerSec float64, bytesPerOp, allocsPerOp int64) {
id, ok := b.findTest(name) id, ok := b.findTest(name)
if !ok || b.tests[id].Result != gtr.Unknown { if !ok || b.tests[id].Result != gtr.Unknown {
b.CreateTest(name) id = b.CreateTest(name)
id = b.lastID
} }
benchmark := Benchmark{iterations, nsPerOp, mbPerSec, bytesPerOp, allocsPerOp} benchmark := Benchmark{iterations, nsPerOp, mbPerSec, bytesPerOp, allocsPerOp}