1
0
mirror of https://github.com/golang/go synced 2024-09-25 13:30:12 -06:00

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

Fixes #12217.

Change-Id: I5ee6cb18eaa66bdec1affe689aa531c05e719fc9
Reviewed-on: https://go-review.googlesource.com/18645
Reviewed-by: Andrew Gerrand <adg@golang.org>
This commit is contained in:
Russ Cox 2016-01-13 22:35:17 -05:00
parent 8319c57890
commit f36ee8c249
6 changed files with 24 additions and 0 deletions

View File

@ -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 = ""

View File

@ -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)

5
src/cmd/go/testdata/src/run/bad.go vendored Normal file
View File

@ -0,0 +1,5 @@
package main
import _ "run/subdir/internal/private"
func main() {}

5
src/cmd/go/testdata/src/run/good.go vendored Normal file
View File

@ -0,0 +1,5 @@
package main
import _ "run/internal"
func main() {}

View File

@ -0,0 +1 @@
package internal

View File

@ -0,0 +1 @@
package private