@@ -2,6 +2,8 @@ package test
22
33import (
44 "bufio"
5+ "fmt"
6+ "io/ioutil"
57 "os"
68 "os/exec"
79 "path/filepath"
@@ -100,7 +102,7 @@ func TestGciLocal(t *testing.T) {
100102func TestMultipleOutputs (t * testing.T ) {
101103 sourcePath := filepath .Join (testdataDir , "gci" , "gci.go" )
102104 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 " ,
104106 sourcePath ,
105107 }
106108 rc := extractRunContextFromComments (t , sourcePath )
@@ -114,6 +116,52 @@ func TestMultipleOutputs(t *testing.T) {
114116 ExpectOutputContains (`"Issues":[` )
115117}
116118
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+
117165func saveConfig (t * testing.T , cfg map [string ]interface {}) (cfgPath string , finishFunc func ()) {
118166 f , err := os .CreateTemp ("" , "golangci_lint_test" )
119167 require .NoError (t , err )
0 commit comments