From eaed228d2ff094a76adb7d5a053cd2e8cd1e91b5 Mon Sep 17 00:00:00 2001 From: Donal Byrne Date: Wed, 5 Jan 2022 09:17:33 +0100 Subject: [PATCH] Print error text in tag content for more readable junit report (#2460) --- pkg/printers/junitxml.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/printers/junitxml.go b/pkg/printers/junitxml.go index 7a68821eff6b..fd3aecac7518 100644 --- a/pkg/printers/junitxml.go +++ b/pkg/printers/junitxml.go @@ -3,6 +3,7 @@ package printers import ( "context" "encoding/xml" + "fmt" "io" "strings" @@ -31,6 +32,7 @@ type testCaseXML struct { type failureXML struct { Message string `xml:"message,attr"` + Type string `xml:"type,attr"` Content string `xml:",cdata"` } @@ -57,8 +59,10 @@ func (p JunitXML) Print(ctx context.Context, issues []result.Issue) error { Name: i.FromLinter, ClassName: i.Pos.String(), Failure: failureXML{ - Message: i.Text, - Content: strings.Join(i.SourceLines, "\n"), + Type: i.Severity, + Message: i.Pos.String() + ": " + i.Text, + Content: fmt.Sprintf("%s: %s\nCategory: %s\nFile: %s\nLine: %d\nDetails: %s", + i.Severity, i.Text, i.FromLinter, i.Pos.Filename, i.Pos.Line, strings.Join(i.SourceLines, "\n")), }, }