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

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

Merged
merged 1 commit into from Sep 10, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 19 additions & 14 deletions pkg/printers/junitxml.go
Expand Up @@ -21,9 +21,14 @@ type testSuiteXML struct {
}

type testCaseXML struct {
Name string `xml:"name,attr"`
ClassName string `xml:"classname,attr"`
Status string `xml:"status,attr"`
Name string `xml:"name,attr"`
ClassName string `xml:"classname,attr"`
Failure failureXML `xml:"failure"`
}

type failureXML struct {
Message string `xml:"message,attr"`
Content string `xml:",cdata"`
}

type JunitXML struct {
Expand All @@ -34,24 +39,24 @@ func NewJunitXML() *JunitXML {
}

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 {
fromLinter := i.FromLinter
testSuite := suites[fromLinter]
testSuite.Suite = fromLinter
suiteName := i.FilePath()
testSuite := suites[suiteName]
testSuite.Suite = i.FilePath()

var source string
for _, line := range i.SourceLines {
source += strings.TrimSpace(line) + "; "
}
tc := testCaseXML{Name: i.Text,
tc := testCaseXML{
Name: i.FromLinter,
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)
suites[fromLinter] = testSuite
suites[suiteName] = testSuite
}

var res testSuitesXML
Expand Down