Skip to content

Commit 4b40bbc

Browse files
committed
remove global variable reference
1 parent a4bb031 commit 4b40bbc

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

go/callgraph/rta/rta_test.go

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,14 @@ import (
2727
"golang.org/x/tools/txtar"
2828
)
2929

30-
var baseConfig = &packages.Config{
31-
Mode: packages.NeedSyntax |
32-
packages.NeedTypesInfo |
33-
packages.NeedDeps |
34-
packages.NeedName |
35-
packages.NeedFiles |
36-
packages.NeedImports |
37-
packages.NeedCompiledGoFiles |
38-
packages.NeedTypes,
39-
}
30+
const packageConfigMode = packages.NeedSyntax |
31+
packages.NeedTypesInfo |
32+
packages.NeedDeps |
33+
packages.NeedName |
34+
packages.NeedFiles |
35+
packages.NeedImports |
36+
packages.NeedCompiledGoFiles |
37+
packages.NeedTypes
4038

4139
// TestRTASingleFile runs RTA on each testdata/*.txtar file containing a single
4240
// go file and compares the results with the expectations expressed in the WANT
@@ -52,11 +50,7 @@ func TestRTASingleFile(t *testing.T) {
5250
}
5351
for _, archive := range archivePaths {
5452
t.Run(archive, func(t *testing.T) {
55-
baseConfig.Dir = restoreArchive(t, archive)
56-
pkgs, err := packages.Load(baseConfig, "./...")
57-
if err != nil {
58-
t.Fatal(err)
59-
}
53+
pkgs := loadPackages(t, archive)
6054

6155
f := pkgs[0].Syntax[0]
6256

@@ -76,11 +70,7 @@ func TestRTASingleFile(t *testing.T) {
7670
// TestRTAOnPackages runs RTA on a go module which contains multiple packages to test the case
7771
// when an interface has implementations across different packages.
7872
func TestRTAOnPackages(t *testing.T) {
79-
baseConfig.Dir = restoreArchive(t, "testdata/multipkgs.txtar")
80-
pkgs, err := packages.Load(baseConfig, "./...")
81-
if err != nil {
82-
t.Fatal(err)
83-
}
73+
pkgs := loadPackages(t, "testdata/multipkgs.txtar")
8474

8575
var f *ast.File
8676
for _, p := range pkgs {
@@ -109,6 +99,18 @@ func TestRTAOnPackages(t *testing.T) {
10999
check(t, f, mainPkg, res)
110100
}
111101

102+
func loadPackages(t *testing.T, archive string) []*packages.Package {
103+
var baseConfig = &packages.Config{
104+
Mode: packageConfigMode,
105+
Dir: restoreArchive(t, archive),
106+
}
107+
pkgs, err := packages.Load(baseConfig, "./...")
108+
if err != nil {
109+
t.Fatal(err)
110+
}
111+
return pkgs
112+
}
113+
112114
// restoreArchive restores a go module from the archive file,
113115
// and puts all contents in a temporary folder.
114116
func restoreArchive(t *testing.T, achieveFilePath string) string {

0 commit comments

Comments
 (0)