Skip to content

Commit

Permalink
Merge pull request #1 from thogarty/allow_parallel_test_parsing
Browse files Browse the repository at this point in the history
fix: parse output from parallel tests
  • Loading branch information
thogarty authored Aug 20, 2024
2 parents 85bf471 + 69b4b0f commit ea7debe
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
go-junit-report
build/
.idea
1 change: 1 addition & 0 deletions parser/gotest/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ func (e *Event) applyMetadata(m *reader.Metadata) {
return
}
e.Package = m.Package
e.Name = m.Test
}
3 changes: 2 additions & 1 deletion parser/gotest/internal/reader/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type LineReader interface {
// Metadata contains metadata that belongs to a line.
type Metadata struct {
Package string
Test string
}

// LimitedLineReader reads lines from an io.Reader object with a configurable
Expand Down Expand Up @@ -117,6 +118,6 @@ func (r *JSONEventReader) ReadLine() (string, *Metadata, error) {
// Skip events without output
continue
}
return strings.TrimSuffix(event.Output, "\n"), &Metadata{Package: event.Package}, nil
return strings.TrimSuffix(event.Output, "\n"), &Metadata{Package: event.Package, Test: event.Test}, nil
}
}
12 changes: 9 additions & 3 deletions parser/gotest/report_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,13 @@ func (b *reportBuilder) ProcessEvent(ev Event) {
b.CreateBuildError(ev.Name)
case "output":
if ev.Package != "" {
b.getPackageBuilder(ev.Package).Output(ev.Data)
pb := b.getPackageBuilder(ev.Package)
testName, _, _ := strings.Cut(ev.Data, " ")
id, found := pb.findTest(testName)
if !found {
id, _ = pb.findTest(ev.Name)
}
pb.Output(id, ev.Data)
} else {
b.output.Append(ev.Data)
}
Expand Down Expand Up @@ -443,8 +449,8 @@ func (b *packageBuilder) Coverage(pct float64, packages []string) {
}

// Output appends data to the output of this package.
func (b *packageBuilder) Output(data string) {
b.output.Append(data)
func (b *packageBuilder) Output(id int, data string) {
b.output.AppendToID(id, data)
}

// findTest returns the id of the most recently created test with the given
Expand Down

0 comments on commit ea7debe

Please sign in to comment.