-
Notifications
You must be signed in to change notification settings - Fork 0
/
shush_test.go
59 lines (51 loc) · 1.33 KB
/
shush_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package shush
import (
"path/filepath"
"testing"
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/analysis/analysistest"
"golang.org/x/tools/go/packages"
)
func TestShush(t *testing.T) {
t.Run("test-data", func(t *testing.T) {
path := analysistest.TestData()
analysistest.Run(t, path, Analyzer, "a")
})
t.Run("self", func(t *testing.T) {
dir, err := filepath.Abs(".")
if err != nil {
t.Fatal(err)
}
analysistest.Run(t, dir, Analyzer, "shush")
})
}
func TestRequiredAnalyzer(t *testing.T) {
mode := packages.NeedName | packages.NeedFiles | packages.NeedCompiledGoFiles | packages.NeedImports |
packages.NeedTypes | packages.NeedTypesSizes | packages.NeedSyntax | packages.NeedTypesInfo |
packages.NeedDeps
cfg := &packages.Config{
Mode: mode,
Dir: analysistest.TestData(),
}
pkgs, err := packages.Load(cfg, "a")
if err != nil {
t.Fatal(err)
}
for _, pkg := range pkgs {
pass := &analysis.Pass{
Analyzer: Analyzer,
Fset: pkg.Fset,
Files: pkg.Syntax,
OtherFiles: pkg.OtherFiles,
IgnoredFiles: pkg.IgnoredFiles,
Pkg: pkg.Types,
TypesInfo: pkg.TypesInfo,
TypesSizes: pkg.TypesSizes,
TypeErrors: pkg.TypeErrors,
Report: func(d analysis.Diagnostic) {},
}
if _, err := run(pass); err == nil {
t.Fatal("expected run to fail")
}
}
}