@@ -2,6 +2,8 @@ package test
2
2
3
3
import (
4
4
"bufio"
5
+ "fmt"
6
+ "io/ioutil"
5
7
"os"
6
8
"os/exec"
7
9
"path/filepath"
@@ -100,7 +102,7 @@ func TestGciLocal(t *testing.T) {
100
102
func TestMultipleOutputs (t * testing.T ) {
101
103
sourcePath := filepath .Join (testdataDir , "gci" , "gci.go" )
102
104
args := []string {
103
- "--disable-all" , "--print-issued-lines=false" , "--print-linter-name=false" , "--out-format=line-number,json" ,
105
+ "--disable-all" , "--print-issued-lines=false" , "--print-linter-name=false" , "--out-format=line-number,json:stdout " ,
104
106
sourcePath ,
105
107
}
106
108
rc := extractRunContextFromComments (t , sourcePath )
@@ -114,6 +116,52 @@ func TestMultipleOutputs(t *testing.T) {
114
116
ExpectOutputContains (`"Issues":[` )
115
117
}
116
118
119
+ func TestStderrOutput (t * testing.T ) {
120
+ sourcePath := filepath .Join (testdataDir , "gci" , "gci.go" )
121
+ args := []string {
122
+ "--disable-all" , "--print-issued-lines=false" , "--print-linter-name=false" , "--out-format=line-number,json:stderr" ,
123
+ sourcePath ,
124
+ }
125
+ rc := extractRunContextFromComments (t , sourcePath )
126
+ args = append (args , rc .args ... )
127
+
128
+ cfg , err := yaml .Marshal (rc .config )
129
+ require .NoError (t , err )
130
+
131
+ testshared .NewLintRunner (t ).RunWithYamlConfig (string (cfg ), args ... ).
132
+ ExpectHasIssue ("testdata/gci/gci.go:7: File is not `gci`-ed" ).
133
+ ExpectOutputContains (`"Issues":[` )
134
+ }
135
+
136
+ func TestFileOutput (t * testing.T ) {
137
+ f , err := os .CreateTemp ("" , "golangci_lint_test_result" )
138
+ require .NoError (t , err )
139
+ f .Close ()
140
+
141
+ resultPath := f .Name ()
142
+ defer os .Remove (resultPath )
143
+
144
+ sourcePath := filepath .Join (testdataDir , "gci" , "gci.go" )
145
+ args := []string {
146
+ "--disable-all" , "--print-issued-lines=false" , "--print-linter-name=false" ,
147
+ fmt .Sprintf ("--out-format=json:%s,line-number" , resultPath ),
148
+ sourcePath ,
149
+ }
150
+ rc := extractRunContextFromComments (t , sourcePath )
151
+ args = append (args , rc .args ... )
152
+
153
+ cfg , err := yaml .Marshal (rc .config )
154
+ require .NoError (t , err )
155
+
156
+ testshared .NewLintRunner (t ).RunWithYamlConfig (string (cfg ), args ... ).
157
+ ExpectHasIssue ("testdata/gci/gci.go:7: File is not `gci`-ed" ).
158
+ ExpectOutputNotContains (`"Issues":[` )
159
+
160
+ b , err := ioutil .ReadFile (resultPath )
161
+ require .NoError (t , err )
162
+ require .Contains (t , string (b ), `"Issues":[` )
163
+ }
164
+
117
165
func saveConfig (t * testing.T , cfg map [string ]interface {}) (cfgPath string , finishFunc func ()) {
118
166
f , err := os .CreateTemp ("" , "golangci_lint_test" )
119
167
require .NoError (t , err )
0 commit comments