From 0c1e60894f50ce4f50a7a4f0b39b39397ce25cdd Mon Sep 17 00:00:00 2001 From: Audrius Butkevicius Date: Sat, 16 Aug 2014 17:33:01 +0100 Subject: [PATCH] Fix tests on Windows --- scanner/walk.go | 3 ++- scanner/walk_test.go | 51 ++++++++++++++++++++++++++------------------ 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/scanner/walk.go b/scanner/walk.go index b5d1cb3a9..2541cbb69 100644 --- a/scanner/walk.go +++ b/scanner/walk.go @@ -13,6 +13,7 @@ import ( "path/filepath" "runtime" "strings" + "code.google.com/p/go.text/unicode/norm" "github.com/syncthing/syncthing/lamport" @@ -229,7 +230,7 @@ func (w *Walker) ignoreFile(patterns map[string][]string, file string) bool { for prefix, pats := range patterns { if prefix == "." || prefix == first || strings.HasPrefix(first, fmt.Sprintf("%s%c", prefix, os.PathSeparator)) { for _, pattern := range pats { - if match, _ := filepath.Match(pattern, last); match { + if match, _ := filepath.Match(pattern, last); match || pattern == last { return true } } diff --git a/scanner/walk_test.go b/scanner/walk_test.go index 32a54960b..77f2ef42d 100644 --- a/scanner/walk_test.go +++ b/scanner/walk_test.go @@ -6,7 +6,9 @@ package scanner import ( "fmt" + "path/filepath" "reflect" + "runtime" "sort" "testing" "time" @@ -124,38 +126,45 @@ func TestWalkError(t *testing.T) { } func TestIgnore(t *testing.T) { + pattern := "q\\[abc\\]y" + // On Windows, escaping is disabled. + // Instead, '\\' is treated as path separator. + if runtime.GOOS == "windows" { + pattern = "q[abc]y" + } + var patterns = map[string][]string{ - ".": {"t2"}, - "foo": {"bar", "z*", "q[abc]x", "q\\[abc\\]y"}, - "foo/baz": {"quux", ".*"}, + ".": {"t2"}, + "foo": {"bar", "z*", "q[abc]x", pattern}, + filepath.Join("foo", "baz"): {"quux", ".*"}, } var tests = []struct { f string r bool }{ - {"foo/bar", true}, - {"foofoo", false}, - {"foo/quux", false}, - {"foo/zuux", true}, - {"foo/qzuux", false}, - {"foo/baz/t1", false}, - {"foo/baz/t2", true}, - {"foo/baz/bar", true}, - {"foo/baz/quuxa", false}, - {"foo/baz/aquux", false}, - {"foo/baz/.quux", true}, - {"foo/baz/zquux", true}, - {"foo/baz/quux", true}, - {"foo/bazz/quux", false}, - {"foo/bazz/q[abc]x", false}, - {"foo/bazz/qax", true}, - {"foo/bazz/q[abc]y", true}, + {filepath.Join("foo", "bar"), true}, + {filepath.Join("foofoo"), false}, + {filepath.Join("foo", "quux"), false}, + {filepath.Join("foo", "zuux"), true}, + {filepath.Join("foo", "qzuux"), false}, + {filepath.Join("foo", "baz", "t1"), false}, + {filepath.Join("foo", "baz", "t2"), true}, + {filepath.Join("foo", "baz", "bar"), true}, + {filepath.Join("foo", "baz", "quuxa"), false}, + {filepath.Join("foo", "baz", "aquux"), false}, + {filepath.Join("foo", "baz", ".quux"), true}, + {filepath.Join("foo", "baz", "zquux"), true}, + {filepath.Join("foo", "baz", "quux"), true}, + {filepath.Join("foo", "bazz", "quux"), false}, + {filepath.Join("foo", "bazz", "q[abc]x"), true}, + {filepath.Join("foo", "bazz", "qax"), true}, + {filepath.Join("foo", "bazz", "q[abc]y"), true}, } w := Walker{} for i, tc := range tests { if r := w.ignoreFile(patterns, tc.f); r != tc.r { - t.Errorf("Incorrect ignoreFile() #%d; E: %v, A: %v", i, tc.r, r) + t.Errorf("Incorrect ignoreFile() #%d (%s); E: %v, A: %v", i, tc.f, tc.r, r) } } }