Merge pull request #161 from cameron-dunn-sublime/accurate-test-run-at

Accurate test timestamps by moving ProcessEvent
This commit is contained in:
Joël Stemmer 2023-03-21 23:03:25 +00:00 committed by GitHub
commit aab80035bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -136,6 +136,14 @@ func (p *Parser) Parse(r io.Reader) (gtr.Report, error) {
func (p *Parser) parse(r reader.LineReader) (gtr.Report, error) { func (p *Parser) parse(r reader.LineReader) (gtr.Report, error) {
p.events = nil p.events = nil
rb := newReportBuilder()
rb.packageName = p.packageName
rb.subtestMode = p.subtestMode
if p.timestampFunc != nil {
rb.timestampFunc = p.timestampFunc
}
for { for {
line, metadata, err := r.ReadLine() line, metadata, err := r.ReadLine()
if err == io.EOF { if err == io.EOF {
@ -162,24 +170,11 @@ func (p *Parser) parse(r reader.LineReader) (gtr.Report, error) {
for _, ev := range evs { for _, ev := range evs {
ev.applyMetadata(metadata) ev.applyMetadata(metadata)
rb.ProcessEvent(ev)
p.events = append(p.events, ev) p.events = append(p.events, ev)
} }
} }
return p.report(p.events), nil return rb.Build(), nil
}
// report generates a gtr.Report from the given list of events.
func (p *Parser) report(events []Event) gtr.Report {
rb := newReportBuilder()
rb.packageName = p.packageName
rb.subtestMode = p.subtestMode
if p.timestampFunc != nil {
rb.timestampFunc = p.timestampFunc
}
for _, ev := range events {
rb.ProcessEvent(ev)
}
return rb.Build()
} }
// Events returns the events created by the parser. // Events returns the events created by the parser.