if i > 0 {
i-- // rewind over slash in ".../vendor"
}
- parent := p.Dir[:i+len(p.Dir)-len(p.ImportPath)]
+ truncateTo := i + len(p.Dir) - len(p.ImportPath)
+ if truncateTo < 0 || len(p.Dir) < truncateTo {
+ return p
+ }
+ parent := p.Dir[:truncateTo]
if hasPathPrefix(filepath.ToSlash(srcDir), filepath.ToSlash(parent)) {
return p
}
vend/vendor/q []
vend/vendor/strings []
vend/x [vend/x/vendor/p vend/vendor/q vend/x/vendor/r]
+ vend/x/invalid [vend/x/invalid/vendor/foo]
vend/x/vendor/p []
vend/x/vendor/p/p [notfound]
vend/x/vendor/r []
tg.grepStdout("TestMsgExternal", "missing use in external test")
}
+func TestVendorInvalid(t *testing.T) {
+ tg := testgo(t)
+ defer tg.cleanup()
+ tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
+ tg.setenv("GO15VENDOREXPERIMENT", "1")
+
+ tg.runFail("build", "vend/x/invalid")
+ tg.grepStderr("must be imported as foo", "missing vendor import error")
+}
+
func TestVendorImportError(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()