GoPLS Viewer

Home|gopls/go/analysis/passes/findcall/findcall_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 findcall_test
6
7import (
8    "testing"
9
10    "golang.org/x/tools/go/analysis/analysistest"
11    "golang.org/x/tools/go/analysis/passes/findcall"
12)
13
14func init() {
15    findcall.Analyzer.Flags.Set("name""println")
16}
17
18// TestFromStringLiterals demonstrates how to test an analysis using
19// a table of string literals for each test case.
20//
21// Such tests are typically quite compact.
22func TestFromStringLiterals(t *testing.T) {
23
24    for _test := range [...]struct {
25        desc    string
26        pkgpath string
27        files   map[string]string
28    }{
29        {
30            desc:    "SimpleTest",
31            pkgpath"main",
32            files: map[string]string{"main/main.go"`package main // want package:"found"
33
34func main() {
35    println("hello") // want "call of println"
36    print("goodbye") // not a call of println
37}
38
39func println(s string) {} // want println:"found"`,
40            },
41        },
42    } {
43        t.Run(test.desc, func(t *testing.T) {
44            dircleanuperr := analysistest.WriteFiles(test.files)
45            if err != nil {
46                t.Fatal(err)
47            }
48            defer cleanup()
49            analysistest.Run(tdirfindcall.Analyzertest.pkgpath)
50        })
51    }
52}
53
54// TestFromFileSystem demonstrates how to test an analysis using input
55// files stored in the file system.
56//
57// These tests have the advantages that test data can be edited
58// directly, and that files named in error messages can be opened.
59// However, they tend to spread a small number of lines of text across a
60// rather deep directory hierarchy, and obscure similarities among
61// related tests, especially when tests involve multiple packages, or
62// multiple variants of a single scenario.
63func TestFromFileSystem(t *testing.T) {
64    testdata := analysistest.TestData()
65    analysistest.RunWithSuggestedFixes(ttestdatafindcall.Analyzer"a"// loads testdata/src/a/a.go.
66}
67
MembersX
TestFromFileSystem
TestFromFileSystem.t
testing
findcall
TestFromStringLiterals
TestFromStringLiterals.RangeStmt_581.test
TestFromStringLiterals.RangeStmt_581.BlockStmt.BlockStmt.dir
TestFromStringLiterals.RangeStmt_581.BlockStmt.BlockStmt.cleanup
TestFromFileSystem.testdata
analysistest
TestFromStringLiterals.t
TestFromStringLiterals.RangeStmt_581.BlockStmt.BlockStmt.err
Members
X