Commit 421cefdc authored by Michael Matloob's avatar Michael Matloob

cmd/go: convert TestRunInternal to the script test framework

This conversion is a bit weird, because the original test runs in the cmd/go
directory, while the script test runs in the GOPATH directory. So even though
it's not necessary for the new test, it changes dircectory to $WORK, so that
its error message regexp can have four components like the original, just
changing the old gopath directory 'testdata' the new one 'gopath'.

Part of converting all tests to script framework to improve test parallelism.

Updates #36320
Updates #17751

Change-Id: Ie5b029c43dc22167278d3104b37c0b57c61326be
Reviewed-on: https://go-review.googlesource.com/c/go/+/212814
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarJay Conrod <jayconrod@google.com>
parent c57665f4
...@@ -1026,16 +1026,6 @@ func TestInternalPackagesOutsideGOROOTAreRespected(t *testing.T) { ...@@ -1026,16 +1026,6 @@ func TestInternalPackagesOutsideGOROOTAreRespected(t *testing.T) {
tg.grepBoth(`testinternal2(\/|\\)p\.go\:3\:8\: use of internal package .*internal/w not allowed`, "wrote error message for testdata/testinternal2") tg.grepBoth(`testinternal2(\/|\\)p\.go\:3\:8\: use of internal package .*internal/w 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(`testdata(\/|\\)src(\/|\\)run(\/|\\)bad\.go\:3\:8\: use of internal package run/subdir/internal/private not allowed`, "unexpected error for run/bad.go")
}
func TestRunPkg(t *testing.T) { func TestRunPkg(t *testing.T) {
tg := testgo(t) tg := testgo(t)
defer tg.cleanup() defer tg.cleanup()
......
env GO111MODULE=off
go list -e -f '{{.Incomplete}}' m/runbad1.go
stdout true
! go run m/runbad1.go
stderr 'use of internal package m/x/internal not allowed'
go list -e -f '{{.Incomplete}}' m/runbad2.go
stdout true
! go run m/runbad2.go
stderr 'use of internal package m/x/internal/y not allowed'
go list -e -f '{{.Incomplete}}' m/runok.go
stdout false
go run m/runok.go
cd m
env GO111MODULE=on env GO111MODULE=on
go list -e -f '{{.Incomplete}}' runbad1.go go list -e -f '{{.Incomplete}}' runbad1.go
...@@ -14,32 +31,33 @@ go list -e -f '{{.Incomplete}}' runok.go ...@@ -14,32 +31,33 @@ go list -e -f '{{.Incomplete}}' runok.go
stdout false stdout false
go run runok.go go run runok.go
-- go.mod --
-- m/go.mod --
module m module m
-- x/internal/internal.go -- -- m/x/internal/internal.go --
package internal package internal
-- x/internal/y/y.go -- -- m/x/internal/y/y.go --
package y package y
-- internal/internal.go -- -- m/internal/internal.go --
package internal package internal
-- internal/z/z.go -- -- m/internal/z/z.go --
package z package z
-- runbad1.go -- -- m/runbad1.go --
package main package main
import _ "m/x/internal" import _ "m/x/internal"
func main() {} func main() {}
-- runbad2.go -- -- m/runbad2.go --
package main package main
import _ "m/x/internal/y" import _ "m/x/internal/y"
func main() {} func main() {}
-- runok.go -- -- m/runok.go --
package main package main
import _ "m/internal" import _ "m/internal"
import _ "m/internal/z" import _ "m/internal/z"
......
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