Skip to content

Commit

Permalink
cmd/go: convert TestRunInternal to the script test framework
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
matloob committed Jan 3, 2020
1 parent c57665f commit 421cefd
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 30 deletions.
10 changes: 0 additions & 10 deletions src/cmd/go/go_test.go
Expand Up @@ -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()
Expand Down
@@ -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
Expand All @@ -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"
Expand Down
5 changes: 0 additions & 5 deletions src/cmd/go/testdata/src/run/bad.go

This file was deleted.

5 changes: 0 additions & 5 deletions src/cmd/go/testdata/src/run/good.go

This file was deleted.

1 change: 0 additions & 1 deletion src/cmd/go/testdata/src/run/internal/internal.go

This file was deleted.

This file was deleted.

0 comments on commit 421cefd

Please sign in to comment.