aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/script_test.go
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2022-08-24 09:45:18 -0400
committerGopher Robot <gobot@golang.org>2022-08-24 15:37:38 +0000
commitd5aa088d822bc8ef3ceb80c20184f40fcb9b8d2e (patch)
tree1d8eed97adf92d277e33e882f84cf58bef805e2d /src/cmd/go/script_test.go
parentf983a9340d5660a9655b63a371966b5df69be8c5 (diff)
downloadgo-d5aa088d822bc8ef3ceb80c20184f40fcb9b8d2e.tar.gz
go-d5aa088d822bc8ef3ceb80c20184f40fcb9b8d2e.zip
cmd/go: avoid registering AtExit handlers in tests
Ever since 'go build' was added (in CL 5483069), it has used an atexit handler to clean up working directories. CL 154109 introduced 'cc' command to the script test framework that called Init on a builder once per invocation. Unfortunately, since base.AtExit is unsynchronized, the Init added there caused any script that invokes that command to be unsafe for concurrent use. This change fixes the race by having the 'cc' command pass in its working directory instead of allowing the Builder to allocate one. Following modern Go best practices, it also replaces the in-place Init method (which is prone to typestate and aliasing bugs) with a NewBuilder constructor function. Fixes #54423. Change-Id: I8fc2127a7d877bb39a1174e398736bb51d03d4d2 Reviewed-on: https://go-review.googlesource.com/c/go/+/425205 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Than McIntosh <thanm@google.com>
Diffstat (limited to 'src/cmd/go/script_test.go')
-rw-r--r--src/cmd/go/script_test.go4
1 files changed, 1 insertions, 3 deletions
diff --git a/src/cmd/go/script_test.go b/src/cmd/go/script_test.go
index d497724331..ca76ab5ab8 100644
--- a/src/cmd/go/script_test.go
+++ b/src/cmd/go/script_test.go
@@ -576,10 +576,8 @@ func (ts *testScript) cmdCc(want simpleStatus, args []string) {
ts.fatalf("usage: cc args... [&]")
}
- var b work.Builder
- b.Init()
+ b := work.NewBuilder(ts.workdir)
ts.cmdExec(want, append(b.GccCmd(".", ""), args...))
- robustio.RemoveAll(b.WorkDir)
}
// cd changes to a different directory.