aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid R. Jenni <david.r.jenni@gmail.com>2015-09-01 22:25:58 +0000
committerandroid-build-merger <android-build-merger@google.com>2015-09-01 22:25:58 +0000
commit085fe311e15481941f448bee94526b55eed37ba6 (patch)
tree46e93dc9fe5bc0edcd9c36f161df9846bdc97311
parent9a7909a4eb9953cae48931e1071f3e60597cc4a1 (diff)
parent20d85c34f38c8b82369f050814228f2af29b5dc0 (diff)
downloadtools-085fe311e15481941f448bee94526b55eed37ba6.tar.gz
refactor/mvpkg: rewrite external test packages.
automerge: 20d85c3 * commit '20d85c34f38c8b82369f050814228f2af29b5dc0': refactor/mvpkg: rewrite external test packages.
-rw-r--r--refactor/rename/mvpkg.go24
-rw-r--r--refactor/rename/mvpkg_test.go32
2 files changed, 56 insertions, 0 deletions
diff --git a/refactor/rename/mvpkg.go b/refactor/rename/mvpkg.go
index bcdbf8b..bb0d9b0 100644
--- a/refactor/rename/mvpkg.go
+++ b/refactor/rename/mvpkg.go
@@ -241,6 +241,30 @@ func (m *mover) move() error {
f.Name.Name = newName // change package decl
filesToUpdate[f] = true
}
+
+ // Look through the external test packages (m.iprog.Created contains the external test packages).
+ for _, info := range m.iprog.Created {
+ // Change the "package" declaration of the external test package.
+ if info.Pkg.Path() == m.from+"_test" {
+ for _, f := range info.Files {
+ f.Name.Name = newName + "_test" // change package decl
+ filesToUpdate[f] = true
+ }
+ }
+
+ // Mark all the loaded external test packages, which import the "from" package,
+ // as affected packages and update the imports.
+ for _, imp := range info.Pkg.Imports() {
+ if imp.Path() == m.from {
+ m.affectedPackages[info.Pkg.Path()] = true
+ m.iprog.Imported[info.Pkg.Path()] = info
+ if err := importName(m.iprog, info, m.from, path.Base(m.from), newName); err != nil {
+ return err
+ }
+ }
+ }
+ }
+
// Update imports of that package to use the new import name.
// None of the subpackages will change their name---only the from package
// itself will.
diff --git a/refactor/rename/mvpkg_test.go b/refactor/rename/mvpkg_test.go
index 3c915b4..61fa354 100644
--- a/refactor/rename/mvpkg_test.go
+++ b/refactor/rename/mvpkg_test.go
@@ -206,6 +206,38 @@ var _ a.T
`,
},
},
+
+ // External test packages
+ {
+ ctxt: buildutil.FakeContext(map[string]map[string]string{
+ "foo": {
+ "0.go": `package foo; type T int`,
+ "0_test.go": `package foo_test; import "foo"; var _ foo.T`,
+ },
+ "baz": {
+ "0_test.go": `package baz_test; import "foo"; var _ foo.T`,
+ },
+ }),
+ from: "foo", to: "bar",
+ want: map[string]string{
+ "/go/src/bar/0.go": `package bar
+
+type T int
+`,
+ "/go/src/bar/0_test.go": `package bar_test
+
+import "bar"
+
+var _ bar.T
+`,
+ "/go/src/baz/0_test.go": `package baz_test
+
+import "bar"
+
+var _ bar.T
+`,
+ },
+ },
}
for _, test := range tests {