1 // Copyright 2018 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.
11 "golang.org/x/tools/go/analysis/analysistest"
12 "golang.org/x/tools/go/analysis/passes/ctrlflow"
15 func Test(t *testing.T) {
16 testdata := analysistest.TestData()
18 // load testdata/src/a/a.go
19 results := analysistest.Run(t, testdata, ctrlflow.Analyzer, "a")
21 // Perform a minimal smoke test on
22 // the result (CFG) computed by ctrlflow.
23 for _, result := range results {
24 cfgs := result.Result.(*ctrlflow.CFGs)
26 for _, decl := range result.Pass.Files[0].Decls {
27 if decl, ok := decl.(*ast.FuncDecl); ok && decl.Body != nil {
28 if cfgs.FuncDecl(decl) == nil {
29 t.Errorf("%s: no CFG for func %s",
30 result.Pass.Fset.Position(decl.Pos()), decl.Name.Name)