feat: add junit-xml-extended format (#4918) · golangci/golangci-lint@0275389 (original) (raw)
6 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -70,6 +70,7 @@ output: | ||
70 | 70 | # - `checkstyle` |
71 | 71 | # - `code-climate` |
72 | 72 | # - `junit-xml` |
73 | +# - `junit-xml-extended` | |
73 | 74 | # - `github-actions` |
74 | 75 | # - `teamcity` |
75 | 76 | # - `sarif` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -521,6 +521,7 @@ | ||
521 | 521 | "checkstyle", |
522 | 522 | "code-climate", |
523 | 523 | "junit-xml", |
524 | +"junit-xml-extended", | |
524 | 525 | "github-actions", |
525 | 526 | "teamcity", |
526 | 527 | "sarif" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -17,6 +17,7 @@ const ( | ||
17 | 17 | OutFormatCodeClimate = "code-climate" |
18 | 18 | OutFormatHTML = "html" |
19 | 19 | OutFormatJunitXML = "junit-xml" |
20 | +OutFormatJunitXMLExtended = "junit-xml-extended" | |
20 | 21 | OutFormatGithubActions = "github-actions" // Deprecated |
21 | 22 | OutFormatTeamCity = "teamcity" |
22 | 23 | OutFormatSarif = "sarif" |
@@ -32,6 +33,7 @@ var AllOutputFormats = []string{ | ||
32 | 33 | OutFormatCodeClimate, |
33 | 34 | OutFormatHTML, |
34 | 35 | OutFormatJunitXML, |
36 | +OutFormatJunitXMLExtended, | |
35 | 37 | OutFormatGithubActions, |
36 | 38 | OutFormatTeamCity, |
37 | 39 | OutFormatSarif, |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -30,6 +30,8 @@ type testCaseXML struct { | ||
30 | 30 | Name string `xml:"name,attr"` |
31 | 31 | ClassName string `xml:"classname,attr"` |
32 | 32 | Failure failureXML `xml:"failure"` |
33 | +File string `xml:"file,attr,omitempty"` | |
34 | +Line int `xml:"line,attr,omitempty"` | |
33 | 35 | } |
34 | 36 | |
35 | 37 | type failureXML struct { |
@@ -39,11 +41,15 @@ type failureXML struct { | ||
39 | 41 | } |
40 | 42 | |
41 | 43 | type JunitXML struct { |
42 | -w io.Writer | |
44 | +extended bool | |
45 | +w io.Writer | |
43 | 46 | } |
44 | 47 | |
45 | -func NewJunitXML(w io.Writer) *JunitXML { | |
46 | -return &JunitXML{w: w} | |
48 | +func NewJunitXML(extended bool, w io.Writer) *JunitXML { | |
49 | +return &JunitXML{ | |
50 | +extended: extended, | |
51 | +w: w, | |
52 | + } | |
47 | 53 | } |
48 | 54 | |
49 | 55 | func (p JunitXML) Print(issues []result.Issue) error { |
@@ -68,6 +74,11 @@ func (p JunitXML) Print(issues []result.Issue) error { | ||
68 | 74 | }, |
69 | 75 | } |
70 | 76 | |
77 | +if p.extended { | |
78 | +tc.File = i.Pos.Filename | |
79 | +tc.Line = i.Pos.Line | |
80 | + } | |
81 | + | |
71 | 82 | testSuite.TestCases = append(testSuite.TestCases, tc) |
72 | 83 | suites[suiteName] = testSuite |
73 | 84 | } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -42,13 +42,14 @@ func TestJunitXML_Print(t *testing.T) { | ||
42 | 42 | }, |
43 | 43 | } |
44 | 44 | |
45 | -buf := new(bytes.Buffer) | |
46 | -printer := NewJunitXML(buf) | |
47 | - | |
48 | -err := printer.Print(issues) | |
49 | -require.NoError(t, err) | |
50 | - | |
51 | -expected := ` | |
45 | +testCases := []struct { | |
46 | +desc string | |
47 | +extended bool | |
48 | +expected string | |
49 | + }{ | |
50 | + { | |
51 | +desc: "basic", | |
52 | +expected: ` | |
52 | 53 | |
53 | 54 | |
54 | 55 | <![CDATA[warning: some issue |
@@ -69,7 +70,47 @@ Details: func foo() { | ||
69 | 70 | }]]> |
70 | 71 | |
71 | 72 | |
72 | -` | |
73 | +`, | |
74 | + }, | |
75 | + { | |
76 | +desc: "extended/complete", | |
77 | +extended: true, | |
78 | +expected: ` | |
79 | + | |
80 | + | |
81 | + <![CDATA[warning: some issue | |
82 | +Category: linter-a | |
83 | +File: path/to/filea.go | |
84 | +Line: 10 | |
85 | +Details: ]]> | |
86 | + | |
87 | + | |
88 | + | |
89 | + | |
90 | + <![CDATA[error: another issue | |
91 | +Category: linter-b | |
92 | +File: path/to/fileb.go | |
93 | +Line: 300 | |
94 | +Details: func foo() { | |
95 | + fmt.Println("bar") | |
96 | +}]]> | |
97 | + | |
98 | + | |
99 | +`, | |
100 | + }, | |
101 | + } | |
102 | + | |
103 | +for _, test := range testCases { | |
104 | +t.Run(test.desc, func(t *testing.T) { | |
105 | +t.Parallel() | |
73 | 106 | |
74 | -assert.Equal(t, expected, buf.String()) | |
107 | +buf := new(bytes.Buffer) | |
108 | +printer := NewJunitXML(test.extended, buf) | |
109 | + | |
110 | +err := printer.Print(issues) | |
111 | +require.NoError(t, err) | |
112 | + | |
113 | +assert.Equal(t, test.expected, buf.String()) | |
114 | + }) | |
115 | + } | |
75 | 116 | } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -115,7 +115,7 @@ func (c *Printer) createPrinter(format string, w io.Writer) (issuePrinter, error | ||
115 | 115 | switch format { |
116 | 116 | case config.OutFormatJSON: |
117 | 117 | p = NewJSON(c.reportData, w) |
118 | -case config.OutFormatColoredLineNumber, config.OutFormatLineNumber: | |
118 | +case config.OutFormatLineNumber, config.OutFormatColoredLineNumber: | |
119 | 119 | p = NewText(c.cfg.PrintIssuedLine, |
120 | 120 | format == config.OutFormatColoredLineNumber, c.cfg.PrintLinterName, |
121 | 121 | c.log.Child(logutils.DebugKeyTextPrinter), w) |
@@ -129,8 +129,8 @@ func (c *Printer) createPrinter(format string, w io.Writer) (issuePrinter, error | ||
129 | 129 | p = NewCodeClimate(w) |
130 | 130 | case config.OutFormatHTML: |
131 | 131 | p = NewHTML(w) |
132 | -case config.OutFormatJunitXML: | |
133 | -p = NewJunitXML(w) | |
132 | +case config.OutFormatJunitXML, config.OutFormatJunitXMLExtended: | |
133 | +p = NewJunitXML(format == config.OutFormatJunitXMLExtended, w) | |
134 | 134 | case config.OutFormatGithubActions: |
135 | 135 | p = NewGitHubAction(w) |
136 | 136 | case config.OutFormatTeamCity: |