forked from t-yuki/gocover-cobertura
-
Notifications
You must be signed in to change notification settings - Fork 28
/
ignore_test.go
104 lines (97 loc) · 2.67 KB
/
ignore_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
97
98
99
100
101
102
103
104
package main
import (
"regexp"
"strings"
"testing"
)
func TestIgnore(t *testing.T) {
empty := Ignore{}
dirs := Ignore{Dirs: regexp.MustCompile(`/bar$`)}
files := Ignore{Files: regexp.MustCompile(`bar/gen\.go$`)}
gen := Ignore{GeneratedFiles: true}
for _, test := range []struct {
FileName string
Contents string
DirsExpected bool
FilesExpected bool
GenExpected bool
}{
{
FileName: "foo/bar/zip.go",
Contents: "blah blah...",
DirsExpected: true,
},
{
FileName: "foo/bar/zip/test.go",
Contents: "blah blah...",
DirsExpected: true,
},
{
FileName: "zip/foobar/gen.go",
Contents: "blah blah...",
FilesExpected: true,
},
{
FileName: "foobar/test.go",
Contents: `package test
// Code generated by zzz; DO NOT EDIT.`,
GenExpected: true,
},
{
FileName: "foobar/test.go",
Contents: `package test
// AUTOGENERATED FILE: zzz stub code to make the package`,
GenExpected: true,
},
{
FileName: "foobar/test.go",
Contents: `package test
// Code generated by zzz v1.0.0`,
GenExpected: true,
},
{
FileName: "foobar/test.go",
Contents: strings.Repeat("x", 256) + `
// Code generated by zzz v1.0.0`,
},
} {
c := []byte(test.Contents)
if empty.Match(test.FileName, nil) {
t.Errorf("empty should NOT match %s+NO contents", test.FileName)
}
empty.cache = nil
if empty.Match(test.FileName, c) {
t.Errorf("empty should NOT match %s+contents", test.FileName)
}
empty.cache = nil
if dirs.Match(test.FileName, nil) != test.DirsExpected {
t.Errorf("dirs.Match(%s+NO contents) == %t but should be %t",
test.FileName, !test.DirsExpected, test.DirsExpected)
}
dirs.cache = nil
if dirs.Match(test.FileName, c) != test.DirsExpected {
t.Errorf("dirs.Match(%s+contents) == %t but should be %t",
test.FileName, !test.DirsExpected, test.DirsExpected)
}
dirs.cache = nil
if files.Match(test.FileName, nil) != test.FilesExpected {
t.Errorf("files.Match(%s+NO contents) == %t but should be %t",
test.FileName, !test.FilesExpected, test.FilesExpected)
}
files.cache = nil
if files.Match(test.FileName, c) != test.FilesExpected {
t.Errorf("files.Match(%s+contents) == %t but should be %t",
test.FileName, !test.FilesExpected, test.FilesExpected)
}
files.cache = nil
if gen.Match(test.FileName, nil) {
t.Errorf("gen should NOT match %s with no contents", test.FileName)
}
// no cache reset needed here as previous call should not be cached
if gen.Match(test.FileName, c) != test.GenExpected {
t.Errorf("gen.Match(%s+contents) == %t but should be %t",
test.FileName, !test.GenExpected, test.GenExpected)
}
gen.cache = nil
}
}