aboutsummaryrefslogtreecommitdiff
path: root/src/internal/testenv/exec.go
diff options
context:
space:
mode:
authorKir Kolyshkin <kolyshkin@gmail.com>2024-08-29 16:46:16 -0700
committerGopher Robot <gobot@golang.org>2024-08-30 16:26:31 +0000
commit46985f4ec2a83241de4c0cec522df0ed19a3635d (patch)
tree53a619e2439e4c8297d53004cf6d8eeefee55ac5 /src/internal/testenv/exec.go
parentffb3e574012ce9d3d5193d7b8df135189b8a6671 (diff)
downloadgo-46985f4ec2a83241de4c0cec522df0ed19a3635d.tar.xz
internal/testenv: MustHaveExec: use sync.OnceValue
Change-Id: I048474fc93bb8c149672b66f98d71eec0eb8aad7 Reviewed-on: https://go-review.googlesource.com/c/go/+/609795 Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alan Donovan <adonovan@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/internal/testenv/exec.go')
-rw-r--r--src/internal/testenv/exec.go16
1 files changed, 4 insertions, 12 deletions
diff --git a/src/internal/testenv/exec.go b/src/internal/testenv/exec.go
index 7f6ad5cac4..ebb70a1375 100644
--- a/src/internal/testenv/exec.go
+++ b/src/internal/testenv/exec.go
@@ -31,20 +31,12 @@ import (
// If exec is not supported, testenv.SyscallIsNotSupported will return true
// for the resulting error.
func MustHaveExec(t testing.TB) {
- tryExecOnce.Do(func() {
- tryExecErr = tryExec()
- })
- if tryExecErr != nil {
- t.Skipf("skipping test: cannot exec subprocess on %s/%s: %v", runtime.GOOS, runtime.GOARCH, tryExecErr)
+ if err := tryExec(); err != nil {
+ t.Skipf("skipping test: cannot exec subprocess on %s/%s: %v", runtime.GOOS, runtime.GOARCH, err)
}
}
-var (
- tryExecOnce sync.Once
- tryExecErr error
-)
-
-func tryExec() error {
+var tryExec = sync.OnceValue(func() error {
switch runtime.GOOS {
case "wasip1", "js", "ios":
default:
@@ -77,7 +69,7 @@ func tryExec() error {
cmd := exec.Command(exe, "-test.list=^$")
cmd.Env = origEnv
return cmd.Run()
-}
+})
var execPaths sync.Map // path -> error