@@ -14,7 +14,6 @@ import (
14
14
15
15
hcversion "github.com/hashicorp/go-version"
16
16
"github.com/stretchr/testify/require"
17
- "gopkg.in/yaml.v3"
18
17
19
18
"github.com/golangci/golangci-lint/pkg/exitcodes"
20
19
"github.com/golangci/golangci-lint/test/testshared"
@@ -82,7 +81,7 @@ func TestGoimportsLocal(t *testing.T) {
82
81
83
82
args = append (args , rc .args ... )
84
83
85
- cfg , err := yaml . Marshal (rc .config )
84
+ cfg , err := os . ReadFile (rc .configPath )
86
85
require .NoError (t , err )
87
86
88
87
testshared .NewLintRunner (t ).RunWithYamlConfig (string (cfg ), args ... ).
@@ -175,25 +174,6 @@ func TestFileOutput(t *testing.T) {
175
174
require .Contains (t , string (b ), `"Issues":[` )
176
175
}
177
176
178
- func saveConfig (t * testing.T , cfg map [string ]interface {}) (cfgPath string , finishFunc func ()) {
179
- f , err := os .CreateTemp ("" , "golangci_lint_test" )
180
- require .NoError (t , err )
181
-
182
- cfgPath = f .Name () + ".yml"
183
- err = os .Rename (f .Name (), cfgPath )
184
- require .NoError (t , err )
185
-
186
- err = yaml .NewEncoder (f ).Encode (cfg )
187
- require .NoError (t , err )
188
-
189
- return cfgPath , func () {
190
- require .NoError (t , f .Close ())
191
- if os .Getenv ("GL_KEEP_TEMP_FILES" ) != "1" {
192
- require .NoError (t , os .Remove (cfgPath ))
193
- }
194
- }
195
- }
196
-
197
177
func testOneSource (t * testing.T , sourcePath string ) {
198
178
args := []string {
199
179
"run" ,
@@ -210,25 +190,16 @@ func testOneSource(t *testing.T, sourcePath string) {
210
190
t .Skipf ("Skipped: %s" , sourcePath )
211
191
}
212
192
213
- var cfgPath string
214
- if rc .config != nil {
215
- p , finish := saveConfig (t , rc .config )
216
- defer finish ()
217
- cfgPath = p
218
- } else if rc .configPath != "" {
219
- cfgPath = rc .configPath
220
- }
221
-
222
193
for _ , addArg := range []string {"" , "-Etypecheck" } {
223
194
caseArgs := append ([]string {}, args ... )
224
195
caseArgs = append (caseArgs , rc .args ... )
225
196
if addArg != "" {
226
197
caseArgs = append (caseArgs , addArg )
227
198
}
228
- if cfgPath == "" {
199
+ if rc . configPath == "" {
229
200
caseArgs = append (caseArgs , "--no-config" )
230
201
} else {
231
- caseArgs = append (caseArgs , "-c" , cfgPath )
202
+ caseArgs = append (caseArgs , "-c" , rc . configPath )
232
203
}
233
204
234
205
caseArgs = append (caseArgs , sourcePath )
@@ -241,41 +212,17 @@ func testOneSource(t *testing.T, sourcePath string) {
241
212
242
213
type runContext struct {
243
214
args []string
244
- config map [string ]interface {}
245
215
configPath string
246
216
expectedLinter string
247
217
}
248
218
249
- func buildConfigFromShortRepr (t * testing.T , repr string , config map [string ]interface {}) {
250
- kv := strings .Split (repr , "=" )
251
- require .Len (t , kv , 2 , "repr: %s" , repr )
252
-
253
- keyParts := strings .Split (kv [0 ], "." )
254
- require .True (t , len (keyParts ) >= 2 , len (keyParts ))
255
-
256
- lastObj := config
257
- for _ , k := range keyParts [:len (keyParts )- 1 ] {
258
- var v map [string ]interface {}
259
- if lastObj [k ] == nil {
260
- v = map [string ]interface {}{}
261
- } else {
262
- v = lastObj [k ].(map [string ]interface {})
263
- }
264
-
265
- lastObj [k ] = v
266
- lastObj = v
267
- }
268
-
269
- lastObj [keyParts [len (keyParts )- 1 ]] = kv [1 ]
270
- }
271
-
272
219
func skipMultilineComment (scanner * bufio.Scanner ) {
273
220
for line := scanner .Text (); ! strings .Contains (line , "*/" ) && scanner .Scan (); {
274
221
line = scanner .Text ()
275
222
}
276
223
}
277
224
278
- //nolint:gocyclo,funlen
225
+ //nolint:gocyclo
279
226
func extractRunContextFromComments (t * testing.T , sourcePath string ) * runContext {
280
227
f , err := os .Open (sourcePath )
281
228
require .NoError (t , err )
@@ -324,14 +271,6 @@ func extractRunContextFromComments(t *testing.T, sourcePath string) *runContext
324
271
rc .args = strings .Split (after , " " )
325
272
continue
326
273
327
- case "//golangcitest:config" :
328
- require .NotEmpty (t , after )
329
- if rc .config == nil {
330
- rc .config = map [string ]interface {}{}
331
- }
332
- buildConfigFromShortRepr (t , after , rc .config )
333
- continue
334
-
335
274
case "//golangcitest:config_path" :
336
275
require .NotEmpty (t , after )
337
276
rc .configPath = after
@@ -394,10 +333,7 @@ func TestTparallel(t *testing.T) {
394
333
395
334
args = append (args , rc .args ... )
396
335
397
- cfg , err := yaml .Marshal (rc .config )
398
- require .NoError (t , err )
399
-
400
- testshared .NewLintRunner (t ).RunWithYamlConfig (string (cfg ), args ... ).
336
+ testshared .NewLintRunner (t ).RunWithYamlConfig ("" , args ... ).
401
337
ExpectHasIssue (
402
338
"testdata/tparallel/missing_toplevel_test.go:7:6: TestTopLevel should call t.Parallel on the top level as well as its subtests\n " ,
403
339
)
@@ -416,10 +352,7 @@ func TestTparallel(t *testing.T) {
416
352
417
353
args = append (args , rc .args ... )
418
354
419
- cfg , err := yaml .Marshal (rc .config )
420
- require .NoError (t , err )
421
-
422
- testshared .NewLintRunner (t ).RunWithYamlConfig (string (cfg ), args ... ).
355
+ testshared .NewLintRunner (t ).RunWithYamlConfig ("" , args ... ).
423
356
ExpectHasIssue (
424
357
"testdata/tparallel/missing_subtest_test.go:7:6: TestSubtests's subtests should call t.Parallel\n " ,
425
358
)
@@ -438,9 +371,6 @@ func TestTparallel(t *testing.T) {
438
371
439
372
args = append (args , rc .args ... )
440
373
441
- cfg , err := yaml .Marshal (rc .config )
442
- require .NoError (t , err )
443
-
444
- testshared .NewLintRunner (t ).RunWithYamlConfig (string (cfg ), args ... ).ExpectNoIssues ()
374
+ testshared .NewLintRunner (t ).RunWithYamlConfig ("" , args ... ).ExpectNoIssues ()
445
375
})
446
376
}
0 commit comments