Fix tests on Windows

This commit is contained in:
Audrius Butkevicius 2014-08-16 17:33:01 +01:00
parent ace87ad7bb
commit 0c1e60894f
2 changed files with 32 additions and 22 deletions

View File

@ -13,6 +13,7 @@ import (
"path/filepath" "path/filepath"
"runtime" "runtime"
"strings" "strings"
"code.google.com/p/go.text/unicode/norm" "code.google.com/p/go.text/unicode/norm"
"github.com/syncthing/syncthing/lamport" "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 { for prefix, pats := range patterns {
if prefix == "." || prefix == first || strings.HasPrefix(first, fmt.Sprintf("%s%c", prefix, os.PathSeparator)) { if prefix == "." || prefix == first || strings.HasPrefix(first, fmt.Sprintf("%s%c", prefix, os.PathSeparator)) {
for _, pattern := range pats { for _, pattern := range pats {
if match, _ := filepath.Match(pattern, last); match { if match, _ := filepath.Match(pattern, last); match || pattern == last {
return true return true
} }
} }

View File

@ -6,7 +6,9 @@ package scanner
import ( import (
"fmt" "fmt"
"path/filepath"
"reflect" "reflect"
"runtime"
"sort" "sort"
"testing" "testing"
"time" "time"
@ -124,38 +126,45 @@ func TestWalkError(t *testing.T) {
} }
func TestIgnore(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{ var patterns = map[string][]string{
".": {"t2"}, ".": {"t2"},
"foo": {"bar", "z*", "q[abc]x", "q\\[abc\\]y"}, "foo": {"bar", "z*", "q[abc]x", pattern},
"foo/baz": {"quux", ".*"}, filepath.Join("foo", "baz"): {"quux", ".*"},
} }
var tests = []struct { var tests = []struct {
f string f string
r bool r bool
}{ }{
{"foo/bar", true}, {filepath.Join("foo", "bar"), true},
{"foofoo", false}, {filepath.Join("foofoo"), false},
{"foo/quux", false}, {filepath.Join("foo", "quux"), false},
{"foo/zuux", true}, {filepath.Join("foo", "zuux"), true},
{"foo/qzuux", false}, {filepath.Join("foo", "qzuux"), false},
{"foo/baz/t1", false}, {filepath.Join("foo", "baz", "t1"), false},
{"foo/baz/t2", true}, {filepath.Join("foo", "baz", "t2"), true},
{"foo/baz/bar", true}, {filepath.Join("foo", "baz", "bar"), true},
{"foo/baz/quuxa", false}, {filepath.Join("foo", "baz", "quuxa"), false},
{"foo/baz/aquux", false}, {filepath.Join("foo", "baz", "aquux"), false},
{"foo/baz/.quux", true}, {filepath.Join("foo", "baz", ".quux"), true},
{"foo/baz/zquux", true}, {filepath.Join("foo", "baz", "zquux"), true},
{"foo/baz/quux", true}, {filepath.Join("foo", "baz", "quux"), true},
{"foo/bazz/quux", false}, {filepath.Join("foo", "bazz", "quux"), false},
{"foo/bazz/q[abc]x", false}, {filepath.Join("foo", "bazz", "q[abc]x"), true},
{"foo/bazz/qax", true}, {filepath.Join("foo", "bazz", "qax"), true},
{"foo/bazz/q[abc]y", true}, {filepath.Join("foo", "bazz", "q[abc]y"), true},
} }
w := Walker{} w := Walker{}
for i, tc := range tests { for i, tc := range tests {
if r := w.ignoreFile(patterns, tc.f); r != tc.r { 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)
} }
} }
} }