1
0
mirror of https://github.com/golang/go synced 2024-11-18 09:34:53 -07:00

refactor/rename: fix two bugs related to MS Windows' path separator

In the package, the added import declarations used backslashes.
In the test, filenames in warning messages used backslashes.
Now both use forward slash.

Fixes golang/go#16384

Change-Id: I43116aab0b3209305f23ed9def7c4adf3259941e
Reviewed-on: https://go-review.googlesource.com/24943
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Alan Donovan 2016-07-15 10:26:15 -04:00
parent e047ae774b
commit 9c3986db53
2 changed files with 17 additions and 9 deletions

View File

@ -61,7 +61,7 @@ func Move(ctxt *build.Context, from, to, moveTmpl string) error {
} }
// Build the import graph and figure out which packages to update. // Build the import graph and figure out which packages to update.
fwd, rev, errors := importgraph.Build(ctxt) _, rev, errors := importgraph.Build(ctxt)
if len(errors) > 0 { if len(errors) > 0 {
// With a large GOPATH tree, errors are inevitable. // With a large GOPATH tree, errors are inevitable.
// Report them but proceed. // Report them but proceed.
@ -74,14 +74,17 @@ func Move(ctxt *build.Context, from, to, moveTmpl string) error {
// Determine the affected packages---the set of packages whose import // Determine the affected packages---the set of packages whose import
// statements need updating. // statements need updating.
affectedPackages := map[string]bool{from: true} affectedPackages := map[string]bool{from: true}
destinations := map[string]string{} // maps old dir to new dir destinations := make(map[string]string) // maps old import path to new import path
for pkg := range subpackages(ctxt, srcDir, from) { for pkg := range subpackages(ctxt, srcDir, from) {
for r := range rev[pkg] { for r := range rev[pkg] {
affectedPackages[r] = true affectedPackages[r] = true
} }
destinations[pkg] = strings.Replace(pkg, // Ensure directories have a trailing separator.
// Ensure directories have a trailing "/". dest := strings.Replace(pkg,
filepath.Join(from, ""), filepath.Join(to, ""), 1) filepath.Join(from, ""),
filepath.Join(to, ""),
1)
destinations[pkg] = filepath.ToSlash(dest)
} }
// Load all the affected packages. // Load all the affected packages.
@ -100,7 +103,6 @@ func Move(ctxt *build.Context, from, to, moveTmpl string) error {
m := mover{ m := mover{
ctxt: ctxt, ctxt: ctxt,
fwd: fwd,
rev: rev, rev: rev,
iprog: iprog, iprog: iprog,
from: from, from: from,
@ -169,8 +171,8 @@ type mover struct {
// with new package names or import paths. // with new package names or import paths.
iprog *loader.Program iprog *loader.Program
ctxt *build.Context ctxt *build.Context
// fwd and rev are the forward and reverse import graphs // rev is the reverse import graph.
fwd, rev importgraph.Graph rev importgraph.Graph
// from and to are the source and destination import // from and to are the source and destination import
// paths. fromDir and toDir are the source and destination // paths. fromDir and toDir are the source and destination
// absolute paths that package source files will be moved between. // absolute paths that package source files will be moved between.

View File

@ -376,7 +376,13 @@ var _ foo.T
}) })
var warnings []string var warnings []string
reportError = func(posn token.Position, message string) { reportError = func(posn token.Position, message string) {
warnings = append(warnings, posn.String()+": "+message) warning := fmt.Sprintf("%s:%d:%d: %s",
filepath.ToSlash(posn.Filename), // for MS Windows
posn.Line,
posn.Column,
message)
warnings = append(warnings, warning)
} }
writeFile = func(filename string, content []byte) error { writeFile = func(filename string, content []byte) error {
got[filename] = string(content) got[filename] = string(content)