]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: fail tests immediately if they attempt to create a tempfile within GOROOT
authorBryan C. Mills <bcmills@google.com>
Mon, 18 Nov 2019 14:01:44 +0000 (09:01 -0500)
committerBryan C. Mills <bcmills@google.com>
Tue, 19 Nov 2019 01:03:25 +0000 (01:03 +0000)
This will help to detect regressions of #28387 when running
'go test cmd/go' in a writable GOROOT.

Updates #28387
Updates #30316

Change-Id: I551e044111535404688b1a76e63163dfcb41bb5c
Reviewed-on: https://go-review.googlesource.com/c/go/+/207701
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/go/go_test.go

index aaeb42d98c8b1be950c21114fa5cc9ef9195a887..c5c5d411b9b71b927b1ad47cc0b51e0a6e539e8a 100644 (file)
@@ -683,8 +683,11 @@ func (tg *testgoData) creatingTemp(path string) {
        // If we have changed the working directory, make sure we have
        // an absolute path, because we are going to change directory
        // back before we remove the temporary.
-       if tg.wd != "" && !filepath.IsAbs(path) {
-               path = filepath.Join(tg.pwd(), path)
+       if !filepath.IsAbs(path) {
+               if tg.wd == "" || strings.HasPrefix(tg.wd, testGOROOT) {
+                       tg.t.Fatalf("internal testsuite error: creatingTemp(%q) within GOROOT/src", path)
+               }
+               path = filepath.Join(tg.wd, path)
        }
        tg.must(robustio.RemoveAll(path))
        tg.temps = append(tg.temps, path)