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 "honnef.co/go/tools/go/callgraph"
17 "honnef.co/go/tools/go/callgraph/static"
18 "honnef.co/go/tools/go/ir/irutil"
20 "golang.org/x/tools/go/loader"
23 const input = `package P
33 p() // IR constant propagation => static
53 func TestStatic(t *testing.T) {
54 conf := loader.Config{ParserMode: parser.ParseComments}
55 f, err := conf.ParseFile("P.go", input)
60 conf.CreateFromFiles("P", f)
61 iprog, err := conf.Load()
66 P := iprog.Created[0].Pkg
68 prog := irutil.CreateProgram(iprog, 0)
71 cg := static.CallGraph(prog)
74 callgraph.GraphVisitEdges(cg, func(e *callgraph.Edge) error {
75 edges = append(edges, fmt.Sprintf("%s -> %s",
76 e.Caller.Func.RelString(P),
77 e.Callee.Func.RelString(P)))
88 if !reflect.DeepEqual(edges, want) {
89 t.Errorf("Got edges %v, want %v", edges, want)