return hasSubdir(rootSym, dirSym)
}
+// hasSubdir reports if dir is within root by performing lexical analysis only.
func hasSubdir(root, dir string) (rel string, ok bool) {
const sep = string(filepath.Separator)
root = filepath.Clean(root)
if !ctxt.isAbsPath(path) {
p.Dir = ctxt.joinPath(srcDir, path)
}
+ if !ctxt.isDir(p.Dir) {
+ // package was not found
+ return p, fmt.Errorf("cannot find package %q in:\n\t%s", path, p.Dir)
+ }
// Determine canonical import path, if any.
// Exclude results where the import path would include /testdata/.
inTestdata := func(sub string) bool {
}
}
+// Want to get a "cannot find package" error when directory for package does not exist.
+func TestImportDirNotExist(t *testing.T) {
+ testenv.MustHaveGoBuild(t) // really must just have source
+ ctxt := Default
+ ctxt.GOPATH = ""
+
+ tests := []struct {
+ label string
+ path, srcDir string
+ mode ImportMode
+ }{
+ {"Import(full, 0)", "go/build/doesnotexist", "", 0},
+ {"Import(local, 0)", "./doesnotexist", filepath.Join(ctxt.GOROOT, "src/go/build"), 0},
+ {"Import(full, FindOnly)", "go/build/doesnotexist", "", FindOnly},
+ {"Import(local, FindOnly)", "./doesnotexist", filepath.Join(ctxt.GOROOT, "src/go/build"), FindOnly},
+ }
+ for _, test := range tests {
+ _, err := ctxt.Import(test.path, test.srcDir, test.mode)
+ if err == nil || !strings.HasPrefix(err.Error(), "cannot find package") {
+ t.Errorf(`%s got error: %q, want "cannot find package" error`, test.label, err)
+ }
+ }
+}
+
func TestImportVendor(t *testing.T) {
testenv.MustHaveGoBuild(t) // really must just have source
ctxt := Default