Update format of junit xml output to mark failures as such (#632)

This commit is contained in:
Glen Mailer 2019-09-10 09:21:08 +01:00 committed by Isaev Denis
parent bad04bb737
commit 97fcafd38c

View File

@ -21,9 +21,14 @@ type testSuiteXML struct {
} }
type testCaseXML struct { type testCaseXML struct {
Name string `xml:"name,attr"` Name string `xml:"name,attr"`
ClassName string `xml:"classname,attr"` ClassName string `xml:"classname,attr"`
Status string `xml:"status,attr"` Failure failureXML `xml:"failure"`
}
type failureXML struct {
Message string `xml:"message,attr"`
Content string `xml:",cdata"`
} }
type JunitXML struct { type JunitXML struct {
@ -34,24 +39,24 @@ func NewJunitXML() *JunitXML {
} }
func (JunitXML) Print(ctx context.Context, issues <-chan result.Issue) error { func (JunitXML) Print(ctx context.Context, issues <-chan result.Issue) error {
suites := make(map[string]testSuiteXML) // use a map to group-by "FromLinter" suites := make(map[string]testSuiteXML) // use a map to group by file
for i := range issues { for i := range issues {
fromLinter := i.FromLinter suiteName := i.FilePath()
testSuite := suites[fromLinter] testSuite := suites[suiteName]
testSuite.Suite = fromLinter testSuite.Suite = i.FilePath()
var source string tc := testCaseXML{
for _, line := range i.SourceLines { Name: i.FromLinter,
source += strings.TrimSpace(line) + "; "
}
tc := testCaseXML{Name: i.Text,
ClassName: i.Pos.String(), ClassName: i.Pos.String(),
Status: strings.TrimSuffix(source, "; "), Failure: failureXML{
Message: i.Text,
Content: strings.Join(i.SourceLines, "\n"),
},
} }
testSuite.TestCases = append(testSuite.TestCases, tc) testSuite.TestCases = append(testSuite.TestCases, tc)
suites[fromLinter] = testSuite suites[suiteName] = testSuite
} }
var res testSuitesXML var res testSuitesXML