Skip to content

Commit

Permalink
cmd/go: convert TestSymlink* to the script framework
Browse files Browse the repository at this point in the history
Part of converting all tests to script framework to improve
test parallelism.

Updates #36320
Updates #17751

Change-Id: I0696fa54184514d69c0763ac772d99b12e133eb0
Reviewed-on: https://go-review.googlesource.com/c/go/+/214288
Reviewed-by: Jay Conrod <[email protected]>
  • Loading branch information
matloob committed Feb 19, 2020
1 parent 1bf9d3c commit 1331113
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 82 deletions.
82 changes: 0 additions & 82 deletions src/cmd/go/go_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1565,88 +1565,6 @@ func TestGoTestDashIDashOWritesBinary(t *testing.T) {
tg.wantExecutable(tg.path("myerrors.test"+exeSuffix), "go test -o myerrors.test did not create myerrors.test")
}

// Issue 4568.
func TestSymlinksList(t *testing.T) {
testenv.MustHaveSymlink(t)

tg := testgo(t)
defer tg.cleanup()
// TODO: tg.parallel()
tg.tempDir("src")
tg.must(os.Symlink(tg.path("."), tg.path("src/dir1")))
tg.tempFile("src/dir1/p.go", "package p")
tg.setenv("GOPATH", tg.path("."))
tg.cd(tg.path("src"))
tg.run("list", "-f", "{{.Root}}", "dir1")
if strings.TrimSpace(tg.getStdout()) != tg.path(".") {
t.Error("confused by symlinks")
}
}

// Issue 14054.
func TestSymlinksVendor(t *testing.T) {
testenv.MustHaveSymlink(t)

tg := testgo(t)
defer tg.cleanup()
// TODO: tg.parallel()
tg.tempDir("gopath/src/dir1/vendor/v")
tg.tempFile("gopath/src/dir1/p.go", "package main\nimport _ `v`\nfunc main(){}")
tg.tempFile("gopath/src/dir1/vendor/v/v.go", "package v")
tg.must(os.Symlink(tg.path("gopath/src/dir1"), tg.path("symdir1")))
tg.setenv("GOPATH", tg.path("gopath"))
tg.cd(tg.path("symdir1"))
tg.run("list", "-f", "{{.Root}}", ".")
if strings.TrimSpace(tg.getStdout()) != tg.path("gopath") {
t.Error("list confused by symlinks")
}

// All of these should succeed, not die in vendor-handling code.
tg.run("run", "p.go")
tg.run("build")
tg.run("install")
}

// Issue 15201.
func TestSymlinksVendor15201(t *testing.T) {
testenv.MustHaveSymlink(t)

tg := testgo(t)
defer tg.cleanup()

tg.tempDir("gopath/src/x/y/_vendor/src/x")
tg.must(os.Symlink("../../..", tg.path("gopath/src/x/y/_vendor/src/x/y")))
tg.tempFile("gopath/src/x/y/w/w.go", "package w\nimport \"x/y/z\"\n")
tg.must(os.Symlink("../_vendor/src", tg.path("gopath/src/x/y/w/vendor")))
tg.tempFile("gopath/src/x/y/z/z.go", "package z\n")

tg.setenv("GOPATH", tg.path("gopath/src/x/y/_vendor")+string(filepath.ListSeparator)+tg.path("gopath"))
tg.cd(tg.path("gopath/src"))
tg.run("list", "./...")
}

func TestSymlinksInternal(t *testing.T) {
testenv.MustHaveSymlink(t)

tg := testgo(t)
defer tg.cleanup()
tg.tempDir("gopath/src/dir1/internal/v")
tg.tempFile("gopath/src/dir1/p.go", "package main\nimport _ `dir1/internal/v`\nfunc main(){}")
tg.tempFile("gopath/src/dir1/internal/v/v.go", "package v")
tg.must(os.Symlink(tg.path("gopath/src/dir1"), tg.path("symdir1")))
tg.setenv("GOPATH", tg.path("gopath"))
tg.cd(tg.path("symdir1"))
tg.run("list", "-f", "{{.Root}}", ".")
if strings.TrimSpace(tg.getStdout()) != tg.path("gopath") {
t.Error("list confused by symlinks")
}

// All of these should succeed, not die in internal-handling code.
tg.run("run", "p.go")
tg.run("build")
tg.run("install")
}

// Issue 4515.
func TestInstallWithTags(t *testing.T) {
tooSlow(t)
Expand Down
11 changes: 11 additions & 0 deletions src/cmd/go/testdata/script/list_symlink.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[!symlink] skip

mkdir $WORK/tmp/src
symlink $WORK/tmp/src/dir1 -> $WORK/tmp
cp p.go $WORK/tmp/src/dir1/p.go
env GOPATH=$WORK/tmp
go list -f '{{.Root}}' dir1
stdout '^'$WORK/tmp'$'

-- p.go --
package p
26 changes: 26 additions & 0 deletions src/cmd/go/testdata/script/list_symlink_internal.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[!symlink] skip

mkdir $WORK/tmp/gopath/src/dir1/internal/v
cp p.go $WORK/tmp/gopath/src/dir1/p.go
cp v.go $WORK/tmp/gopath/src/dir1/internal/v/v.go
symlink $WORK/tmp/symdir1 -> $WORK/tmp/gopath/src/dir1
env GOPATH=$WORK/tmp/gopath
cd $WORK/tmp/symdir1
go list -f '{{.Root}}' .
stdout '^'$WORK/tmp/gopath'$'

# All of these should succeed, not die in internal-handling code.
go run p.go &
go build &
go install &

wait

-- p.go --
package main

import _ `dir1/internal/v`

func main() {}
-- v.go --
package v
27 changes: 27 additions & 0 deletions src/cmd/go/testdata/script/list_symlink_vendor_issue14054.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[!symlink] skip

mkdir $WORK/tmp/gopath/src/dir1/vendor/v
cp p.go $WORK/tmp/gopath/src/dir1/p.go
cp v.go $WORK/tmp/gopath/src/dir1/vendor/v/v.go
symlink $WORK/tmp/symdir1 -> $WORK/tmp/gopath/src/dir1
env GOPATH=$WORK/tmp/gopath
cd $WORK/tmp/symdir1

go list -f '{{.Root}}' .
stdout '^'$WORK/tmp/gopath'$'

# All of these should succeed, not die in vendor-handling code.
go run p.go &
go build &
go install &

wait

-- p.go --
package main

import _ `v`

func main () {}
-- v.go --
package v
20 changes: 20 additions & 0 deletions src/cmd/go/testdata/script/list_symlink_vendor_issue15201.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[!symlink] skip

mkdir $WORK/tmp/gopath/src/x/y/_vendor/src/x
symlink $WORK/tmp/gopath/src/x/y/_vendor/src/x/y -> ../../..
mkdir $WORK/tmp/gopath/src/x/y/_vendor/src/x/y/w
cp w.go $WORK/tmp/gopath/src/x/y/w/w.go
symlink $WORK/tmp/gopath/src/x/y/w/vendor -> ../_vendor/src
mkdir $WORK/tmp/gopath/src/x/y/_vendor/src/x/y/z
cp z.go $WORK/tmp/gopath/src/x/y/z/z.go

env GOPATH=$WORK/tmp/gopath/src/x/y/_vendor${:}$WORK/tmp/gopath
cd $WORK/tmp/gopath/src
go list ./...

-- w.go --
package w

import "x/y/z"
-- z.go --
package z

0 comments on commit 1331113

Please sign in to comment.