-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcall_test.go
46 lines (38 loc) · 1.08 KB
/
call_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
package analysisutil_test
import (
"errors"
"testing"
"github.com/gostaticanalysis/analysisutil"
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/analysis/analysistest"
"golang.org/x/tools/go/analysis/passes/buildssa"
)
var callAnalyzer = &analysis.Analyzer{
Name: "test_call",
Run: callAnalyzerRun,
Requires: []*analysis.Analyzer{
buildssa.Analyzer,
},
}
func TestCall(t *testing.T) {
testdata := analysistest.TestData()
analysistest.Run(t, testdata, callAnalyzer, "call")
}
func callAnalyzerRun(pass *analysis.Pass) (interface{}, error) {
resTyp := analysisutil.TypeOf(pass, "call", "*res")
if resTyp == nil {
return nil, errors.New("analyzer does not find *call.res type")
}
close := analysisutil.MethodOf(resTyp, "close")
if close == nil {
return nil, errors.New("analyzer does not find (call.res).close method")
}
funcs := pass.ResultOf[buildssa.Analyzer].(*buildssa.SSA).SrcFuncs
for _, f := range funcs {
instrs := analysisutil.NotCalledIn(f, resTyp, close)
for _, instr := range instrs {
pass.Reportf(instr.Pos(), "NG")
}
}
return nil, nil
}