@@ -133,16 +133,18 @@ func (p *Parser) Parse(r io.Reader) (gtr.Report, error) {
133
133
return p .parse (reader .NewLimitedLineReader (r , maxLineSize ))
134
134
}
135
135
136
- func (p * Parser ) parse (r * reader.LimitedLineReader ) (gtr.Report , error ) {
136
+ func (p * Parser ) parse (r reader.LineReader ) (gtr.Report , error ) {
137
137
p .events = nil
138
138
for {
139
- line , err := r .ReadLine ()
139
+ line , metadata , err := r .ReadLine ()
140
140
if err == io .EOF {
141
141
break
142
142
} else if err != nil {
143
143
return gtr.Report {}, err
144
144
}
145
145
146
+ var evs []Event
147
+
146
148
// Lines that exceed bufio.MaxScanTokenSize are not expected to contain
147
149
// any relevant test infrastructure output, so instead of parsing them
148
150
// we treat them as regular output to increase performance.
@@ -152,9 +154,14 @@ func (p *Parser) parse(r *reader.LimitedLineReader) (gtr.Report, error) {
152
154
// turned out to be fine in almost all cases, it seemed an appropriate
153
155
// value to use to decide whether or not to attempt parsing this line.
154
156
if len (line ) > bufio .MaxScanTokenSize {
155
- p .output (line )
157
+ evs = p .output (line )
156
158
} else {
157
- p .parseLine (line )
159
+ evs = p .parseLine (line )
160
+ }
161
+
162
+ for _ , ev := range evs {
163
+ ev .applyMetadata (metadata )
164
+ p .events = append (p .events , ev )
158
165
}
159
166
}
160
167
return p .report (p .events ), nil
@@ -181,130 +188,124 @@ func (p *Parser) Events() []Event {
181
188
return events
182
189
}
183
190
184
- func (p * Parser ) parseLine (line string ) {
191
+ func (p * Parser ) parseLine (line string ) ( events [] Event ) {
185
192
if strings .HasPrefix (line , "=== RUN " ) {
186
- p .runTest (strings .TrimSpace (line [8 :]))
193
+ return p .runTest (strings .TrimSpace (line [8 :]))
187
194
} else if strings .HasPrefix (line , "=== PAUSE " ) {
188
- p .pauseTest (strings .TrimSpace (line [10 :]))
195
+ return p .pauseTest (strings .TrimSpace (line [10 :]))
189
196
} else if strings .HasPrefix (line , "=== CONT " ) {
190
- p .contTest (strings .TrimSpace (line [9 :]))
197
+ return p .contTest (strings .TrimSpace (line [9 :]))
191
198
} else if matches := regexEndTest .FindStringSubmatch (line ); len (matches ) == 5 {
192
- p .endTest (line , matches [1 ], matches [2 ], matches [3 ], matches [4 ])
199
+ return p .endTest (line , matches [1 ], matches [2 ], matches [3 ], matches [4 ])
193
200
} else if matches := regexStatus .FindStringSubmatch (line ); len (matches ) == 2 {
194
- p .status (matches [1 ])
201
+ return p .status (matches [1 ])
195
202
} else if matches := regexSummary .FindStringSubmatch (line ); len (matches ) == 8 {
196
- p .summary (matches [1 ], matches [2 ], matches [3 ], matches [4 ], matches [5 ], matches [6 ], matches [7 ])
203
+ return p .summary (matches [1 ], matches [2 ], matches [3 ], matches [4 ], matches [5 ], matches [6 ], matches [7 ])
197
204
} else if matches := regexCoverage .FindStringSubmatch (line ); len (matches ) == 3 {
198
- p .coverage (matches [1 ], matches [2 ])
205
+ return p .coverage (matches [1 ], matches [2 ])
199
206
} else if matches := regexBenchmark .FindStringSubmatch (line ); len (matches ) == 2 {
200
- p .runBench (matches [1 ])
207
+ return p .runBench (matches [1 ])
201
208
} else if matches := regexBenchSummary .FindStringSubmatch (line ); len (matches ) == 7 {
202
- p .benchSummary (matches [1 ], matches [2 ], matches [3 ], matches [4 ], matches [5 ], matches [6 ])
209
+ return p .benchSummary (matches [1 ], matches [2 ], matches [3 ], matches [4 ], matches [5 ], matches [6 ])
203
210
} else if matches := regexEndBenchmark .FindStringSubmatch (line ); len (matches ) == 3 {
204
- p .endBench (matches [1 ], matches [2 ])
211
+ return p .endBench (matches [1 ], matches [2 ])
205
212
} else if strings .HasPrefix (line , "# " ) {
206
- // TODO(jstemmer): this should just be output; we should detect build output when building report
207
213
fields := strings .Fields (strings .TrimPrefix (line , "# " ))
208
214
if len (fields ) == 1 || len (fields ) == 2 {
209
- p .buildOutput (fields [0 ])
210
- } else {
211
- p .output (line )
215
+ return p .buildOutput (fields [0 ])
212
216
}
213
- } else {
214
- p .output (line )
215
217
}
218
+ return p .output (line )
216
219
}
217
220
218
- func (p * Parser ) add ( event Event ) {
219
- p . events = append ( p . events , event )
221
+ func (p * Parser ) runTest ( name string ) [] Event {
222
+ return [] Event {{ Type : "run_test" , Name : name }}
220
223
}
221
224
222
- func (p * Parser ) runTest (name string ) {
223
- p . add ( Event {Type : "run_test " , Name : name })
225
+ func (p * Parser ) pauseTest (name string ) [] Event {
226
+ return [] Event {{ Type : "pause_test " , Name : name }}
224
227
}
225
228
226
- func (p * Parser ) pauseTest (name string ) {
227
- p . add ( Event {Type : "pause_test " , Name : name })
229
+ func (p * Parser ) contTest (name string ) [] Event {
230
+ return [] Event {{ Type : "cont_test " , Name : name }}
228
231
}
229
232
230
- func (p * Parser ) contTest (name string ) {
231
- p .add (Event {Type : "cont_test" , Name : name })
232
- }
233
-
234
- func (p * Parser ) endTest (line , indent , result , name , duration string ) {
233
+ func (p * Parser ) endTest (line , indent , result , name , duration string ) []Event {
234
+ var events []Event
235
235
if idx := strings .Index (line , fmt .Sprintf ("%s--- %s:" , indent , result )); idx > 0 {
236
- p .output (line [:idx ])
236
+ events = append ( events , p .output (line [:idx ]) ... )
237
237
}
238
238
_ , n := stripIndent (indent )
239
- p . add ( Event {
239
+ events = append ( events , Event {
240
240
Type : "end_test" ,
241
241
Name : name ,
242
242
Result : result ,
243
243
Indent : n ,
244
244
Duration : parseSeconds (duration ),
245
245
})
246
+ return events
246
247
}
247
248
248
- func (p * Parser ) status (result string ) {
249
- p . add ( Event {Type : "status" , Result : result })
249
+ func (p * Parser ) status (result string ) [] Event {
250
+ return [] Event {{ Type : "status" , Result : result }}
250
251
}
251
252
252
- func (p * Parser ) summary (result , name , duration , cached , status , covpct , packages string ) {
253
- p . add ( Event {
253
+ func (p * Parser ) summary (result , name , duration , cached , status , covpct , packages string ) [] Event {
254
+ return [] Event { {
254
255
Type : "summary" ,
255
256
Result : result ,
256
257
Name : name ,
257
258
Duration : parseSeconds (duration ),
258
259
Data : strings .TrimSpace (cached + " " + status ),
259
260
CovPct : parseFloat (covpct ),
260
261
CovPackages : parsePackages (packages ),
261
- })
262
+ }}
262
263
}
263
264
264
- func (p * Parser ) coverage (percent , packages string ) {
265
- p . add ( Event {
265
+ func (p * Parser ) coverage (percent , packages string ) [] Event {
266
+ return [] Event { {
266
267
Type : "coverage" ,
267
268
CovPct : parseFloat (percent ),
268
269
CovPackages : parsePackages (packages ),
269
- })
270
+ }}
270
271
}
271
272
272
- func (p * Parser ) runBench (name string ) {
273
- p . add ( Event {
273
+ func (p * Parser ) runBench (name string ) [] Event {
274
+ return [] Event { {
274
275
Type : "run_benchmark" ,
275
276
Name : name ,
276
- })
277
+ }}
277
278
}
278
279
279
- func (p * Parser ) benchSummary (name , iterations , nsPerOp , mbPerSec , bytesPerOp , allocsPerOp string ) {
280
- p . add ( Event {
280
+ func (p * Parser ) benchSummary (name , iterations , nsPerOp , mbPerSec , bytesPerOp , allocsPerOp string ) [] Event {
281
+ return [] Event { {
281
282
Type : "benchmark" ,
282
283
Name : name ,
283
284
Iterations : parseInt (iterations ),
284
285
NsPerOp : parseFloat (nsPerOp ),
285
286
MBPerSec : parseFloat (mbPerSec ),
286
287
BytesPerOp : parseInt (bytesPerOp ),
287
288
AllocsPerOp : parseInt (allocsPerOp ),
288
- })
289
+ }}
289
290
}
290
291
291
- func (p * Parser ) endBench (result , name string ) {
292
- p . add ( Event {
292
+ func (p * Parser ) endBench (result , name string ) [] Event {
293
+ return [] Event { {
293
294
Type : "end_benchmark" ,
294
295
Name : name ,
295
296
Result : result ,
296
- })
297
+ }}
297
298
}
298
299
299
- func (p * Parser ) buildOutput (packageName string ) {
300
- p . add ( Event {
300
+ func (p * Parser ) buildOutput (packageName string ) [] Event {
301
+ return [] Event { {
301
302
Type : "build_output" ,
302
303
Name : packageName ,
303
- })
304
+ }}
304
305
}
305
306
306
- func (p * Parser ) output (line string ) {
307
- p . add ( Event {Type : "output" , Data : line })
307
+ func (p * Parser ) output (line string ) [] Event {
308
+ return [] Event {{ Type : "output" , Data : line }}
308
309
}
309
310
310
311
func parseSeconds (s string ) time.Duration {
0 commit comments