Skip to content

Commit c726361

Browse files
author
Bryan C. Mills
committed
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 <[email protected]> Reviewed-by: Jay Conrod <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 9bba63b commit c726361

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/cmd/go/go_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,8 +683,11 @@ func (tg *testgoData) creatingTemp(path string) {
683683
// If we have changed the working directory, make sure we have
684684
// an absolute path, because we are going to change directory
685685
// back before we remove the temporary.
686-
if tg.wd != "" && !filepath.IsAbs(path) {
687-
path = filepath.Join(tg.pwd(), path)
686+
if !filepath.IsAbs(path) {
687+
if tg.wd == "" || strings.HasPrefix(tg.wd, testGOROOT) {
688+
tg.t.Fatalf("internal testsuite error: creatingTemp(%q) within GOROOT/src", path)
689+
}
690+
path = filepath.Join(tg.wd, path)
688691
}
689692
tg.must(robustio.RemoveAll(path))
690693
tg.temps = append(tg.temps, path)

0 commit comments

Comments
 (0)