Avoid platform-specific NewPatternMatcher function in TestCompile

Signed-off-by: Aaron Lehmann <alehmann@netflix.com>
This commit is contained in:
Aaron Lehmann 2022-01-20 08:04:50 -08:00
parent 8d250be008
commit 38e2e756c9
1 changed files with 10 additions and 5 deletions

View File

@ -737,14 +737,19 @@ func TestCompile(t *testing.T) {
func testCompile(sl string) func(*testing.T) {
return func(t *testing.T) {
for _, tt := range compileTests {
pattern := tt.pattern
// Avoid NewPatternMatcher, which has platform-specific behavior
pm := &PatternMatcher{
patterns: make([]*Pattern, 1),
}
pattern := path.Clean(tt.pattern)
if sl != "/" {
pattern = strings.ReplaceAll(pattern, "/", sl)
}
pm, err := NewPatternMatcher([]string{pattern})
if err != nil {
t.Fatalf("Failed to create PatternMatcher for pattern %q: %v", pattern, err)
}
newp := &Pattern{}
newp.cleanedPattern = pattern
newp.dirs = strings.Split(pattern, sl)
pm.patterns[0] = newp
if err := pm.patterns[0].compile(sl); err != nil {
t.Fatalf("Failed to compile pattern %q: %v", pattern, err)
}