Commit f36ee8c2 authored by Russ Cox's avatar Russ Cox

cmd/go: respect internal directories during 'go run'

Fixes #12217.

Change-Id: I5ee6cb18eaa66bdec1affe689aa531c05e719fc9
Reviewed-on: https://go-review.googlesource.com/18645Reviewed-by: default avatarAndrew Gerrand <adg@golang.org>
parent 8319c578
......@@ -822,7 +822,9 @@ func goFilesPackage(gofiles []string) *Package {
pkg := new(Package)
pkg.local = true
pkg.cmdline = true
stk.push("main")
pkg.load(&stk, bp, err)
stk.pop()
pkg.localPrefix = dirToImportPath(dir)
pkg.ImportPath = "command-line-arguments"
pkg.target = ""
......
......@@ -961,6 +961,16 @@ func TestInternalPackagesOutsideGOROOTAreRespected(t *testing.T) {
tg.grepBoth("use of internal package not allowed", "wrote error message for testdata/testinternal2")
}
func TestRunInternal(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
dir := filepath.Join(tg.pwd(), "testdata")
tg.setenv("GOPATH", dir)
tg.run("run", filepath.Join(dir, "src/run/good.go"))
tg.runFail("run", filepath.Join(dir, "src/run/bad.go"))
tg.grepStderr("use of internal package not allowed", "unexpected error for run/bad.go")
}
func testMove(t *testing.T, vcs, url, base, config string) {
testenv.MustHaveExternalNetwork(t)
......
package main
import _ "run/subdir/internal/private"
func main() {}
package main
import _ "run/internal"
func main() {}
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