1
0
mirror of https://github.com/golang/go synced 2024-11-18 00:04:43 -07:00

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: Jay Conrod <jayconrod@google.com>
This commit is contained in:
Michael Matloob 2019-12-30 16:56:00 -05:00
parent c57665f4e6
commit 421cefdc59
6 changed files with 26 additions and 30 deletions

View File

@ -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")
}
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) {
tg := testgo(t)
defer tg.cleanup()

View File

@ -1,3 +1,20 @@
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
go list -e -f '{{.Incomplete}}' runbad1.go
@ -14,32 +31,33 @@ go list -e -f '{{.Incomplete}}' runok.go
stdout false
go run runok.go
-- go.mod --
-- m/go.mod --
module m
-- x/internal/internal.go --
-- m/x/internal/internal.go --
package internal
-- x/internal/y/y.go --
-- m/x/internal/y/y.go --
package y
-- internal/internal.go --
-- m/internal/internal.go --
package internal
-- internal/z/z.go --
-- m/internal/z/z.go --
package z
-- runbad1.go --
-- m/runbad1.go --
package main
import _ "m/x/internal"
func main() {}
-- runbad2.go --
-- m/runbad2.go --
package main
import _ "m/x/internal/y"
func main() {}
-- runok.go --
-- m/runok.go --
package main
import _ "m/internal"
import _ "m/internal/z"

View File

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

View File

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

View File

@ -1 +0,0 @@
package internal

View File

@ -1 +0,0 @@
package private