Skip to content

Commit 1c826cb

Browse files
committed
parser/gotest: Switch to output collector for active id tracking
1 parent 83ca558 commit 1c826cb

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

parser/gotest/report_builder.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ type reportBuilder struct {
2727

2828
// state
2929
nextID int // next free unused id
30-
lastID int // most recently created id
3130
output *collector.Output // output collected for each id
3231
coverage float64 // coverage percentage
3332
parentIDs map[int]struct{} // set of test id's that contain subtests
@@ -86,7 +85,6 @@ func (b *reportBuilder) ProcessEvent(ev Event) {
8685
// newID returns a new unique id and sets the active context this id.
8786
func (b *reportBuilder) newID() int {
8887
id := b.nextID
89-
b.lastID = id
9088
b.nextID++
9189
return id
9290
}
@@ -113,6 +111,7 @@ func (b *reportBuilder) CreateTest(name string) int {
113111
b.parentIDs[parentID] = struct{}{}
114112
}
115113
id := b.newID()
114+
b.output.SetActiveID(id)
116115
b.tests[id] = gtr.NewTest(id, name)
117116
return id
118117
}
@@ -121,14 +120,15 @@ func (b *reportBuilder) CreateTest(name string) int {
121120
// output added to the report after calling PauseTest will no longer be assumed
122121
// to belong to this test.
123122
func (b *reportBuilder) PauseTest(name string) {
124-
b.lastID = 0
123+
b.output.SetActiveID(0)
125124
}
126125

127126
// ContinueTest finds the test with the given name and marks it as active. If
128127
// more than one test exist with this name, the most recently created test will
129128
// be used.
130129
func (b *reportBuilder) ContinueTest(name string) {
131-
b.lastID, _ = b.findTest(name)
130+
id, _ := b.findTest(name)
131+
b.output.SetActiveID(id)
132132
}
133133

134134
// EndTest finds the test with the given name, sets the result, duration and
@@ -149,12 +149,12 @@ func (b *reportBuilder) EndTest(name, result string, duration time.Duration, lev
149149
t.Duration = duration
150150
t.Level = level
151151
b.tests[id] = t
152-
b.lastID = 0
152+
b.output.SetActiveID(0)
153153
}
154154

155155
// End marks the active context as no longer active.
156156
func (b *reportBuilder) End() {
157-
b.lastID = 0
157+
b.output.SetActiveID(0)
158158
}
159159

160160
// BenchmarkResult updates an existing or adds a new test with the given
@@ -178,6 +178,7 @@ func (b *reportBuilder) BenchmarkResult(name string, iterations int64, nsPerOp,
178178
// CreateBuildError creates a new build error and marks it as active.
179179
func (b *reportBuilder) CreateBuildError(packageName string) {
180180
id := b.newID()
181+
b.output.SetActiveID(id)
181182
b.buildErrors[id] = gtr.Error{ID: id, Name: packageName}
182183
}
183184

@@ -268,7 +269,7 @@ func (b *reportBuilder) CreatePackage(name, result string, duration time.Duratio
268269
b.packages = append(b.packages, pkg)
269270

270271
// reset state, except for nextID to ensure all id's are unique.
271-
b.lastID = 0
272+
b.output.SetActiveID(0)
272273
b.output.Clear(globalID)
273274
b.coverage = 0
274275
b.tests = make(map[int]gtr.Test)
@@ -283,16 +284,12 @@ func (b *reportBuilder) Coverage(pct float64, packages []string) {
283284
// AppendOutput appends the given text to the currently active context. If no
284285
// active context exists, the output is assumed to belong to the package.
285286
func (b *reportBuilder) AppendOutput(text string) {
286-
b.output.Append(b.lastID, text)
287+
b.output.Append(text)
287288
}
288289

289290
// findTest returns the id of the most recently created test with the given
290291
// name if it exists.
291292
func (b *reportBuilder) findTest(name string) (int, bool) {
292-
// check if this test was lastID
293-
if t, ok := b.tests[b.lastID]; ok && t.Name == name {
294-
return b.lastID, true
295-
}
296293
for i := b.nextID; i > 0; i-- {
297294
if test, ok := b.tests[i]; ok && test.Name == name {
298295
return i, true

0 commit comments

Comments
 (0)