@@ -27,7 +27,6 @@ type reportBuilder struct {
27
27
28
28
// state
29
29
nextID int // next free unused id
30
- lastID int // most recently created id
31
30
output * collector.Output // output collected for each id
32
31
coverage float64 // coverage percentage
33
32
parentIDs map [int ]struct {} // set of test id's that contain subtests
@@ -86,7 +85,6 @@ func (b *reportBuilder) ProcessEvent(ev Event) {
86
85
// newID returns a new unique id and sets the active context this id.
87
86
func (b * reportBuilder ) newID () int {
88
87
id := b .nextID
89
- b .lastID = id
90
88
b .nextID ++
91
89
return id
92
90
}
@@ -113,6 +111,7 @@ func (b *reportBuilder) CreateTest(name string) int {
113
111
b .parentIDs [parentID ] = struct {}{}
114
112
}
115
113
id := b .newID ()
114
+ b .output .SetActiveID (id )
116
115
b .tests [id ] = gtr .NewTest (id , name )
117
116
return id
118
117
}
@@ -121,14 +120,15 @@ func (b *reportBuilder) CreateTest(name string) int {
121
120
// output added to the report after calling PauseTest will no longer be assumed
122
121
// to belong to this test.
123
122
func (b * reportBuilder ) PauseTest (name string ) {
124
- b .lastID = 0
123
+ b .output . SetActiveID ( 0 )
125
124
}
126
125
127
126
// ContinueTest finds the test with the given name and marks it as active. If
128
127
// more than one test exist with this name, the most recently created test will
129
128
// be used.
130
129
func (b * reportBuilder ) ContinueTest (name string ) {
131
- b .lastID , _ = b .findTest (name )
130
+ id , _ := b .findTest (name )
131
+ b .output .SetActiveID (id )
132
132
}
133
133
134
134
// 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
149
149
t .Duration = duration
150
150
t .Level = level
151
151
b .tests [id ] = t
152
- b .lastID = 0
152
+ b .output . SetActiveID ( 0 )
153
153
}
154
154
155
155
// End marks the active context as no longer active.
156
156
func (b * reportBuilder ) End () {
157
- b .lastID = 0
157
+ b .output . SetActiveID ( 0 )
158
158
}
159
159
160
160
// 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,
178
178
// CreateBuildError creates a new build error and marks it as active.
179
179
func (b * reportBuilder ) CreateBuildError (packageName string ) {
180
180
id := b .newID ()
181
+ b .output .SetActiveID (id )
181
182
b .buildErrors [id ] = gtr.Error {ID : id , Name : packageName }
182
183
}
183
184
@@ -268,7 +269,7 @@ func (b *reportBuilder) CreatePackage(name, result string, duration time.Duratio
268
269
b .packages = append (b .packages , pkg )
269
270
270
271
// reset state, except for nextID to ensure all id's are unique.
271
- b .lastID = 0
272
+ b .output . SetActiveID ( 0 )
272
273
b .output .Clear (globalID )
273
274
b .coverage = 0
274
275
b .tests = make (map [int ]gtr.Test )
@@ -283,16 +284,12 @@ func (b *reportBuilder) Coverage(pct float64, packages []string) {
283
284
// AppendOutput appends the given text to the currently active context. If no
284
285
// active context exists, the output is assumed to belong to the package.
285
286
func (b * reportBuilder ) AppendOutput (text string ) {
286
- b .output .Append (b . lastID , text )
287
+ b .output .Append (text )
287
288
}
288
289
289
290
// findTest returns the id of the most recently created test with the given
290
291
// name if it exists.
291
292
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
- }
296
293
for i := b .nextID ; i > 0 ; i -- {
297
294
if test , ok := b .tests [i ]; ok && test .Name == name {
298
295
return i , true
0 commit comments