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. |
4 | |
5 | package ctrlflow_test |
6 | |
7 | import ( |
8 | "go/ast" |
9 | "testing" |
10 | |
11 | "golang.org/x/tools/go/analysis/analysistest" |
12 | "golang.org/x/tools/go/analysis/passes/ctrlflow" |
13 | "golang.org/x/tools/internal/typeparams" |
14 | ) |
15 | |
16 | func Test(t *testing.T) { |
17 | testdata := analysistest.TestData() |
18 | |
19 | // load testdata/src/a/a.go |
20 | tests := []string{"a"} |
21 | if typeparams.Enabled { |
22 | // and testdata/src/typeparams/typeparams.go when possible |
23 | tests = append(tests, "typeparams") |
24 | } |
25 | results := analysistest.Run(t, testdata, ctrlflow.Analyzer, tests...) |
26 | |
27 | // Perform a minimal smoke test on |
28 | // the result (CFG) computed by ctrlflow. |
29 | for _, result := range results { |
30 | cfgs := result.Result.(*ctrlflow.CFGs) |
31 | |
32 | for _, decl := range result.Pass.Files[0].Decls { |
33 | if decl, ok := decl.(*ast.FuncDecl); ok && decl.Body != nil { |
34 | if cfgs.FuncDecl(decl) == nil { |
35 | t.Errorf("%s: no CFG for func %s", |
36 | result.Pass.Fset.Position(decl.Pos()), decl.Name.Name) |
37 | } |
38 | } |
39 | } |
40 | } |
41 | } |
42 |
Members