From 9ed3fb84bc6148590757995c651bd4a6e85b4531 Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Tue, 17 Mar 2020 17:50:25 -0400 Subject: [release-branch.go1.13] cmd/go: fix and skip known Windows test failures These non-short Windows test failures were resolved fully in CL 206144. Both TestScript/build_trimpath and TestScript/version tests can be fixed by backporting the changes to test scripts only, so that is done here. Fixing TestScript/mod_list_dir requires backporting non-test changes in addition to the test script changes, which is unlikely to be appropriate this late in Go 1.13 release cycle. A failing test can cover up other regressions, so skip this known failing test to fix the builder. For #36181. Change-Id: I4f140bd373554eb4664f04638666dee77986ec3e Reviewed-on: https://go-review.googlesource.com/c/go/+/223782 Run-TryBot: Dmitri Shuralyov TryBot-Result: Gobot Gobot Reviewed-by: Jay Conrod --- src/cmd/go/testdata/script/build_trimpath.txt | 103 +++++++++++++++++++------- src/cmd/go/testdata/script/mod_list_dir.txt | 1 + src/cmd/go/testdata/script/version.txt | 5 ++ 3 files changed, 82 insertions(+), 27 deletions(-) diff --git a/src/cmd/go/testdata/script/build_trimpath.txt b/src/cmd/go/testdata/script/build_trimpath.txt index 668f75599e..ba414372d3 100644 --- a/src/cmd/go/testdata/script/build_trimpath.txt +++ b/src/cmd/go/testdata/script/build_trimpath.txt @@ -1,44 +1,93 @@ [short] skip - -env -r GOROOT_REGEXP=$GOROOT -env -r WORK_REGEXP='$WORK' # don't expand $WORK; grep replaces $WORK in text before matching. -env GOROOT GOROOT_REGEXP WORK WORK_REGEXP +env GO111MODULE=on # A binary built without -trimpath should contain the current workspace # and GOROOT for debugging and stack traces. cd a -go build -o hello.exe hello.go -grep -q $WORK_REGEXP hello.exe -grep -q $GOROOT_REGEXP hello.exe +go build -o $WORK/paths-a.exe paths.go +exec $WORK/paths-a.exe $WORK/paths-a.exe +stdout 'binary contains GOPATH: true' +stdout 'binary contains GOROOT: true' # A binary built with -trimpath should not contain the current workspace # or GOROOT. -go build -trimpath -o hello.exe hello.go -! grep -q $GOROOT_REGEXP hello.exe -! grep -q $WORK_REGEXP hello.exe -cd .. +go build -trimpath -o $WORK/paths-a.exe paths.go +exec $WORK/paths-a.exe $WORK/paths-a.exe +stdout 'binary contains GOPATH: false' +stdout 'binary contains GOROOT: false' # A binary from an external module built with -trimpath should not contain # the current workspace or GOROOT. -env GO111MODULE=on -go build -trimpath -o fortune.exe rsc.io/fortune -! grep -q $GOROOT_REGEXP fortune.exe -! grep -q $WORK_REGEXP fortune.exe +cd $WORK +go get -trimpath rsc.io/fortune +exec $WORK/paths-a.exe $GOPATH/bin/fortune$GOEXE +stdout 'binary contains GOPATH: false' +stdout 'binary contains GOROOT: false' # Two binaries built from identical packages in different directories # should be identical. -mkdir b -cp a/go.mod a/hello.go b -cd a -go build -trimpath -o ../a.exe . -cd ../b -go build -trimpath -o ../b.exe . -cd .. -cmp -q a.exe b.exe +# TODO(golang.org/issue/35435): at the moment, they are not. +#mkdir $GOPATH/src/b +#cp $GOPATH/src/a/go.mod $GOPATH/src/b/go.mod +#cp $GOPATH/src/a/paths.go $GOPATH/src/b/paths.go +#cd $GOPATH/src/b +#go build -trimpath -o $WORK/paths-b.exe . +#cmp -q $WORK/paths-a.exe $WORK/paths-b.exe + +[!exec:gccgo] stop + +# A binary built with gccgo without -trimpath should contain the current +# GOPATH and GOROOT. +env GO111MODULE=off # The current released gccgo does not support builds in module mode. +cd $GOPATH/src/a +go build -compiler=gccgo -o $WORK/gccgo-paths-a.exe . +exec $WORK/gccgo-paths-a.exe $WORK/gccgo-paths-b.exe +stdout 'binary contains GOPATH: true' +stdout 'binary contains GOROOT: true' + +# A binary built with gccgo with -trimpath should not contain GOPATH or GOROOT. +go build -compiler=gccgo -trimpath -o $WORK/gccgo-paths-a.exe . +exec $WORK/gccgo-paths-a.exe $WORK/gccgo-paths-b.exe +stdout 'binary contains GOPATH: false' +stdout 'binary contains GOROOT: false' --- a/hello.go -- +# Two binaries built from identical packages in different directories +# should be identical. +# TODO(golang.org/issue/35435): at the moment, they are not. +#cd ../b +#go build -compiler=gccgo -trimpath -o $WORK/gccgo-paths-b.exe . +#cmp -q $WORK/gccgo-paths-a.exe $WORK/gccgo-paths-b.exe + +-- $GOPATH/src/a/paths.go -- package main -func main() { println("hello") } --- a/go.mod -- -module m +import ( + "bytes" + "fmt" + "io/ioutil" + "log" + "os" + "path/filepath" +) + +func main() { + exe := os.Args[1] + data, err := ioutil.ReadFile(exe) + if err != nil { + log.Fatal(err) + } + + gopath := []byte(filepath.ToSlash(os.Getenv("GOPATH"))) + if len(gopath) == 0 { + log.Fatal("GOPATH not set") + } + fmt.Printf("binary contains GOPATH: %v\n", bytes.Contains(data, gopath)) + + goroot := []byte(filepath.ToSlash(os.Getenv("GOROOT"))) + if len(goroot) == 0 { + log.Fatal("GOROOT not set") + } + fmt.Printf("binary contains GOROOT: %v\n", bytes.Contains(data, goroot)) +} +-- $GOPATH/src/a/go.mod -- +module example.com/a diff --git a/src/cmd/go/testdata/script/mod_list_dir.txt b/src/cmd/go/testdata/script/mod_list_dir.txt index a8023cce9c..39834f2249 100644 --- a/src/cmd/go/testdata/script/mod_list_dir.txt +++ b/src/cmd/go/testdata/script/mod_list_dir.txt @@ -1,4 +1,5 @@ [short] skip +[windows] skip # known Windows test failure on release-branch.go1.13; fix is in CL 206144 but requires non-test code changes unlikely to be appropriate for backporting this late # go list with path to directory should work diff --git a/src/cmd/go/testdata/script/version.txt b/src/cmd/go/testdata/script/version.txt index 9086f047e4..42526247f1 100644 --- a/src/cmd/go/testdata/script/version.txt +++ b/src/cmd/go/testdata/script/version.txt @@ -1,6 +1,7 @@ env GO111MODULE=on [short] skip +# Check that 'go version' and 'go version -m' work on a binary built in module mode. go build -o fortune.exe rsc.io/fortune go version fortune.exe stdout '^fortune.exe: .+' @@ -8,6 +9,10 @@ go version -m fortune.exe stdout '^\tpath\trsc.io/fortune' stdout '^\tmod\trsc.io/fortune\tv1.0.0' +# Repeat the test with -buildmode=pie. +# TODO(golang.org/issue/27144): don't skip after -buildmode=pie is implemented +# on Windows. +[windows] skip # -buildmode=pie not supported go build -buildmode=pie -o external.exe rsc.io/fortune go version external.exe stdout '^external.exe: .+' -- cgit v1.2.3-54-g00ecf