Merge pull request #32768 from dnephin/try-enable-test-matches-on-windows

Enable TestMatches on windows
This commit is contained in:
Vincent Demeester 2017-04-23 15:54:45 +02:00 коммит произвёл GitHub
Родитель 83ee902ecc 9484c3bd81
Коммит c264aefdac
1 изменённых файлов: 22 добавлений и 19 удалений

Просмотреть файл

@ -8,6 +8,10 @@ import (
"runtime" "runtime"
"strings" "strings"
"testing" "testing"
"fmt"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
) )
// CopyFile with invalid src // CopyFile with invalid src
@ -299,17 +303,14 @@ func TestMatchesWithMalformedPatterns(t *testing.T) {
} }
} }
// Test lots of variants of patterns & strings type matchesTestCase struct {
pattern string
text string
pass bool
}
func TestMatches(t *testing.T) { func TestMatches(t *testing.T) {
// TODO Windows: Port this test tests := []matchesTestCase{
if runtime.GOOS == "windows" {
t.Skip("Needs porting to Windows")
}
tests := []struct {
pattern string
text string
pass bool
}{
{"**", "file", true}, {"**", "file", true},
{"**", "file/", true}, {"**", "file/", true},
{"**/", "file", true}, // weird one {"**/", "file", true}, // weird one
@ -361,9 +362,6 @@ func TestMatches(t *testing.T) {
{"abc.def", "abcZdef", false}, {"abc.def", "abcZdef", false},
{"abc?def", "abcZdef", true}, {"abc?def", "abcZdef", true},
{"abc?def", "abcdef", false}, {"abc?def", "abcdef", false},
{"a\\*b", "a*b", true},
{"a\\", "a", false},
{"a\\", "a\\", false},
{"a\\\\", "a\\", true}, {"a\\\\", "a\\", true},
{"**/foo/bar", "foo/bar", true}, {"**/foo/bar", "foo/bar", true},
{"**/foo/bar", "dir/foo/bar", true}, {"**/foo/bar", "dir/foo/bar", true},
@ -375,15 +373,20 @@ func TestMatches(t *testing.T) {
{"**/.foo", "bar.foo", false}, {"**/.foo", "bar.foo", false},
} }
if runtime.GOOS != "windows" {
tests = append(tests, []matchesTestCase{
{"a\\*b", "a*b", true},
{"a\\", "a", false},
{"a\\", "a\\", false},
}...)
}
for _, test := range tests { for _, test := range tests {
desc := fmt.Sprintf("pattern=%q text=%q", test.pattern, test.text)
pm, err := NewPatternMatcher([]string{test.pattern}) pm, err := NewPatternMatcher([]string{test.pattern})
if err != nil { require.NoError(t, err, desc)
t.Fatalf("invalid pattern %s", test.pattern)
}
res, _ := pm.Matches(test.text) res, _ := pm.Matches(test.text)
if res != test.pass { assert.Equal(t, test.pass, res, desc)
t.Fatalf("Failed: %v - res:%v", test, res)
}
} }
} }