@@ -8,37 +8,29 @@ import (
8
8
9
9
"github.com/stretchr/testify/require"
10
10
11
- "github.com/golangci/golangci-lint/pkg/exitcodes"
12
11
"github.com/golangci/golangci-lint/test/testshared"
13
12
)
14
13
15
14
func TestFix (t * testing.T ) {
16
- findSources := func (pathPatterns ... string ) []string {
17
- sources , err := filepath .Glob (filepath .Join (pathPatterns ... ))
18
- require .NoError (t , err )
19
- require .NotEmpty (t , sources )
20
- return sources
21
- }
22
-
23
15
tmpDir := filepath .Join (testdataDir , "fix.tmp" )
24
- os .RemoveAll (tmpDir ) // cleanup after previous runs
16
+ _ = os .RemoveAll (tmpDir ) // cleanup previous runs
25
17
26
18
if os .Getenv ("GL_KEEP_TEMP_FILES" ) == "1" {
27
19
t .Logf ("Temp dir for fix test: %s" , tmpDir )
28
20
} else {
29
- t .Cleanup (func () {
30
- os .RemoveAll (tmpDir )
31
- })
21
+ t .Cleanup (func () { _ = os .RemoveAll (tmpDir ) })
32
22
}
33
23
34
- fixDir := filepath .Join (testdataDir , "fix" )
35
- err := exec .Command ("cp" , "-R" , fixDir , tmpDir ).Run ()
24
+ sourcesDir := filepath .Join (testdataDir , "fix" )
25
+
26
+ err := exec .Command ("cp" , "-R" , sourcesDir , tmpDir ).Run ()
36
27
require .NoError (t , err )
37
28
38
29
testshared .InstallGolangciLint (t )
39
30
40
- inputs := findSources (tmpDir , "in" , "*.go" )
41
- for _ , input := range inputs {
31
+ sources := findSources (t , tmpDir , "in" , "*.go" )
32
+
33
+ for _ , input := range sources {
42
34
input := input
43
35
t .Run (filepath .Base (input ), func (t * testing.T ) {
44
36
t .Parallel ()
@@ -49,22 +41,19 @@ func TestFix(t *testing.T) {
49
41
return
50
42
}
51
43
52
- runResult := testshared .NewRunnerBuilder (t ).
53
- WithRunContext (rc ).
54
- WithTargetPath (input ).
44
+ testshared .NewRunnerBuilder (t ).
55
45
WithArgs (
56
46
"--disable-all" ,
57
47
"--print-issued-lines=false" ,
58
48
"--print-linter-name=false" ,
59
49
"--out-format=line-number" ,
60
- "--fix" ).
50
+ "--fix" ,
51
+ ).
52
+ WithRunContext (rc ).
53
+ WithTargetPath (input ).
61
54
Runner ().
62
- Run ()
63
-
64
- // nolintlint test uses non existing linters (bob, alice)
65
- if rc .ExpectedLinter != "nolintlint" {
66
- runResult .ExpectExitCode (exitcodes .Success )
67
- }
55
+ Run ().
56
+ ExpectExitCode (rc .ExitCode )
68
57
69
58
output , err := os .ReadFile (input )
70
59
require .NoError (t , err )
0 commit comments