Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use jstemmer/go-junit-report/v2 to correctly parse the output of go test #22

Merged
merged 1 commit into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module github.com/Songmu/gotesplit
go 1.18

require (
github.com/jstemmer/go-junit-report v1.0.0
github.com/jstemmer/go-junit-report/v2 v2.0.0
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29
)
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
github.com/jstemmer/go-junit-report v1.0.0 h1:8X1gzZpR+nVQLAht+L/foqOeX2l9DTZoaIPbEQHxsds=
github.com/jstemmer/go-junit-report v1.0.0/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/jstemmer/go-junit-report/v2 v2.0.0 h1:bMZNO9B16VFn07tKyi4YJFIbZtVmJaa5Xakv9dcwK58=
github.com/jstemmer/go-junit-report/v2 v2.0.0/go.mod h1:mgHVr7VUo5Tn8OLVr1cKnLuEy0M92wdRntM99h7RkgQ=
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29 h1:w8s32wxx3sY+OjLlv9qltkLU5yvJzxjjgiHWLjdIcw4=
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
30 changes: 25 additions & 5 deletions run.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gotesplit
import (
"bytes"
"context"
"encoding/xml"
"errors"
"fmt"
"io"
Expand All @@ -13,8 +14,9 @@ import (
"path/filepath"
"strings"

"github.com/jstemmer/go-junit-report/formatter"
"github.com/jstemmer/go-junit-report/parser"
"github.com/jstemmer/go-junit-report/v2/gtr"
"github.com/jstemmer/go-junit-report/v2/junit"
parser "github.com/jstemmer/go-junit-report/v2/parser/gotest"
"golang.org/x/sync/errgroup"
)

Expand Down Expand Up @@ -138,7 +140,7 @@ func run(ctx context.Context, total, idx uint, junitDir string, argv []string, o
log.Printf("failed to open file to store test report: %s\n", err)
} else {
defer f.Close()
if err := formatter.JUnitReportXML(report.report.report, false, "", f); err != nil {
if err := writeJUnitReportXML(f, report.report.report); err != nil {
log.Printf("failed to store test report: %s\n", err)
}
}
Expand All @@ -149,7 +151,7 @@ func run(ctx context.Context, total, idx uint, junitDir string, argv []string, o
}

type junitReport struct {
report *parser.Report
report gtr.Report
err error
}

Expand Down Expand Up @@ -225,11 +227,29 @@ func goTest(args []string, stdout, stderr io.Writer, junitDir string) *testRepor
err: err,
}
if junitDir != "" {
report, err := parser.Parse(outBuf, "")
report, err := parser.NewParser().Parse(outBuf)
ret.report = &junitReport{
report: report,
err: err,
}
}
return ret
}

func writeJUnitReportXML(w io.Writer, report gtr.Report) error {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied and pasted from https://github.com/jstemmer/go-junit-report/blob/v2.0.0/internal/gojunitreport/go-junit-report.go#L73-L93.

If the master branch of go-junit-report is released, https://github.com/jstemmer/go-junit-report/blob/master/junit/junit.go#L41 can be used, but it has not been but it has not been released for a while. ref: jstemmer/go-junit-report#164

testsuites := junit.CreateFromReport(report, "")
if _, err := fmt.Fprintf(w, xml.Header); err != nil {
return err
}

enc := xml.NewEncoder(w)
enc.Indent("", "\t")
if err := enc.Encode(testsuites); err != nil {
return err
}
if err := enc.Flush(); err != nil {
return err
}
_, err := fmt.Fprintf(w, "\n")
return err
}