mirror of
https://github.com/jstemmer/go-junit-report.git
synced 2025-04-05 05:00:15 -05:00
Accurate test timestamps by moving ProcessEvent
https://github.com/jstemmer/go-junit-report/issues/147 By moving the ProcessEvent call up to parse we call it as soon as each event is read. This ensures that the timestampFunc is called approximately when the test is run. This ensures that the time of the whole test suite can be measured.
This commit is contained in:
parent
bfac3ec01f
commit
145d8019af
@ -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.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user