1 // Copyright 2014 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 //lint:file-ignore SA1019 go/callgraph's test suite is built around the deprecated go/loader. We'll leave fixing that to upstream.
16 "golang.org/x/tools/go/loader"
17 "honnef.co/go/tools/callgraph"
18 "honnef.co/go/tools/callgraph/static"
19 "honnef.co/go/tools/ir/irutil"
22 const input = `package P
32 p() // IR constant propagation => static
52 func TestStatic(t *testing.T) {
53 conf := loader.Config{ParserMode: parser.ParseComments}
54 f, err := conf.ParseFile("P.go", input)
59 conf.CreateFromFiles("P", f)
60 iprog, err := conf.Load()
65 P := iprog.Created[0].Pkg
67 prog := irutil.CreateProgram(iprog, 0)
70 cg := static.CallGraph(prog)
73 callgraph.GraphVisitEdges(cg, func(e *callgraph.Edge) error {
74 edges = append(edges, fmt.Sprintf("%s -> %s",
75 e.Caller.Func.RelString(P),
76 e.Callee.Func.RelString(P)))
87 if !reflect.DeepEqual(edges, want) {
88 t.Errorf("Got edges %v, want %v", edges, want)