Commit 239ec73e authored by Chris Broadfoot's avatar Chris Broadfoot

cmd/go: reject relative paths that don't start with a dot (.)

Change-Id: Idc4a7fdb561ba5b3b52094d895deaf3fcdf475bf
Reviewed-on: https://go-review.googlesource.com/10716Reviewed-by: 's avatarAndrew Gerrand <adg@golang.org>
parent 0beb931c
...@@ -1036,11 +1036,12 @@ func TestInstalls(t *testing.T) { ...@@ -1036,11 +1036,12 @@ func TestInstalls(t *testing.T) {
tg.wantExecutable(tg.path("bin/progname")+exeSuffix, "did not install progname to $GOPATH/bin/progname") tg.wantExecutable(tg.path("bin/progname")+exeSuffix, "did not install progname to $GOPATH/bin/progname")
} }
func TestRejectRelativePathsInGOPATHCommandLinePackage(t *testing.T) { func TestRejectRelativeDotPathInGOPATHCommandLinePackage(t *testing.T) {
tg := testgo(t) tg := testgo(t)
defer tg.cleanup() defer tg.cleanup()
tg.setenv("GOPATH", ".") tg.setenv("GOPATH", ".")
tg.runFail("build", "testdata/src/go-cmd-test/helloworld.go") tg.runFail("build", "testdata/src/go-cmd-test/helloworld.go")
tg.grepStderr("GOPATH entry is relative", "expected an error message rejecting relative GOPATH entries")
} }
func TestRejectRelativePathsInGOPATH(t *testing.T) { func TestRejectRelativePathsInGOPATH(t *testing.T) {
...@@ -1049,6 +1050,15 @@ func TestRejectRelativePathsInGOPATH(t *testing.T) { ...@@ -1049,6 +1050,15 @@ func TestRejectRelativePathsInGOPATH(t *testing.T) {
sep := string(filepath.ListSeparator) sep := string(filepath.ListSeparator)
tg.setenv("GOPATH", sep+filepath.Join(tg.pwd(), "testdata")+sep+".") tg.setenv("GOPATH", sep+filepath.Join(tg.pwd(), "testdata")+sep+".")
tg.runFail("build", "go-cmd-test") tg.runFail("build", "go-cmd-test")
tg.grepStderr("GOPATH entry is relative", "expected an error message rejecting relative GOPATH entries")
}
func TestRejectRelativePathsInGOPATHCommandLinePackage(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.setenv("GOPATH", "testdata")
tg.runFail("build", "testdata/src/go-cmd-test/helloworld.go")
tg.grepStderr("GOPATH entry is relative", "expected an error message rejecting relative GOPATH entries")
} }
// Issue 4104. // Issue 4104.
......
...@@ -142,7 +142,7 @@ func main() { ...@@ -142,7 +142,7 @@ func main() {
fmt.Fprintf(os.Stderr, "go: GOPATH entry cannot start with shell metacharacter '~': %q\n", p) fmt.Fprintf(os.Stderr, "go: GOPATH entry cannot start with shell metacharacter '~': %q\n", p)
os.Exit(2) os.Exit(2)
} }
if build.IsLocalImport(p) { if !filepath.IsAbs(p) {
fmt.Fprintf(os.Stderr, "go: GOPATH entry is relative; must be absolute path: %q.\nRun 'go help gopath' for usage.\n", p) fmt.Fprintf(os.Stderr, "go: GOPATH entry is relative; must be absolute path: %q.\nRun 'go help gopath' for usage.\n", p)
os.Exit(2) os.Exit(2)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment