diff --git a/go/buildutil/fakecontext.go b/go/buildutil/fakecontext.go index 79c5a1bf..24cbcbea 100644 --- a/go/buildutil/fakecontext.go +++ b/go/buildutil/fakecontext.go @@ -67,8 +67,8 @@ func FakeContext(pkgs map[string]map[string]string) *build.Context { } ctxt.OpenFile = func(filename string) (io.ReadCloser, error) { filename = clean(filename) - dir, base := filepath.Split(filename) - content, ok := pkgs[filepath.Clean(dir)][base] + dir, base := path.Split(filename) + content, ok := pkgs[path.Clean(dir)][base] if !ok { return nil, fmt.Errorf("file not found: %s", filename) } diff --git a/refactor/rename/mvpkg_test.go b/refactor/rename/mvpkg_test.go index cdcfae25..7245ce37 100644 --- a/refactor/rename/mvpkg_test.go +++ b/refactor/rename/mvpkg_test.go @@ -13,6 +13,7 @@ import ( "go/token" "io/ioutil" "path/filepath" + "regexp" "strings" "sync" "testing" @@ -39,7 +40,7 @@ var _ foo.T `}, }), from: "foo", to: "bar", - want: "invalid move destination: bar conflicts with directory /go/src/bar", + want: `invalid move destination: bar conflicts with directory .go.src.bar`, }, // Subpackage already exists. { @@ -104,7 +105,12 @@ var _ foo.T t.Errorf("%s: nil error. Expected error: %s", prefix, test.want) continue } - if test.want != err.Error() { + matched, err2 := regexp.MatchString(test.want, err.Error()) + if err2 != nil { + t.Errorf("regexp.MatchString failed %s", err2) + continue + } + if !matched { t.Errorf("%s: conflict does not match expectation:\n"+ "Error: %q\n"+ "Pattern: %q", @@ -235,8 +241,9 @@ type T int } for file, wantContent := range test.want { - gotContent, ok := got[file] - delete(got, file) + k := filepath.FromSlash(file) + gotContent, ok := got[k] + delete(got, k) if !ok { // TODO(matloob): some testcases might have files that won't be // rewritten