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.
14 "golang.org/x/tools/go/callgraph"
15 "golang.org/x/tools/go/callgraph/static"
16 "golang.org/x/tools/go/loader"
17 "golang.org/x/tools/go/ssa/ssautil"
20 const input = `package P
30 p() // SSA constant propagation => static
50 func TestStatic(t *testing.T) {
51 conf := loader.Config{ParserMode: parser.ParseComments}
52 f, err := conf.ParseFile("P.go", input)
57 conf.CreateFromFiles("P", f)
58 iprog, err := conf.Load()
63 P := iprog.Created[0].Pkg
65 prog := ssautil.CreateProgram(iprog, 0)
68 cg := static.CallGraph(prog)
71 callgraph.GraphVisitEdges(cg, func(e *callgraph.Edge) error {
72 edges = append(edges, fmt.Sprintf("%s -> %s",
73 e.Caller.Func.RelString(P),
74 e.Callee.Func.RelString(P)))
85 if !reflect.DeepEqual(edges, want) {
86 t.Errorf("Got edges %v, want %v", edges, want)