From 9c3986db53d305e3872da341e84daa265dc74a64 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Fri, 15 Jul 2016 10:26:15 -0400 Subject: [PATCH] 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 Reviewed-by: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- refactor/rename/mvpkg.go | 18 ++++++++++-------- refactor/rename/mvpkg_test.go | 8 +++++++- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/refactor/rename/mvpkg.go b/refactor/rename/mvpkg.go index 927195c11c..cd416c56f9 100644 --- a/refactor/rename/mvpkg.go +++ b/refactor/rename/mvpkg.go @@ -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. - fwd, rev, errors := importgraph.Build(ctxt) + _, rev, errors := importgraph.Build(ctxt) if len(errors) > 0 { // With a large GOPATH tree, errors are inevitable. // 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 // statements need updating. 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 r := range rev[pkg] { affectedPackages[r] = true } - destinations[pkg] = strings.Replace(pkg, - // Ensure directories have a trailing "/". - filepath.Join(from, ""), filepath.Join(to, ""), 1) + // Ensure directories have a trailing separator. + dest := strings.Replace(pkg, + filepath.Join(from, ""), + filepath.Join(to, ""), + 1) + destinations[pkg] = filepath.ToSlash(dest) } // Load all the affected packages. @@ -100,7 +103,6 @@ func Move(ctxt *build.Context, from, to, moveTmpl string) error { m := mover{ ctxt: ctxt, - fwd: fwd, rev: rev, iprog: iprog, from: from, @@ -169,8 +171,8 @@ type mover struct { // with new package names or import paths. iprog *loader.Program ctxt *build.Context - // fwd and rev are the forward and reverse import graphs - fwd, rev importgraph.Graph + // rev is the reverse import graph. + rev importgraph.Graph // from and to are the source and destination import // paths. fromDir and toDir are the source and destination // absolute paths that package source files will be moved between. diff --git a/refactor/rename/mvpkg_test.go b/refactor/rename/mvpkg_test.go index 1800f6b1de..674fe6cc97 100644 --- a/refactor/rename/mvpkg_test.go +++ b/refactor/rename/mvpkg_test.go @@ -376,7 +376,13 @@ var _ foo.T }) var warnings []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 { got[filename] = string(content)