Skip to content

Commit 7b0afb1

Browse files
ldezCrocmagnon
authored andcommitted
tests: rewrite tests
1 parent f887074 commit 7b0afb1

File tree

4 files changed

+40
-20
lines changed

4 files changed

+40
-20
lines changed

pkg/analyzer/analyzer_test.go

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package analyzer_test
22

33
import (
4-
"os"
5-
"path/filepath"
64
"testing"
75

86
"golang.org/x/tools/go/analysis/analysistest"
@@ -11,27 +9,49 @@ import (
119
)
1210

1311
func TestAnalyzer(t *testing.T) {
14-
wd, err := os.Getwd()
15-
if err != nil {
16-
t.Fatalf("Failed to get wd: %s", err)
12+
testCases := []struct {
13+
desc string
14+
dir string
15+
options map[string]string
16+
}{
17+
{
18+
desc: "no func decl",
19+
dir: "common",
20+
},
21+
{
22+
desc: "no func decl",
23+
dir: "no_structpointer",
24+
},
25+
{
26+
desc: "func decl",
27+
dir: "common",
28+
options: map[string]string{
29+
analyzer.FlagCheckStructPointers: "true",
30+
},
31+
},
32+
{
33+
desc: "func decl",
34+
dir: "structpointer",
35+
options: map[string]string{
36+
analyzer.FlagCheckStructPointers: "true",
37+
},
38+
},
1739
}
18-
testdata := filepath.Join(wd, "testdata")
1940

20-
t.Run("no func decl", func(t *testing.T) {
21-
an := analyzer.NewAnalyzer()
22-
analysistest.Run(t, testdata, an, "./common")
23-
analysistest.Run(t, testdata, an, "./no_structpointer")
24-
})
41+
for _, test := range testCases {
42+
t.Run(test.desc+"_"+test.dir, func(t *testing.T) {
43+
t.Parallel()
2544

26-
t.Run("func decl", func(t *testing.T) {
27-
an := analyzer.NewAnalyzer()
45+
a := analyzer.NewAnalyzer()
2846

29-
err := an.Flags.Set(analyzer.FlagCheckStructPointers, "true")
30-
if err != nil {
31-
t.Fatal(err)
32-
}
47+
for k, v := range test.options {
48+
err := a.Flags.Set(k, v)
49+
if err != nil {
50+
t.Fatal(err)
51+
}
52+
}
3353

34-
analysistest.Run(t, testdata, an, "./common")
35-
analysistest.Run(t, testdata, an, "./structpointer")
36-
})
54+
analysistest.Run(t, analysistest.TestData(), a, test.dir)
55+
})
56+
}
3757
}

0 commit comments

Comments
 (0)