-
Notifications
You must be signed in to change notification settings - Fork 0
/
nomainreturn_test.go
53 lines (45 loc) · 1.1 KB
/
nomainreturn_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
package nomainreturn
import (
"os"
"path/filepath"
"testing"
"golang.org/x/tools/go/analysis/analysistest"
)
func TestWithDefaultConfig(t *testing.T) {
wd, err := os.Getwd()
if err != nil {
t.Fatalf("Failed to get wd: %s", err)
}
analysistest.Run(t,
filepath.Join(filepath.Dir(wd), "nomainreturn/testdata"),
NewAnalyzer(DefaultConfig),
"default")
}
func TestWithCustomConfig(t *testing.T) {
wd, err := os.Getwd()
if err != nil {
t.Fatalf("Failed to get wd: %s", err)
}
analysistest.Run(t,
filepath.Join(filepath.Dir(wd), "nomainreturn/testdata"),
NewAnalyzer(Config{
AllowPackages: []string{"custom"},
}),
"custom")
}
func Test_isPkgAllowed_PkgIsAllowed(t *testing.T) {
pkg := "foo"
allowedPkgs := []string{"main", "bar", "foo"}
allowed := isPkgAllowed(pkg, allowedPkgs)
if !allowed {
t.Errorf("isPkgAllowed() = %t; want = %t", allowed, true)
}
}
func Test_isPkgAllowed_PkgIsNotAllowed(t *testing.T) {
pkg := "bar"
allowedPkgs := []string{"main", "server"}
allowed := isPkgAllowed(pkg, allowedPkgs)
if allowed {
t.Errorf("isPkgAllowed() = %t; want = %t", allowed, false)
}
}