aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Brainman <alex.brainman@gmail.com>2015-01-22 10:40:50 +1100
committerAlex Brainman <alex.brainman@gmail.com>2015-01-23 05:30:55 +0000
commit2ef5a0d23bc4e07573bb094b97e96c9cd9844fca (patch)
tree17f525bfee35f4fc100b276cfc6e79c609022649
parent96af1504f60193ba43510e8d515cc0ad6cac5c5c (diff)
downloadtools-2ef5a0d23bc4e07573bb094b97e96c9cd9844fca.tar.gz
refactor/rename: make tests pass on windows (fixes build)
- use import path not file path in go/buildutil.FakeContext OpenFile; - use regexp to compare error messages in TestErrors, because they contain windows file paths; - use OS file path (not unix path), when checking move results in TestMoves. Change-Id: Ib62d344acb551fb612d8a0773ae1ab5f18341294 Reviewed-on: https://go-review.googlesource.com/3171 Reviewed-by: Alan Donovan <adonovan@google.com>
-rw-r--r--go/buildutil/fakecontext.go4
-rw-r--r--refactor/rename/mvpkg_test.go15
2 files changed, 13 insertions, 6 deletions
diff --git a/go/buildutil/fakecontext.go b/go/buildutil/fakecontext.go
index 79c5a1b..24cbcbe 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 cdcfae2..7245ce3 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