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:
parent
8319c57890
commit
f36ee8c249
@ -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)
|
||||
|
||||
|
5
src/cmd/go/testdata/src/run/bad.go
vendored
Normal file
5
src/cmd/go/testdata/src/run/bad.go
vendored
Normal 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
5
src/cmd/go/testdata/src/run/good.go
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
package main
|
||||
|
||||
import _ "run/internal"
|
||||
|
||||
func main() {}
|
1
src/cmd/go/testdata/src/run/internal/internal.go
vendored
Normal file
1
src/cmd/go/testdata/src/run/internal/internal.go
vendored
Normal file
@ -0,0 +1 @@
|
||||
package internal
|
1
src/cmd/go/testdata/src/run/subdir/internal/private/private.go
vendored
Normal file
1
src/cmd/go/testdata/src/run/subdir/internal/private/private.go
vendored
Normal file
@ -0,0 +1 @@
|
||||
package private
|
Loading…
Reference in New Issue
Block a user