GoPLS Viewer

Home|gopls/go/analysis/passes/ctrlflow/ctrlflow_test.go
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
5package ctrlflow_test
6
7import (
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
16func 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(ttestdatactrlflow.Analyzertests...)
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 declok := 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
MembersX
testing
analysistest
ctrlflow
typeparams
Test.results
Test
Test.t
Test.testdata
Test.tests
Test.RangeStmt_753.result
Test.RangeStmt_753.BlockStmt.RangeStmt_830.decl
Members
X