junit-xml output
This commit is contained in:
parent
7f91ce8067
commit
5c86bfc905
@ -460,7 +460,7 @@ Usage:
|
|||||||
golangci-lint run [flags]
|
golangci-lint run [flags]
|
||||||
|
|
||||||
Flags:
|
Flags:
|
||||||
--out-format string Format of output: colored-line-number|line-number|json|tab|checkstyle|code-climate (default "colored-line-number")
|
--out-format string Format of output: colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml (default "colored-line-number")
|
||||||
--print-issued-lines Print lines of code with issue (default true)
|
--print-issued-lines Print lines of code with issue (default true)
|
||||||
--print-linter-name Print linter name in issue line (default true)
|
--print-linter-name Print linter name in issue line (default true)
|
||||||
--issues-exit-code int Exit code when issues were found (default 1)
|
--issues-exit-code int Exit code when issues were found (default 1)
|
||||||
|
@ -372,6 +372,8 @@ func (e *Executor) createPrinter() (printers.Printer, error) {
|
|||||||
p = printers.NewCheckstyle()
|
p = printers.NewCheckstyle()
|
||||||
case config.OutFormatCodeClimate:
|
case config.OutFormatCodeClimate:
|
||||||
p = printers.NewCodeClimate()
|
p = printers.NewCodeClimate()
|
||||||
|
case config.OutFormatJunitXML:
|
||||||
|
p = printers.NewJunitXML()
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unknown output format %s", format)
|
return nil, fmt.Errorf("unknown output format %s", format)
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ const (
|
|||||||
OutFormatTab = "tab"
|
OutFormatTab = "tab"
|
||||||
OutFormatCheckstyle = "checkstyle"
|
OutFormatCheckstyle = "checkstyle"
|
||||||
OutFormatCodeClimate = "code-climate"
|
OutFormatCodeClimate = "code-climate"
|
||||||
|
OutFormatJunitXML = "junit-xml"
|
||||||
)
|
)
|
||||||
|
|
||||||
var OutFormats = []string{
|
var OutFormats = []string{
|
||||||
@ -23,6 +24,7 @@ var OutFormats = []string{
|
|||||||
OutFormatTab,
|
OutFormatTab,
|
||||||
OutFormatCheckstyle,
|
OutFormatCheckstyle,
|
||||||
OutFormatCodeClimate,
|
OutFormatCodeClimate,
|
||||||
|
OutFormatJunitXML,
|
||||||
}
|
}
|
||||||
|
|
||||||
type ExcludePattern struct {
|
type ExcludePattern struct {
|
||||||
|
68
pkg/printers/junitxml.go
Normal file
68
pkg/printers/junitxml.go
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
package printers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/xml"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/golangci/golangci-lint/pkg/logutils"
|
||||||
|
"github.com/golangci/golangci-lint/pkg/result"
|
||||||
|
)
|
||||||
|
|
||||||
|
type testSuitesXML struct {
|
||||||
|
XMLName xml.Name `xml:"testsuites"`
|
||||||
|
TestSuites []testSuiteXML
|
||||||
|
}
|
||||||
|
|
||||||
|
type testSuiteXML struct {
|
||||||
|
XMLName xml.Name `xml:"testsuite"`
|
||||||
|
Suite string `xml:"name,attr"`
|
||||||
|
TestCases []testCaseXML `xml:"testcase"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type testCaseXML struct {
|
||||||
|
Name string `xml:"name,attr"`
|
||||||
|
ClassName string `xml:"classname,attr"`
|
||||||
|
Status string `xml:"status,attr"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type JunitXML struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewJunitXML() *JunitXML {
|
||||||
|
return &JunitXML{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (JunitXML) Print(ctx context.Context, issues <-chan result.Issue) error {
|
||||||
|
suites := make(map[string]testSuiteXML) // use a map to group-by "FromLinter"
|
||||||
|
|
||||||
|
for i := range issues {
|
||||||
|
fromLinter := i.FromLinter
|
||||||
|
testSuite := suites[fromLinter]
|
||||||
|
testSuite.Suite = fromLinter
|
||||||
|
|
||||||
|
var source string
|
||||||
|
for _, line := range i.SourceLines {
|
||||||
|
source += strings.TrimSpace(line) + "; "
|
||||||
|
}
|
||||||
|
tc := testCaseXML{Name: i.Text,
|
||||||
|
ClassName: i.Pos.String(),
|
||||||
|
Status: strings.TrimSuffix(source, "; "),
|
||||||
|
}
|
||||||
|
|
||||||
|
testSuite.TestCases = append(testSuite.TestCases, tc)
|
||||||
|
suites[fromLinter] = testSuite
|
||||||
|
}
|
||||||
|
|
||||||
|
var res testSuitesXML
|
||||||
|
for _, val := range suites {
|
||||||
|
res.TestSuites = append(res.TestSuites, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
enc := xml.NewEncoder(logutils.StdOut)
|
||||||
|
enc.Indent("", " ")
|
||||||
|
if err := enc.Encode(res); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user