Skip to content

Commit df628f6

Browse files
committed
chore: clean test files
1 parent 01dedca commit df628f6

12 files changed

+121
-219
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ test_race: build_race
4040
.PHONY: test_race
4141

4242
test_linters:
43-
GL_TEST_RUN=1 go test -v ./test -count 1 -run TestSourcesFromTestdataWithIssuesDir/$T
43+
GL_TEST_RUN=1 go test -v ./test -count 1 -run TestSourcesFromTestdata/$T
4444
.PHONY: test_linters
4545

4646
# Maintenance

test/linters_test.go

+1-163
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package test
22

33
import (
4-
"fmt"
5-
"os"
64
"os/exec"
7-
"path"
85
"path/filepath"
96
"testing"
107

@@ -16,7 +13,7 @@ import (
1613

1714
const testdataDir = "testdata"
1815

19-
func TestSourcesFromTestdataWithIssuesDir(t *testing.T) {
16+
func TestSourcesFromTestdata(t *testing.T) {
2017
testSourcesFromDir(t, testdataDir)
2118
}
2219

@@ -90,162 +87,3 @@ func testOneSource(t *testing.T, sourcePath string) {
9087
testshared.Analyze(t, sourcePath, output)
9188
}
9289
}
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-
}

test/output_test.go

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package test
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"path"
7+
"path/filepath"
8+
"testing"
9+
10+
"github.com/stretchr/testify/require"
11+
12+
"github.com/golangci/golangci-lint/test/testshared"
13+
)
14+
15+
func TestOutput_Stderr(t *testing.T) {
16+
sourcePath := filepath.Join(testdataDir, "gci.go")
17+
fmt.Println(filepath.Abs(sourcePath))
18+
19+
testshared.NewRunnerBuilder(t).
20+
WithArgs(
21+
"--disable-all",
22+
"--print-issued-lines=false",
23+
"--print-linter-name=false",
24+
"--out-format=line-number,json:stderr",
25+
).
26+
WithDirectives(sourcePath).
27+
WithTargetPath(sourcePath).
28+
Runner().
29+
Install().
30+
Run().
31+
ExpectHasIssue("testdata/gci.go:8: File is not `gci`-ed").
32+
ExpectOutputContains(`"Issues":[`)
33+
}
34+
35+
func TestOutput_File(t *testing.T) {
36+
resultPath := path.Join(t.TempDir(), "golangci_lint_test_result")
37+
38+
sourcePath := filepath.Join(testdataDir, "gci.go")
39+
40+
testshared.NewRunnerBuilder(t).
41+
WithArgs(
42+
"--disable-all",
43+
"--print-issued-lines=false",
44+
"--print-linter-name=false",
45+
fmt.Sprintf("--out-format=json:%s,line-number", resultPath),
46+
).
47+
WithDirectives(sourcePath).
48+
WithTargetPath(sourcePath).
49+
Runner().
50+
Install().
51+
Run().
52+
ExpectHasIssue("testdata/gci.go:8: File is not `gci`-ed").
53+
ExpectOutputNotContains(`"Issues":[`)
54+
55+
b, err := os.ReadFile(resultPath)
56+
require.NoError(t, err)
57+
require.Contains(t, string(b), `"Issues":[`)
58+
}
59+
60+
func TestOutput_Multiple(t *testing.T) {
61+
sourcePath := filepath.Join(testdataDir, "gci.go")
62+
63+
testshared.NewRunnerBuilder(t).
64+
WithArgs(
65+
"--disable-all",
66+
"--print-issued-lines=false",
67+
"--print-linter-name=false",
68+
"--out-format=line-number,json:stdout",
69+
).
70+
WithDirectives(sourcePath).
71+
WithTargetPath(sourcePath).
72+
Runner().
73+
Install().
74+
Run().
75+
ExpectHasIssue("testdata/gci.go:8: File is not `gci`-ed").
76+
ExpectOutputContains(`"Issues":[`)
77+
}

test/testdata/gci/gci.go

-16
This file was deleted.

test/testdata/goimports/goimports.go

-16
This file was deleted.

test/testdata/goimports_local.go

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//golangcitest:args -Egoimports
2+
//golangcitest:config_path testdata/configs/goimports_local.yml
3+
package testdata
4+
5+
import (
6+
"fmt"
7+
8+
"github.com/golangci/golangci-lint/pkg/config" // want "File is not `goimports`-ed with -local github.com/golangci/golangci-lint"
9+
"github.com/pkg/errors"
10+
)
11+
12+
func GoimportsLocalPrefixTest() {
13+
fmt.Print("x")
14+
_ = config.Config{}
15+
_ = errors.New("")
16+
}

test/testdata/tparallel/missing_subtest_test.go

-12
This file was deleted.

test/testdata/tparallel/missing_toplevel_test.go

-11
This file was deleted.

test/testdata/tparallel/happy_path_test.go renamed to test/testdata/tparallel_happy_path_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//golangcitest:args -Etparallel
12
package testdata
23

34
import (
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//golangcitest:args -Etparallel
2+
package testdata
3+
4+
import (
5+
"testing"
6+
)
7+
8+
func TestSubtests(t *testing.T) { // want "TestSubtests's subtests should call t.Parallel"
9+
t.Parallel()
10+
11+
t.Run("", func(t *testing.T) {
12+
})
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//golangcitest:args -Etparallel
2+
package testdata
3+
4+
import (
5+
"testing"
6+
)
7+
8+
func TestTopLevel(t *testing.T) { // want "TestTopLevel should call t.Parallel on the top level as well as its subtests"
9+
t.Run("", func(t *testing.T) {
10+
t.Parallel()
11+
})
12+
}

0 commit comments

Comments
 (0)