}
}
+// hasFilePathPrefix reports whether the filesystem path s begins with the
+// elements in prefix.
+func hasFilePathPrefix(s, prefix string) bool {
+ sv := strings.ToUpper(filepath.VolumeName(s))
+ pv := strings.ToUpper(filepath.VolumeName(prefix))
+ s = s[len(sv):]
+ prefix = prefix[len(pv):]
+ switch {
+ default:
+ return false
+ case sv != pv:
+ return false
+ case len(s) == len(prefix):
+ return s == prefix
+ case len(s) > len(prefix):
+ if prefix != "" && prefix[len(prefix)-1] == filepath.Separator {
+ return strings.HasPrefix(s, prefix)
+ }
+ return s[len(prefix)] == filepath.Separator && s[:len(prefix)] == prefix
+ }
+}
+
// treeCanMatchPattern(pattern)(name) reports whether
// name or children of name can possibly match pattern.
// Pattern is the same limited glob accepted by matchPattern.
}
dir := filepath.Clean(parent.Dir)
root := filepath.Clean(parent.Root)
- if !strings.HasPrefix(dir, root) || len(dir) <= len(root) || dir[len(root)] != filepath.Separator {
+ if !hasFilePathPrefix(dir, root) || len(dir) <= len(root) || dir[len(root)] != filepath.Separator {
fatalf("invalid vendoredImportPath: dir=%q root=%q separator=%q", dir, root, string(filepath.Separator))
}
vpath := "vendor/" + path
tg.grepStdout("hello, world", "missing hello world output")
}
+func TestVendorGOPATH(t *testing.T) {
+ tg := testgo(t)
+ defer tg.cleanup()
+ changeVolume := func(s string, f func(s string) string) string {
+ vol := filepath.VolumeName(s)
+ return f(vol) + s[len(vol):]
+ }
+ gopath := changeVolume(filepath.Join(tg.pwd(), "testdata"), strings.ToLower)
+ tg.setenv("GOPATH", gopath)
+ tg.setenv("GO15VENDOREXPERIMENT", "1")
+ cd := changeVolume(filepath.Join(tg.pwd(), "testdata/src/vend/hello"), strings.ToUpper)
+ tg.cd(cd)
+ tg.run("run", "hello.go")
+ tg.grepStdout("hello, world", "missing hello world output")
+}
+
func TestVendorTest(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()