-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdiagnostic_test.go
47 lines (42 loc) · 1.02 KB
/
diagnostic_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package analysisutil_test
import (
"go/ast"
"go/token"
"testing"
"github.com/gostaticanalysis/analysisutil"
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/analysis/analysistest"
)
func TestReportWithoutIgnore(t *testing.T) {
testdata := analysistest.TestData()
cases := []struct {
pkg string
names []string
}{
{"withoutnames", nil},
{"withnames", []string{"check1", "check2"}},
}
for _, tt := range cases {
tt := tt
t.Run(tt.pkg, func(t *testing.T) {
analyzer := &analysis.Analyzer{
Name: "test",
Run: func(pass *analysis.Pass) (interface{}, error) {
pass.Report = analysisutil.ReportWithoutIgnore(pass, tt.names...)
for _, f := range pass.Files {
for _, decl := range f.Decls {
decl, ok := decl.(*ast.GenDecl)
if !ok || decl.Tok != token.VAR {
continue
}
pass.Reportf(decl.Pos(), "NG")
pass.ReportRangef(decl, "NG")
}
}
return nil, nil
},
}
analysistest.Run(t, testdata, analyzer, "diagnostic/"+tt.pkg)
})
}
}