1
1
package analyzer_test
2
2
3
3
import (
4
- "os"
5
- "path/filepath"
6
4
"testing"
7
5
8
6
"golang.org/x/tools/go/analysis/analysistest"
@@ -11,27 +9,49 @@ import (
11
9
)
12
10
13
11
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
+ },
17
39
}
18
- testdata := filepath .Join (wd , "testdata" )
19
40
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 ()
25
44
26
- t .Run ("func decl" , func (t * testing.T ) {
27
- an := analyzer .NewAnalyzer ()
45
+ a := analyzer .NewAnalyzer ()
28
46
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
+ }
33
53
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
+ }
37
57
}
0 commit comments