-
Notifications
You must be signed in to change notification settings - Fork 83
/
analyze_test.go
96 lines (92 loc) · 2.48 KB
/
analyze_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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package gocyclo_test
import (
"reflect"
"strings"
"testing"
"github.com/fzipp/gocyclo"
)
func TestAnalyze(t *testing.T) {
tests := []struct {
paths []string
want string
}{
{
[]string{"testdata/ifs.go"},
`3 testdata f3nested testdata/ifs.go:24:1
3 testdata f3 testdata/ifs.go:17:1
2 testdata f2else testdata/ifs.go:11:1
2 testdata f2 testdata/ifs.go:6:1
1 testdata f1 testdata/ifs.go:3:1`,
},
{
[]string{"testdata/loops.go"},
`4 testdata l4 testdata/loops.go:20:1
3 testdata l3 testdata/loops.go:8:1
2 testdata l2range testdata/loops.go:15:1
2 testdata l2 testdata/loops.go:3:1`,
},
{
[]string{"testdata/cases.go"},
`3 testdata c3nested testdata/cases.go:40:1
3 testdata c3default testdata/cases.go:32:1
3 testdata c3 testdata/cases.go:25:1
2 testdata c2multi testdata/cases.go:19:1
2 testdata c2default testdata/cases.go:12:1
2 testdata c2 testdata/cases.go:6:1
1 testdata c1 testdata/cases.go:3:1`,
},
{
[]string{"testdata/comms.go"},
`3 testdata comm3nested testdata/comms.go:33:1
3 testdata comm3default testdata/comms.go:25:1
3 testdata comm3 testdata/comms.go:18:1
2 testdata comm2default testdata/comms.go:11:1
2 testdata comm2 testdata/comms.go:5:1`,
},
{
[]string{"testdata/methods.go"},
`2 testdata (*S).m2ptr testdata/methods.go:16:1
2 testdata (S).m2 testdata/methods.go:8:1
1 testdata (*S).m1ptr testdata/methods.go:13:1
1 testdata (S).m1 testdata/methods.go:5:1`,
},
{
[]string{"testdata/literals.go"},
`3 testdata lit3 testdata/literals.go:13:12
2 testdata lit2 testdata/literals.go:8:12
1 testdata lit1 testdata/literals.go:5:12`,
},
{
[]string{"testdata/ignores.go"},
`1 testdata notIgnoredNotADirective testdata/ignores.go:13:1
1 testdata notIgnoredUnknownDirective testdata/ignores.go:10:1`,
},
{
[]string{"testdata/operators.go"},
`3 testdata op3mixed testdata/operators.go:11:1
2 testdata op2and testdata/operators.go:7:1
2 testdata op2or testdata/operators.go:3:1`,
},
{
[]string{"testdata/directory"},
`1 directory b testdata/directory/file2.go:3:1
1 directory a testdata/directory/file1.go:3:1`,
},
{
[]string{"testdata/ignore"},
"",
},
}
for _, tt := range tests {
stats := gocyclo.Analyze(tt.paths, nil).
SortAndFilter(-1, 0)
statLines := make([]string, len(stats))
for i, s := range stats {
statLines[i] = s.String()
}
got := strings.Join(statLines, "\n")
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("Analyzed %q and got:\n%s\n\twant:\n%s", tt.paths, got, tt.want)
}
}
}