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>
This commit is contained in:
parent
96af1504f6
commit
2ef5a0d23b
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue