mirror of
https://github.com/golang/go
synced 2024-11-18 11:24:41 -07:00
refactor/mvpkg: rewrite external test packages.
Rename the package name of the external test package, e.g. <from>_test to <to>_test. Rewrite the import statements of external test packages which import the renamed package. Fixes #10507 Change-Id: Iad702189469c54776e55ed4a821610bd9977618c Reviewed-on: https://go-review.googlesource.com/12637 Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
parent
14b8253455
commit
20d85c34f3
@ -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.
|
||||
|
@ -203,6 +203,38 @@ var _ a.T
|
||||
import "bar/a"
|
||||
|
||||
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
|
||||
`,
|
||||
},
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user