@@ -143,6 +143,8 @@ func (p *Parser) parse(r *reader.LimitedLineReader) (gtr.Report, error) {
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,13 @@ 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
+ p .events = append (p .events , ev )
158
164
}
159
165
}
160
166
return p .report (p .events ), nil
@@ -181,130 +187,124 @@ func (p *Parser) Events() []Event {
181
187
return events
182
188
}
183
189
184
- func (p * Parser ) parseLine (line string ) {
190
+ func (p * Parser ) parseLine (line string ) ( events [] Event ) {
185
191
if strings .HasPrefix (line , "=== RUN " ) {
186
- p .runTest (strings .TrimSpace (line [8 :]))
192
+ return p .runTest (strings .TrimSpace (line [8 :]))
187
193
} else if strings .HasPrefix (line , "=== PAUSE " ) {
188
- p .pauseTest (strings .TrimSpace (line [10 :]))
194
+ return p .pauseTest (strings .TrimSpace (line [10 :]))
189
195
} else if strings .HasPrefix (line , "=== CONT " ) {
190
- p .contTest (strings .TrimSpace (line [9 :]))
196
+ return p .contTest (strings .TrimSpace (line [9 :]))
191
197
} else if matches := regexEndTest .FindStringSubmatch (line ); len (matches ) == 5 {
192
- p .endTest (line , matches [1 ], matches [2 ], matches [3 ], matches [4 ])
198
+ return p .endTest (line , matches [1 ], matches [2 ], matches [3 ], matches [4 ])
193
199
} else if matches := regexStatus .FindStringSubmatch (line ); len (matches ) == 2 {
194
- p .status (matches [1 ])
200
+ return p .status (matches [1 ])
195
201
} 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 ])
202
+ return p .summary (matches [1 ], matches [2 ], matches [3 ], matches [4 ], matches [5 ], matches [6 ], matches [7 ])
197
203
} else if matches := regexCoverage .FindStringSubmatch (line ); len (matches ) == 3 {
198
- p .coverage (matches [1 ], matches [2 ])
204
+ return p .coverage (matches [1 ], matches [2 ])
199
205
} else if matches := regexBenchmark .FindStringSubmatch (line ); len (matches ) == 2 {
200
- p .runBench (matches [1 ])
206
+ return p .runBench (matches [1 ])
201
207
} else if matches := regexBenchSummary .FindStringSubmatch (line ); len (matches ) == 7 {
202
- p .benchSummary (matches [1 ], matches [2 ], matches [3 ], matches [4 ], matches [5 ], matches [6 ])
208
+ return p .benchSummary (matches [1 ], matches [2 ], matches [3 ], matches [4 ], matches [5 ], matches [6 ])
203
209
} else if matches := regexEndBenchmark .FindStringSubmatch (line ); len (matches ) == 3 {
204
- p .endBench (matches [1 ], matches [2 ])
210
+ return p .endBench (matches [1 ], matches [2 ])
205
211
} else if strings .HasPrefix (line , "# " ) {
206
- // TODO(jstemmer): this should just be output; we should detect build output when building report
207
212
fields := strings .Fields (strings .TrimPrefix (line , "# " ))
208
213
if len (fields ) == 1 || len (fields ) == 2 {
209
- p .buildOutput (fields [0 ])
210
- } else {
211
- p .output (line )
214
+ return p .buildOutput (fields [0 ])
212
215
}
213
- } else {
214
- p .output (line )
215
216
}
217
+ return p .output (line )
216
218
}
217
219
218
- func (p * Parser ) add ( event Event ) {
219
- p . events = append ( p . events , event )
220
+ func (p * Parser ) runTest ( name string ) [] Event {
221
+ return [] Event {{ Type : "run_test" , Name : name }}
220
222
}
221
223
222
- func (p * Parser ) runTest (name string ) {
223
- p . add ( Event {Type : "run_test " , Name : name })
224
+ func (p * Parser ) pauseTest (name string ) [] Event {
225
+ return [] Event {{ Type : "pause_test " , Name : name }}
224
226
}
225
227
226
- func (p * Parser ) pauseTest (name string ) {
227
- p . add ( Event {Type : "pause_test " , Name : name })
228
+ func (p * Parser ) contTest (name string ) [] Event {
229
+ return [] Event {{ Type : "cont_test " , Name : name }}
228
230
}
229
231
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 ) {
232
+ func (p * Parser ) endTest (line , indent , result , name , duration string ) []Event {
233
+ var events []Event
235
234
if idx := strings .Index (line , fmt .Sprintf ("%s--- %s:" , indent , result )); idx > 0 {
236
- p .output (line [:idx ])
235
+ events = append ( events , p .output (line [:idx ]) ... )
237
236
}
238
237
_ , n := stripIndent (indent )
239
- p . add ( Event {
238
+ events = append ( events , Event {
240
239
Type : "end_test" ,
241
240
Name : name ,
242
241
Result : result ,
243
242
Indent : n ,
244
243
Duration : parseSeconds (duration ),
245
244
})
245
+ return events
246
246
}
247
247
248
- func (p * Parser ) status (result string ) {
249
- p . add ( Event {Type : "status" , Result : result })
248
+ func (p * Parser ) status (result string ) [] Event {
249
+ return [] Event {{ Type : "status" , Result : result }}
250
250
}
251
251
252
- func (p * Parser ) summary (result , name , duration , cached , status , covpct , packages string ) {
253
- p . add ( Event {
252
+ func (p * Parser ) summary (result , name , duration , cached , status , covpct , packages string ) [] Event {
253
+ return [] Event { {
254
254
Type : "summary" ,
255
255
Result : result ,
256
256
Name : name ,
257
257
Duration : parseSeconds (duration ),
258
258
Data : strings .TrimSpace (cached + " " + status ),
259
259
CovPct : parseFloat (covpct ),
260
260
CovPackages : parsePackages (packages ),
261
- })
261
+ }}
262
262
}
263
263
264
- func (p * Parser ) coverage (percent , packages string ) {
265
- p . add ( Event {
264
+ func (p * Parser ) coverage (percent , packages string ) [] Event {
265
+ return [] Event { {
266
266
Type : "coverage" ,
267
267
CovPct : parseFloat (percent ),
268
268
CovPackages : parsePackages (packages ),
269
- })
269
+ }}
270
270
}
271
271
272
- func (p * Parser ) runBench (name string ) {
273
- p . add ( Event {
272
+ func (p * Parser ) runBench (name string ) [] Event {
273
+ return [] Event { {
274
274
Type : "run_benchmark" ,
275
275
Name : name ,
276
- })
276
+ }}
277
277
}
278
278
279
- func (p * Parser ) benchSummary (name , iterations , nsPerOp , mbPerSec , bytesPerOp , allocsPerOp string ) {
280
- p . add ( Event {
279
+ func (p * Parser ) benchSummary (name , iterations , nsPerOp , mbPerSec , bytesPerOp , allocsPerOp string ) [] Event {
280
+ return [] Event { {
281
281
Type : "benchmark" ,
282
282
Name : name ,
283
283
Iterations : parseInt (iterations ),
284
284
NsPerOp : parseFloat (nsPerOp ),
285
285
MBPerSec : parseFloat (mbPerSec ),
286
286
BytesPerOp : parseInt (bytesPerOp ),
287
287
AllocsPerOp : parseInt (allocsPerOp ),
288
- })
288
+ }}
289
289
}
290
290
291
- func (p * Parser ) endBench (result , name string ) {
292
- p . add ( Event {
291
+ func (p * Parser ) endBench (result , name string ) [] Event {
292
+ return [] Event { {
293
293
Type : "end_benchmark" ,
294
294
Name : name ,
295
295
Result : result ,
296
- })
296
+ }}
297
297
}
298
298
299
- func (p * Parser ) buildOutput (packageName string ) {
300
- p . add ( Event {
299
+ func (p * Parser ) buildOutput (packageName string ) [] Event {
300
+ return [] Event { {
301
301
Type : "build_output" ,
302
302
Name : packageName ,
303
- })
303
+ }}
304
304
}
305
305
306
- func (p * Parser ) output (line string ) {
307
- p . add ( Event {Type : "output" , Data : line })
306
+ func (p * Parser ) output (line string ) [] Event {
307
+ return [] Event {{ Type : "output" , Data : line }}
308
308
}
309
309
310
310
func parseSeconds (s string ) time.Duration {
0 commit comments