forked from emartech/escher-go
/
test_file_for.go
71 lines (51 loc) · 1.07 KB
/
test_file_for.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
package cases
import (
"io/ioutil"
"path/filepath"
"regexp"
"strings"
"testing"
)
func testFilesFor(t testing.TB, dirname string, includes, ignores []string) []string {
files, err := ioutil.ReadDir(dirname)
if err != nil {
t.Fatal(err)
}
testFiles := make([]string, 0)
for _, file := range files {
if file.IsDir() {
continue
}
if !strings.HasSuffix(file.Name(), ".json") {
continue
}
if !isIncludedTestCase(file.Name(), includes, ignores) {
continue
}
if !isTestCaseAllowed(file.Name()) {
continue
}
if !file.IsDir() {
testFiles = append(testFiles, filepath.Join(dirname, file.Name()))
}
}
return testFiles
}
func isIncludedTestCase(s string, includes, ignores []string) bool {
for _, ignore := range ignores {
rgx := rgxForMatcher(ignore)
if rgx.MatchString(s) {
return false
}
}
for _, include := range includes {
rgx := rgxForMatcher(include)
if !rgx.MatchString(s) {
return false
}
}
return true
}
func rgxForMatcher(s string) *regexp.Regexp {
return regexp.MustCompile("(?i)" + regexp.QuoteMeta(s))
}