})
}
}
+
+// Issue 22986.
+func TestImportPath(t *testing.T) {
+ tg := testgo(t)
+ defer tg.cleanup()
+ tg.parallel()
+
+ tg.tempFile("src/a/a.go", `
+package main
+
+import (
+ "log"
+ p "a/p-1.0"
+)
+
+func main() {
+ if !p.V {
+ log.Fatal("false")
+ }
+}`)
+
+ tg.tempFile("src/a/a_test.go", `
+package main_test
+
+import (
+ p "a/p-1.0"
+ "testing"
+)
+
+func TestV(t *testing.T) {
+ if !p.V {
+ t.Fatal("false")
+ }
+}`)
+
+ tg.tempFile("src/a/p-1.0/p.go", `
+package p
+
+var V = true
+
+func init() {}
+`)
+
+ tg.setenv("GOPATH", tg.path("."))
+ tg.run("build", "-o", tg.path("a.exe"), "a")
+ tg.run("test", "a")
+}
}
}
-func pkgname(lib string) string {
+func pkgname(ctxt *Link, lib string) string {
name := path.Clean(lib)
+
+ // When using importcfg, we have the final package name.
+ if ctxt.PackageFile != nil {
+ return name
+ }
+
// runtime.a -> runtime, runtime.6 -> runtime
pkg := name
if len(pkg) >= 2 && pkg[len(pkg)-2] == '.' {
if filepath.IsAbs(name) {
pname = name
} else {
- pkg := pkgname(lib)
+ pkg := pkgname(ctxt, lib)
// Add .a if needed; the new -importcfg modes
// do not put .a into the package name anymore.
// This only matters when people try to mix
}
func addlib(ctxt *Link, src string, obj string, lib string) *sym.Library {
- pkg := pkgname(lib)
+ pkg := pkgname(ctxt, lib)
// already loaded?
if l := ctxt.LibraryByPkg[pkg]; l != nil {