1
1
package test
2
2
3
3
import (
4
- "fmt"
5
- "os"
6
4
"os/exec"
7
- "path"
8
5
"path/filepath"
9
6
"testing"
10
7
@@ -16,7 +13,7 @@ import (
16
13
17
14
const testdataDir = "testdata"
18
15
19
- func TestSourcesFromTestdataWithIssuesDir (t * testing.T ) {
16
+ func TestSourcesFromTestdata (t * testing.T ) {
20
17
testSourcesFromDir (t , testdataDir )
21
18
}
22
19
@@ -90,162 +87,3 @@ func testOneSource(t *testing.T, sourcePath string) {
90
87
testshared .Analyze (t , sourcePath , output )
91
88
}
92
89
}
93
-
94
- func TestMultipleOutputs (t * testing.T ) {
95
- sourcePath := filepath .Join (testdataDir , "gci" , "gci.go" )
96
-
97
- testshared .NewRunnerBuilder (t ).
98
- WithArgs (
99
- "--disable-all" ,
100
- "--print-issued-lines=false" ,
101
- "--print-linter-name=false" ,
102
- "--out-format=line-number,json:stdout" ,
103
- ).
104
- WithDirectives (sourcePath ).
105
- WithTargetPath (sourcePath ).
106
- Runner ().
107
- Install ().
108
- Run ().
109
- ExpectHasIssue ("testdata/gci/gci.go:8: File is not `gci`-ed" ).
110
- ExpectOutputContains (`"Issues":[` )
111
- }
112
-
113
- func TestStderrOutput (t * testing.T ) {
114
- sourcePath := filepath .Join (testdataDir , "gci" , "gci.go" )
115
-
116
- testshared .NewRunnerBuilder (t ).
117
- WithArgs (
118
- "--disable-all" ,
119
- "--print-issued-lines=false" ,
120
- "--print-linter-name=false" ,
121
- "--out-format=line-number,json:stderr" ,
122
- ).
123
- WithDirectives (sourcePath ).
124
- WithTargetPath (sourcePath ).
125
- Runner ().
126
- Install ().
127
- Run ().
128
- ExpectHasIssue ("testdata/gci/gci.go:8: File is not `gci`-ed" ).
129
- ExpectOutputContains (`"Issues":[` )
130
- }
131
-
132
- func TestFileOutput (t * testing.T ) {
133
- resultPath := path .Join (t .TempDir (), "golangci_lint_test_result" )
134
-
135
- sourcePath := filepath .Join (testdataDir , "gci" , "gci.go" )
136
-
137
- testshared .NewRunnerBuilder (t ).
138
- WithArgs (
139
- "--disable-all" ,
140
- "--print-issued-lines=false" ,
141
- "--print-linter-name=false" ,
142
- fmt .Sprintf ("--out-format=json:%s,line-number" , resultPath ),
143
- ).
144
- WithDirectives (sourcePath ).
145
- WithTargetPath (sourcePath ).
146
- Runner ().
147
- Install ().
148
- Run ().
149
- ExpectHasIssue ("testdata/gci/gci.go:8: File is not `gci`-ed" ).
150
- ExpectOutputNotContains (`"Issues":[` )
151
-
152
- b , err := os .ReadFile (resultPath )
153
- require .NoError (t , err )
154
- require .Contains (t , string (b ), `"Issues":[` )
155
- }
156
-
157
- func TestLinter_goimports_local (t * testing.T ) {
158
- sourcePath := filepath .Join (testdataDir , "goimports" , "goimports.go" )
159
-
160
- testshared .NewRunnerBuilder (t ).
161
- WithArgs (
162
- "--disable-all" ,
163
- "--print-issued-lines=false" ,
164
- "--print-linter-name=false" ,
165
- "--out-format=line-number" ,
166
- ).
167
- WithDirectives (sourcePath ).
168
- WithTargetPath (sourcePath ).
169
- Runner ().
170
- Install ().
171
- Run ().
172
- ExpectHasIssue ("testdata/goimports/goimports.go:8: File is not `goimports`-ed" )
173
- }
174
-
175
- func TestLinter_gci_Local (t * testing.T ) {
176
- sourcePath := filepath .Join (testdataDir , "gci" , "gci.go" )
177
-
178
- testshared .NewRunnerBuilder (t ).
179
- WithArgs (
180
- "--disable-all" ,
181
- "--print-issued-lines=false" ,
182
- "--print-linter-name=false" ,
183
- "--out-format=line-number" ,
184
- ).
185
- WithDirectives (sourcePath ).
186
- WithTargetPath (sourcePath ).
187
- Runner ().
188
- Install ().
189
- Run ().
190
- ExpectHasIssue ("testdata/gci/gci.go:8: File is not `gci`-ed" )
191
- }
192
-
193
- // TODO(ldez) need to be converted to a classic linter test.
194
- func TestLinter_tparallel (t * testing.T ) {
195
- testCases := []struct {
196
- desc string
197
- sourcePath string
198
- expected func (result * testshared.RunnerResult )
199
- }{
200
- {
201
- desc : "should fail on missing top-level Parallel()" ,
202
- sourcePath : filepath .Join (testdataDir , "tparallel" , "missing_toplevel_test.go" ),
203
- expected : func (result * testshared.RunnerResult ) {
204
- result .ExpectHasIssue (
205
- "testdata/tparallel/missing_toplevel_test.go:7:6: TestTopLevel should call t.Parallel on the top level as well as its subtests\n " ,
206
- )
207
- },
208
- },
209
- {
210
- desc : "should fail on missing subtest Parallel()" ,
211
- sourcePath : filepath .Join (testdataDir , "tparallel" , "missing_subtest_test.go" ),
212
- expected : func (result * testshared.RunnerResult ) {
213
- result .ExpectHasIssue (
214
- "testdata/tparallel/missing_subtest_test.go:7:6: TestSubtests's subtests should call t.Parallel\n " ,
215
- )
216
- },
217
- },
218
- {
219
- desc : "should pass on parallel test with no subtests" ,
220
- sourcePath : filepath .Join (testdataDir , "tparallel" , "happy_path_test.go" ),
221
- expected : func (result * testshared.RunnerResult ) {
222
- result .ExpectNoIssues ()
223
- },
224
- },
225
- }
226
-
227
- testshared .InstallGolangciLint (t )
228
-
229
- for _ , test := range testCases {
230
- test := test
231
- t .Run (test .desc , func (t * testing.T ) {
232
- t .Parallel ()
233
-
234
- result := testshared .NewRunnerBuilder (t ).
235
- WithDirectives (test .sourcePath ).
236
- WithArgs (
237
- "--disable-all" ,
238
- "--enable" ,
239
- "tparallel" ,
240
- "--print-issued-lines=false" ,
241
- "--print-linter-name=false" ,
242
- "--out-format=line-number" ,
243
- ).
244
- WithTargetPath (test .sourcePath ).
245
- Runner ().
246
- Run ()
247
-
248
- test .expected (result )
249
- })
250
- }
251
- }
0 commit comments