Debian Codegraph @

go/analysis/passes/findcall/findcall_test.go

raw symbols SCIP
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 findcall_testscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis/passes/findcall_test`/
6
7 import (
8 "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/"
9
10 "golang.org/x/tools/go/analysis/analysistestscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis/analysistest`/"
11 "golang.org/x/tools/go/analysis/passes/findcallscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis/passes/findcall`/"
12 )
13
14 func initscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis/passes/findcall_test`/init().() {
15 findcallscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis/passes/findcall`/.Analyzerscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis/passes/findcall`/Analyzer..Flagsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Analyzer#Flags..Setscip-go gomod github.com/golang/go/src go1.25.0 flag/FlagSet#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.
22 func TestFromStringLiteralsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis/passes/findcall_test`/TestFromStringLiterals().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 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
34 func main() {
35 println("hello") // want "call of println"
36 print("goodbye") // not a call of println
37 }
38
39 func println(s string) {} // want println:"found"`,
40 },
41 },
42 } {
43 t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().(test.desc, func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
44 dir, cleanup, err := analysistestscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis/analysistest`/.WriteFilesscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis/analysistest`/WriteFiles().(test.files)
45 if err != nil {
46 t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err)
47 }
48 defer cleanup()
49 analysistestscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis/analysistest`/.Runscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis/analysistest`/Run().(t, dir, findcallscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis/passes/findcall`/.Analyzerscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis/passes/findcall`/Analyzer., test.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.
63 func TestFromFileSystemscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis/passes/findcall_test`/TestFromFileSystem().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
64 testdata := analysistestscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis/analysistest`/.TestDatascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis/analysistest`/TestData.()
65 analysistestscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis/analysistest`/.RunWithSuggestedFixesscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis/analysistest`/RunWithSuggestedFixes().(t, testdata, findcallscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis/passes/findcall`/.Analyzerscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis/passes/findcall`/Analyzer., "a") // loads testdata/src/a/a.go.
66 }