Commit c726361f authored by Bryan C. Mills's avatar Bryan C. Mills

cmd/go: fail tests immediately if they attempt to create a tempfile within GOROOT

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: default avatarJay Conrod <jayconrod@google.com>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 9bba63bb
...@@ -683,8 +683,11 @@ func (tg *testgoData) creatingTemp(path string) { ...@@ -683,8 +683,11 @@ func (tg *testgoData) creatingTemp(path string) {
// If we have changed the working directory, make sure we have // If we have changed the working directory, make sure we have
// an absolute path, because we are going to change directory // an absolute path, because we are going to change directory
// back before we remove the temporary. // back before we remove the temporary.
if tg.wd != "" && !filepath.IsAbs(path) { if !filepath.IsAbs(path) {
path = filepath.Join(tg.pwd(), 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.must(robustio.RemoveAll(path))
tg.temps = append(tg.temps, path) tg.temps = append(tg.temps, path)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment