Merge pull request #529 from syncthing/windows-build

Fix tests on Windows
This commit is contained in:
Jakob Borg 2014-08-16 21:37:00 +02:00
commit f2f051d6de
2 changed files with 32 additions and 22 deletions

View File

@ -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
}
}

View File

@ -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)
}
}
}