Skip to content

Commit

Permalink
cmd/go: convert TestGoBuildGOPATHOrder to the script framework
Browse files Browse the repository at this point in the history
It looks like TestGoBuildGOPATHOrderBroken has been fixed so I've converted
that too, without the skip.

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

Updates #36320
Updates #17751

Change-Id: I7ee77f22fb888811c175bcdc5eb814c80fbec420
Reviewed-on: https://go-review.googlesource.com/c/go/+/214432
Reviewed-by: Jay Conrod <[email protected]>
  • Loading branch information
matloob committed Feb 27, 2020
1 parent 4d6c171 commit 2cfc5e2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 53 deletions.
53 changes: 0 additions & 53 deletions src/cmd/go/go_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1945,59 +1945,6 @@ func TestGoInstallPkgdir(t *testing.T) {
tg.mustExist(filepath.Join(pkg, "sync/atomic.a"))
}

func TestGoBuildGOPATHOrder(t *testing.T) {
// golang.org/issue/14176#issuecomment-179895769
// golang.org/issue/14192
// -I arguments to compiler could end up not in GOPATH order,
// leading to unexpected import resolution in the compiler.
// This is still not a complete fix (see golang.org/issue/14271 and next test)
// but it is clearly OK and enough to fix both of the two reported
// instances of the underlying problem. It will have to do for now.

tg := testgo(t)
defer tg.cleanup()
tg.makeTempdir()
tg.setenv("GOPATH", tg.path("p1")+string(filepath.ListSeparator)+tg.path("p2"))

tg.tempFile("p1/src/foo/foo.go", "package foo\n")
tg.tempFile("p2/src/baz/baz.go", "package baz\n")
tg.tempFile("p2/pkg/"+runtime.GOOS+"_"+runtime.GOARCH+"/foo.a", "bad\n")
tg.tempFile("p1/src/bar/bar.go", `
package bar
import _ "baz"
import _ "foo"
`)

tg.run("install", "-x", "bar")
}

func TestGoBuildGOPATHOrderBroken(t *testing.T) {
// This test is known not to work.
// See golang.org/issue/14271.
t.Skip("golang.org/issue/14271")

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

tg.tempFile("p1/src/foo/foo.go", "package foo\n")
tg.tempFile("p2/src/baz/baz.go", "package baz\n")
tg.tempFile("p1/pkg/"+runtime.GOOS+"_"+runtime.GOARCH+"/baz.a", "bad\n")
tg.tempFile("p2/pkg/"+runtime.GOOS+"_"+runtime.GOARCH+"/foo.a", "bad\n")
tg.tempFile("p1/src/bar/bar.go", `
package bar
import _ "baz"
import _ "foo"
`)

colon := string(filepath.ListSeparator)
tg.setenv("GOPATH", tg.path("p1")+colon+tg.path("p2"))
tg.run("install", "-x", "bar")

tg.setenv("GOPATH", tg.path("p2")+colon+tg.path("p1"))
tg.run("install", "-x", "bar")
}

// For issue 14337.
func TestParallelTest(t *testing.T) {
tooSlow(t)
Expand Down
35 changes: 35 additions & 0 deletions src/cmd/go/testdata/script/build_gopath_order.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# golang.org/issue/14176#issuecomment-179895769
# golang.org/issue/14192
# -I arguments to compiler could end up not in GOPATH order,
# leading to unexpected import resolution in the compiler.

env GOPATH=$WORK/p1${:}$WORK/p2
mkdir $WORK/p1/src/foo $WORK/p2/src/baz
mkdir $WORK/p2/pkg/${GOOS}_${GOARCH} $WORK/p1/src/bar
cp foo.go $WORK/p1/src/foo/foo.go
cp baz.go $WORK/p2/src/baz/baz.go
cp foo.a $WORK/p2/pkg/${GOOS}_${GOARCH}/foo.a
cp bar.go $WORK/p1/src/bar/bar.go

go install -x bar

# add in baz.a to the mix
mkdir $WORK/p1/pkg/${GOOS}_${GOARCH}
cp baz.a $WORK/p1/pkg/${GOOS}_${GOARCH}/baz.a
env GOPATH=$WORK/p1${:}$WORK/p2
go install -x bar
env GOPATH=$WORK/p2${:}$WORK/p1
go install -x bar

-- foo.go --
package foo
-- baz.go --
package baz
-- foo.a --
bad
-- baz.a --
bad
-- bar.go --
package bar
import _ "baz"
import _ "foo"

0 comments on commit 2cfc5e2

Please sign in to comment.